Search in sources :

Example 26 with ConversionException

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

the class CustomerFacadeImpl method updateAuthCustomer.

private PersistableCustomer updateAuthCustomer(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);
    }
    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)

Example 27 with ConversionException

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

the class OrderFacadeImpl method populateOrderList.

private com.salesmanager.shop.model.order.v0.ReadableOrderList populateOrderList(final OrderList orderList, final MerchantStore store, final Language language) {
    List<Order> orders = orderList.getOrders();
    com.salesmanager.shop.model.order.v0.ReadableOrderList returnList = new com.salesmanager.shop.model.order.v0.ReadableOrderList();
    if (CollectionUtils.isEmpty(orders)) {
        LOGGER.info("Order list if empty..Returning empty list");
        returnList.setRecordsTotal(0);
        // returnList.setMessage("No results for store code " + store);
        return returnList;
    }
    // ReadableOrderPopulator orderPopulator = new ReadableOrderPopulator();
    Locale locale = LocaleUtils.getLocale(language);
    readableOrderPopulator.setLocale(locale);
    List<com.salesmanager.shop.model.order.v0.ReadableOrder> readableOrders = new ArrayList<com.salesmanager.shop.model.order.v0.ReadableOrder>();
    for (Order order : orders) {
        com.salesmanager.shop.model.order.v0.ReadableOrder readableOrder = new com.salesmanager.shop.model.order.v0.ReadableOrder();
        try {
            readableOrderPopulator.populate(order, readableOrder, store, language);
            setOrderProductList(order, locale, store, language, readableOrder);
        } catch (ConversionException ex) {
            LOGGER.error("Error while converting order to order data", ex);
        }
        readableOrders.add(readableOrder);
    }
    returnList.setOrders(readableOrders);
    return returnList;
}
Also used : ShopOrder(com.salesmanager.shop.model.order.ShopOrder) Order(com.salesmanager.core.model.order.Order) Locale(java.util.Locale) ConversionException(com.salesmanager.core.business.exception.ConversionException) ArrayList(java.util.ArrayList)

Example 28 with ConversionException

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

the class SearchFacadeImpl method convertCategoryToReadableCategory.

private ReadableCategory convertCategoryToReadableCategory(MerchantStore merchantStore, Language language, Map<String, Long> productCategoryCount, Category category) {
    ReadableCategoryPopulator populator = new ReadableCategoryPopulator();
    try {
        ReadableCategory categoryProxy = populator.populate(category, new ReadableCategory(), merchantStore, language);
        Long total = productCategoryCount.get(categoryProxy.getCode());
        if (total != null) {
            categoryProxy.setProductCount(total.intValue());
        }
        return categoryProxy;
    } catch (ConversionException e) {
        throw new ConversionRuntimeException(e);
    }
}
Also used : ConversionException(com.salesmanager.core.business.exception.ConversionException) ReadableCategory(com.salesmanager.shop.model.catalog.category.ReadableCategory) ReadableCategoryPopulator(com.salesmanager.shop.populator.catalog.ReadableCategoryPopulator) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException)

Example 29 with ConversionException

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

the class ReadableTransactionPopulator method populate.

@Override
public ReadableTransaction populate(Transaction source, ReadableTransaction 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 ReadableTransaction();
    }
    try {
        target.setAmount(pricingService.getDisplayAmount(source.getAmount(), store));
        target.setDetails(source.getDetails());
        target.setPaymentType(source.getPaymentType());
        target.setTransactionType(source.getTransactionType());
        target.setTransactionDate(DateUtil.formatDate(source.getTransactionDate()));
        target.setId(source.getId());
        if (source.getOrder() != null) {
            target.setOrderId(source.getOrder().getId());
        }
        return target;
    } catch (Exception e) {
        throw new ConversionException(e);
    }
}
Also used : ConversionException(com.salesmanager.core.business.exception.ConversionException) ReadableTransaction(com.salesmanager.shop.model.order.transaction.ReadableTransaction) ConversionException(com.salesmanager.core.business.exception.ConversionException)

Example 30 with ConversionException

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

the class PersistableMerchantStorePopulator method populate.

