use of org.broadleafcommerce.core.rating.domain.ReviewDetailImpl 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);
}
Aggregations