on domain add use default domainoptions only if no optins are given

This commit is contained in:
Peter Hormanns 2013-01-21 13:33:19 +01:00
parent 21ae1802e3
commit 9910aeb9e0

View File

@ -135,20 +135,22 @@ public class DomainModuleImpl extends AbstractModuleImpl {
dom.setUser((UnixUser) adminQuery.getSingleResult()); dom.setUser((UnixUser) adminQuery.getSingleResult());
needsWriteAccessOn(newEntity, "add"); needsWriteAccessOn(newEntity, "add");
em.persist(dom); em.persist(dom);
HashSet<DomainOption> domainOptions = new HashSet<DomainOption>(); if (dom.getDomainoptions() == null) { // set default-domainoptions
for (String domOpt : DEFAULT_DOMOPTS) { HashSet<DomainOption> domainOptions = new HashSet<DomainOption>();
Query q = em.createQuery("SELECT opt FROM " + for (String domOpt : DEFAULT_DOMOPTS) {
DomainOption.class.getAnnotation(javax.persistence.Entity.class).name() + Query q = em.createQuery("SELECT opt FROM " +
" opt WHERE opt.name=:optName"); DomainOption.class.getAnnotation(javax.persistence.Entity.class).name() +
q.setParameter("optName", domOpt); " opt WHERE opt.name=:optName");
List<?> list = q.getResultList(); q.setParameter("optName", domOpt);
if (list.size() == 1) { List<?> list = q.getResultList();
domainOptions.add((DomainOption) list.get(0)); if (list.size() == 1) {
} else { domainOptions.add((DomainOption) list.get(0));
throw new HSAdminException("invalid domain option: " + domOpt); } else {
throw new HSAdminException("invalid domain option: " + domOpt);
}
} }
dom.setDomainoptions(domainOptions);
} }
dom.setDomainoptions(domainOptions);
if (dom.isPacDomain()) { if (dom.isPacDomain()) {
em.persist(new EMailAddress("owner", "", dom, dom.getUser().getPac().getCustomer().getName().substring(6) + "@hostsharing.net")); 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")); em.persist(new EMailAddress("admin", "", dom, dom.getUser().getPac().getName() + "@hostsharing.net"));