Search in sources :

Example 56 with ServiceRuntimeException

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

the class CustomerFacadeImpl method create.

@Override
public ReadableCustomer create(PersistableCustomer customer, MerchantStore store, Language language) {
    Validate.notNull(customer, "Customer cannot be null");
    Validate.notNull(customer.getEmailAddress(), "Customer email address is required");
    // set customer user name
    customer.setUserName(customer.getEmailAddress());
    if (userExist(customer.getUserName())) {
        throw new ServiceRuntimeException("User already exist");
    }
    // end user exists
    Customer customerToPopulate = convertPersistableCustomerToCustomer(customer, store);
    try {
        setCustomerModelDefaultProperties(customerToPopulate, store);
    } catch (Exception e) {
        throw new ServiceRuntimeException("Cannot set default customer properties", e);
    }
    saveCustomer(customerToPopulate);
    customer.setId(customerToPopulate.getId());
    notifyNewCustomer(customer, store, customerToPopulate.getDefaultLanguage());
    // convert to readable
    return convertCustomerToReadableCustomer(customerToPopulate, store, language);
}
Also used : ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer) Customer(com.salesmanager.core.model.customer.Customer) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer) 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) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 57 with ServiceRuntimeException

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

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

the class CustomerFacadeImpl method changePassword.

@Override
public void changePassword(Customer customer, String newPassword) {
    String encoded = passwordEncoder.encode(newPassword);
    customer.setPassword(encoded);
    try {
        customerService.update(customer);
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Exception while changing password", e);
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 59 with ServiceRuntimeException

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

the class ShippingFacadeImpl method getDbConfig.

private ShippingConfiguration getDbConfig(MerchantStore store) {
    try {
        // get original configuration
        ShippingConfiguration config = shippingService.getShippingConfiguration(store);
        if (config == null) {
            config = new ShippingConfiguration();
            config.setShippingType(ShippingType.INTERNATIONAL);
        }
        return config;
    } catch (ServiceException e) {
        LOGGER.error("Error while getting expedition configuration", e);
        throw new ServiceRuntimeException("Error while getting Expedition configuration for store[" + store.getCode() + "]", e);
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) ShippingConfiguration(com.salesmanager.core.model.shipping.ShippingConfiguration) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 60 with ServiceRuntimeException

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

the class ShippingFacadeImpl method getExpeditionConfiguration.

@Override
public ExpeditionConfiguration getExpeditionConfiguration(MerchantStore store, Language language) {
    ExpeditionConfiguration expeditionConfiguration = new ExpeditionConfiguration();
    try {
        ShippingConfiguration config = getDbConfig(store);
        if (config != null) {
            expeditionConfiguration.setIternationalShipping(config.getShipType() != null && config.getShipType().equals(ShippingType.INTERNATIONAL.name()) ? true : false);
            expeditionConfiguration.setTaxOnShipping(config.isTaxOnShipping());
        }
        List<String> countries = shippingService.getSupportedCountries(store);
        if (!CollectionUtils.isEmpty(countries)) {
            List<String> countryCode = countries.stream().sorted(Comparator.comparing(n -> n.toString())).collect(Collectors.toList());
            expeditionConfiguration.setShipToCountry(countryCode);
        }
    } catch (ServiceException e) {
        LOGGER.error("Error while getting expedition configuration", e);
        throw new ServiceRuntimeException("Error while getting Expedition configuration for store[" + store.getCode() + "]", e);
    }
    return expeditionConfiguration;
}
Also used : ExpeditionConfiguration(com.salesmanager.shop.model.shipping.ExpeditionConfiguration) ServiceException(com.salesmanager.core.business.exception.ServiceException) ShippingConfiguration(com.salesmanager.core.model.shipping.ShippingConfiguration) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Aggregations

ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)146 ServiceException (com.salesmanager.core.business.exception.ServiceException)123 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)100 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)37 OperationNotAllowedException (com.salesmanager.shop.store.api.exception.OperationNotAllowedException)31 List (java.util.List)31 Collectors (java.util.stream.Collectors)31 Language (com.salesmanager.core.model.reference.language.Language)30 UnauthorizedException (com.salesmanager.shop.store.api.exception.UnauthorizedException)27 ArrayList (java.util.ArrayList)27 ConversionException (com.salesmanager.core.business.exception.ConversionException)26 Autowired (org.springframework.beans.factory.annotation.Autowired)21 Service (org.springframework.stereotype.Service)20 Optional (java.util.Optional)19 Product (com.salesmanager.core.model.catalog.product.Product)17 IOException (java.io.IOException)17 Logger (org.slf4j.Logger)17 LoggerFactory (org.slf4j.LoggerFactory)17 Inject (javax.inject.Inject)16 Page (org.springframework.data.domain.Page)16