Search in sources :

Example 1 with CustomerReviewDescription

use of com.salesmanager.core.model.customer.review.CustomerReviewDescription in project shopizer by shopizer-ecommerce.

the class ReadableCustomerReviewPopulator method populate.

@Override
public ReadableCustomerReview populate(CustomerReview source, ReadableCustomerReview target, MerchantStore store, Language language) throws ConversionException {
    try {
        if (target == null) {
            target = new ReadableCustomerReview();
        }
        if (source.getReviewDate() != null) {
            target.setDate(DateUtil.formatDate(source.getReviewDate()));
        }
        ReadableCustomer reviewed = new ReadableCustomer();
        reviewed.setId(source.getReviewedCustomer().getId());
        reviewed.setFirstName(source.getReviewedCustomer().getBilling().getFirstName());
        reviewed.setLastName(source.getReviewedCustomer().getBilling().getLastName());
        target.setId(source.getId());
        target.setCustomerId(source.getCustomer().getId());
        target.setReviewedCustomer(reviewed);
        target.setRating(source.getReviewRating());
        target.setReviewedCustomer(reviewed);
        target.setCustomerId(source.getCustomer().getId());
        Set<CustomerReviewDescription> descriptions = source.getDescriptions();
        if (CollectionUtils.isNotEmpty(descriptions)) {
            CustomerReviewDescription description = null;
            if (descriptions.size() > 1) {
                for (CustomerReviewDescription desc : descriptions) {
                    if (desc.getLanguage().getCode().equals(language.getCode())) {
                        description = desc;
                        break;
                    }
                }
            } else {
                description = descriptions.iterator().next();
            }
            if (description != null) {
                target.setDescription(description.getDescription());
                target.setLanguage(description.getLanguage().getCode());
            }
        }
    } catch (Exception e) {
        throw new ConversionException("Cannot populate ReadableCustomerReview", e);
    }
    return target;
}
Also used : ConversionException(com.salesmanager.core.business.exception.ConversionException) ReadableCustomerReview(com.salesmanager.shop.model.customer.ReadableCustomerReview) ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer) ConversionException(com.salesmanager.core.business.exception.ConversionException) CustomerReviewDescription(com.salesmanager.core.model.customer.review.CustomerReviewDescription)

Example 2 with CustomerReviewDescription

use of com.salesmanager.core.model.customer.review.CustomerReviewDescription 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;
}
Also used : ConversionException(com.salesmanager.core.business.exception.ConversionException) Language(com.salesmanager.core.model.reference.language.Language) Customer(com.salesmanager.core.model.customer.Customer) PersistableCustomerReview(com.salesmanager.shop.model.customer.PersistableCustomerReview) CustomerReview(com.salesmanager.core.model.customer.review.CustomerReview) Date(java.util.Date) ConversionException(com.salesmanager.core.business.exception.ConversionException) CustomerReviewDescription(com.salesmanager.core.model.customer.review.CustomerReviewDescription) HashSet(java.util.HashSet)

Aggregations

ConversionException (com.salesmanager.core.business.exception.ConversionException)2 CustomerReviewDescription (com.salesmanager.core.model.customer.review.CustomerReviewDescription)2 Customer (com.salesmanager.core.model.customer.Customer)1 CustomerReview (com.salesmanager.core.model.customer.review.CustomerReview)1 Language (com.salesmanager.core.model.reference.language.Language)1 PersistableCustomerReview (com.salesmanager.shop.model.customer.PersistableCustomerReview)1 ReadableCustomer (com.salesmanager.shop.model.customer.ReadableCustomer)1 ReadableCustomerReview (com.salesmanager.shop.model.customer.ReadableCustomerReview)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1