member.delete moeglich nach Pruefungen

member.add legt billdata und bankaccount an
This commit is contained in:
Peter Hormanns 2011-05-24 13:22:25 +00:00
parent 611b1f0a94
commit d74cbf8b2f

View File

@ -1,13 +1,16 @@
package de.hsadmin.mods.cust;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Set;
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.core.util.TextUtil;
import de.hsadmin.mods.pac.Pac;
import de.hsadmin.mods.user.UnixUser;
public class CustomerModuleImpl extends AbstractModuleImpl {
@ -15,7 +18,7 @@ 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");
throw new AuthorisationException(getLoginUser(), "add", newEntity);
}
Customer newCustomer = (Customer) newEntity;
assertNotNull("membercode", newCustomer.getName());
@ -26,6 +29,17 @@ public class CustomerModuleImpl extends AbstractModuleImpl {
if (contact.getFirstName() != null && contact.getFirstName().length() > 0) {
custComment = contact.getFirstName() + " " + contact.getLastName();
}
BankAccount bankAccount = newCustomer.getBankAccount();
if (bankAccount == null) {
bankAccount = new BankAccount();
bankAccount.setCustomer(newCustomer);
newCustomer.setBankAccount(bankAccount);
}
CustomersTariff billData = newCustomer.getBillData();
if (billData == null) {
billData = new CustomersTariff(newCustomer);
newCustomer.setBillData(billData);
}
GenericModuleImpl helperModule = new GenericModuleImpl(getTransaction());
UnixUser custAccount = new UnixUser();
custAccount.setComment(TextUtil.replaceUmlautCharacters(custComment));
@ -49,7 +63,7 @@ public class CustomerModuleImpl extends AbstractModuleImpl {
public AbstractEntity update(AbstractEntity existingEntity)
throws HSAdminException {
if (!getLoginUser().hasHostmasterRole()) {
throw new HSAdminException("role hostmaster required to update customers");
throw new AuthorisationException(getLoginUser(), "update", existingEntity);
}
return super.update(existingEntity);
}
@ -57,22 +71,29 @@ public class CustomerModuleImpl extends AbstractModuleImpl {
@Override
public void delete(AbstractEntity existingEntity) throws HSAdminException {
if (!getLoginUser().hasHostmasterRole()) {
throw new HSAdminException("role hostmaster required to delete customers");
throw new AuthorisationException(getLoginUser(), "delete", existingEntity);
}
Customer cust = (Customer) existingEntity;
// Diese Zeilen loeschen den hsh00-Mitglieds-Account
// GenericModuleImpl helper = new GenericModuleImpl(getTransaction());
// AbstractEntity custAccount = helper.findByString(UnixUser.class, cust.getName());
// helper.delete(custAccount);
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(System.currentTimeMillis());
cal.set(Calendar.MONTH, Calendar.DECEMBER);
cal.set(Calendar.DAY_OF_MONTH, 31);
cal.set(Calendar.HOUR_OF_DAY, 23);
cal.set(Calendar.MINUTE, 59);
cal.set(Calendar.SECOND, 59);
cust.setMemberUntil(cal.getTime());
super.update(existingEntity);
// Pruefe, ob geloescht werden kann..
// member_until < heute (nicht mehr Mitglied) oder member_since leer (nie Mitglied geworden)
Date memberSince = cust.getMemberSince();
Date memberUntil = cust.getMemberUntil();
if (memberSince != null) {
if (memberUntil == null || memberUntil.after(new Date())) {
throw new AuthorisationException(getLoginUser(), "delete", existingEntity);
}
}
// keine Pakete mehr!
Set<Pac> pacs = cust.getPacs();
if (pacs != null && pacs.size() > 0) {
throw new AuthorisationException(getLoginUser(), "delete", 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 {