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);
}
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;
}
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;
}
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);
}
Aggregations