Search in sources :

Example 1 with ReviewDetailImpl

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);
}
Also used : RatingSummary(org.broadleafcommerce.core.rating.domain.RatingSummary) ReviewDetail(org.broadleafcommerce.core.rating.domain.ReviewDetail) RatingDetail(org.broadleafcommerce.core.rating.domain.RatingDetail) ReviewDetailImpl(org.broadleafcommerce.core.rating.domain.ReviewDetailImpl) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

RatingDetail (org.broadleafcommerce.core.rating.domain.RatingDetail)1 RatingSummary (org.broadleafcommerce.core.rating.domain.RatingSummary)1 ReviewDetail (org.broadleafcommerce.core.rating.domain.ReviewDetail)1 ReviewDetailImpl (org.broadleafcommerce.core.rating.domain.ReviewDetailImpl)1 Transactional (org.springframework.transaction.annotation.Transactional)1