Search in sources :

Example 21 with ConversionException

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

the class PersistableCustomerReviewPopulator method populate.

@Override
public CustomerReview populate(PersistableCustomerReview source, CustomerReview target, MerchantStore store, Language language) throws ConversionException {
    Validate.notNull(customerService, "customerService cannot be null");
    Validate.notNull(languageService, "languageService cannot be null");
    Validate.notNull(source.getRating(), "Rating cannot bot be null");
    try {
        if (target == null) {
            target = new CustomerReview();
        }
        if (source.getDate() == null) {
            String date = DateUtil.formatDate(new Date());
            source.setDate(date);
        }
        target.setReviewDate(DateUtil.getDate(source.getDate()));
        if (source.getId() != null && source.getId().longValue() == 0) {
            source.setId(null);
        } else {
            target.setId(source.getId());
        }
        Customer reviewer = customerService.getById(source.getCustomerId());
        Customer reviewed = customerService.getById(source.getReviewedCustomer());
        target.setReviewRating(source.getRating());
        target.setCustomer(reviewer);
        target.setReviewedCustomer(reviewed);
        Language lang = languageService.getByCode(language.getCode());
        if (lang == null) {
            throw new ConversionException("Invalid language code, use iso codes (en, fr ...)");
        }
        CustomerReviewDescription description = new CustomerReviewDescription();
        description.setDescription(source.getDescription());
        description.setLanguage(lang);
        description.setName("-");
        description.setCustomerReview(target);
        Set<CustomerReviewDescription> descriptions = new HashSet<CustomerReviewDescription>();
        descriptions.add(description);
        target.setDescriptions(descriptions);
    } catch (Exception e) {
        throw new ConversionException("Cannot populate CustomerReview", e);
    }
    return target;
}
Also used : ConversionException(com.salesmanager.core.business.exception.ConversionException) Language(com.salesmanager.core.model.reference.language.Language) Customer(com.salesmanager.core.model.customer.Customer) PersistableCustomerReview(com.salesmanager.shop.model.customer.PersistableCustomerReview) CustomerReview(com.salesmanager.core.model.customer.review.CustomerReview) Date(java.util.Date) ConversionException(com.salesmanager.core.business.exception.ConversionException) CustomerReviewDescription(com.salesmanager.core.model.customer.review.CustomerReviewDescription) HashSet(java.util.HashSet)

Example 22 with ConversionException

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

the class PersistableCategoryPopulator method buildDescription.

private com.salesmanager.core.model.catalog.category.CategoryDescription buildDescription(com.salesmanager.shop.model.catalog.category.CategoryDescription source, com.salesmanager.core.model.catalog.category.CategoryDescription target) throws Exception {
    // com.salesmanager.core.model.catalog.category.CategoryDescription desc = new com.salesmanager.core.model.catalog.category.CategoryDescription();
    target.setCategoryHighlight(source.getHighlights());
    target.setDescription(source.getDescription());
    target.setName(source.getName());
    target.setMetatagDescription(source.getMetaDescription());
    target.setMetatagTitle(source.getTitle());
    target.setSeUrl(source.getFriendlyUrl());
    Language lang = languageService.getByCode(source.getLanguage());
    if (lang == null) {
        throw new ConversionException("Language is null for code " + source.getLanguage() + " use language ISO code [en, fr ...]");
    }
    // description.setId(description.getId());
    target.setLanguage(lang);
    return target;
}
Also used : ConversionException(com.salesmanager.core.business.exception.ConversionException) Language(com.salesmanager.core.model.reference.language.Language)

Example 23 with ConversionException

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

the class PersistableProductOptionValuePopulator method populate.

