Search in sources :

Example 1 with RatingSummary

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

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

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

the class RatingServiceImpl method readRatingSummaries.

@Override
public Map<String, RatingSummary> readRatingSummaries(List<String> itemIds, RatingType type) {
    List<RatingSummary> ratings = ratingSummaryDao.readRatingSummaries(itemIds, type);
    Map<String, RatingSummary> ratingsMap = new HashMap<String, RatingSummary>();
    for (RatingSummary ratingSummary : ratings) {
        ratingsMap.put(ratingSummary.getItemId(), ratingSummary);
    }
    return ratingsMap;
}
Also used : RatingSummary(org.broadleafcommerce.core.rating.domain.RatingSummary) HashMap(java.util.HashMap)

Example 4 with RatingSummary

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

the class RatingSummaryDaoImpl method readRatingSummaries.

@Override
public List<RatingSummary> readRatingSummaries(final List<String> itemIds, final RatingType type) {
    final Query query = em.createNamedQuery("BC_READ_RATING_SUMMARIES_BY_ITEM_ID_AND_TYPE");
    query.setParameter("ratingType", type.getType());
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog");
    List<RatingSummary> ratings = batchExecuteReadQuery(query, itemIds, "itemIds");
    return ratings;
}
Also used : RatingSummary(org.broadleafcommerce.core.rating.domain.RatingSummary) Query(javax.persistence.Query)

Example 5 with RatingSummary

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

the class RatingSummaryDaoImpl method readRatingSummary.

@Override
public RatingSummary readRatingSummary(final String itemId, final RatingType type) {
    final Query query = em.createNamedQuery("BC_READ_RATING_SUMMARY_BY_ITEM_ID_AND_TYPE");
    query.setParameter("itemId", itemId);
    query.setParameter("ratingType", type.getType());
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog");
    RatingSummary ratingSummary = null;
    try {
        ratingSummary = (RatingSummary) query.getSingleResult();
    } catch (NoResultException e) {
    // ignore
    }
    return ratingSummary;
}
Also used : RatingSummary(org.broadleafcommerce.core.rating.domain.RatingSummary) Query(javax.persistence.Query) NoResultException(javax.persistence.NoResultException)

Aggregations

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