}
return articles;
}
public IArticlesDto getIArticlesDto(Product product, boolean completeInfo, String email) {
ArticlesDtoOut dto = new ArticlesDtoOut();
dto.setName(product.getName());
dto.setDate(product.getDate());
dto.setTag(Tags.valueOf(product.getTag().getTagId()));
dto.setKeyHash(KeyFactory.keyToString(product.getKey()));
dto.setLocale(Locales.getLocale(product.getLocale()));
if (completeInfo) {
dto.setDescription(product.getDescription().getValue());
dto.setInterestedIn(product.getInterestedIn().getValue());
List<Offers> allOffers = new ArrayList<Offers>();
if (product.getOffer() != null) {
for (Offer offer : product.getOffer()) {
Map<String, String> offerPerUser = new HashMap<String, String>();
for (ProductOffered productOffered : offer.getProductOffered()) {
String productId = productOffered.getProductId();
Product offered = model.find(Product.class,
KeyFactory.stringToKey(productId));
// Maybe it was removed
if(offered != null)
offerPerUser.put(productId, offered.getName());
}
if(offerPerUser.size()>0){
Offers offers = new Offers();
offers.setIdNameProducts(offerPerUser);
offers.setUserId(offer.getUserId());
if(email != null){
User user = model.find(User.class, email);
offers.setFriend(user.getFriends().contains(offer.getUserId()));
}
allOffers.add(offers);
}
}
}
dto.setOffers(allOffers);
}
return dto;
}