Search in sources :

Example 11 with ConversionException

use of com.salesmanager.core.business.exception.ConversionException in project shopizer by shopizer-ecommerce.

the class ReadableOrderProductMapper method merge.

@Override
public ReadableOrderProduct merge(OrderProduct source, ReadableOrderProduct target, MerchantStore store, Language language) {
    Validate.notNull(source, "OrderProduct cannot be null");
    Validate.notNull(target, "ReadableOrderProduct cannot be null");
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(language, "Language cannot be null");
    target.setId(source.getId());
    target.setOrderedQuantity(source.getProductQuantity());
    try {
        target.setPrice(pricingService.getDisplayAmount(source.getOneTimeCharge(), store));
    } catch (Exception e) {
        throw new ConversionRuntimeException("Cannot convert price", e);
    }
    target.setProductName(source.getProductName());
    target.setSku(source.getSku());
    // subtotal = price * quantity
    BigDecimal subTotal = source.getOneTimeCharge();
    subTotal = subTotal.multiply(new BigDecimal(source.getProductQuantity()));
    try {
        String subTotalPrice = pricingService.getDisplayAmount(subTotal, store);
        target.setSubTotal(subTotalPrice);
    } catch (Exception e) {
        throw new ConversionRuntimeException("Cannot format price", e);
    }
    if (source.getOrderAttributes() != null) {
        List<ReadableOrderProductAttribute> attributes = new ArrayList<ReadableOrderProductAttribute>();
        for (OrderProductAttribute attr : source.getOrderAttributes()) {
            ReadableOrderProductAttribute readableAttribute = new ReadableOrderProductAttribute();
            try {
                String price = pricingService.getDisplayAmount(attr.getProductAttributePrice(), store);
                readableAttribute.setAttributePrice(price);
            } catch (ServiceException e) {
                throw new ConversionRuntimeException("Cannot format price", e);
            }
            readableAttribute.setAttributeName(attr.getProductAttributeName());
            readableAttribute.setAttributeValue(attr.getProductAttributeValueName());
            attributes.add(readableAttribute);
        }
        target.setAttributes(attributes);
    }
    String productSku = source.getSku();
    if (!StringUtils.isBlank(productSku)) {
        Product product = productService.getByCode(productSku, language);
        if (product != null) {
            // TODO autowired
            ReadableProductPopulator populator = new ReadableProductPopulator();
            populator.setPricingService(pricingService);
            populator.setimageUtils(imageUtils);
            ReadableProduct productProxy;
            try {
                productProxy = populator.populate(product, new ReadableProduct(), store, language);
                target.setProduct(productProxy);
            } catch (ConversionException e) {
                throw new ConversionRuntimeException("Cannot convert product", e);
            }
            Set<ProductImage> images = product.getImages();
            ProductImage defaultImage = null;
            if (images != null) {
                for (ProductImage image : images) {
                    if (defaultImage == null) {
                        defaultImage = image;
                    }
                    if (image.isDefaultImage()) {
                        defaultImage = image;
                    }
                }
            }
            if (defaultImage != null) {
                target.setImage(defaultImage.getProductImage());
            }
        }
    }
    return target;
}
Also used : ConversionException(com.salesmanager.core.business.exception.ConversionException) ProductImage(com.salesmanager.core.model.catalog.product.image.ProductImage) ReadableOrderProductAttribute(com.salesmanager.shop.model.order.ReadableOrderProductAttribute) ArrayList(java.util.ArrayList) OrderProduct(com.salesmanager.core.model.order.orderproduct.OrderProduct) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) Product(com.salesmanager.core.model.catalog.product.Product) ReadableOrderProduct(com.salesmanager.shop.model.order.ReadableOrderProduct) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) ServiceException(com.salesmanager.core.business.exception.ServiceException) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) ConversionException(com.salesmanager.core.business.exception.ConversionException) BigDecimal(java.math.BigDecimal) ServiceException(com.salesmanager.core.business.exception.ServiceException) ReadableProductPopulator(com.salesmanager.shop.populator.catalog.ReadableProductPopulator) OrderProductAttribute(com.salesmanager.core.model.order.orderproduct.OrderProductAttribute) ReadableOrderProductAttribute(com.salesmanager.shop.model.order.ReadableOrderProductAttribute) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException)

Example 12 with ConversionException

use of com.salesmanager.core.business.exception.ConversionException in project shopizer by shopizer-ecommerce.

the class ReadableOrderProductPopulator method populate.

