use of com.salesmanager.core.model.catalog.product.review.ProductReviewDescription in project shopizer by shopizer-ecommerce.
the class PersistableProductReviewPopulator method populate.
@Override
public ProductReview populate(PersistableProductReview source, ProductReview target, MerchantStore store, Language language) throws ConversionException {
Validate.notNull(customerService, "customerService cannot be null");
Validate.notNull(productService, "productService 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 ProductReview();
}
Customer customer = customerService.getById(source.getCustomerId());
// check if customer belongs to store
if (customer == null || customer.getMerchantStore().getId().intValue() != store.getId().intValue()) {
throw new ConversionException("Invalid customer id for the given store");
}
if (source.getDate() == null) {
String date = DateUtil.formatDate(new Date());
source.setDate(date);
}
target.setReviewDate(DateUtil.getDate(source.getDate()));
target.setCustomer(customer);
target.setReviewRating(source.getRating());
Product product = productService.getById(source.getProductId());
// check if product belongs to store
if (product == null || product.getMerchantStore().getId().intValue() != store.getId().intValue()) {
throw new ConversionException("Invalid product id for the given store");
}
target.setProduct(product);
Language lang = languageService.getByCode(language.getCode());
if (lang == null) {
throw new ConversionException("Invalid language code, use iso codes (en, fr ...)");
}
ProductReviewDescription description = new ProductReviewDescription();
description.setDescription(source.getDescription());
description.setLanguage(lang);
description.setName("-");
description.setProductReview(target);
Set<ProductReviewDescription> descriptions = new HashSet<ProductReviewDescription>();
descriptions.add(description);
target.setDescriptions(descriptions);
return target;
} catch (Exception e) {
throw new ConversionException("Cannot populate ProductReview", e);
}
}
use of com.salesmanager.core.model.catalog.product.review.ProductReviewDescription in project shopizer by shopizer-ecommerce.
the class ReadableProductReviewPopulator method populate.
@Override
public ReadableProductReview populate(ProductReview source, ReadableProductReview target, MerchantStore store, Language language) throws ConversionException {
try {
ReadableCustomerPopulator populator = new ReadableCustomerPopulator();
ReadableCustomer customer = new ReadableCustomer();
populator.populate(source.getCustomer(), customer, store, language);
target.setId(source.getId());
target.setDate(DateUtil.formatDate(source.getReviewDate()));
target.setCustomer(customer);
target.setRating(source.getReviewRating());
target.setProductId(source.getProduct().getId());
Set<ProductReviewDescription> descriptions = source.getDescriptions();
if (descriptions != null) {
for (ProductReviewDescription description : descriptions) {
target.setDescription(description.getDescription());
target.setLanguage(description.getLanguage().getCode());
break;
}
}
return target;
} catch (Exception e) {
throw new ConversionException("Cannot populate ProductReview", e);
}
}
use of com.salesmanager.core.model.catalog.product.review.ProductReviewDescription in project shopizer by shopizer-ecommerce.
the class ProductTest method testReview.
// REVIEW
private void testReview(Product product) throws Exception {
ProductReview review = new ProductReview();
review.setProduct(product);
review.setReviewRating(4d);
Language en = languageService.getByCode("en");
ProductReviewDescription reviewDescription = new ProductReviewDescription();
reviewDescription.setLanguage(en);
reviewDescription.setDescription("This is a product review");
reviewDescription.setName("A review for you");
reviewDescription.setProductReview(review);
review.getDescriptions().add(reviewDescription);
productReviewService.create(review);
}
Aggregations