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