@Override
public ReadableOrderProduct populate(OrderProduct source, ReadableOrderProduct target, MerchantStore store, Language language) throws ConversionException {
    Validate.notNull(productService, "Requires ProductService");
    Validate.notNull(pricingService, "Requires PricingService");
    Validate.notNull(imageUtils, "Requires imageUtils");
    target.setId(source.getId());
    target.setOrderedQuantity(source.getProductQuantity());
    try {
        target.setPrice(pricingService.getDisplayAmount(source.getOneTimeCharge(), store));
    } catch (Exception e) {
        throw new ConversionException("Cannot convert price", e);
    }
    target.setProductName(source.getProductName());
    target.setSku(source.getSku());
    // subtotal = price * quantity
    BigDecimal subTotal = source.getOneTimeCharge();
    subTotal = subTotal.multiply(new BigDecimal(source.getProductQuantity()));
    try {
        String subTotalPrice = pricingService.getDisplayAmount(subTotal, store);
        target.setSubTotal(subTotalPrice);
    } catch (Exception e) {
        throw new ConversionException("Cannot format price", e);
    }
    if (source.getOrderAttributes() != null) {
        List<ReadableOrderProductAttribute> attributes = new ArrayList<ReadableOrderProductAttribute>();
        for (OrderProductAttribute attr : source.getOrderAttributes()) {
            ReadableOrderProductAttribute readableAttribute = new ReadableOrderProductAttribute();
            try {
                String price = pricingService.getDisplayAmount(attr.getProductAttributePrice(), store);
                readableAttribute.setAttributePrice(price);
            } catch (ServiceException e) {
                throw new ConversionException("Cannot format price", e);
            }
            readableAttribute.setAttributeName(attr.getProductAttributeName());
            readableAttribute.setAttributeValue(attr.getProductAttributeValueName());
            attributes.add(readableAttribute);
        }
        target.setAttributes(attributes);
    }
    String productSku = source.getSku();
    if (!StringUtils.isBlank(productSku)) {
        Product product = productService.getByCode(productSku, language);
        if (product != null) {
            ReadableProductPopulator populator = new ReadableProductPopulator();
            populator.setPricingService(pricingService);
            populator.setimageUtils(imageUtils);
            ReadableProduct productProxy = populator.populate(product, new ReadableProduct(), store, language);
            target.setProduct(productProxy);
            Set<ProductImage> images = product.getImages();
            ProductImage defaultImage = null;
            if (images != null) {
                for (ProductImage image : images) {
                    if (defaultImage == null) {
                        defaultImage = image;
                    }
                    if (image.isDefaultImage()) {
                        defaultImage = image;
                    }
                }
            }
            if (defaultImage != null) {
                target.setImage(defaultImage.getProductImage());
            }
        }
    }
    return target;
}
Also used : ConversionException(com.salesmanager.core.business.exception.ConversionException) ProductImage(com.salesmanager.core.model.catalog.product.image.ProductImage) ReadableOrderProductAttribute(com.salesmanager.shop.model.order.ReadableOrderProductAttribute) ArrayList(java.util.ArrayList) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) Product(com.salesmanager.core.model.catalog.product.Product) OrderProduct(com.salesmanager.core.model.order.orderproduct.OrderProduct) ReadableOrderProduct(com.salesmanager.shop.model.order.ReadableOrderProduct) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) ServiceException(com.salesmanager.core.business.exception.ServiceException) ConversionException(com.salesmanager.core.business.exception.ConversionException) BigDecimal(java.math.BigDecimal) ServiceException(com.salesmanager.core.business.exception.ServiceException) ReadableProductPopulator(com.salesmanager.shop.populator.catalog.ReadableProductPopulator) OrderProductAttribute(com.salesmanager.core.model.order.orderproduct.OrderProductAttribute) ReadableOrderProductAttribute(com.salesmanager.shop.model.order.ReadableOrderProductAttribute)

Example 13 with ConversionException

use of com.salesmanager.core.business.exception.ConversionException in project shopizer by shopizer-ecommerce.

the class ReadableOrderSummaryPopulator method populate.

