HSAdmin Backend Domains, E-Mail, Datenbanken
Peter Hormanns
2013-05-01 8976d93e03b34ed68eb8364a9116dfbc396e0bac
pac migration (contains error)
5 files modified
52 ■■■■ changed files
hsarback/src/de/hsadmin/mods/pac/Pac.java 1 ●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/pac/PacModuleImpl.java 24 ●●●● patch | view | raw | blame | history
hsarback/test/de/hsadmin/remote/ContinuousIntegrationTest.java 3 ●●●● patch | view | raw | blame | history
hsarback/test/de/hsadmin/remote/PacMigrationTest.java 21 ●●●●● patch | view | raw | blame | history
hsarback/test/de/hsadmin/remote/RemoteTest.java 3 ●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/pac/Pac.java
@@ -10,6 +10,7 @@
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
hsarback/src/de/hsadmin/mods/pac/PacModuleImpl.java
@@ -78,11 +78,14 @@
        for (Object cObj : componentsList) {
            Component comp = (Component) cObj;
            PacComponent pacComponent = new PacComponent();
            pacComponent.setBaseComponent(comp.getBaseComponent());
            BaseComponent baseComponent = comp.getBaseComponent();
            pacComponent.setBaseComponent(baseComponent);
            pacComponent.setbasePac(comp.getBasePac());
            pacComponent.setCreated(now);
            pacComponent.setPac(pac);
            pacComponent.setQuantity(comp.getDefaultQuantity());
            String feature = baseComponent.getFeature();
            int requestedQuantity = pac.getPacComponent(feature).getQuantity();
            pacComponent.setQuantity(requestedQuantity);
            pacComponents.add(pacComponent);
        }
        pac.setPacComponents(pacComponents);
@@ -128,7 +131,8 @@
        EntityManager em = getTransaction().getEntityManager();
        Pac oldState = em.find(Pac.class, newState.getId());
        String oldBasepacName = oldState.getBasepac().getName();
        String newBasepacName = newState.getBasepac().getName();
        BasePac newBasepac = newState.getBasepac();
        String newBasepacName = newBasepac.getName();
        if (!oldBasepacName.equals(newBasepacName)) {
            Set<PacComponent> oldPacComponents = oldState.getPacComponents();
            Map<String, Integer> oldQuantities = new HashMap<String, Integer>();
@@ -136,17 +140,27 @@
                String feature = c.getBaseComponent().getFeature();
                int quantity = c.getQuantity();
                oldQuantities.put(feature, new Integer(quantity));
                em.remove(c);
            }
            oldPacComponents.clear();
            newState.getPacComponents().clear();
            em.flush();
            newState.initPacComponents(em, newState.getBasepac());
            newState.setBasepac(newBasepac);
            newState.initPacComponents(em, newBasepac);
            Set<PacComponent> newPacComponents = newState.getPacComponents();
            for (PacComponent pc : newPacComponents) {
                BaseComponent bc = pc.getBaseComponent();
                String feature = bc.getFeature();
                pc.setQuantity(oldQuantities.get(feature).intValue());
                int quantity = oldQuantities.get(feature).intValue();
                int increment = newBasepac.getComponent(feature).getIncrementQuantity();
                if (quantity % increment != 0) {
                    int numOfIncrements = quantity / increment;
                    quantity = increment * numOfIncrements + increment;
                }
                pc.setQuantity(quantity);
            }
        }
        em.flush();
        return super.update(entity);
    }
hsarback/test/de/hsadmin/remote/ContinuousIntegrationTest.java
@@ -17,7 +17,8 @@
    DomainTest.class,
    EMailAddressTest.class,
    SSLCertDomainTest.class,
    DatabaseCleanTest.class
    DatabaseCleanTest.class,
    PacMigrationTest.class
//    CustomerTest.class,
//    LongCustomerNameTest.class,
//    QueueTaskTest.class
hsarback/test/de/hsadmin/remote/PacMigrationTest.java
@@ -60,6 +60,26 @@
        try {
            Object execute = client.execute(MODULE + ".add", params);
            assertTrue(execute instanceof Map<?, ?>);
            Map<String, Object> whereParams = new HashMap<String, Object>();
            whereParams.put("name", "aaa04");
            params = new Object[] { user,
                    cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
                    whereParams };
            execute = client.execute(MODULE + ".search", params);
            assertNotNull(execute);
            assertTrue(execute instanceof Object[]);
            Object[] untypedResultArray = (Object[]) execute;
            assertEquals(1, untypedResultArray.length);
            assertTrue(untypedResultArray[0] instanceof Map<?,?>);
            @SuppressWarnings("unchecked")
            Map<String, ?> pacResultMap = (Map<String, ?>) untypedResultArray[0];
            assertEquals(Pac.PAC_DW, pacResultMap.get("basepac"));
            Object compMapObj = pacResultMap.get("components");
            assertTrue(compMapObj instanceof Map<?,?>);
            @SuppressWarnings("unchecked")
            Map<String,String> compMap = (Map<String, String>) compMapObj;
            assertEquals("512", compMap.get("QUOTA"));
            assertEquals("4", compMap.get("TRAFFIC"));
        } catch (XmlRpcException e) {
            fail(e.getMessage());
        }
@@ -109,6 +129,7 @@
            assertEquals(Pac.PAC_WEB, pacResultMap.get("basepac"));
            Object compMapObj = pacResultMap.get("components");
            assertTrue(compMapObj instanceof Map<?,?>);
            @SuppressWarnings("unchecked")
            Map<String,String> compMap = (Map<String, String>) compMapObj;
            assertEquals("512", compMap.get("QUOTA"));
            assertEquals("5", compMap.get("TRAFFIC"));
hsarback/test/de/hsadmin/remote/RemoteTest.java
@@ -16,7 +16,8 @@
    EMailAliasTest.class,
    DomainTest.class,
    EMailAddressTest.class,
    DatabaseCleanTest.class
    DatabaseCleanTest.class,
    PacMigrationTest.class
//  LongCustomerNameTest.class    
//    CustomerTest.class,
//    QueueTaskTest.class