@Override
public ProductOptionValue populate(PersistableProductOptionValue source, ProductOptionValue target, MerchantStore store, Language language) throws ConversionException {
    Validate.notNull(languageService, "Requires to set LanguageService");
    try {
        target.setMerchantStore(store);
        target.setProductOptionValueSortOrder(source.getOrder());
        target.setCode(source.getCode());
        if (!CollectionUtils.isEmpty(source.getDescriptions())) {
            Set<com.salesmanager.core.model.catalog.product.attribute.ProductOptionValueDescription> descriptions = new HashSet<com.salesmanager.core.model.catalog.product.attribute.ProductOptionValueDescription>();
            for (ProductOptionValueDescription desc : source.getDescriptions()) {
                com.salesmanager.core.model.catalog.product.attribute.ProductOptionValueDescription description = new com.salesmanager.core.model.catalog.product.attribute.ProductOptionValueDescription();
                Language lang = languageService.getByCode(desc.getLanguage());
                if (lang == null) {
                    throw new ConversionException("Language is null for code " + description.getLanguage() + " use language ISO code [en, fr ...]");
                }
                description.setLanguage(lang);
                description.setName(desc.getName());
                description.setTitle(desc.getTitle());
                description.setProductOptionValue(target);
                descriptions.add(description);
            }
            target.setDescriptions(descriptions);
        }
    } catch (Exception e) {
        throw new ConversionException(e);
    }
    return target;
}
Also used : ConversionException(com.salesmanager.core.business.exception.ConversionException) ConversionException(com.salesmanager.core.business.exception.ConversionException) Language(com.salesmanager.core.model.reference.language.Language) ProductOptionValueDescription(com.salesmanager.shop.model.catalog.product.attribute.ProductOptionValueDescription) HashSet(java.util.HashSet)

Example 24 with ConversionException

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

the class CustomerFacadeImpl method updateAddress.

@Override
public void updateAddress(Long userId, MerchantStore merchantStore, Address address, final Language language) throws Exception {
    Customer customerModel = customerService.getById(userId);
    Map<String, Country> countriesMap = countryService.getCountriesMap(language);
    Country country = countriesMap.get(address.getCountry());
    if (customerModel == null) {
        LOG.error("Customer with ID {} does not exists..", userId);
        // throw new CustomerNotFoundException( "customer with given id does not exists" );
        throw new Exception("customer with given id does not exists");
    }
    if (address.isBillingAddress()) {
        LOG.info("updating customer billing address..");
        PersistableCustomerBillingAddressPopulator billingAddressPopulator = new PersistableCustomerBillingAddressPopulator();
        customerModel = billingAddressPopulator.populate(address, customerModel, merchantStore, merchantStore.getDefaultLanguage());
        customerModel.getBilling().setCountry(country);
        if (StringUtils.isNotBlank(address.getZone())) {
            Zone zone = zoneService.getByCode(address.getZone());
            if (zone == null) {
                throw new ConversionException("Unsuported zone code " + address.getZone());
            }
            customerModel.getBilling().setZone(zone);
            customerModel.getBilling().setState(null);
        } else {
            customerModel.getBilling().setZone(null);
        }
    } else {
        LOG.info("updating customer shipping address..");
        PersistableCustomerShippingAddressPopulator shippingAddressPopulator = new PersistableCustomerShippingAddressPopulator();
        customerModel = shippingAddressPopulator.populate(address, customerModel, merchantStore, merchantStore.getDefaultLanguage());
        customerModel.getDelivery().setCountry(country);
        if (StringUtils.isNotBlank(address.getZone())) {
            Zone zone = zoneService.getByCode(address.getZone());
            if (zone == null) {
                throw new ConversionException("Unsuported zone code " + address.getZone());
            }
            customerModel.getDelivery().setZone(zone);
            customerModel.getDelivery().setState(null);
        } else {
            customerModel.getDelivery().setZone(null);
        }
    }
    // same update address with customer model
    this.customerService.saveOrUpdate(customerModel);
}
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) Zone(com.salesmanager.core.model.reference.zone.Zone) Country(com.salesmanager.core.model.reference.country.Country) PersistableCustomerBillingAddressPopulator(com.salesmanager.shop.populator.customer.PersistableCustomerBillingAddressPopulator) 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) PersistableCustomerShippingAddressPopulator(com.salesmanager.shop.populator.customer.PersistableCustomerShippingAddressPopulator)

Example 25 with ConversionException

use of com.salesmanager.core.business.exception.ConversionException 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

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