}
@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);
} else {
ratingDetail.setRating(rating);
}
ratingSummary.getRatings().add(ratingDetail);
ReviewDetail reviewDetail = ratingSummaryDao.readReview(customer.getId(), ratingSummary.getId());
if (reviewDetail == null) {
reviewDetail = new ReviewDetailImpl(customer, SystemTime.asDate(), ratingDetail, reviewText, ratingSummary);
} else {
reviewDetail.setReviewText(reviewText);
}
ratingSummary.getReviews().add(reviewDetail);
// load reviews
ratingSummary.getReviews().size();
ratingSummaryDao.saveRatingSummary(ratingSummary);
}