Search in sources :

Example 6 with ConversionRuntimeException

use of com.salesmanager.shop.store.api.exception.ConversionRuntimeException 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 7 with ConversionRuntimeException

use of com.salesmanager.shop.store.api.exception.ConversionRuntimeException in project shopizer by shopizer-ecommerce.

the class ReadableProductAttributeMapper method merge.

@Override
public ReadableProductAttributeEntity merge(ProductAttribute source, ReadableProductAttributeEntity destination, MerchantStore store, Language language) {
    ReadableProductAttributeEntity attr = new ReadableProductAttributeEntity();
    if (destination != null) {
        attr = destination;
    }
    try {
        // attribute of the option
        attr.setId(source.getId());
        if (source.getProductAttributePrice() != null && source.getProductAttributePrice().doubleValue() > 0) {
            String formatedPrice;
            formatedPrice = pricingService.getDisplayAmount(source.getProductAttributePrice(), store);
            attr.setProductAttributePrice(formatedPrice);
            attr.setProductAttributeUnformattedPrice(pricingService.getStringAmount(source.getProductAttributePrice(), store));
        }
        attr.setProductAttributeWeight(source.getAttributeAdditionalWeight());
        attr.setAttributeDisplayOnly(source.getAttributeDisplayOnly());
        attr.setAttributeDefault(source.getAttributeDefault());
        if (!StringUtils.isBlank(source.getAttributeSortOrder())) {
            attr.setSortOrder(Integer.parseInt(source.getAttributeSortOrder()));
        }
        if (source.getProductOption() != null) {
            ReadableProductOptionEntity option = readableProductOptionMapper.convert(source.getProductOption(), store, language);
            attr.setOption(option);
        }
        if (source.getProductOptionValue() != null) {
            ReadableProductOptionValueEntity optionValue = readableProductOptionValueMapper.convert(source.getProductOptionValue(), store, language);
            attr.setOptionValue(optionValue);
        }
    } catch (Exception e) {
        throw new ConversionRuntimeException("Exception while product attribute conversion", e);
    }
    return attr;
}
Also used : ReadableProductOptionValueEntity(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductOptionValueEntity) ReadableProductAttributeEntity(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductAttributeEntity) ReadableProductOptionEntity(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductOptionEntity) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException)

Example 8 with ConversionRuntimeException

use of com.salesmanager.shop.store.api.exception.ConversionRuntimeException in project shopizer by shopizer-ecommerce.

the class PersistableCatalogCategoryEntryMapper method merge.

@Override
public CatalogCategoryEntry merge(PersistableCatalogCategoryEntry source, CatalogCategoryEntry destination, MerchantStore store, Language language) {
    Validate.notNull(source, "CatalogEntry must not be null");
    Validate.notNull(store, "MerchantStore must not be null");
    Validate.notNull(source.getProductCode(), "ProductCode must not be null");
    Validate.notNull(source.getCategoryCode(), "CategoryCode must not be null");
    Validate.notNull(source.getCatalog(), "Catalog must not be null");
    if (destination == null) {
        destination = new CatalogCategoryEntry();
    }
    destination.setId(source.getId());
    destination.setVisible(source.isVisible());
    try {
        String catalog = source.getCatalog();
        Catalog catalogModel = catalogFacade.getCatalog(catalog, store);
        if (catalogModel == null) {
            throw new ConversionRuntimeException("Error while converting CatalogEntry product [" + source.getCatalog() + "] not found");
        }
        destination.setCatalog(catalogModel);
        /*			Product productModel = productFacade.getProduct(source.getProductCode(), store);
			if(productModel == null) {
				throw new ConversionRuntimeException("Error while converting CatalogEntry product [" + source.getProductCode() + "] not found");
			}*/
        // destination.setProduct(productModel);
        Category categoryModel = categoryFacade.getByCode(source.getCategoryCode(), store);
        if (categoryModel == null) {
            throw new ConversionRuntimeException("Error while converting CatalogEntry category [" + source.getCategoryCode() + "] not found");
        }
        destination.setCategory(categoryModel);
    } catch (Exception e) {
        throw new ConversionRuntimeException("Error while converting CatalogEntry", e);
    }
    return destination;
}
Also used : CatalogCategoryEntry(com.salesmanager.core.model.catalog.catalog.CatalogCategoryEntry) PersistableCatalogCategoryEntry(com.salesmanager.shop.model.catalog.catalog.PersistableCatalogCategoryEntry) Category(com.salesmanager.core.model.catalog.category.Category) Catalog(com.salesmanager.core.model.catalog.catalog.Catalog) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException)

Example 9 with ConversionRuntimeException

use of com.salesmanager.shop.store.api.exception.ConversionRuntimeException in project shopizer by shopizer-ecommerce.

the class PersistableProductVariationMapper method merge.

@Override
public ProductVariation merge(PersistableProductVariation source, ProductVariation destination, MerchantStore store, Language language) {
    Validate.notNull(destination, "ProductVariation cannot be null");
    destination.setId(source.getId());
    destination.setCode(source.getCode());
    destination.setMerchantStore(store);
    ProductOption option = productOptionService.getById(store, source.getOption());
    if (option == null) {
        throw new ConversionRuntimeException("ProductOption [" + source.getOption() + "] does not exists");
    }
    destination.setProductOption(option);
    ProductOptionValue optionValue = productOptionValueService.getById(store, source.getOptionValue());
    if (optionValue == null) {
        throw new ConversionRuntimeException("ProductOptionValue [" + source.getOptionValue() + "] does not exists");
    }
    destination.setProductOptionValue(optionValue);
    return destination;
}
Also used : ProductOption(com.salesmanager.core.model.catalog.product.attribute.ProductOption) ProductOptionValue(com.salesmanager.core.model.catalog.product.attribute.ProductOptionValue) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException)

Example 10 with ConversionRuntimeException

use of com.salesmanager.shop.store.api.exception.ConversionRuntimeException 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;
}
Also used : ConversionException(com.salesmanager.core.business.exception.ConversionException) ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer) Customer(com.salesmanager.core.model.customer.Customer) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException)

Aggregations

ConversionRuntimeException (com.salesmanager.shop.store.api.exception.ConversionRuntimeException)29 ConversionException (com.salesmanager.core.business.exception.ConversionException)17 ArrayList (java.util.ArrayList)9 ServiceException (com.salesmanager.core.business.exception.ServiceException)8 Product (com.salesmanager.core.model.catalog.product.Product)7 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)7 Language (com.salesmanager.core.model.reference.language.Language)7 Category (com.salesmanager.core.model.catalog.category.Category)6 ProductDescription (com.salesmanager.core.model.catalog.product.description.ProductDescription)6 ProductAvailability (com.salesmanager.core.model.catalog.product.availability.ProductAvailability)5 ProductImage (com.salesmanager.core.model.catalog.product.image.ProductImage)5 ReadableCategory (com.salesmanager.shop.model.catalog.category.ReadableCategory)5 List (java.util.List)5 Collectors (java.util.stream.Collectors)5 CollectionUtils (org.apache.commons.collections4.CollectionUtils)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5 ProductOptionValue (com.salesmanager.core.model.catalog.product.attribute.ProductOptionValue)4 FinalPrice (com.salesmanager.core.model.catalog.product.price.FinalPrice)4 Mapper (com.salesmanager.shop.mapper.Mapper)4 ProductSpecification (com.salesmanager.shop.model.catalog.product.ProductSpecification)4