@Override
public ReadableOrderTotalSummary populate(OrderTotalSummary source, ReadableOrderTotalSummary target, MerchantStore store, Language language) throws ConversionException {
    Validate.notNull(pricingService, "PricingService must be set");
    Validate.notNull(messages, "LabelUtils must be set");
    if (target == null) {
        target = new ReadableOrderTotalSummary();
    }
    try {
        if (source.getSubTotal() != null) {
            target.setSubTotal(pricingService.getDisplayAmount(source.getSubTotal(), store));
        }
        if (source.getTaxTotal() != null) {
            target.setTaxTotal(pricingService.getDisplayAmount(source.getTaxTotal(), store));
        }
        if (source.getTotal() != null) {
            target.setTotal(pricingService.getDisplayAmount(source.getTotal(), store));
        }
        if (!CollectionUtils.isEmpty(source.getTotals())) {
            ReadableOrderTotalPopulator orderTotalPopulator = new ReadableOrderTotalPopulator();
            orderTotalPopulator.setMessages(messages);
            orderTotalPopulator.setPricingService(pricingService);
            for (OrderTotal orderTotal : source.getTotals()) {
                ReadableOrderTotal t = new ReadableOrderTotal();
                orderTotalPopulator.populate(orderTotal, t, store, language);
                target.getTotals().add(t);
            }
        }
    } catch (Exception e) {
        LOGGER.error("Error during amount formatting " + e.getMessage());
        throw new ConversionException(e);
    }
    return target;
}
Also used : ConversionException(com.salesmanager.core.business.exception.ConversionException) ReadableOrderTotal(com.salesmanager.shop.model.order.total.ReadableOrderTotal) ReadableOrderTotal(com.salesmanager.shop.model.order.total.ReadableOrderTotal) OrderTotal(com.salesmanager.core.model.order.OrderTotal) ReadableOrderTotalSummary(com.salesmanager.shop.model.order.ReadableOrderTotalSummary) ConversionException(com.salesmanager.core.business.exception.ConversionException)

Example 14 with ConversionException

use of com.salesmanager.core.business.exception.ConversionException in project shopizer by shopizer-ecommerce.

the class ReadableShippingSummaryPopulator method populate.

@Override
public ReadableShippingSummary populate(ShippingSummary source, ReadableShippingSummary target, MerchantStore store, Language language) throws ConversionException {
    Validate.notNull(pricingService, "PricingService must be set");
    Validate.notNull(source, "ShippingSummary cannot be null");
    try {
        target.setShippingQuote(source.isShippingQuote());
        target.setFreeShipping(source.isFreeShipping());
        target.setHandling(source.getHandling());
        target.setShipping(source.getShipping());
        target.setShippingModule(source.getShippingModule());
        target.setShippingOption(source.getShippingOption());
        target.setTaxOnShipping(source.isTaxOnShipping());
        target.setHandlingText(pricingService.getDisplayAmount(source.getHandling(), store));
        target.setShippingText(pricingService.getDisplayAmount(source.getShipping(), store));
        if (source.getDeliveryAddress() != null) {
            ReadableDelivery deliveryAddress = new ReadableDelivery();
            deliveryAddress.setAddress(source.getDeliveryAddress().getAddress());
            deliveryAddress.setPostalCode(source.getDeliveryAddress().getPostalCode());
            deliveryAddress.setCity(source.getDeliveryAddress().getCity());
            if (source.getDeliveryAddress().getZone() != null) {
                deliveryAddress.setZone(source.getDeliveryAddress().getZone().getCode());
            }
            if (source.getDeliveryAddress().getCountry() != null) {
                deliveryAddress.setCountry(source.getDeliveryAddress().getCountry().getIsoCode());
            }
            deliveryAddress.setLatitude(source.getDeliveryAddress().getLatitude());
            deliveryAddress.setLongitude(source.getDeliveryAddress().getLongitude());
            deliveryAddress.setStateProvince(source.getDeliveryAddress().getState());
            target.setDelivery(deliveryAddress);
        }
    } catch (Exception e) {
        throw new ConversionException(e);
    }
    return target;
}
Also used : ConversionException(com.salesmanager.core.business.exception.ConversionException) ReadableDelivery(com.salesmanager.shop.model.customer.ReadableDelivery) ConversionException(com.salesmanager.core.business.exception.ConversionException)

Example 15 with ConversionException

use of com.salesmanager.core.business.exception.ConversionException in project shopizer by shopizer-ecommerce.

the class ReadableShopOrderPopulator method populate.

