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());
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"));