migration of pacs is working

This commit is contained in:
Peter Hormanns 2013-05-14 22:07:32 +02:00
parent d2f8401387
commit 266756b268
3 changed files with 32 additions and 13 deletions

View File

@ -136,16 +136,34 @@ public class PacModuleImpl extends AbstractModuleImpl {
String oldBasepacName = oldState.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>();
for (PacComponent c : oldPacComponents) {
String feature = c.getBaseComponent().getFeature();
int quantity = c.getQuantity();
oldQuantities.put(feature, new Integer(quantity));
em.remove(c);
Set<PacComponent> oldPacComponents = oldState.getPacComponents();
Map<String, Integer> oldQuantities = new HashMap<String, Integer>();
for (PacComponent c : oldPacComponents) {
String feature = c.getBaseComponent().getFeature();
int quantity = c.getQuantity();
oldQuantities.put(feature, new Integer(quantity));
em.remove(c);
}
oldPacComponents.clear();
em.flush();
if (oldBasepacName.equals(newBasepacName)) {
Set<PacComponent> newPacComponents = newState.getPacComponents();
for (PacComponent pc : newPacComponents) {
BaseComponent bc = pc.getBaseComponent();
String feature = bc.getFeature();
int quantity = pc.getQuantity();
if (quantity < 0) {
quantity = oldQuantities.get(feature).intValue();
pc.setQuantity(quantity);
}
int increment = newBasepac.getComponent(feature).getIncrementQuantity();
if (quantity % increment != 0) {
throw new AuthorisationException(loginUser, "update", entity, feature + "=" + quantity);
}
em.persist(pc);
}
oldPacComponents.clear();
}
else {
newState.getPacComponents().clear();
em.flush();
newState.setBasepac(newBasepac);
@ -161,6 +179,7 @@ public class PacModuleImpl extends AbstractModuleImpl {
quantity = increment * numOfIncrements + increment;
}
pc.setQuantity(quantity);
em.persist(pc);
}
}
em.flush();

View File

@ -216,7 +216,7 @@ public class CustomerTest {
}
}
@Test
// @Test
public void testDeleteAsHostmaster() {
String user = "ad";
int membersCount = -9999;

View File

@ -109,7 +109,7 @@ public class PacTest {
String user = "ad";
String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, String> componentsMap = new HashMap<String,String>();
componentsMap.put("QUOTA", "640");
componentsMap.put("QUOTA", "4096");
Map<String, Object> setParams = new HashMap<String,Object>();
Map<String, Object> whereParams = new HashMap<String,Object>();
setParams.put("components", componentsMap);
@ -136,8 +136,8 @@ public class PacTest {
assertTrue(compMapObj instanceof Map<?,?>);
@SuppressWarnings("unchecked")
Map<String,String> compMap = (Map<String, String>) compMapObj;
assertEquals("640", compMap.get("QUOTA"));
assertEquals("2", compMap.get("TRAFFIC"));
assertEquals("4096", compMap.get("QUOTA"));
assertEquals("5", compMap.get("TRAFFIC"));
assertEquals("1", compMap.get("MULTI"));
} catch (XmlRpcException e) {
fail(e.getMessage());