From 001946a6d0ce76cfa8524d0f0c37f4c8a0b334fa Mon Sep 17 00:00:00 2001
From: Purodha Blissenbach <purodha.blissenbach@hostsharing.net>
Date: Fri, 21 Sep 2012 16:16:55 +0200
Subject: [PATCH] Fix fatal error setting default domain options for newly created domain.

---
 hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java |   14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java b/hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java
index e075d94..83b6762 100644
--- a/hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java
+++ b/hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java
@@ -96,10 +96,20 @@
 		DomainOption domainOption = new DomainOption();
 		domainOption.setName("greylisting");
 		domainOptions.add(domainOption);
+		EntityManager em = getTransaction().getEntityManager();
+		Query q = em.createQuery("SELECT opt FROM " + 
+				DomainOption.class.getAnnotation(javax.persistence.Entity.class).name() +
+				" opt WHERE opt.name=:optName");
+		for (DomainOption opt : domainOptions) {
+			q.setParameter("optName", opt.getName());
+			List<?> list = q.getResultList();
+			if (list.size() != 1) {
+				throw new HSAdminException("invalid domain option: " + opt.getName());
+			} else {
+				opt.setId(((DomainOption) list.get(0)).getId());
+			}
 		dom.setDomainoptions(domainOptions);
 		
-		EntityManager em = getTransaction().getEntityManager();
-
 		UnixUser loginUser = getTransaction().getLoginUser();
 		if (!loginUser.hasHostmasterRole()) {
 			// search for domains superior to dom

--
Gitblit v1.9.0-SNAPSHOT