package de.hsadmin.mods.cust; import java.util.List; import de.hsadmin.core.model.AbstractEntity; import de.hsadmin.core.model.AbstractModuleImpl; import de.hsadmin.core.model.GenericModuleImpl; import de.hsadmin.core.model.HSAdminException; import de.hsadmin.core.util.TextUtil; import de.hsadmin.mods.user.UnixUser; public class CustomerModuleImpl extends AbstractModuleImpl { @Override public AbstractEntity add(AbstractEntity newEntity) throws HSAdminException { if (!getLoginUser().hasHostmasterRole()) { throw new HSAdminException("role hostmaster required to create new customer"); } Customer newCustomer = (Customer) newEntity; assertNotNull("membercode", newCustomer.getName()); assertNotNull("password", newCustomer.getPassword()); Contact contact = newCustomer.getContacts().iterator().next(); assertNotNull("contact_lastname", contact.getLastName()); String custComment = contact.getLastName(); if (contact.getFirstName() != null && contact.getFirstName().length() > 0) { custComment = contact.getFirstName() + " " + contact.getLastName(); } GenericModuleImpl helperModule = new GenericModuleImpl(getTransaction()); UnixUser custAccount = new UnixUser(); custAccount.setComment(TextUtil.replaceUmlauts(custComment)); custAccount.setName(newCustomer.getName()); custAccount.setPassword(newCustomer.getPassword()); custAccount.setShell("/usr/bin/passwd"); custAccount.setQuotaSoftlimit(8); custAccount.setQuotaHardlimit(12); helperModule.add(custAccount); return super.add(newEntity); } @Override public List search( Class entityClass, String condition, String orderBy) throws HSAdminException { return super.search(entityClass, condition, orderBy); } @Override public AbstractEntity update(AbstractEntity existingEntity) throws HSAdminException { if (!getLoginUser().hasHostmasterRole()) { throw new HSAdminException("role hostmaster required to update customers"); } return super.update(existingEntity); } @Override public void delete(AbstractEntity existingEntity) throws HSAdminException { if (!getLoginUser().hasHostmasterRole()) { throw new HSAdminException("role hostmaster required to delete customers"); } Customer cust = (Customer) existingEntity; GenericModuleImpl helper = new GenericModuleImpl(getTransaction()); AbstractEntity custAccount = helper.findByString(UnixUser.class, cust.getName()); helper.delete(custAccount); super.delete(existingEntity); } private void assertNotNull(String name, String value) throws HSAdminException { if (value == null || value.length() < 1) { throw new HSAdminException("field '" + name + "' is mandatory"); } } }