use of com.salesmanager.core.business.exception.ConversionException 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.business.exception.ConversionException in project shopizer by shopizer-ecommerce.
the class PersistableCategoryPopulator method buildDescription.
private com.salesmanager.core.model.catalog.category.CategoryDescription buildDescription(com.salesmanager.shop.model.catalog.category.CategoryDescription source, com.salesmanager.core.model.catalog.category.CategoryDescription target) throws Exception {
// com.salesmanager.core.model.catalog.category.CategoryDescription desc = new com.salesmanager.core.model.catalog.category.CategoryDescription();
target.setCategoryHighlight(source.getHighlights());
target.setDescription(source.getDescription());
target.setName(source.getName());
target.setMetatagDescription(source.getMetaDescription());
target.setMetatagTitle(source.getTitle());
target.setSeUrl(source.getFriendlyUrl());
Language lang = languageService.getByCode(source.getLanguage());
if (lang == null) {
throw new ConversionException("Language is null for code " + source.getLanguage() + " use language ISO code [en, fr ...]");
}
// description.setId(description.getId());
target.setLanguage(lang);
return target;
}
use of com.salesmanager.core.business.exception.ConversionException in project shopizer by shopizer-ecommerce.
the class PersistableProductOptionValuePopulator method populate.
@Override
public ProductOptionValue populate(PersistableProductOptionValue source, ProductOptionValue target, MerchantStore store, Language language) throws ConversionException {
Validate.notNull(languageService, "Requires to set LanguageService");
try {
target.setMerchantStore(store);
target.setProductOptionValueSortOrder(source.getOrder());
target.setCode(source.getCode());
if (!CollectionUtils.isEmpty(source.getDescriptions())) {
Set<com.salesmanager.core.model.catalog.product.attribute.ProductOptionValueDescription> descriptions = new HashSet<com.salesmanager.core.model.catalog.product.attribute.ProductOptionValueDescription>();
for (ProductOptionValueDescription desc : source.getDescriptions()) {
com.salesmanager.core.model.catalog.product.attribute.ProductOptionValueDescription description = new com.salesmanager.core.model.catalog.product.attribute.ProductOptionValueDescription();
Language lang = languageService.getByCode(desc.getLanguage());
if (lang == null) {
throw new ConversionException("Language is null for code " + description.getLanguage() + " use language ISO code [en, fr ...]");
}
description.setLanguage(lang);
description.setName(desc.getName());
description.setTitle(desc.getTitle());
description.setProductOptionValue(target);
descriptions.add(description);
}
target.setDescriptions(descriptions);
}
} catch (Exception e) {
throw new ConversionException(e);
}
return target;
}
use of com.salesmanager.core.business.exception.ConversionException in project shopizer by shopizer-ecommerce.
the class CustomerFacadeImpl method updateAddress.
@Override
public void updateAddress(Long userId, MerchantStore merchantStore, Address address, final Language language) throws Exception {
Customer customerModel = customerService.getById(userId);
Map<String, Country> countriesMap = countryService.getCountriesMap(language);
Country country = countriesMap.get(address.getCountry());
if (customerModel == null) {
LOG.error("Customer with ID {} does not exists..", userId);
// throw new CustomerNotFoundException( "customer with given id does not exists" );
throw new Exception("customer with given id does not exists");
}
if (address.isBillingAddress()) {
LOG.info("updating customer billing address..");
PersistableCustomerBillingAddressPopulator billingAddressPopulator = new PersistableCustomerBillingAddressPopulator();
customerModel = billingAddressPopulator.populate(address, customerModel, merchantStore, merchantStore.getDefaultLanguage());
customerModel.getBilling().setCountry(country);
if (StringUtils.isNotBlank(address.getZone())) {
Zone zone = zoneService.getByCode(address.getZone());
if (zone == null) {
throw new ConversionException("Unsuported zone code " + address.getZone());
}
customerModel.getBilling().setZone(zone);
customerModel.getBilling().setState(null);
} else {
customerModel.getBilling().setZone(null);
}
} else {
LOG.info("updating customer shipping address..");
PersistableCustomerShippingAddressPopulator shippingAddressPopulator = new PersistableCustomerShippingAddressPopulator();
customerModel = shippingAddressPopulator.populate(address, customerModel, merchantStore, merchantStore.getDefaultLanguage());
customerModel.getDelivery().setCountry(country);
if (StringUtils.isNotBlank(address.getZone())) {
Zone zone = zoneService.getByCode(address.getZone());
if (zone == null) {
throw new ConversionException("Unsuported zone code " + address.getZone());
}
customerModel.getDelivery().setZone(zone);
customerModel.getDelivery().setState(null);
} else {
customerModel.getDelivery().setZone(null);
}
}
// same update address with customer model
this.customerService.saveOrUpdate(customerModel);
}
use of com.salesmanager.core.business.exception.ConversionException in project shopizer by shopizer-ecommerce.
the class CustomerFacadeImpl method update.
@Override
public PersistableCustomer update(PersistableCustomer customer, MerchantStore store) {
if (customer.getId() == null || customer.getId() == 0) {
throw new ServiceRuntimeException("Can't update a customer with null id");
}
Customer cust = customerService.getById(customer.getId());
try {
customerPopulator.populate(customer, cust, store, store.getDefaultLanguage());
} catch (ConversionException e) {
throw new ConversionRuntimeException(e);
}
String password = customer.getPassword();
if (StringUtils.isBlank(password)) {
password = new String(UUID.generateRandomBytes());
customer.setPassword(password);
}
saveCustomer(cust);
customer.setId(cust.getId());
return customer;
}
Aggregations