log.info(userId + " has " + offers.size() + " products");
return offers;
}
public GetOffersResult createOffer(String productId, String userId) {
GetOffersResult result = null;
Product product = model.find(Product.class,
KeyFactory.stringToKey(productId));
Offer offer = new Offer();
offer.setAcceptIt(false);
offer.setProduct(product);
offer.setProductOffered(new HashSet<ProductOffered>());
offer.setUserId(userId);
model.getTransaction().begin();
model.persist(offer);
model.getTransaction().commit();
OffersPerProduct offerPerProduct = new OffersPerProduct(KeyFactory.keyToString(offer.getKey()), productId, product.getName(), new HashMap<String, String>());
Map<String, OffersPerProduct> offers = new HashMap<String, OffersPerProduct>();
offers.put(offerPerProduct.getOfferKey(), offerPerProduct);
result = new GetOffersResult(offers);
log.info("Offer created");
return result;
}