Skip most actions if pac is not a web packet.

This commit is contained in:
Michael Hierweck 2013-04-30 20:32:25 +02:00
parent ce5c545bef
commit 9b206322f0

View File

@ -86,28 +86,34 @@ public class PacModuleImpl extends AbstractModuleImpl {
pacComponents.add(pacComponent); pacComponents.add(pacComponent);
} }
pac.setPacComponents(pacComponents); pac.setPacComponents(pacComponents);
Set<UnixUser> users = new HashSet<UnixUser>(); AbstractEntity newPacEntity = null;
pac.setUnixUser(users); String pacType = pac.getBasepac().getName();
UnixUser admin = new UnixUser(); if (!pacType.equals(Pac.PAC_WEB) && !pacType.equals(Pac.PAC_DW) && !pacType.equals(Pac.PAC_SW)) {
Contact contact = customer.getContractualContact(); Set<UnixUser> users = new HashSet<UnixUser>();
admin.setComment(TextUtil.replaceUmlautCharacters(contact.getFirstName() + " " + contact.getLastName())); pac.setUnixUser(users);
admin.setHomedir("/home/pacs/" + pac.getName()); UnixUser admin = new UnixUser();
admin.setName(pac.getName()); Contact contact = customer.getContractualContact();
admin.setShell("/bin/bash"); admin.setComment(TextUtil.replaceUmlautCharacters(contact.getFirstName() + " " + contact.getLastName()));
admin.setQuotaSoftlimit(0); admin.setHomedir("/home/pacs/" + pac.getName());
admin.setQuotaHardlimit(0); admin.setName(pac.getName());
admin.setPac(pac); admin.setShell("/bin/bash");
long nUID = 20000; admin.setQuotaSoftlimit(0);
Long maxUid = (Long) em.createQuery("SELECT MAX(u.userId) FROM UnixUsers u").getSingleResult(); admin.setQuotaHardlimit(0);
if (maxUid >= nUID) nUID = maxUid + 1; admin.setPac(pac);
admin.setUserId(nUID); long nUID = 20000;
users.add(admin); Long maxUid = (Long) em.createQuery("SELECT MAX(u.userId) FROM UnixUsers u").getSingleResult();
AbstractEntity newPacEntity = super.add(newEntity); if (maxUid >= nUID) nUID = maxUid + 1;
GenericModuleImpl helperModule = new GenericModuleImpl(getTransaction()); admin.setUserId(nUID);
Domain pacDomain = new Domain(); users.add(admin);
pacDomain.setName(pac.getName() + ".hostsharing.net"); newPacEntity = super.add(newEntity);
pacDomain.setUser(admin); GenericModuleImpl helperModule = new GenericModuleImpl(getTransaction());
helperModule.add(pacDomain); Domain pacDomain = new Domain();
pacDomain.setName(pac.getName() + ".hostsharing.net");
pacDomain.setUser(admin);
helperModule.add(pacDomain);
} else {
newPacEntity = super.add(newEntity);
}
return newPacEntity; return newPacEntity;
} }
@ -150,31 +156,34 @@ public class PacModuleImpl extends AbstractModuleImpl {
if (dateCancelled == null || dateCancelled.getTime() > System.currentTimeMillis()) { if (dateCancelled == null || dateCancelled.getTime() > System.currentTimeMillis()) {
throw new AuthorisationException(getTransaction().getLoginUser(), "delete", existingEntity); throw new AuthorisationException(getTransaction().getLoginUser(), "delete", existingEntity);
} }
GenericModuleImpl helperModule = new GenericModuleImpl(getTransaction()); String pacType = pac.getBasepac().getName();
if (!pacType.equals(Pac.PAC_WEB) && !pacType.equals(Pac.PAC_DW) && !pacType.equals(Pac.PAC_SW)) {
String[] dependQueries = new String[] { GenericModuleImpl helperModule = new GenericModuleImpl(getTransaction());
"SELECT dom FROM Domains dom WHERE dom.user.pac.name = :pac",
"SELECT db FROM MySqlDatabases db WHERE db.pac.name = :pac", String[] dependQueries = new String[] {
"SELECT db FROM PgSqlDatabases db WHERE db.pac.name = :pac", "SELECT dom FROM Domains dom WHERE dom.user.pac.name = :pac",
"SELECT dbusr FROM MySqlUsers dbusr WHERE dbusr.pac.name = :pac", "SELECT db FROM MySqlDatabases db WHERE db.pac.name = :pac",
"SELECT dbusr FROM PgSqlUsers dbusr WHERE dbusr.pac.name = :pac", "SELECT db FROM PgSqlDatabases db WHERE db.pac.name = :pac",
"SELECT alias FROM EMailAliases alias WHERE alias.pac.name = :pac" "SELECT dbusr FROM MySqlUsers dbusr WHERE dbusr.pac.name = :pac",
}; "SELECT dbusr FROM PgSqlUsers dbusr WHERE dbusr.pac.name = :pac",
"SELECT alias FROM EMailAliases alias WHERE alias.pac.name = :pac"
for (String queryString : dependQueries) { };
Query qDoms = em.createQuery(queryString);
qDoms.setParameter("pac", pacName); for (String queryString : dependQueries) {
List<?> domsList = qDoms.getResultList(); Query qDoms = em.createQuery(queryString);
for (Object o : domsList) { qDoms.setParameter("pac", pacName);
if (o instanceof AbstractEntity) { List<?> domsList = qDoms.getResultList();
helperModule.delete((AbstractEntity) o); for (Object o : domsList) {
if (o instanceof AbstractEntity) {
helperModule.delete((AbstractEntity) o);
}
} }
} }
}
for (UnixUser user : pac.getUnixUser()) { for (UnixUser user : pac.getUnixUser()) {
if (!pacName.equals(user.getName())) { if (!pacName.equals(user.getName())) {
helperModule.delete(user); helperModule.delete(user);
}
} }
} }
super.delete(existingEntity); super.delete(existingEntity);