HSAdmin Backend Domains, E-Mail, Datenbanken
Peter Hormanns
2014-03-21 d7390031e96e14e3a9ac668662113c58d03ddf1e
create customer-alias and -email
4 files modified
71 ■■■■■ changed files
hsarback/database/data.sql 7 ●●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/cust/CustomerModuleImpl.java 43 ●●●●● patch | view | raw | blame | history
hsarback/test/de/hsadmin/remote/CustomerTest.java 5 ●●●●● patch | view | raw | blame | history
hsarback/test/de/hsadmin/remote/PacMigrationTest.java 16 ●●●● patch | view | raw | blame | history
hsarback/database/data.sql
@@ -179,6 +179,13 @@
        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) 
hsarback/src/de/hsadmin/mods/cust/CustomerModuleImpl.java
@@ -11,6 +11,9 @@
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 @@
        }
        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 @@
            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 @@
        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 @@
        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 @@
        }
    }
    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'");
        }
    }
}
hsarback/test/de/hsadmin/remote/CustomerTest.java
@@ -50,7 +50,7 @@
        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 @@
        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);
hsarback/test/de/hsadmin/remote/PacMigrationTest.java
@@ -42,6 +42,18 @@
    }
    @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 @@
        }
    }
    @Test
    public void testCreateSW() {
        int count = getPacsCount();
        String user = "ad";
@@ -75,7 +86,6 @@
        }
    }
    @Test
    public void testUpdateDW() {
        String user = "ad";
        try {
@@ -116,7 +126,6 @@
        }
    }
    @Test
    public void testUpdateSW() {
        String user = "ad";
        try {
@@ -157,7 +166,6 @@
        }
    }
    @Test
    public void testDeleteSW() {
        String user = "ad";
        try {