Map<Long, PromotableFulfillmentGroupAdjustment> promotableAdjMap = buildPromFulfillmentAdjMap(promotableFG);
// First try and update existing adjustment records
while (adjustmentIterator.hasNext()) {
FulfillmentGroupAdjustment currentAdj = adjustmentIterator.next();
PromotableFulfillmentGroupAdjustment newAdj = promotableAdjMap.remove(currentAdj.getOffer().getId());
if (newAdj != null) {
if (!currentAdj.getValue().equals(newAdj.getAdjustmentValue())) {
// Update the currentAdj.
currentAdj.setValue(newAdj.getAdjustmentValue());
}
} else {
// Removing no longer valid adjustment
adjustmentIterator.remove();
}
}
// Now add missing adjustments
for (PromotableFulfillmentGroupAdjustment newAdj : promotableAdjMap.values()) {
FulfillmentGroupAdjustment fa = offerDao.createFulfillmentGroupAdjustment();
fa.setFulfillmentGroup(fg);
fa.init(fg, newAdj.getPromotableCandidateFulfillmentGroupOffer().getOffer(), null);
fa.setValue(newAdj.getAdjustmentValue());
fg.getFulfillmentGroupAdjustments().add(fa);
}
}