Search in sources :

Example 1 with ReviewDetail

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>();
    }
}
Also used : RatingSummary(org.broadleafcommerce.core.rating.domain.RatingSummary) ReviewDetail(org.broadleafcommerce.core.rating.domain.ReviewDetail) ArrayList(java.util.ArrayList) BeanComparator(org.apache.commons.beanutils.BeanComparator)

Example 2 with 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);
}
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 3 with ReviewDetail

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

Example 4 with 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;
}
Also used : ReviewDetail(org.broadleafcommerce.core.rating.domain.ReviewDetail) Query(javax.persistence.Query) NoResultException(javax.persistence.NoResultException)

Example 5 with 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;
}
Also used : ReviewDetail(org.broadleafcommerce.core.rating.domain.ReviewDetail) Query(javax.persistence.Query) NoResultException(javax.persistence.NoResultException)

Aggregations

ReviewDetail (org.broadleafcommerce.core.rating.domain.ReviewDetail)8 RatingSummary (org.broadleafcommerce.core.rating.domain.RatingSummary)4 NoResultException (javax.persistence.NoResultException)2 Query (javax.persistence.Query)2 Transactional (org.springframework.transaction.annotation.Transactional)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 BeanComparator (org.apache.commons.beanutils.BeanComparator)1 Product (org.broadleafcommerce.core.catalog.domain.Product)1 RatingDetail (org.broadleafcommerce.core.rating.domain.RatingDetail)1 ReviewDetailImpl (org.broadleafcommerce.core.rating.domain.ReviewDetailImpl)1 ReviewFeedback (org.broadleafcommerce.core.rating.domain.ReviewFeedback)1 Customer (org.broadleafcommerce.profile.core.domain.Customer)1 JSONArray (org.codehaus.jettison.json.JSONArray)1 JSONObject (org.codehaus.jettison.json.JSONObject)1