use of com.salesmanager.core.business.exception.ConversionException in project shopizer by shopizer-ecommerce.
the class ShoppingCartItemPopulator method populate.
@Override
public ShoppingCartItem populate(PersistableOrderProduct source, /**
* TODO: Fix, target not used possible future bug ! *
*/
ShoppingCartItem target, MerchantStore store, Language language) throws ConversionException {
Validate.notNull(productService, "Requires to set productService");
Validate.notNull(productAttributeService, "Requires to set productAttributeService");
Validate.notNull(shoppingCartService, "Requires to set shoppingCartService");
Product product = productService.getById(source.getProduct().getId());
if (source.getAttributes() != null) {
for (com.salesmanager.shop.model.catalog.product.attribute.ProductAttribute attr : source.getAttributes()) {
ProductAttribute attribute = productAttributeService.getById(attr.getId());
if (attribute == null) {
throw new ConversionException("ProductAttribute with id " + attr.getId() + " is null");
}
if (attribute.getProduct().getId().longValue() != source.getProduct().getId().longValue()) {
throw new ConversionException("ProductAttribute with id " + attr.getId() + " is not assigned to Product id " + source.getProduct().getId());
}
product.getAttributes().add(attribute);
}
}
try {
return shoppingCartService.populateShoppingCartItem(product);
} catch (ServiceException e) {
throw new ConversionException(e);
}
}
use of com.salesmanager.core.business.exception.ConversionException in project shopizer by shopizer-ecommerce.
the class PersistablePaymentPopulator method populate.
@Override
public Payment populate(PersistablePayment source, Payment target, MerchantStore store, Language language) throws ConversionException {
Validate.notNull(source, "PersistablePayment cannot be null");
Validate.notNull(pricingService, "pricingService must be set");
if (target == null) {
target = new Payment();
}
try {
target.setAmount(pricingService.getAmount(source.getAmount()));
target.setModuleName(source.getPaymentModule());
target.setPaymentType(PaymentType.valueOf(source.getPaymentType()));
target.setTransactionType(TransactionType.valueOf(source.getTransactionType()));
Map<String, String> metadata = new HashMap<String, String>();
metadata.put("paymentToken", source.getPaymentToken());
target.setPaymentMetaData(metadata);
return target;
} catch (Exception e) {
throw new ConversionException(e);
}
}
use of com.salesmanager.core.business.exception.ConversionException in project shopizer by shopizer-ecommerce.
the class PersistableTransactionPopulator method populate.
@Override
public Transaction populate(PersistableTransaction source, Transaction target, MerchantStore store, Language language) throws ConversionException {
Validate.notNull(source, "PersistableTransaction must not be null");
Validate.notNull(orderService, "OrderService must not be null");
Validate.notNull(pricingService, "OrderService must not be null");
if (target == null) {
target = new Transaction();
}
try {
target.setAmount(pricingService.getAmount(source.getAmount()));
target.setDetails(source.getDetails());
target.setPaymentType(PaymentType.valueOf(source.getPaymentType()));
target.setTransactionType(TransactionType.valueOf(source.getTransactionType()));
target.setTransactionDate(DateUtil.formatDate(source.getTransactionDate()));
if (source.getOrderId() != null && source.getOrderId().longValue() > 0) {
Order order = orderService.getById(source.getOrderId());
if (order == null) {
throw new ConversionException("Order with id " + source.getOrderId() + "does not exist");
}
target.setOrder(order);
}
return target;
} catch (Exception e) {
throw new ConversionException(e);
}
}
use of com.salesmanager.core.business.exception.ConversionException in project shopizer by shopizer-ecommerce.
the class CustomerPopulator method populate.
/**
* Creates a Customer entity ready to be saved
*/
@Override
public Customer populate(PersistableCustomer source, Customer target, MerchantStore store, Language language) throws ConversionException {
try {
if (source.getId() != null && source.getId() > 0) {
target.setId(source.getId());
}
if (!StringUtils.isBlank(source.getPassword())) {
target.setPassword(passwordEncoder.encode(source.getPassword()));
target.setNick(source.getUserName());
target.setAnonymous(false);
}
if (source.getBilling() != null) {
target.setBilling(new Billing());
if (!StringUtils.isEmpty(source.getFirstName())) {
target.getBilling().setFirstName(source.getFirstName());
}
if (!StringUtils.isEmpty(source.getLastName())) {
target.getBilling().setLastName(source.getLastName());
}
}
if (!StringUtils.isBlank(source.getProvider())) {
target.setProvider(source.getProvider());
}
if (!StringUtils.isBlank(source.getEmailAddress())) {
target.setEmailAddress(source.getEmailAddress());
}
if (source.getGender() != null && target.getGender() == null) {
target.setGender(com.salesmanager.core.model.customer.CustomerGender.valueOf(source.getGender()));
}
if (target.getGender() == null) {
target.setGender(com.salesmanager.core.model.customer.CustomerGender.M);
}
Map<String, Country> countries = countryService.getCountriesMap(language);
Map<String, Zone> zones = zoneService.getZones(language);
target.setMerchantStore(store);
Address sourceBilling = source.getBilling();
if (sourceBilling != null) {
Billing billing = target.getBilling();
billing.setAddress(sourceBilling.getAddress());
billing.setCity(sourceBilling.getCity());
billing.setCompany(sourceBilling.getCompany());
// billing.setCountry(country);
if (!StringUtils.isEmpty(sourceBilling.getFirstName()))
billing.setFirstName(sourceBilling.getFirstName());
if (!StringUtils.isEmpty(sourceBilling.getLastName()))
billing.setLastName(sourceBilling.getLastName());
billing.setTelephone(sourceBilling.getPhone());
billing.setPostalCode(sourceBilling.getPostalCode());
billing.setState(sourceBilling.getStateProvince());
Country billingCountry = null;
if (!StringUtils.isBlank(sourceBilling.getCountry())) {
billingCountry = countries.get(sourceBilling.getCountry());
if (billingCountry == null) {
throw new ConversionException("Unsuported country code " + sourceBilling.getCountry());
}
billing.setCountry(billingCountry);
}
if (billingCountry != null && !StringUtils.isBlank(sourceBilling.getZone())) {
Zone zone = zoneService.getByCode(sourceBilling.getZone());
if (zone == null) {
throw new ConversionException("Unsuported zone code " + sourceBilling.getZone());
}
Zone zoneDescription = zones.get(zone.getCode());
billing.setZone(zoneDescription);
}
// target.setBilling(billing);
}
if (target.getBilling() == null && source.getBilling() != null) {
LOG.info("Setting default values for billing");
Billing billing = new Billing();
Country billingCountry = null;
if (StringUtils.isNotBlank(source.getBilling().getCountry())) {
billingCountry = countries.get(source.getBilling().getCountry());
if (billingCountry == null) {
throw new ConversionException("Unsuported country code " + sourceBilling.getCountry());
}
billing.setCountry(billingCountry);
target.setBilling(billing);
}
}
Address sourceShipping = source.getDelivery();
if (sourceShipping != null) {
Delivery delivery = new Delivery();
delivery.setAddress(sourceShipping.getAddress());
delivery.setCity(sourceShipping.getCity());
delivery.setCompany(sourceShipping.getCompany());
delivery.setFirstName(sourceShipping.getFirstName());
delivery.setLastName(sourceShipping.getLastName());
delivery.setTelephone(sourceShipping.getPhone());
delivery.setPostalCode(sourceShipping.getPostalCode());
delivery.setState(sourceShipping.getStateProvince());
Country deliveryCountry = null;
if (!StringUtils.isBlank(sourceShipping.getCountry())) {
deliveryCountry = countries.get(sourceShipping.getCountry());
if (deliveryCountry == null) {
throw new ConversionException("Unsuported country code " + sourceShipping.getCountry());
}
delivery.setCountry(deliveryCountry);
}
if (deliveryCountry != null && !StringUtils.isBlank(sourceShipping.getZone())) {
Zone zone = zoneService.getByCode(sourceShipping.getZone());
if (zone == null) {
throw new ConversionException("Unsuported zone code " + sourceShipping.getZone());
}
Zone zoneDescription = zones.get(zone.getCode());
delivery.setZone(zoneDescription);
}
target.setDelivery(delivery);
}
if (source.getRating() != null && source.getRating().doubleValue() > 0) {
target.setCustomerReviewAvg(new BigDecimal(source.getRating().doubleValue()));
}
if (source.getRatingCount() > 0) {
target.setCustomerReviewCount(source.getRatingCount());
}
if (target.getDelivery() == null && source.getDelivery() != null) {
LOG.info("Setting default value for delivery");
Delivery delivery = new Delivery();
Country deliveryCountry = null;
if (StringUtils.isNotBlank(source.getDelivery().getCountry())) {
deliveryCountry = countries.get(source.getDelivery().getCountry());
if (deliveryCountry == null) {
throw new ConversionException("Unsuported country code " + sourceShipping.getCountry());
}
delivery.setCountry(deliveryCountry);
target.setDelivery(delivery);
}
}
if (source.getAttributes() != null) {
for (PersistableCustomerAttribute attr : source.getAttributes()) {
CustomerOption customerOption = customerOptionService.getById(attr.getCustomerOption().getId());
if (customerOption == null) {
throw new ConversionException("Customer option id " + attr.getCustomerOption().getId() + " does not exist");
}
CustomerOptionValue customerOptionValue = customerOptionValueService.getById(attr.getCustomerOptionValue().getId());
if (customerOptionValue == null) {
throw new ConversionException("Customer option value id " + attr.getCustomerOptionValue().getId() + " does not exist");
}
if (customerOption.getMerchantStore().getId().intValue() != store.getId().intValue()) {
throw new ConversionException("Invalid customer option id ");
}
if (customerOptionValue.getMerchantStore().getId().intValue() != store.getId().intValue()) {
throw new ConversionException("Invalid customer option value id ");
}
CustomerAttribute attribute = new CustomerAttribute();
attribute.setCustomer(target);
attribute.setCustomerOption(customerOption);
attribute.setCustomerOptionValue(customerOptionValue);
attribute.setTextValue(attr.getTextValue());
target.getAttributes().add(attribute);
}
}
if (target.getDefaultLanguage() == null) {
Language lang = source.getLanguage() == null ? language : languageService.getByCode(source.getLanguage());
target.setDefaultLanguage(lang);
}
} 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 PersistableCustomerPopulator method populate.
@Override
public PersistableCustomer populate(Customer source, PersistableCustomer target, MerchantStore store, Language language) throws ConversionException {
try {
if (source.getBilling() != null) {
Address address = new Address();
address.setCity(source.getBilling().getCity());
address.setCompany(source.getBilling().getCompany());
address.setFirstName(source.getBilling().getFirstName());
address.setLastName(source.getBilling().getLastName());
address.setPostalCode(source.getBilling().getPostalCode());
address.setPhone(source.getBilling().getTelephone());
if (source.getBilling().getTelephone() == null) {
address.setPhone(source.getBilling().getTelephone());
}
address.setAddress(source.getBilling().getAddress());
if (source.getBilling().getCountry() != null) {
address.setCountry(source.getBilling().getCountry().getIsoCode());
}
if (source.getBilling().getZone() != null) {
address.setZone(source.getBilling().getZone().getCode());
}
if (source.getBilling().getState() != null) {
address.setStateProvince(source.getBilling().getState());
}
target.setBilling(address);
}
target.setProvider(source.getProvider());
if (source.getCustomerReviewAvg() != null) {
target.setRating(source.getCustomerReviewAvg().doubleValue());
}
if (source.getCustomerReviewCount() != null) {
target.setRatingCount(source.getCustomerReviewCount().intValue());
}
if (source.getDelivery() != null) {
Address address = new Address();
address.setAddress(source.getDelivery().getAddress());
address.setCity(source.getDelivery().getCity());
address.setCompany(source.getDelivery().getCompany());
address.setFirstName(source.getDelivery().getFirstName());
address.setLastName(source.getDelivery().getLastName());
address.setPostalCode(source.getDelivery().getPostalCode());
address.setPhone(source.getDelivery().getTelephone());
if (source.getDelivery().getCountry() != null) {
address.setCountry(source.getDelivery().getCountry().getIsoCode());
}
if (source.getDelivery().getZone() != null) {
address.setZone(source.getDelivery().getZone().getCode());
}
if (source.getDelivery().getState() != null) {
address.setStateProvince(source.getDelivery().getState());
}
target.setDelivery(address);
}
target.setId(source.getId());
target.setEmailAddress(source.getEmailAddress());
if (source.getGender() != null) {
target.setGender(source.getGender().name());
}
if (source.getDefaultLanguage() != null) {
target.setLanguage(source.getDefaultLanguage().getCode());
}
target.setUserName(source.getNick());
target.setStoreCode(store.getCode());
if (source.getDefaultLanguage() != null) {
target.setLanguage(source.getDefaultLanguage().getCode());
} else {
target.setLanguage(store.getDefaultLanguage().getCode());
}
} catch (Exception e) {
throw new ConversionException(e);
}
return target;
}
Aggregations