hs.hsadmin/hsarback/src/de/hsadmin/mods/cust/CustomerModuleImpl.java

75 lines
2.7 KiB
Java
Raw Normal View History

2010-10-04 19:44:49 +02:00
package de.hsadmin.mods.cust;
2010-10-05 21:42:07 +02:00
import java.util.List;
import de.hsadmin.core.model.AbstractEntity;
2010-10-04 19:44:49 +02:00
import de.hsadmin.core.model.AbstractModuleImpl;
2010-10-05 21:42:07 +02:00
import de.hsadmin.core.model.GenericModuleImpl;
import de.hsadmin.core.model.HSAdminException;
import de.hsadmin.core.util.TextUtil;
import de.hsadmin.mods.user.UnixUser;
2010-10-04 19:44:49 +02:00
public class CustomerModuleImpl extends AbstractModuleImpl {
2010-10-05 21:42:07 +02:00
@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<AbstractEntity> search(
Class<? extends AbstractEntity> 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");
}
}
2010-10-04 19:44:49 +02:00
}