Refactoring deletion of email addresses as part of the domain deletion

process.
This commit is contained in:
Michael Hierweck 2012-09-21 13:37:18 +02:00
parent 9f568eef06
commit e33737aaf6
2 changed files with 5 additions and 15 deletions

View File

@ -11,6 +11,7 @@ import javax.persistence.Query;
import de.hsadmin.core.model.AbstractEntity; import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.model.AbstractModuleImpl; import de.hsadmin.core.model.AbstractModuleImpl;
import de.hsadmin.core.model.AuthorisationException; import de.hsadmin.core.model.AuthorisationException;
import de.hsadmin.core.model.GenericModuleImpl;
import de.hsadmin.core.model.HSAdminException; import de.hsadmin.core.model.HSAdminException;
import de.hsadmin.mods.email.EMailAddress; import de.hsadmin.mods.email.EMailAddress;
import de.hsadmin.mods.pac.Pac; import de.hsadmin.mods.pac.Pac;
@ -177,9 +178,9 @@ public class DomainModuleImpl extends AbstractModuleImpl {
Query query = em.createQuery("SELECT adr FROM " + EMailAddress.class.getAnnotation(javax.persistence.Entity.class).name() Query query = em.createQuery("SELECT adr FROM " + EMailAddress.class.getAnnotation(javax.persistence.Entity.class).name()
+ " adr WHERE adr.domain.name='" + dom.getName() + "'"); + " adr WHERE adr.domain.name='" + dom.getName() + "'");
List<?> resultList = query.getResultList(); List<?> resultList = query.getResultList();
GenericModuleImpl helperModule = new GenericModuleImpl(getTransaction());
for (Object obj : resultList) { for (Object obj : resultList) {
EMailAddress eMailAddress = (EMailAddress) obj; helperModule.delete((EMailAddress) obj);
em.remove(eMailAddress);
} }
super.delete(existingEntity); super.delete(existingEntity);
} }

View File

@ -101,10 +101,7 @@ public class DomainProcessorFactory implements EntityProcessorFactory {
Domain dom = (Domain) entity; Domain dom = (Domain) entity;
String domName = dom.getName(); String domName = dom.getName();
WaitingTasksProcessor mainProcessor = new WaitingTasksProcessor( WaitingTasksProcessor mainProcessor = new WaitingTasksProcessor(
new CompoundProcessor( createHiveDNSRemoveProcessor(domName)
createHiveEMailRemoveProcessor(domName),
createHiveDNSRemoveProcessor(domName)
)
); );
Config config = Config.getInstance(); Config config = Config.getInstance();
for (String queueName : config.getProperty("queues.dns").split(",")) { for (String queueName : config.getProperty("queues.dns").split(",")) {
@ -158,14 +155,6 @@ public class DomainProcessorFactory implements EntityProcessorFactory {
return emailAdrProcessor; 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) { private Processor createDNSServerSetupProcessor(String domName, String pacInetAddr) {
Processor seczonesFileProcessor; Processor seczonesFileProcessor;
seczonesFileProcessor = seczonesFileProcessor =