pac migration (contains error)
This commit is contained in:
parent
3cab6d2c7f
commit
8976d93e03
@ -10,6 +10,7 @@ import java.util.Date;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.persistence.CascadeType;
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
|
@ -78,11 +78,14 @@ public class PacModuleImpl extends AbstractModuleImpl {
|
|||||||
for (Object cObj : componentsList) {
|
for (Object cObj : componentsList) {
|
||||||
Component comp = (Component) cObj;
|
Component comp = (Component) cObj;
|
||||||
PacComponent pacComponent = new PacComponent();
|
PacComponent pacComponent = new PacComponent();
|
||||||
pacComponent.setBaseComponent(comp.getBaseComponent());
|
BaseComponent baseComponent = comp.getBaseComponent();
|
||||||
|
pacComponent.setBaseComponent(baseComponent);
|
||||||
pacComponent.setbasePac(comp.getBasePac());
|
pacComponent.setbasePac(comp.getBasePac());
|
||||||
pacComponent.setCreated(now);
|
pacComponent.setCreated(now);
|
||||||
pacComponent.setPac(pac);
|
pacComponent.setPac(pac);
|
||||||
pacComponent.setQuantity(comp.getDefaultQuantity());
|
String feature = baseComponent.getFeature();
|
||||||
|
int requestedQuantity = pac.getPacComponent(feature).getQuantity();
|
||||||
|
pacComponent.setQuantity(requestedQuantity);
|
||||||
pacComponents.add(pacComponent);
|
pacComponents.add(pacComponent);
|
||||||
}
|
}
|
||||||
pac.setPacComponents(pacComponents);
|
pac.setPacComponents(pacComponents);
|
||||||
@ -128,7 +131,8 @@ public class PacModuleImpl extends AbstractModuleImpl {
|
|||||||
EntityManager em = getTransaction().getEntityManager();
|
EntityManager em = getTransaction().getEntityManager();
|
||||||
Pac oldState = em.find(Pac.class, newState.getId());
|
Pac oldState = em.find(Pac.class, newState.getId());
|
||||||
String oldBasepacName = oldState.getBasepac().getName();
|
String oldBasepacName = oldState.getBasepac().getName();
|
||||||
String newBasepacName = newState.getBasepac().getName();
|
BasePac newBasepac = newState.getBasepac();
|
||||||
|
String newBasepacName = newBasepac.getName();
|
||||||
if (!oldBasepacName.equals(newBasepacName)) {
|
if (!oldBasepacName.equals(newBasepacName)) {
|
||||||
Set<PacComponent> oldPacComponents = oldState.getPacComponents();
|
Set<PacComponent> oldPacComponents = oldState.getPacComponents();
|
||||||
Map<String, Integer> oldQuantities = new HashMap<String, Integer>();
|
Map<String, Integer> oldQuantities = new HashMap<String, Integer>();
|
||||||
@ -136,17 +140,27 @@ public class PacModuleImpl extends AbstractModuleImpl {
|
|||||||
String feature = c.getBaseComponent().getFeature();
|
String feature = c.getBaseComponent().getFeature();
|
||||||
int quantity = c.getQuantity();
|
int quantity = c.getQuantity();
|
||||||
oldQuantities.put(feature, new Integer(quantity));
|
oldQuantities.put(feature, new Integer(quantity));
|
||||||
|
em.remove(c);
|
||||||
}
|
}
|
||||||
oldPacComponents.clear();
|
oldPacComponents.clear();
|
||||||
|
newState.getPacComponents().clear();
|
||||||
em.flush();
|
em.flush();
|
||||||
newState.initPacComponents(em, newState.getBasepac());
|
newState.setBasepac(newBasepac);
|
||||||
|
newState.initPacComponents(em, newBasepac);
|
||||||
Set<PacComponent> newPacComponents = newState.getPacComponents();
|
Set<PacComponent> newPacComponents = newState.getPacComponents();
|
||||||
for (PacComponent pc : newPacComponents) {
|
for (PacComponent pc : newPacComponents) {
|
||||||
BaseComponent bc = pc.getBaseComponent();
|
BaseComponent bc = pc.getBaseComponent();
|
||||||
String feature = bc.getFeature();
|
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);
|
return super.update(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,8 @@ import org.junit.runners.Suite;
|
|||||||
DomainTest.class,
|
DomainTest.class,
|
||||||
EMailAddressTest.class,
|
EMailAddressTest.class,
|
||||||
SSLCertDomainTest.class,
|
SSLCertDomainTest.class,
|
||||||
DatabaseCleanTest.class
|
DatabaseCleanTest.class,
|
||||||
|
PacMigrationTest.class
|
||||||
// CustomerTest.class,
|
// CustomerTest.class,
|
||||||
// LongCustomerNameTest.class,
|
// LongCustomerNameTest.class,
|
||||||
// QueueTaskTest.class
|
// QueueTaskTest.class
|
||||||
|
@ -60,6 +60,26 @@ public class PacMigrationTest {
|
|||||||
try {
|
try {
|
||||||
Object execute = client.execute(MODULE + ".add", params);
|
Object execute = client.execute(MODULE + ".add", params);
|
||||||
assertTrue(execute instanceof Map<?, ?>);
|
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) {
|
} catch (XmlRpcException e) {
|
||||||
fail(e.getMessage());
|
fail(e.getMessage());
|
||||||
}
|
}
|
||||||
@ -109,6 +129,7 @@ public class PacMigrationTest {
|
|||||||
assertEquals(Pac.PAC_WEB, pacResultMap.get("basepac"));
|
assertEquals(Pac.PAC_WEB, pacResultMap.get("basepac"));
|
||||||
Object compMapObj = pacResultMap.get("components");
|
Object compMapObj = pacResultMap.get("components");
|
||||||
assertTrue(compMapObj instanceof Map<?,?>);
|
assertTrue(compMapObj instanceof Map<?,?>);
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
Map<String,String> compMap = (Map<String, String>) compMapObj;
|
Map<String,String> compMap = (Map<String, String>) compMapObj;
|
||||||
assertEquals("512", compMap.get("QUOTA"));
|
assertEquals("512", compMap.get("QUOTA"));
|
||||||
assertEquals("5", compMap.get("TRAFFIC"));
|
assertEquals("5", compMap.get("TRAFFIC"));
|
||||||
|
@ -16,7 +16,8 @@ import org.junit.runners.Suite;
|
|||||||
EMailAliasTest.class,
|
EMailAliasTest.class,
|
||||||
DomainTest.class,
|
DomainTest.class,
|
||||||
EMailAddressTest.class,
|
EMailAddressTest.class,
|
||||||
DatabaseCleanTest.class
|
DatabaseCleanTest.class,
|
||||||
|
PacMigrationTest.class
|
||||||
// LongCustomerNameTest.class
|
// LongCustomerNameTest.class
|
||||||
// CustomerTest.class,
|
// CustomerTest.class,
|
||||||
// QueueTaskTest.class
|
// QueueTaskTest.class
|
||||||
|
Loading…
Reference in New Issue
Block a user