Search in sources :

Example 1 with PersistableCustomerReview

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;
}
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)

Example 2 with PersistableCustomerReview

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;
}
Also used : ReadableCustomerReview(com.salesmanager.shop.model.customer.ReadableCustomerReview) CustomerReview(com.salesmanager.core.model.customer.review.CustomerReview) PersistableCustomerReview(com.salesmanager.shop.model.customer.PersistableCustomerReview)

Example 3 with PersistableCustomerReview

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);
    }
}
Also used : ConversionException(com.salesmanager.core.business.exception.ConversionException) PersistableCustomerReviewPopulator(com.salesmanager.shop.populator.customer.PersistableCustomerReviewPopulator) ReadableCustomerReview(com.salesmanager.shop.model.customer.ReadableCustomerReview) CustomerReview(com.salesmanager.core.model.customer.review.CustomerReview) PersistableCustomerReview(com.salesmanager.shop.model.customer.PersistableCustomerReview) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException)

Example 4 with PersistableCustomerReview

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;
}
Also used : ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ReadableCustomerReview(com.salesmanager.shop.model.customer.ReadableCustomerReview) CustomerReview(com.salesmanager.core.model.customer.review.CustomerReview) PersistableCustomerReview(com.salesmanager.shop.model.customer.PersistableCustomerReview) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Aggregations

CustomerReview (com.salesmanager.core.model.customer.review.CustomerReview)4 PersistableCustomerReview (com.salesmanager.shop.model.customer.PersistableCustomerReview)4 ReadableCustomerReview (com.salesmanager.shop.model.customer.ReadableCustomerReview)3 ConversionException (com.salesmanager.core.business.exception.ConversionException)2 Customer (com.salesmanager.core.model.customer.Customer)1 CustomerReviewDescription (com.salesmanager.core.model.customer.review.CustomerReviewDescription)1 Language (com.salesmanager.core.model.reference.language.Language)1 PersistableCustomerReviewPopulator (com.salesmanager.shop.populator.customer.PersistableCustomerReviewPopulator)1 ConversionRuntimeException (com.salesmanager.shop.store.api.exception.ConversionRuntimeException)1 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)1 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1