Search in sources :

Example 1 with ProductReviewDescription

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);
    }
}
Also used : ConversionException(com.salesmanager.core.business.exception.ConversionException) Language(com.salesmanager.core.model.reference.language.Language) Customer(com.salesmanager.core.model.customer.Customer) Product(com.salesmanager.core.model.catalog.product.Product) ProductReviewDescription(com.salesmanager.core.model.catalog.product.review.ProductReviewDescription) ProductReview(com.salesmanager.core.model.catalog.product.review.ProductReview) PersistableProductReview(com.salesmanager.shop.model.catalog.product.PersistableProductReview) Date(java.util.Date) ConversionException(com.salesmanager.core.business.exception.ConversionException) HashSet(java.util.HashSet)

Example 2 with ProductReviewDescription

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);
    }
}
Also used : ConversionException(com.salesmanager.core.business.exception.ConversionException) ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer) ProductReviewDescription(com.salesmanager.core.model.catalog.product.review.ProductReviewDescription) ReadableCustomerPopulator(com.salesmanager.shop.populator.customer.ReadableCustomerPopulator) ConversionException(com.salesmanager.core.business.exception.ConversionException)

Example 3 with ProductReviewDescription

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);
}
Also used : Language(com.salesmanager.core.model.reference.language.Language) ProductReviewDescription(com.salesmanager.core.model.catalog.product.review.ProductReviewDescription) ProductReview(com.salesmanager.core.model.catalog.product.review.ProductReview)

Aggregations

ProductReviewDescription (com.salesmanager.core.model.catalog.product.review.ProductReviewDescription)3 ConversionException (com.salesmanager.core.business.exception.ConversionException)2 ProductReview (com.salesmanager.core.model.catalog.product.review.ProductReview)2 Language (com.salesmanager.core.model.reference.language.Language)2 Product (com.salesmanager.core.model.catalog.product.Product)1 Customer (com.salesmanager.core.model.customer.Customer)1 PersistableProductReview (com.salesmanager.shop.model.catalog.product.PersistableProductReview)1 ReadableCustomer (com.salesmanager.shop.model.customer.ReadableCustomer)1 ReadableCustomerPopulator (com.salesmanager.shop.populator.customer.ReadableCustomerPopulator)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1