use of com.salesmanager.core.model.customer.review.CustomerReview 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.core.model.customer.review.CustomerReview 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.core.model.customer.review.CustomerReview 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.core.model.customer.review.CustomerReview in project shopizer by shopizer-ecommerce.
the class CustomerFacadeImpl method getAllCustomerReviewsByReviewed.
@Override
public List<ReadableCustomerReview> getAllCustomerReviewsByReviewed(Long customerId, MerchantStore store, Language language) {
// customer exist
Customer customer = getCustomerById(customerId);
Validate.notNull(customer, "Reviewed customer cannot be null");
return customerReviewService.getByReviewedCustomer(customer).stream().map(customerReview -> convertCustomerReviewToReadableCustomerReview(customerReview, store, language)).collect(Collectors.toList());
}
use of com.salesmanager.core.model.customer.review.CustomerReview in project shopizer by shopizer-ecommerce.
the class CustomerFacadeImpl method deleteCustomerReview.
@Override
public void deleteCustomerReview(Long customerId, Long reviewId, MerchantStore store, Language language) {
CustomerReview customerReview = getCustomerReviewById(reviewId);
if (!customerReview.getReviewedCustomer().getId().equals(customerId)) {
throw new ResourceNotFoundException("Customer review with id " + reviewId + " does not exist for this customer");
}
deleteCustomerReview(customerReview);
}
Aggregations