diff --git a/hsarback/src/de/hsadmin/mods/pac/Pac.java b/hsarback/src/de/hsadmin/mods/pac/Pac.java index 23fa538..db1f988 100644 --- a/hsarback/src/de/hsadmin/mods/pac/Pac.java +++ b/hsarback/src/de/hsadmin/mods/pac/Pac.java @@ -10,6 +10,7 @@ import java.util.Date; import java.util.HashSet; import java.util.Set; +import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.EntityManager; diff --git a/hsarback/src/de/hsadmin/mods/pac/PacModuleImpl.java b/hsarback/src/de/hsadmin/mods/pac/PacModuleImpl.java index facba6b..6b472b2 100644 --- a/hsarback/src/de/hsadmin/mods/pac/PacModuleImpl.java +++ b/hsarback/src/de/hsadmin/mods/pac/PacModuleImpl.java @@ -78,11 +78,14 @@ public class PacModuleImpl extends AbstractModuleImpl { 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 @@ public class PacModuleImpl extends AbstractModuleImpl { 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 oldPacComponents = oldState.getPacComponents(); Map oldQuantities = new HashMap(); @@ -136,17 +140,27 @@ public class PacModuleImpl extends AbstractModuleImpl { 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 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); } diff --git a/hsarback/test/de/hsadmin/remote/ContinuousIntegrationTest.java b/hsarback/test/de/hsadmin/remote/ContinuousIntegrationTest.java index 7fdf00b..15ac6bd 100644 --- a/hsarback/test/de/hsadmin/remote/ContinuousIntegrationTest.java +++ b/hsarback/test/de/hsadmin/remote/ContinuousIntegrationTest.java @@ -17,7 +17,8 @@ import org.junit.runners.Suite; DomainTest.class, EMailAddressTest.class, SSLCertDomainTest.class, - DatabaseCleanTest.class + DatabaseCleanTest.class, + PacMigrationTest.class // CustomerTest.class, // LongCustomerNameTest.class, // QueueTaskTest.class diff --git a/hsarback/test/de/hsadmin/remote/PacMigrationTest.java b/hsarback/test/de/hsadmin/remote/PacMigrationTest.java index de0c0ee..e9a2b5c 100644 --- a/hsarback/test/de/hsadmin/remote/PacMigrationTest.java +++ b/hsarback/test/de/hsadmin/remote/PacMigrationTest.java @@ -60,6 +60,26 @@ public class PacMigrationTest { try { Object execute = client.execute(MODULE + ".add", params); assertTrue(execute instanceof Map); + Map whereParams = new HashMap(); + 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 pacResultMap = (Map) untypedResultArray[0]; + assertEquals(Pac.PAC_DW, pacResultMap.get("basepac")); + Object compMapObj = pacResultMap.get("components"); + assertTrue(compMapObj instanceof Map); + @SuppressWarnings("unchecked") + Map compMap = (Map) compMapObj; + assertEquals("512", compMap.get("QUOTA")); + assertEquals("4", compMap.get("TRAFFIC")); } catch (XmlRpcException e) { fail(e.getMessage()); } @@ -109,6 +129,7 @@ public class PacMigrationTest { assertEquals(Pac.PAC_WEB, pacResultMap.get("basepac")); Object compMapObj = pacResultMap.get("components"); assertTrue(compMapObj instanceof Map); + @SuppressWarnings("unchecked") Map compMap = (Map) compMapObj; assertEquals("512", compMap.get("QUOTA")); assertEquals("5", compMap.get("TRAFFIC")); diff --git a/hsarback/test/de/hsadmin/remote/RemoteTest.java b/hsarback/test/de/hsadmin/remote/RemoteTest.java index e302888..537f62f 100644 --- a/hsarback/test/de/hsadmin/remote/RemoteTest.java +++ b/hsarback/test/de/hsadmin/remote/RemoteTest.java @@ -16,7 +16,8 @@ import org.junit.runners.Suite; EMailAliasTest.class, DomainTest.class, EMailAddressTest.class, - DatabaseCleanTest.class + DatabaseCleanTest.class, + PacMigrationTest.class // LongCustomerNameTest.class // CustomerTest.class, // QueueTaskTest.class