Search in sources :

Example 36 with ConversionException

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

the class CustomerFacadeImpl method getCustomerDataByUserName.

/**
 * Method used to fetch customer based on the username and storecode. Customer username is unique
 * to each store.
 *
 * @param userName
 * @param store
 * @throws ConversionException
 */
@Override
public CustomerEntity getCustomerDataByUserName(final String userName, final MerchantStore store, final Language language) throws Exception {
    LOG.info("Fetching customer with userName" + userName);
    Customer customer = customerService.getByNick(userName);
    if (customer != null) {
        LOG.info("Found customer, converting to CustomerEntity");
        try {
            CustomerEntityPopulator customerEntityPopulator = new CustomerEntityPopulator();
            // store, language
            return customerEntityPopulator.populate(customer, store, language);
        } catch (ConversionException ex) {
            LOG.error("Error while converting Customer to CustomerEntity", ex);
            throw new Exception(ex);
        }
    }
    return null;
}
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) CustomerEntityPopulator(com.salesmanager.shop.populator.customer.CustomerEntityPopulator) ServiceException(com.salesmanager.core.business.exception.ServiceException) UserAlreadyExistException(com.salesmanager.shop.model.customer.UserAlreadyExistException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ConversionException(com.salesmanager.core.business.exception.ConversionException)

Example 37 with ConversionException

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

the class CustomerFacadeImpl method convertPersistableCustomerToCustomer.

private Customer convertPersistableCustomerToCustomer(PersistableCustomer customer, MerchantStore store) {
    Customer cust = new Customer();
    try {
        customerPopulator.populate(customer, cust, store, store.getDefaultLanguage());
    } catch (ConversionException e) {
        throw new ConversionRuntimeException(e);
    }
    List<Group> groups = getListOfGroups(GroupType.CUSTOMER);
    cust.setGroups(groups);
    String password = customer.getPassword();
    if (StringUtils.isBlank(password)) {
        password = new String(UUID.generateRandomBytes());
        customer.setPassword(password);
    }
    return cust;
}
Also used : ConversionException(com.salesmanager.core.business.exception.ConversionException) Group(com.salesmanager.core.model.user.Group) ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer) Customer(com.salesmanager.core.model.customer.Customer) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException)

Example 38 with ConversionException

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

the class SearchFacadeImpl method convertProductToReadableProduct.

private ReadableProduct convertProductToReadableProduct(Product product, MerchantStore merchantStore, Language language) {
    ReadableProductPopulator populator = new ReadableProductPopulator();
    populator.setPricingService(pricingService);
    populator.setimageUtils(imageUtils);
    try {
        return populator.populate(product, new ReadableProduct(), merchantStore, language);
    } catch (ConversionException e) {
        throw new ConversionRuntimeException(e);
    }
}
Also used : ConversionException(com.salesmanager.core.business.exception.ConversionException) ReadableProductPopulator(com.salesmanager.shop.populator.catalog.ReadableProductPopulator) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException)

Example 39 with ConversionException

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

the class ShippingFacadeImpl method shipToCountry.

@Override
public List<ReadableCountry> shipToCountry(MerchantStore store, Language language) {
    try {
        List<Country> countries = shippingService.getShipToCountryList(store, language);
        List<ReadableCountry> countryList = new ArrayList<ReadableCountry>();
        if (!CollectionUtils.isEmpty(countries)) {
            countryList = countries.stream().map(c -> {
                try {
                    return convert(c, store, language);
                } catch (ConversionException e) {
                    throw new ConversionRuntimeException("Error converting Country to readable country,e");
                }
            }).sorted(Comparator.comparing(ReadableCountry::getName)).collect(Collectors.toList());
        }
        return countryList;
    } catch (Exception e) {
        throw new ServiceRuntimeException("Error getting shipping country", e);
    }
}
Also used : ExpeditionConfiguration(com.salesmanager.shop.model.shipping.ExpeditionConfiguration) ShippingOrigin(com.salesmanager.core.model.shipping.ShippingOrigin) ShippingType(com.salesmanager.core.model.shipping.ShippingType) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Zone(com.salesmanager.core.model.reference.zone.Zone) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) ServiceException(com.salesmanager.core.business.exception.ServiceException) ZoneService(com.salesmanager.core.business.services.reference.zone.ZoneService) Language(com.salesmanager.core.model.reference.language.Language) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) ShippingOriginService(com.salesmanager.core.business.services.shipping.ShippingOriginService) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Service(org.springframework.stereotype.Service) ReadableCountryPopulator(com.salesmanager.shop.populator.references.ReadableCountryPopulator) ShippingService(com.salesmanager.core.business.services.shipping.ShippingService) ReadableCountry(com.salesmanager.shop.model.references.ReadableCountry) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) CountryService(com.salesmanager.core.business.services.reference.country.CountryService) Validate(org.jsoup.helper.Validate) Logger(org.slf4j.Logger) Country(com.salesmanager.core.model.reference.country.Country) Collectors(java.util.stream.Collectors) List(java.util.List) ShippingPackageType(com.salesmanager.core.model.shipping.ShippingPackageType) PackageDetails(com.salesmanager.core.model.shipping.PackageDetails) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ConversionException(com.salesmanager.core.business.exception.ConversionException) PersistableAddress(com.salesmanager.shop.model.references.PersistableAddress) ReadableAddress(com.salesmanager.shop.model.references.ReadableAddress) ShippingConfiguration(com.salesmanager.core.model.shipping.ShippingConfiguration) Comparator(java.util.Comparator) ConversionException(com.salesmanager.core.business.exception.ConversionException) ArrayList(java.util.ArrayList) ReadableCountry(com.salesmanager.shop.model.references.ReadableCountry) Country(com.salesmanager.core.model.reference.country.Country) ReadableCountry(com.salesmanager.shop.model.references.ReadableCountry) ServiceException(com.salesmanager.core.business.exception.ServiceException) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ConversionException(com.salesmanager.core.business.exception.ConversionException) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 40 with ConversionException

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

the class ProductCommonFacadeImpl method getProduct.

@Override
public ReadableProduct getProduct(MerchantStore store, Long id, Language language) {
    Product product = productService.findOne(id, store);
    if (product == null) {
        throw new ResourceNotFoundException("Product [" + id + "] not found");
    }
    if (product.getMerchantStore().getId() != store.getId()) {
        throw new ResourceNotFoundException("Product [" + id + "] not found for store [" + store.getId() + "]");
    }
    ReadableProduct readableProduct = new ReadableProduct();
    ReadableProductPopulator populator = new ReadableProductPopulator();
    populator.setPricingService(pricingService);
    populator.setimageUtils(imageUtils);
    try {
        readableProduct = populator.populate(product, readableProduct, store, language);
    } catch (ConversionException e) {
        throw new ConversionRuntimeException("Error converting product [" + id + "]", e);
    }
    return readableProduct;
}
Also used : ConversionException(com.salesmanager.core.business.exception.ConversionException) ReadableProductPopulator(com.salesmanager.shop.populator.catalog.ReadableProductPopulator) PersistableProduct(com.salesmanager.shop.model.catalog.product.PersistableProduct) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) Product(com.salesmanager.core.model.catalog.product.Product) LightPersistableProduct(com.salesmanager.shop.model.catalog.product.LightPersistableProduct) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException)

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