@Override
public ReadableShopOrder populate(ShopOrder source, ReadableShopOrder target, MerchantStore store, Language language) throws ConversionException {
    try {
        ReadableCustomer customer = new ReadableCustomer();
        PersistableCustomer persistableCustomer = source.getCustomer();
        customer.setEmailAddress(persistableCustomer.getEmailAddress());
        if (persistableCustomer.getBilling() != null) {
            Address address = new Address();
            address.setCity(persistableCustomer.getBilling().getCity());
            address.setCompany(persistableCustomer.getBilling().getCompany());
            address.setFirstName(persistableCustomer.getBilling().getFirstName());
            address.setLastName(persistableCustomer.getBilling().getLastName());
            address.setPostalCode(persistableCustomer.getBilling().getPostalCode());
            address.setPhone(persistableCustomer.getBilling().getPhone());
            if (persistableCustomer.getBilling().getCountry() != null) {
                address.setCountry(persistableCustomer.getBilling().getCountry());
            }
            if (persistableCustomer.getBilling().getZone() != null) {
                address.setZone(persistableCustomer.getBilling().getZone());
            }
            customer.setBilling(address);
        }
        if (persistableCustomer.getDelivery() != null) {
            Address address = new Address();
            address.setCity(persistableCustomer.getDelivery().getCity());
            address.setCompany(persistableCustomer.getDelivery().getCompany());
            address.setFirstName(persistableCustomer.getDelivery().getFirstName());
            address.setLastName(persistableCustomer.getDelivery().getLastName());
            address.setPostalCode(persistableCustomer.getDelivery().getPostalCode());
            address.setPhone(persistableCustomer.getDelivery().getPhone());
            if (persistableCustomer.getDelivery().getCountry() != null) {
                address.setCountry(persistableCustomer.getDelivery().getCountry());
            }
            if (persistableCustomer.getDelivery().getZone() != null) {
                address.setZone(persistableCustomer.getDelivery().getZone());
            }
            customer.setDelivery(address);
        }
        // TODO if ship to billing enabled, set delivery = billing
        /*			if(persistableCustomer.getAttributes()!=null) {
				for(PersistableCustomerAttribute attribute : persistableCustomer.getAttributes()) {
					ReadableCustomerAttribute readableAttribute = new ReadableCustomerAttribute();
					readableAttribute.setId(attribute.getId());
					ReadableCustomerOption option = new ReadableCustomerOption();
					option.setId(attribute.getCustomerOption().getId());
					option.setCode(attribute.getCustomerOption());
					
					CustomerOptionDescription d = new CustomerOptionDescription();
					d.setDescription(attribute.getCustomerOption().getDescriptionsSettoList().get(0).getDescription());
					d.setName(attribute.getCustomerOption().getDescriptionsSettoList().get(0).getName());
					option.setDescription(d);
					
					readableAttribute.setCustomerOption(option);
					
					ReadableCustomerOptionValue optionValue = new ReadableCustomerOptionValue();
					optionValue.setId(attribute.getCustomerOptionValue().getId());
					CustomerOptionValueDescription vd = new CustomerOptionValueDescription();
					vd.setDescription(attribute.getCustomerOptionValue().getDescriptionsSettoList().get(0).getDescription());
					vd.setName(attribute.getCustomerOptionValue().getDescriptionsSettoList().get(0).getName());
					optionValue.setCode(attribute.getCustomerOptionValue().getCode());
					optionValue.setDescription(vd);
					
					
					readableAttribute.setCustomerOptionValue(optionValue);
					customer.getAttributes().add(readableAttribute);
				}
			}*/
        target.setCustomer(customer);
    } catch (Exception e) {
        throw new ConversionException(e);
    }
    return target;
}
Also used : ConversionException(com.salesmanager.core.business.exception.ConversionException) Address(com.salesmanager.shop.model.customer.address.Address) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer) ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer) ConversionException(com.salesmanager.core.business.exception.ConversionException)

Aggregations

ConversionException (com.salesmanager.core.business.exception.ConversionException)57 ConversionRuntimeException (com.salesmanager.shop.store.api.exception.ConversionRuntimeException)17 Language (com.salesmanager.core.model.reference.language.Language)16 HashSet (java.util.HashSet)15 ArrayList (java.util.ArrayList)11 ServiceException (com.salesmanager.core.business.exception.ServiceException)10 Product (com.salesmanager.core.model.catalog.product.Product)10 Customer (com.salesmanager.core.model.customer.Customer)9 ReadableCustomer (com.salesmanager.shop.model.customer.ReadableCustomer)9 PersistableCustomer (com.salesmanager.shop.model.customer.PersistableCustomer)8 BigDecimal (java.math.BigDecimal)8 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)7 ProductAttribute (com.salesmanager.core.model.catalog.product.attribute.ProductAttribute)6 OrderProduct (com.salesmanager.core.model.order.orderproduct.OrderProduct)6 Country (com.salesmanager.core.model.reference.country.Country)6 Zone (com.salesmanager.core.model.reference.zone.Zone)6 ReadableProduct (com.salesmanager.shop.model.catalog.product.ReadableProduct)6 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)6 Date (java.util.Date)6 Category (com.salesmanager.core.model.catalog.category.Category)5