From a5527411d8551a50ca934e98f82f499915242350 Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Fri, 21 Sep 2012 16:37:13 +0200 Subject: [PATCH] set domain admin before persisting domain --- .../de/hsadmin/mods/dom/DomainModuleImpl.java | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java b/hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java index 623ae65..b45ddc6 100644 --- a/hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java +++ b/hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java @@ -96,21 +96,6 @@ public class DomainModuleImpl extends AbstractModuleImpl { domainOption.setName("greylisting"); domainOptions.add(domainOption); EntityManager em = getTransaction().getEntityManager(); - em.persist(dom); - 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); - UnixUser loginUser = getTransaction().getLoginUser(); if (!loginUser.hasHostmasterRole()) { // search for domains superior to dom @@ -137,12 +122,24 @@ public class DomainModuleImpl extends AbstractModuleImpl { } } } - Query adminQuery = em.createQuery("SELECT u FROM UnixUsers u WHERE u.name = :adminName"); adminQuery.setParameter("adminName", admin.getName()); dom.setUser((UnixUser) adminQuery.getSingleResult()); needsWriteAccessOn(newEntity, "add"); em.persist(dom); + 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); 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"));