pac migration partial implementation
This commit is contained in:
parent
6ec7999be6
commit
ce5c545bef
@ -1,8 +1,10 @@
|
|||||||
package de.hsadmin.mods.pac;
|
package de.hsadmin.mods.pac;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
@ -116,6 +118,26 @@ public class PacModuleImpl extends AbstractModuleImpl {
|
|||||||
throw new AuthorisationException(loginUser, "update", entity);
|
throw new AuthorisationException(loginUser, "update", entity);
|
||||||
}
|
}
|
||||||
needsWriteAccessOn(entity, "update");
|
needsWriteAccessOn(entity, "update");
|
||||||
|
Pac newState = (Pac) entity;
|
||||||
|
EntityManager em = getTransaction().getEntityManager();
|
||||||
|
Pac oldState = em.find(Pac.class, newState.getId());
|
||||||
|
if (!oldState.getBasepac().getName().equals(newState.getBasepac().getName())) {
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
oldPacComponents.clear();
|
||||||
|
em.flush();
|
||||||
|
newState.initPacComponents(em, newState.getBasepac());
|
||||||
|
Set<PacComponent> newPacComponents = newState.getPacComponents();
|
||||||
|
for (PacComponent c : newPacComponents) {
|
||||||
|
String feature = c.getBaseComponent().getFeature();
|
||||||
|
c.setQuantity(oldQuantities.get(feature).intValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
return super.update(entity);
|
return super.update(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ public class PacMigrationTest {
|
|||||||
setParams.put("curinetaddr", "176.9.242.77");
|
setParams.put("curinetaddr", "176.9.242.77");
|
||||||
HashMap<String, String> components = new HashMap<String, String>();
|
HashMap<String, String> components = new HashMap<String, String>();
|
||||||
components.put("QUOTA", "512");
|
components.put("QUOTA", "512");
|
||||||
components.put("TRAFFIC", "5");
|
components.put("TRAFFIC", "4");
|
||||||
components.put("DAEMON", "1");
|
components.put("DAEMON", "1");
|
||||||
setParams.put("components", components);
|
setParams.put("components", components);
|
||||||
Object[] params = new Object[] { user,
|
Object[] params = new Object[] { user,
|
||||||
@ -87,7 +87,6 @@ public class PacMigrationTest {
|
|||||||
setParams.put("basepac", Pac.PAC_WEB);
|
setParams.put("basepac", Pac.PAC_WEB);
|
||||||
setParams.put("components", components);
|
setParams.put("components", components);
|
||||||
components.put("QUOTA", "1024");
|
components.put("QUOTA", "1024");
|
||||||
components.put("TRAFFIC", "5");
|
|
||||||
Map<String, String> whereParams = new HashMap<String, String>();
|
Map<String, String> whereParams = new HashMap<String, String>();
|
||||||
whereParams.put("name", "aaa04");
|
whereParams.put("name", "aaa04");
|
||||||
Object[] params = new Object[] { user,
|
Object[] params = new Object[] { user,
|
||||||
@ -108,6 +107,8 @@ public class PacMigrationTest {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Map<String, ?> pacResultMap = (Map<String, ?>) untypedResultArray[0];
|
Map<String, ?> pacResultMap = (Map<String, ?>) untypedResultArray[0];
|
||||||
assertEquals(Pac.PAC_WEB, pacResultMap.get("basepac"));
|
assertEquals(Pac.PAC_WEB, pacResultMap.get("basepac"));
|
||||||
|
Object compMapObj = pacResultMap.get("components");
|
||||||
|
assertTrue(compMapObj instanceof Map<?,?>);
|
||||||
} catch (XmlRpcException e) {
|
} catch (XmlRpcException e) {
|
||||||
fail(e.getMessage());
|
fail(e.getMessage());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user