@Override
public MerchantStore populate(PersistableMerchantStore source, MerchantStore target, MerchantStore store, Language language) throws ConversionException {
    Validate.notNull(source, "PersistableMerchantStore mst not be null");
    if (target == null) {
        target = new MerchantStore();
    }
    target.setCode(source.getCode());
    if (source.getId() != 0) {
        target.setId(source.getId());
    }
    if (store.getStoreLogo() != null) {
        target.setStoreLogo(store.getStoreLogo());
    }
    if (!StringUtils.isEmpty(source.getInBusinessSince())) {
        try {
            Date dt = DateUtil.getDate(source.getInBusinessSince());
            target.setInBusinessSince(dt);
        } catch (Exception e) {
            throw new ConversionException("Cannot parse date [" + source.getInBusinessSince() + "]", e);
        }
    }
    if (source.getDimension() != null) {
        target.setSeizeunitcode(source.getDimension().name());
    }
    if (source.getWeight() != null) {
        target.setWeightunitcode(source.getWeight().name());
    }
    target.setCurrencyFormatNational(source.isCurrencyFormatNational());
    target.setStorename(source.getName());
    target.setStorephone(source.getPhone());
    target.setStoreEmailAddress(source.getEmail());
    target.setUseCache(source.isUseCache());
    target.setRetailer(source.isRetailer());
    // get parent store
    if (!StringUtils.isBlank(source.getRetailerStore())) {
        if (source.getRetailerStore().equals(source.getCode())) {
            throw new ConversionException("Parent store [" + source.getRetailerStore() + "] cannot be parent of current store");
        }
        try {
            MerchantStore parent = merchantStoreService.getByCode(source.getRetailerStore());
            if (parent == null) {
                throw new ConversionException("Parent store [" + source.getRetailerStore() + "] does not exist");
            }
            target.setParent(parent);
        } catch (ServiceException e) {
            throw new ConversionException(e);
        }
    }
    try {
        if (!StringUtils.isEmpty(source.getDefaultLanguage())) {
            Language l = languageService.getByCode(source.getDefaultLanguage());
            target.setDefaultLanguage(l);
        }
        if (!StringUtils.isEmpty(source.getCurrency())) {
            Currency c = currencyService.getByCode(source.getCurrency());
            target.setCurrency(c);
        } else {
            target.setCurrency(currencyService.getByCode(Constants.DEFAULT_CURRENCY.getCurrencyCode()));
        }
        List<String> languages = source.getSupportedLanguages();
        if (!CollectionUtils.isEmpty(languages)) {
            for (String lang : languages) {
                Language ll = languageService.getByCode(lang);
                target.getLanguages().add(ll);
            }
        }
    } catch (Exception e) {
        throw new ConversionException(e);
    }
    // address population
    PersistableAddress address = source.getAddress();
    if (address != null) {
        Country country;
        try {
            country = countryService.getByCode(address.getCountry());
            Zone zone = zoneService.getByCode(address.getStateProvince());
            if (zone != null) {
                target.setZone(zone);
            } else {
                target.setStorestateprovince(address.getStateProvince());
            }
            target.setStoreaddress(address.getAddress());
            target.setStorecity(address.getCity());
            target.setCountry(country);
            target.setStorepostalcode(address.getPostalCode());
        } catch (ServiceException e) {
            throw new ConversionException(e);
        }
    }
    if (StringUtils.isNotEmpty(source.getTemplate()))
        target.setStoreTemplate(source.getTemplate());
    return target;
}
Also used : ConversionException(com.salesmanager.core.business.exception.ConversionException) ServiceException(com.salesmanager.core.business.exception.ServiceException) Language(com.salesmanager.core.model.reference.language.Language) Zone(com.salesmanager.core.model.reference.zone.Zone) Currency(com.salesmanager.core.model.reference.currency.Currency) PersistableAddress(com.salesmanager.shop.model.references.PersistableAddress) Country(com.salesmanager.core.model.reference.country.Country) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) PersistableMerchantStore(com.salesmanager.shop.model.store.PersistableMerchantStore) Date(java.util.Date) ServiceException(com.salesmanager.core.business.exception.ServiceException) 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