pac migration (contains error)

This commit is contained in:
Peter Hormanns 2013-05-01 22:23:13 +02:00
parent 3cab6d2c7f
commit 8976d93e03
5 changed files with 45 additions and 7 deletions

View File

@ -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;

View File

@ -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<PacComponent> oldPacComponents = oldState.getPacComponents();
Map<String, Integer> oldQuantities = new HashMap<String, Integer>();
@ -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<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);
}

View File

@ -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

View File

@ -60,6 +60,26 @@ public class PacMigrationTest {
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 @@ public class PacMigrationTest {
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"));

View File

@ -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