From e33737aaf638b7dc2328e748a5a5240db7a385f5 Mon Sep 17 00:00:00 2001
From: Michael Hierweck <michael.hierweck@hostsharing.net>
Date: Fri, 21 Sep 2012 13:37:18 +0200
Subject: [PATCH] Refactoring deletion of email addresses as part of the domain deletion process.

---
 hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java       |    5 +++--
 hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java |   15 ++-------------
 2 files changed, 5 insertions(+), 15 deletions(-)

diff --git a/hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java b/hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java
index ec201e0..2e7038d 100644
--- a/hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java
+++ b/hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java
@@ -11,6 +11,7 @@
 import de.hsadmin.core.model.AbstractEntity;
 import de.hsadmin.core.model.AbstractModuleImpl;
 import de.hsadmin.core.model.AuthorisationException;
+import de.hsadmin.core.model.GenericModuleImpl;
 import de.hsadmin.core.model.HSAdminException;
 import de.hsadmin.mods.email.EMailAddress;
 import de.hsadmin.mods.pac.Pac;
@@ -177,9 +178,9 @@
 		Query query = em.createQuery("SELECT adr FROM " + EMailAddress.class.getAnnotation(javax.persistence.Entity.class).name() 
 				+ " adr WHERE adr.domain.name='" + dom.getName() + "'");
 		List<?> resultList = query.getResultList();
+		GenericModuleImpl helperModule = new GenericModuleImpl(getTransaction());
 		for (Object obj : resultList) {
-			EMailAddress eMailAddress = (EMailAddress) obj;
-			em.remove(eMailAddress);
+			helperModule.delete((EMailAddress) obj);
 		}
 		super.delete(existingEntity);
 	}
diff --git a/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java b/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java
index d6df480..dc7652f 100644
--- a/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java
+++ b/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java
@@ -100,11 +100,8 @@
 	public <T extends AbstractEntity> Processor createDeleteProcessor(EntityManager em, T entity) throws ProcessorException {
 		Domain dom = (Domain) entity;
 		String domName = dom.getName();
-		WaitingTasksProcessor mainProcessor = new WaitingTasksProcessor(
-				new CompoundProcessor(
-					createHiveEMailRemoveProcessor(domName), 
-					createHiveDNSRemoveProcessor(domName)
-				)
+		WaitingTasksProcessor mainProcessor = new WaitingTasksProcessor(						 
+				createHiveDNSRemoveProcessor(domName)
 			);
 		Config config = Config.getInstance();
 		for (String queueName : config.getProperty("queues.dns").split(",")) {
@@ -156,14 +153,6 @@
 			emailAdrProcessor.appendProcessor(eMailAddressProcessorFactory.createCreateProcessor(em, eMailAddress));
 		}
 		return emailAdrProcessor;
-	}
-
-	private ShellProcessor createHiveEMailRemoveProcessor(String domName) {
-		return new ShellProcessor(
-			"postmap -d '" + domName + "' /etc/postfix-mailin/virtual && " + 
-			"for KEY in $(postmap -s /etc/postfix-mailin/virtual|grep '@" + domName + "\\s'|cut -f1); " +
-				"do postmap -d $KEY /etc/postfix-mailin/virtual; done"
-			);
 	}
 
 	private Processor createDNSServerSetupProcessor(String domName, String pacInetAddr) {

--
Gitblit v1.9.0-SNAPSHOT