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'; 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 -- table: domain_option
-- --
INSERT INTO domain_option (domain_option_name) 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.HSAdminException;
import de.hsadmin.core.model.Transaction; import de.hsadmin.core.model.Transaction;
import de.hsadmin.core.util.TextUtil; 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.pac.Pac;
import de.hsadmin.mods.user.UnixUser; import de.hsadmin.mods.user.UnixUser;
@ -24,9 +27,11 @@ public class CustomerModuleImpl extends AbstractModuleImpl {
} }
Customer newCustomer = (Customer) newEntity; Customer newCustomer = (Customer) newEntity;
assertNotNull("membercode", newCustomer.getName()); assertNotNull("membercode", newCustomer.getName());
assertValidMemberCode("membercode", newCustomer.getName());
assertNotNull("password", newCustomer.getPassword()); assertNotNull("password", newCustomer.getPassword());
Contact contact = newCustomer.getContacts().iterator().next(); Contact contact = newCustomer.getContacts().iterator().next();
assertNotNull("contact_lastname", contact.getLastName()); assertNotNull("contact_lastname", contact.getLastName());
assertNotNull("contact_email", contact.getEmail());
String custComment = contact.getLastName(); String custComment = contact.getLastName();
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();
@ -38,6 +43,7 @@ public class CustomerModuleImpl extends AbstractModuleImpl {
newCustomer.setBankAccount(bankAccount); newCustomer.setBankAccount(bankAccount);
} }
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));
custAccount.setName(newCustomer.getName()); custAccount.setName(newCustomer.getName());
@ -46,6 +52,30 @@ public class CustomerModuleImpl extends AbstractModuleImpl {
custAccount.setQuotaSoftlimit(8); custAccount.setQuotaSoftlimit(8);
custAccount.setQuotaHardlimit(12); custAccount.setQuotaHardlimit(12);
helperModule.add(custAccount); 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); return super.add(newEntity);
} }
@ -92,6 +122,12 @@ public class CustomerModuleImpl extends AbstractModuleImpl {
GenericModuleImpl helper = new GenericModuleImpl(getTransaction()); GenericModuleImpl helper = new GenericModuleImpl(getTransaction());
AbstractEntity custAccount = helper.findByString(UnixUser.class, cust.getName()); AbstractEntity custAccount = helper.findByString(UnixUser.class, cust.getName());
helper.delete(custAccount); 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); 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_salut", "Herr");
setParams.put("contact_title", "Dr."); setParams.put("contact_title", "Dr.");
setParams.put("contact_firstname", "Ömer Günther"); 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_street", "Hauptstr. 1");
setParams.put("contact_zipcode", "99998"); setParams.put("contact_zipcode", "99998");
setParams.put("contact_city", "Musterstadt"); setParams.put("contact_city", "Musterstadt");
@ -63,9 +63,10 @@ public class CustomerTest {
try { try {
client.execute(MODULE + ".add", params); client.execute(MODULE + ".add", params);
assertEquals(membersCount + 1, getMembersCount(user)); 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("membercode", "hsh00-n" + idx);
setParams.put("memberno", "200" + idx); setParams.put("memberno", "200" + idx);
setParams.put("contact_lastname", "Janßen-Müller" + idx);
setParams.put("contact_street", "Hauptstr. " + idx); setParams.put("contact_street", "Hauptstr. " + idx);
params[1] = cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()); params[1] = cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL());
client.execute(MODULE + ".add", params); client.execute(MODULE + ".add", params);

View File

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