pmb.setId(measurement.getId());
pmb.setDescription(measurement.getDescription());
pmb.setIsMutable(measurement.getMutable());
if(productMeasurementMap.get(measurement.getId()) != null){
ProductMeasurement pm = productMeasurementMap.get(measurement.getId());
pmb.setQty(pm.getOverrideQty());
pmb.setIsDefault(false);
}else{
pmb.setQty(measurement.getDefaultQty());
pmb.setIsDefault(true);
}
resultList.add(pmb);
}
}else if(request.getOperationType() == OPERATION_TYPE.ADD){
Map<Integer, ProductMeasurement> productMeasurementMap = new HashMap<Integer, ProductMeasurement>();
ResultList<ProductMeasurement> productMeasurementList = coreManager.searchProductMeasurement(productId);
for (ProductMeasurement productMeasurement : productMeasurementList) {
productMeasurementMap.put(productMeasurement.getMeasurement().getId(), productMeasurement);
}
Collection<Measurement> measurementList = coreManager.getAllMeasurement();
for (Measurement measurement : measurementList) {
Integer id = measurement.getId();
if(measurement.getMutable()){
Integer overrideQty = RequestUtil.getInteger(request.getData().get(String.valueOf(id)));
ProductMeasurement pm = productMeasurementMap.get(id);
if(overrideQty.intValue() == measurement.getDefaultQty().intValue()){
//default qty, delete override measurement
if(pm != null){
coreManager.remove(pm);
productMeasurementMap.remove(id);
}
}else{
if(pm != null){
pm.setOverrideQty(overrideQty);
ProductMeasurement pm1 = coreManager.save(ProductMeasurement.class, pm);
productMeasurementMap.put(id, pm1);
}else{
pm = new ProductMeasurement();
Product p = coreManager.get(Product.class, productId);
pm.setProduct(p);
pm.setOverrideQty(overrideQty);
pm.setMeasurement(measurement);
ProductMeasurement pm1 = coreManager.save(ProductMeasurement.class, pm);
productMeasurementMap.put(id, pm1);
}
}
}
ProductMeasurementBase pmb = new ProductMeasurementBase();
pmb.setId(id);
pmb.setDescription(measurement.getDescription());
pmb.setIsMutable(measurement.getMutable());
if(productMeasurementMap.get(id) != null){
ProductMeasurement pm = productMeasurementMap.get(id);
pmb.setQty(pm.getOverrideQty());
pmb.setIsDefault(false);
}else{
pmb.setQty(measurement.getDefaultQty());
pmb.setIsDefault(true);
}