Search in sources :

Example 1 with RatingDetail

use of org.broadleafcommerce.core.rating.domain.RatingDetail 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)

Example 2 with RatingDetail

use of org.broadleafcommerce.core.rating.domain.RatingDetail in project BroadleafCommerce by BroadleafCommerce.

the class RatingSummaryDaoImpl method readRating.

@Override
public RatingDetail readRating(final Long customerId, final Long ratingSummaryId) {
    final Query query = em.createNamedQuery("BC_READ_RATING_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");
    RatingDetail ratingDetail = null;
    try {
        ratingDetail = (RatingDetail) query.getSingleResult();
    } catch (NoResultException e) {
    // ignore
    }
    return ratingDetail;
}
Also used : Query(javax.persistence.Query) RatingDetail(org.broadleafcommerce.core.rating.domain.RatingDetail) NoResultException(javax.persistence.NoResultException)

Example 3 with RatingDetail

use of org.broadleafcommerce.core.rating.domain.RatingDetail in project BroadleafCommerce by BroadleafCommerce.

the class RatingSummaryDaoImpl method createDetail.

@Override
public RatingDetail createDetail(RatingSummary ratingSummary, Double rating, Date submittedDate, Customer customer) {
    RatingDetail detail = createDetail();
    detail.setRatingSummary(ratingSummary);
    detail.setRating(rating);
    detail.setRatingSubmittedDate(submittedDate);
    detail.setCustomer(customer);
    return detail;
}
Also used : RatingDetail(org.broadleafcommerce.core.rating.domain.RatingDetail)

Example 4 with RatingDetail

use of org.broadleafcommerce.core.rating.domain.RatingDetail in project BroadleafCommerce by BroadleafCommerce.

the class RatingServiceImpl method rateItem.

@Override
@Transactional("blTransactionManager")
public void rateItem(String itemId, RatingType type, Customer customer, Double rating) {
    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);
    }
    ratingDetail.setRating(rating);
    ratingSummary.getRatings().add(ratingDetail);
    ratingSummaryDao.saveRatingSummary(ratingSummary);
}
Also used : RatingSummary(org.broadleafcommerce.core.rating.domain.RatingSummary) RatingDetail(org.broadleafcommerce.core.rating.domain.RatingDetail) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

RatingDetail (org.broadleafcommerce.core.rating.domain.RatingDetail)4 RatingSummary (org.broadleafcommerce.core.rating.domain.RatingSummary)2 Transactional (org.springframework.transaction.annotation.Transactional)2 NoResultException (javax.persistence.NoResultException)1 Query (javax.persistence.Query)1 ReviewDetail (org.broadleafcommerce.core.rating.domain.ReviewDetail)1 ReviewDetailImpl (org.broadleafcommerce.core.rating.domain.ReviewDetailImpl)1