create customer-alias and -email

This commit is contained in:
Peter Hormanns 2014-03-21 18:44:19 +01:00
parent ff75a342e8
commit d7390031e9
4 changed files with 65 additions and 6 deletions

View File

@ -179,6 +179,13 @@ INSERT INTO unixuser (name, comment, shell, homedir, locked, packet_id, userid)
WHERE packet_name='hsh01';
--
-- table: domain
--
INSERT INTO domain (domain_name, domain_since, domain_dns_master, domain_owner)
SELECT 'hostsharing.net', current_date, 'dns.hostsharing.net', unixuser_id FROM unixuser
WHERE unixuser.name='hsh00';
--
-- table: domain_option
--
INSERT INTO domain_option (domain_option_name)

View File

@ -11,6 +11,9 @@ 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;
@ -24,9 +27,11 @@ public class CustomerModuleImpl extends AbstractModuleImpl {
}
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();
@ -38,6 +43,7 @@ public class CustomerModuleImpl extends AbstractModuleImpl {
newCustomer.setBankAccount(bankAccount);
}
GenericModuleImpl helperModule = new GenericModuleImpl(getTransaction());
UnixUser custAccount = new UnixUser();
custAccount.setComment(TextUtil.replaceUmlautCharacters(custComment));
custAccount.setName(newCustomer.getName());
@ -46,6 +52,30 @@ public class CustomerModuleImpl extends AbstractModuleImpl {
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);
}
@ -92,6 +122,12 @@ public class CustomerModuleImpl extends AbstractModuleImpl {
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);
}
@ -101,4 +137,11 @@ public class CustomerModuleImpl extends AbstractModuleImpl {
}
}
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'");
}
}
}

View File

@ -50,7 +50,7 @@ public class CustomerTest {
setParams.put("contact_salut", "Herr");
setParams.put("contact_title", "Dr.");
setParams.put("contact_firstname", "Ömer Günther");
setParams.put("contact_lastname", "Janßen-Müller");
setParams.put("contact_lastname", "Müller-Zwo");
setParams.put("contact_street", "Hauptstr. 1");
setParams.put("contact_zipcode", "99998");
setParams.put("contact_city", "Musterstadt");
@ -63,9 +63,10 @@ public class CustomerTest {
try {
client.execute(MODULE + ".add", params);
assertEquals(membersCount + 1, getMembersCount(user));
for (int idx=11; idx < 12; idx++) {
for (int idx=11; idx < 14; idx++) {
setParams.put("membercode", "hsh00-n" + idx);
setParams.put("memberno", "200" + idx);
setParams.put("contact_lastname", "Janßen-Müller" + idx);
setParams.put("contact_street", "Hauptstr. " + idx);
params[1] = cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL());
client.execute(MODULE + ".add", params);

View File

@ -42,6 +42,18 @@ public class PacMigrationTest {
}
@Test
public void testSW() {
testCreateSW();
testUpdateSW();
testDeleteSW();
}
@Test
public void testDW() {
testCreateDW();
testUpdateDW();
}
public void testCreateDW() {
int count = getPacsCount();
String user = "ad";
@ -58,7 +70,6 @@ public class PacMigrationTest {
}
}
@Test
public void testCreateSW() {
int count = getPacsCount();
String user = "ad";
@ -75,7 +86,6 @@ public class PacMigrationTest {
}
}
@Test
public void testUpdateDW() {
String user = "ad";
try {
@ -116,7 +126,6 @@ public class PacMigrationTest {
}
}
@Test
public void testUpdateSW() {
String user = "ad";
try {
@ -157,7 +166,6 @@ public class PacMigrationTest {
}
}
@Test
public void testDeleteSW() {
String user = "ad";
try {