remote deprecated customer module

This commit is contained in:
Peter Hormanns 2014-12-08 19:51:35 +01:00
parent 5484bd3cb7
commit f5e82b4ecc
3 changed files with 0 additions and 277 deletions

View File

@ -1,129 +0,0 @@
package de.hsadmin.mods.cust;
import static javax.persistence.FetchType.EAGER;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.mods.user.UnixUser;
@Entity(name = "BankAccounts")
@Table(name = "bank_account")
public class BankAccount extends AbstractEntity implements Serializable {
private static final long serialVersionUID = 2965368183976686458L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "bank_account_id", columnDefinition = "integer")
private long id;
@JoinColumn(name = "bp_id", columnDefinition = "integer")
@OneToOne(fetch = EAGER)
private Customer customer;
@Column(name = "bank_customer", columnDefinition = "character varying(50)")
private String bankCustomer;
@Column(name = "bank_iban", columnDefinition = "character varying(30)")
private String bankIBAN;
@Column(name = "bank_bic", columnDefinition = "character varying(15)")
private String bankBIC;
@Column(name = "mandat_ref", columnDefinition = "character varying(10)")
private String mandatRef;
@Column(name = "bank_name", columnDefinition = "character varying(50)")
private String bankName;
public static String createQueryFromStringKey(String humanKey) {
return "customer.name = " + humanKey;
}
@Override
public String createStringKey() {
return getCustomer().getName();
}
@Override
public long id() {
return id;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
public String getBankCustomer() {
return bankCustomer;
}
public void setBankCustomer(String bankCustomer) {
this.bankCustomer = bankCustomer;
}
public String getBankName() {
return bankName;
}
public void setBankName(String bankName) {
this.bankName = bankName;
}
@Override
public boolean isNew() {
return id == 0;
}
@Override
public UnixUser owningUser(EntityManager em) {
return customer.owningUser(em);
}
public String getBankIBAN() {
return bankIBAN;
}
public void setBankIBAN(String bankIBAN) {
this.bankIBAN = bankIBAN;
}
public String getBankBIC() {
return bankBIC;
}
public void setBankBIC(String bankBIC) {
this.bankBIC = bankBIC;
}
public String getMandatRef() {
return mandatRef;
}
public void setMandatRef(String mandatRef) {
this.mandatRef = mandatRef;
}
}

View File

@ -31,7 +31,6 @@ import de.hsadmin.mods.user.UnixUser;
@Entity(name = "Customers")
@Table(name = "business_partner")
@AnnModuleImpl(de.hsadmin.mods.cust.CustomerModuleImpl.class)
public class Customer extends AbstractEntity implements Serializable {
private static final long serialVersionUID = -7450594652238392616L;

View File

@ -1,147 +0,0 @@
package de.hsadmin.mods.cust;
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.model.Transaction;
import de.hsadmin.core.util.TextUtil;
import de.hsadmin.mods.dom.Domain;
import de.hsadmin.mods.email.EMailAddress;
import de.hsadmin.mods.email.EMailAlias;
import de.hsadmin.mods.pac.Pac;
import de.hsadmin.mods.user.UnixUser;
public class CustomerModuleImpl extends AbstractModuleImpl {
@Override
public AbstractEntity add(AbstractEntity newEntity) throws HSAdminException {
Transaction transaction = getTransaction();
if (!transaction.getLoginUser().hasHostmasterRole()) {
throw new AuthorisationException(transaction.getLoginUser(), "add", newEntity);
}
Customer newCustomer = (Customer) newEntity;
assertNotNull("membercode", newCustomer.getName());
assertValidMemberCode("membercode", newCustomer.getName());
assertNotNull("password", newCustomer.getPassword());
Contact contact = newCustomer.getContacts().iterator().next();
assertNotNull("contact_lastname", contact.getLastName());
assertNotNull("contact_email", contact.getEmail());
String custComment = contact.getLastName();
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);
// }
GenericModuleImpl helperModule = new GenericModuleImpl(getTransaction());
UnixUser custAccount = new UnixUser();
custAccount.setComment(TextUtil.replaceUmlautCharacters(custComment));
custAccount.setName(newCustomer.getName());
custAccount.setPassword(newCustomer.getPassword());
custAccount.setShell("/usr/bin/passwd");
custAccount.setQuotaSoftlimit(8);
custAccount.setQuotaHardlimit(12);
helperModule.add(custAccount);
EMailAlias custAlias = new EMailAlias();
custAlias.setName(newCustomer.getName());
custAlias.setTarget(contact.getEmail());
helperModule.add(custAlias);
String memberCode = newCustomer.getName();
EMailAddress custEMail1 = new EMailAddress();
custEMail1.setLocalpart(memberCode.substring(6));
Domain dom = (Domain) helperModule.findByString(Domain.class, "hostsharing.net");
custEMail1.setDomain(dom);
custEMail1.setTarget(memberCode);
helperModule.add(custEMail1);
if (contact.getFirstName() != null && contact.getFirstName().length() > 0) {
custComment = TextUtil.replaceUmlautCharacters(contact.getFirstName().toLowerCase())
+ "." + TextUtil.replaceUmlautCharacters(contact.getLastName().toLowerCase());
EMailAddress custEMail2 = new EMailAddress();
custEMail2.setLocalpart(custComment.replace(' ', '-'));
custEMail2.setDomain(dom);
custEMail2.setTarget(memberCode);
helperModule.add(custEMail2);
}
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 {
Transaction transaction = getTransaction();
if (!transaction.getLoginUser().hasHostmasterRole()) {
throw new AuthorisationException(transaction.getLoginUser(), "update", existingEntity);
}
return super.update(existingEntity);
}
@Override
public void delete(AbstractEntity existingEntity) throws HSAdminException {
Transaction transaction = getTransaction();
if (!transaction.getLoginUser().hasHostmasterRole()) {
throw new AuthorisationException(transaction.getLoginUser(), "delete", existingEntity);
}
Customer cust = (Customer) 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(transaction.getLoginUser(), "delete", existingEntity);
}
}
// keine Pakete mehr!
Set<Pac> pacs = cust.getPacs();
if (pacs != null && pacs.size() > 0) {
throw new AuthorisationException(transaction.getLoginUser(), "delete", existingEntity);
}
GenericModuleImpl helper = new GenericModuleImpl(getTransaction());
AbstractEntity custAccount = helper.findByString(UnixUser.class, cust.getName());
helper.delete(custAccount);
AbstractEntity custAlias = helper.findByString(EMailAlias.class, cust.getName());
helper.delete(custAlias);
List<AbstractEntity> custEMailsList = helper.search(EMailAddress.class, "target='" + cust.getName() + "'", null);
for (AbstractEntity email : custEMailsList) {
helper.delete(email);
}
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");
}
}
private void assertValidMemberCode(String name, String value) throws HSAdminException {
if (value == null || value.length() != 9 || !value.startsWith("hsh00-")) {
throw new HSAdminException("field '" + name + "' has to be like 'hsh00-xyz'");
}
}
}