use of com.salesmanager.shop.model.customer.PersistableCustomerReview in project shopizer by shopizer-ecommerce.
the class PersistableCustomerReviewPopulator method populate.
@Override
public CustomerReview populate(PersistableCustomerReview source, CustomerReview target, MerchantStore store, Language language) throws ConversionException {
Validate.notNull(customerService, "customerService cannot be null");
Validate.notNull(languageService, "languageService cannot be null");
Validate.notNull(source.getRating(), "Rating cannot bot be null");
try {
if (target == null) {
target = new CustomerReview();
}
if (source.getDate() == null) {
String date = DateUtil.formatDate(new Date());
source.setDate(date);
}
target.setReviewDate(DateUtil.getDate(source.getDate()));
if (source.getId() != null && source.getId().longValue() == 0) {
source.setId(null);
} else {
target.setId(source.getId());
}
Customer reviewer = customerService.getById(source.getCustomerId());
Customer reviewed = customerService.getById(source.getReviewedCustomer());
target.setReviewRating(source.getRating());
target.setCustomer(reviewer);
target.setReviewedCustomer(reviewed);
Language lang = languageService.getByCode(language.getCode());
if (lang == null) {
throw new ConversionException("Invalid language code, use iso codes (en, fr ...)");
}
CustomerReviewDescription description = new CustomerReviewDescription();
description.setDescription(source.getDescription());
description.setLanguage(lang);
description.setName("-");
description.setCustomerReview(target);
Set<CustomerReviewDescription> descriptions = new HashSet<CustomerReviewDescription>();
descriptions.add(description);
target.setDescriptions(descriptions);
} catch (Exception e) {
throw new ConversionException("Cannot populate CustomerReview", e);
}
return target;
}
use of com.salesmanager.shop.model.customer.PersistableCustomerReview in project shopizer by shopizer-ecommerce.
the class CustomerFacadeImpl method saveOrUpdateCustomerReview.
@Override
public PersistableCustomerReview saveOrUpdateCustomerReview(PersistableCustomerReview reviewTO, MerchantStore store, Language language) {
CustomerReview review = convertPersistableCustomerReviewToCustomerReview(reviewTO, store, language);
createReview(review);
reviewTO.setId(review.getId());
return reviewTO;
}
use of com.salesmanager.shop.model.customer.PersistableCustomerReview in project shopizer by shopizer-ecommerce.
the class CustomerFacadeImpl method convertPersistableCustomerReviewToCustomerReview.
private CustomerReview convertPersistableCustomerReviewToCustomerReview(PersistableCustomerReview review, MerchantStore store, Language language) {
PersistableCustomerReviewPopulator populator = new PersistableCustomerReviewPopulator();
populator.setCustomerService(customerService);
populator.setLanguageService(languageService);
try {
return populator.populate(review, new CustomerReview(), store, language);
} catch (ConversionException e) {
throw new ConversionRuntimeException(e);
}
}
use of com.salesmanager.shop.model.customer.PersistableCustomerReview in project shopizer by shopizer-ecommerce.
the class CustomerFacadeImpl method updateCustomerReview.
@Override
public PersistableCustomerReview updateCustomerReview(Long id, Long reviewId, PersistableCustomerReview review, MerchantStore store, Language language) {
CustomerReview customerReview = getCustomerReviewById(reviewId);
if (!customerReview.getReviewedCustomer().getId().equals(id)) {
throw new ResourceNotFoundException("Customer review with id " + reviewId + " does not exist for this customer");
}
// rating maximum 5
if (review.getRating() > Constants.MAX_REVIEW_RATING_SCORE) {
throw new ServiceRuntimeException("Maximum rating score is " + Constants.MAX_REVIEW_RATING_SCORE);
}
review.setReviewedCustomer(id);
return review;
}
Aggregations