From 93a4c560ab98a4d43c7998e7672ad999afa0063e Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Wed, 18 Jul 2012 12:26:08 +0000 Subject: [PATCH] DomainOptions Impl --- .../de/hsadmin/mods/dom/DomainModuleImpl.java | 32 +++++++++++-------- .../src/de/hsadmin/remote/DomainRemote.java | 19 +++++++++++ .../de/hsadmin/remote/EMailAddressRemote.java | 8 +---- 3 files changed, 39 insertions(+), 20 deletions(-) diff --git a/hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java b/hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java index 6a8e6a0..ab0b43b 100644 --- a/hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java +++ b/hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java @@ -139,26 +139,32 @@ public class DomainModuleImpl extends AbstractModuleImpl { @Override public AbstractEntity update(AbstractEntity existingEntity) throws HSAdminException { - Domain dom = (Domain) existingEntity; - UnixUser loginUser = getTransaction().getLoginUser(); - if (dom.isPacDomain() && !loginUser.hasHostmasterRole()) { - throw new AuthorisationException(loginUser, "update", existingEntity); - } - if (dom.getName() == null || dom.getName().length() == 0) { + Domain updatedDom = (Domain) existingEntity; + if (updatedDom.getName() == null || updatedDom.getName().length() == 0) { throw new HSAdminException("domain name required"); } - UnixUser admin = dom.getUser(); + UnixUser loginUser = getTransaction().getLoginUser(); + EntityManager em = getTransaction().getEntityManager(); + Domain oldDom = em.find(Domain.class, updatedDom.getId()); + UnixUser admin = updatedDom.getUser(); if (admin == null || admin.getName() == null || admin.getName().length() == 0) { throw new HSAdminException("domain admin required"); } - if (admin.getPac() == null) { - EntityManager em = getTransaction().getEntityManager(); - Query query = em.createQuery("SELECT u FROM UnixUsers u WHERE u.name = :adminName"); - query.setParameter("adminName", admin.getName()); - dom.setUser((UnixUser) query.getSingleResult()); + if (!admin.getName().equals(oldDom.getUser().getName())) { + throw new AuthorisationException(loginUser, "update", existingEntity); + } + Query q = em.createQuery("SELECT opt FROM " + + DomainOption.class.getAnnotation(javax.persistence.Entity.class).name() + + " opt WHERE opt.name=:optName"); + for (DomainOption opt : updatedDom.getDomainOptions()) { + q.setParameter("optName", opt.getName()); + List list = q.getResultList(); + if (list.size() != 1) { + throw new HSAdminException("invalid domain option: " + opt.getName()); + } } needsWriteAccessOn(existingEntity, "update"); - throw new AuthorisationException(loginUser, "update", existingEntity); + return super.update(existingEntity); } @Override diff --git a/hsarback/src/de/hsadmin/remote/DomainRemote.java b/hsarback/src/de/hsadmin/remote/DomainRemote.java index f4024df..8ee31f2 100644 --- a/hsarback/src/de/hsadmin/remote/DomainRemote.java +++ b/hsarback/src/de/hsadmin/remote/DomainRemote.java @@ -2,11 +2,16 @@ package de.hsadmin.remote; import java.text.DateFormat; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Date; +import java.util.List; import java.util.Map; +import java.util.Set; +import java.util.TreeSet; import de.hsadmin.core.model.AbstractEntity; import de.hsadmin.mods.dom.Domain; +import de.hsadmin.mods.dom.DomainOption; import de.hsadmin.mods.user.UnixUser; public class DomainRemote extends AbstractRemote { @@ -36,6 +41,11 @@ public class DomainRemote extends AbstractRemote { String since = df.format(sDate); resultMap.put("since", since); } + List domainOptionsList = new ArrayList(); + resultMap.put("domainoptions", domainOptionsList); + for (DomainOption opt : dom.getDomainOptions()) { + domainOptionsList.add(opt.getName()); + } } @Override @@ -51,6 +61,15 @@ public class DomainRemote extends AbstractRemote { u.setName(user); dom.setUser(u); } + Set domainOptionsSet = new TreeSet(); + Object domOptsObj = setParams.get("domainoptions"); + if (domOptsObj != null && domOptsObj instanceof List) { + List domOptions = (List) domOptsObj; + for (String optString : domOptions) { + domOptions.add(optString); + } + } + dom.setDomainOptions(domainOptionsSet); } @Override diff --git a/hsarback/src/de/hsadmin/remote/EMailAddressRemote.java b/hsarback/src/de/hsadmin/remote/EMailAddressRemote.java index f41b98c..ccb791e 100644 --- a/hsarback/src/de/hsadmin/remote/EMailAddressRemote.java +++ b/hsarback/src/de/hsadmin/remote/EMailAddressRemote.java @@ -53,13 +53,7 @@ public class EMailAddressRemote extends AbstractRemote { adr.setSubdomain(subdomain); } Object l = map.get("target"); - if (l instanceof String) { - String target = (String) l; - if (assertNotNull(target)) { - adr.setTarget(target); - } - } - if (l instanceof List) { + if (l != null && l instanceof List) { StringBuffer tBuff = new StringBuffer(); for (Object o : (List) l) { if (o instanceof String) {