return result;
}
@Transactional
public UpdateOfferResult updateOffer(String userId, String offerId, Map<String,String> productIdNames){
UpdateOfferResult result = null;
Offer offer = model.find(Offer.class, KeyFactory.stringToKey(offerId));
if(!userId.equals(offer.getUserId())){
log.log(Level.WARNING, "User "+userId+" is trying to update an offer of "+offer.getUserId());
return null;
}
Set<ProductOffered> offers = new HashSet<ProductOffered>();
for(Entry<String,String> entry : productIdNames.entrySet()){
ProductOffered productOffered = new ProductOffered();
productOffered.setOffer(offer);
productOffered.setProductId(entry.getKey());
productOffered.setProductName(entry.getValue());
offers.add(productOffered);
model.persist(productOffered);
}
offer.setProductOffered(offers);
result = new UpdateOfferResult(new OffersPerProduct(offerId, KeyFactory.keyToString(offer.getProduct().getKey()), offer.getProduct().getName(), productIdNames));
log.info("Offer updated");
return result;
}