From 9910aeb9e098e1b29252eb354f5a909503cc0662 Mon Sep 17 00:00:00 2001
From: Peter Hormanns <peter.hormanns@jalin.de>
Date: Mon, 21 Jan 2013 13:33:19 +0100
Subject: [PATCH] on domain add use default domainoptions only if no optins are given

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

diff --git a/hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java b/hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java
index 01511e1..245a1b3 100644
--- a/hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java
+++ b/hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java
@@ -135,20 +135,22 @@
 		dom.setUser((UnixUser) adminQuery.getSingleResult());
 		needsWriteAccessOn(newEntity, "add");
 		em.persist(dom);
-		HashSet<DomainOption> domainOptions = new HashSet<DomainOption>();
-		for (String domOpt : DEFAULT_DOMOPTS) {
-			Query q = em.createQuery("SELECT opt FROM " + 
-					DomainOption.class.getAnnotation(javax.persistence.Entity.class).name() +
-					" opt WHERE opt.name=:optName");
-			q.setParameter("optName", domOpt);
-			List<?> list = q.getResultList();
-			if (list.size() == 1) {
-				domainOptions.add((DomainOption) list.get(0));
-			} else {
-				throw new HSAdminException("invalid domain option: " + domOpt);
+		if (dom.getDomainoptions() == null) { // set default-domainoptions
+			HashSet<DomainOption> domainOptions = new HashSet<DomainOption>();
+			for (String domOpt : DEFAULT_DOMOPTS) {
+				Query q = em.createQuery("SELECT opt FROM " + 
+						DomainOption.class.getAnnotation(javax.persistence.Entity.class).name() +
+						" opt WHERE opt.name=:optName");
+				q.setParameter("optName", domOpt);
+				List<?> list = q.getResultList();
+				if (list.size() == 1) {
+					domainOptions.add((DomainOption) list.get(0));
+				} else {
+					throw new HSAdminException("invalid domain option: " + domOpt);
+				}
 			}
+			dom.setDomainoptions(domainOptions);
 		}
-		dom.setDomainoptions(domainOptions);
 		if (dom.isPacDomain()) {
 			em.persist(new EMailAddress("owner", "", dom, dom.getUser().getPac().getCustomer().getName().substring(6) + "@hostsharing.net"));
 			em.persist(new EMailAddress("admin", "", dom, dom.getUser().getPac().getName() + "@hostsharing.net"));

--
Gitblit v1.9.3