member.delete moeglich nach Pruefungen
member.add legt billdata und bankaccount an
This commit is contained in:
parent
611b1f0a94
commit
d74cbf8b2f
@ -1,13 +1,16 @@
|
|||||||
package de.hsadmin.mods.cust;
|
package de.hsadmin.mods.cust;
|
||||||
|
|
||||||
import java.util.Calendar;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
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.GenericModuleImpl;
|
import de.hsadmin.core.model.GenericModuleImpl;
|
||||||
import de.hsadmin.core.model.HSAdminException;
|
import de.hsadmin.core.model.HSAdminException;
|
||||||
import de.hsadmin.core.util.TextUtil;
|
import de.hsadmin.core.util.TextUtil;
|
||||||
|
import de.hsadmin.mods.pac.Pac;
|
||||||
import de.hsadmin.mods.user.UnixUser;
|
import de.hsadmin.mods.user.UnixUser;
|
||||||
|
|
||||||
public class CustomerModuleImpl extends AbstractModuleImpl {
|
public class CustomerModuleImpl extends AbstractModuleImpl {
|
||||||
@ -15,7 +18,7 @@ public class CustomerModuleImpl extends AbstractModuleImpl {
|
|||||||
@Override
|
@Override
|
||||||
public AbstractEntity add(AbstractEntity newEntity) throws HSAdminException {
|
public AbstractEntity add(AbstractEntity newEntity) throws HSAdminException {
|
||||||
if (!getLoginUser().hasHostmasterRole()) {
|
if (!getLoginUser().hasHostmasterRole()) {
|
||||||
throw new HSAdminException("role hostmaster required to create new customer");
|
throw new AuthorisationException(getLoginUser(), "add", newEntity);
|
||||||
}
|
}
|
||||||
Customer newCustomer = (Customer) newEntity;
|
Customer newCustomer = (Customer) newEntity;
|
||||||
assertNotNull("membercode", newCustomer.getName());
|
assertNotNull("membercode", newCustomer.getName());
|
||||||
@ -26,6 +29,17 @@ public class CustomerModuleImpl extends AbstractModuleImpl {
|
|||||||
if (contact.getFirstName() != null && contact.getFirstName().length() > 0) {
|
if (contact.getFirstName() != null && contact.getFirstName().length() > 0) {
|
||||||
custComment = contact.getFirstName() + " " + contact.getLastName();
|
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());
|
GenericModuleImpl helperModule = new GenericModuleImpl(getTransaction());
|
||||||
UnixUser custAccount = new UnixUser();
|
UnixUser custAccount = new UnixUser();
|
||||||
custAccount.setComment(TextUtil.replaceUmlautCharacters(custComment));
|
custAccount.setComment(TextUtil.replaceUmlautCharacters(custComment));
|
||||||
@ -49,7 +63,7 @@ public class CustomerModuleImpl extends AbstractModuleImpl {
|
|||||||
public AbstractEntity update(AbstractEntity existingEntity)
|
public AbstractEntity update(AbstractEntity existingEntity)
|
||||||
throws HSAdminException {
|
throws HSAdminException {
|
||||||
if (!getLoginUser().hasHostmasterRole()) {
|
if (!getLoginUser().hasHostmasterRole()) {
|
||||||
throw new HSAdminException("role hostmaster required to update customers");
|
throw new AuthorisationException(getLoginUser(), "update", existingEntity);
|
||||||
}
|
}
|
||||||
return super.update(existingEntity);
|
return super.update(existingEntity);
|
||||||
}
|
}
|
||||||
@ -57,22 +71,29 @@ public class CustomerModuleImpl extends AbstractModuleImpl {
|
|||||||
@Override
|
@Override
|
||||||
public void delete(AbstractEntity existingEntity) throws HSAdminException {
|
public void delete(AbstractEntity existingEntity) throws HSAdminException {
|
||||||
if (!getLoginUser().hasHostmasterRole()) {
|
if (!getLoginUser().hasHostmasterRole()) {
|
||||||
throw new HSAdminException("role hostmaster required to delete customers");
|
throw new AuthorisationException(getLoginUser(), "delete", existingEntity);
|
||||||
}
|
}
|
||||||
Customer cust = (Customer) existingEntity;
|
Customer cust = (Customer) existingEntity;
|
||||||
// Diese Zeilen loeschen den hsh00-Mitglieds-Account
|
|
||||||
// GenericModuleImpl helper = new GenericModuleImpl(getTransaction());
|
// Pruefe, ob geloescht werden kann..
|
||||||
// AbstractEntity custAccount = helper.findByString(UnixUser.class, cust.getName());
|
// member_until < heute (nicht mehr Mitglied) oder member_since leer (nie Mitglied geworden)
|
||||||
// helper.delete(custAccount);
|
Date memberSince = cust.getMemberSince();
|
||||||
Calendar cal = Calendar.getInstance();
|
Date memberUntil = cust.getMemberUntil();
|
||||||
cal.setTimeInMillis(System.currentTimeMillis());
|
if (memberSince != null) {
|
||||||
cal.set(Calendar.MONTH, Calendar.DECEMBER);
|
if (memberUntil == null || memberUntil.after(new Date())) {
|
||||||
cal.set(Calendar.DAY_OF_MONTH, 31);
|
throw new AuthorisationException(getLoginUser(), "delete", existingEntity);
|
||||||
cal.set(Calendar.HOUR_OF_DAY, 23);
|
}
|
||||||
cal.set(Calendar.MINUTE, 59);
|
}
|
||||||
cal.set(Calendar.SECOND, 59);
|
// keine Pakete mehr!
|
||||||
cust.setMemberUntil(cal.getTime());
|
Set<Pac> pacs = cust.getPacs();
|
||||||
super.update(existingEntity);
|
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 {
|
private void assertNotNull(String name, String value) throws HSAdminException {
|
||||||
|
Loading…
Reference in New Issue
Block a user