use of org.broadleafcommerce.core.rating.domain.ReviewDetail 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.ReviewDetail 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.ReviewDetail in project BroadleafCommerce by BroadleafCommerce.
the class RatingServiceImpl method markReviewHelpful.
@Override
@Transactional("blTransactionManager")
public void markReviewHelpful(Long reviewId, Customer customer, Boolean helpful) {
ReviewDetail reviewDetail = reviewDetailDao.readReviewDetailById(reviewId);
if (reviewDetail != null) {
ReviewFeedback reviewFeedback = reviewDetailDao.createFeedback();
reviewFeedback.setCustomer(customer);
reviewFeedback.setIsHelpful(helpful);
reviewFeedback.setReviewDetail(reviewDetail);
reviewDetail.getReviewFeedback().add(reviewFeedback);
reviewDetailDao.saveReviewDetail(reviewDetail);
}
}
use of org.broadleafcommerce.core.rating.domain.ReviewDetail in project BroadleafCommerce by BroadleafCommerce.
the class RatingSummaryDaoImpl method readReview.
@Override
public ReviewDetail readReview(final Long customerId, final Long ratingSummaryId) {
final Query query = em.createNamedQuery("BC_READ_REVIEW_DETAIL_BY_CUSTOMER_ID_AND_RATING_SUMMARY_ID");
query.setParameter("customerId", customerId);
query.setParameter("ratingSummaryId", ratingSummaryId);
query.setHint(QueryHints.HINT_CACHEABLE, true);
query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog");
ReviewDetail reviewDetail = null;
try {
reviewDetail = (ReviewDetail) query.getSingleResult();
} catch (NoResultException e) {
// ignore
}
return reviewDetail;
}
use of org.broadleafcommerce.core.rating.domain.ReviewDetail in project BroadleafCommerce by BroadleafCommerce.
the class ReviewDetailDaoImpl method readReviewByCustomerAndItem.
@Override
public ReviewDetail readReviewByCustomerAndItem(Customer customer, String itemId) {
final Query query = em.createNamedQuery("BC_READ_REVIEW_DETAIL_BY_CUSTOMER_ID_AND_ITEM_ID");
query.setParameter("customerId", customer.getId());
query.setParameter("itemId", itemId);
ReviewDetail reviewDetail = null;
try {
reviewDetail = (ReviewDetail) query.getSingleResult();
} catch (NoResultException nre) {
// ignore
}
return reviewDetail;
}
Aggregations