use of org.broadleafcommerce.core.rating.domain.RatingSummary in project BroadleafCommerce by BroadleafCommerce.
the class RatingServiceImpl method readReviews.
@Override
@SuppressWarnings("unchecked")
public List<ReviewDetail> readReviews(String itemId, RatingType type, int start, int finish, RatingSortType sortBy) {
RatingSummary summary = this.readRatingSummary(itemId, type);
if (summary != null) {
List<ReviewDetail> reviews = summary.getReviews();
List<ReviewDetail> reviewsToReturn = new ArrayList<ReviewDetail>();
int i = 0;
for (ReviewDetail review : reviews) {
if (i > finish) {
break;
}
if (i >= start) {
reviewsToReturn.add(review);
}
i++;
}
String sortByBeanProperty = "reviewSubmittedDate";
if (sortBy == RatingSortType.MOST_HELPFUL) {
sortByBeanProperty = "helpfulCount";
}
Collections.sort(reviewsToReturn, new BeanComparator(sortByBeanProperty));
return reviewsToReturn;
} else {
return new ArrayList<ReviewDetail>();
}
}
use of org.broadleafcommerce.core.rating.domain.RatingSummary in project BroadleafCommerce by BroadleafCommerce.
the class RatingServiceImpl method reviewItem.
@Override
@Transactional("blTransactionManager")
public void reviewItem(String itemId, RatingType type, Customer customer, Double rating, String reviewText) {
RatingSummary ratingSummary = this.readRatingSummary(itemId, type);
if (ratingSummary == null) {
ratingSummary = ratingSummaryDao.createSummary(itemId, type);
}
RatingDetail ratingDetail = ratingSummaryDao.readRating(customer.getId(), ratingSummary.getId());
if (ratingDetail == null) {
ratingDetail = ratingSummaryDao.createDetail(ratingSummary, rating, SystemTime.asDate(), customer);
ratingSummary.getRatings().add(ratingDetail);
} else {
ratingDetail.setRating(rating);
}
ReviewDetail reviewDetail = ratingSummaryDao.readReview(customer.getId(), ratingSummary.getId());
if (reviewDetail == null) {
reviewDetail = new ReviewDetailImpl(customer, SystemTime.asDate(), ratingDetail, reviewText, ratingSummary);
ratingSummary.getReviews().add(reviewDetail);
} else {
reviewDetail.setReviewText(reviewText);
}
// load reviews
ratingSummary.getReviews().size();
ratingSummaryDao.saveRatingSummary(ratingSummary);
}
use of org.broadleafcommerce.core.rating.domain.RatingSummary in project BroadleafCommerce by BroadleafCommerce.
the class RatingServiceImpl method readRatingSummaries.
@Override
public Map<String, RatingSummary> readRatingSummaries(List<String> itemIds, RatingType type) {
List<RatingSummary> ratings = ratingSummaryDao.readRatingSummaries(itemIds, type);
Map<String, RatingSummary> ratingsMap = new HashMap<String, RatingSummary>();
for (RatingSummary ratingSummary : ratings) {
ratingsMap.put(ratingSummary.getItemId(), ratingSummary);
}
return ratingsMap;
}
use of org.broadleafcommerce.core.rating.domain.RatingSummary in project BroadleafCommerce by BroadleafCommerce.
the class RatingSummaryDaoImpl method readRatingSummaries.
@Override
public List<RatingSummary> readRatingSummaries(final List<String> itemIds, final RatingType type) {
final Query query = em.createNamedQuery("BC_READ_RATING_SUMMARIES_BY_ITEM_ID_AND_TYPE");
query.setParameter("ratingType", type.getType());
query.setHint(QueryHints.HINT_CACHEABLE, true);
query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog");
List<RatingSummary> ratings = batchExecuteReadQuery(query, itemIds, "itemIds");
return ratings;
}
use of org.broadleafcommerce.core.rating.domain.RatingSummary in project BroadleafCommerce by BroadleafCommerce.
the class RatingSummaryDaoImpl method readRatingSummary.
@Override
public RatingSummary readRatingSummary(final String itemId, final RatingType type) {
final Query query = em.createNamedQuery("BC_READ_RATING_SUMMARY_BY_ITEM_ID_AND_TYPE");
query.setParameter("itemId", itemId);
query.setParameter("ratingType", type.getType());
query.setHint(QueryHints.HINT_CACHEABLE, true);
query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog");
RatingSummary ratingSummary = null;
try {
ratingSummary = (RatingSummary) query.getSingleResult();
} catch (NoResultException e) {
// ignore
}
return ratingSummary;
}
Aggregations