From fd53e7dc33260e04aa2e73600a8f04495570a99a Mon Sep 17 00:00:00 2001
From: Michael Hierweck <michael.hierweck@hostsharing.net>
Date: Tue, 30 Apr 2013 21:15:24 +0200
Subject: [PATCH] Skip most actions if pac is not a web packet.

---
 hsarback/src/de/hsadmin/mods/pac/PacModuleImpl.java |   97 ++++++++++++++++++++++++++----------------------
 1 files changed, 53 insertions(+), 44 deletions(-)

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

--
Gitblit v1.9.0-SNAPSHOT