| | |
| | | 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); |
| | |
| | | quantity = increment * numOfIncrements + increment; |
| | | } |
| | | pc.setQuantity(quantity); |
| | | em.persist(pc); |
| | | } |
| | | } |
| | | em.flush(); |