Search in sources :

Example 36 with ServiceException

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

the class PaymentConfigurationFacadeImpl method configuration.

@Override
public ReadableConfiguration configuration(String module, MerchantStore store) {
    try {
        ReadableConfiguration config = null;
        List<PaymentMethod> methods = paymentService.getAcceptedPaymentMethods(store);
        Optional<ReadableConfiguration> configuration = methods.stream().filter(m -> module.equals(m.getModule().getCode())).map(m -> this.configuration(m.getInformations(), store)).findFirst();
        if (configuration.isPresent()) {
            config = configuration.get();
        }
        return config;
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Error while getting payment configuration [" + module + "]", e);
    }
}
Also used : PersistableConfiguration(com.salesmanager.shop.model.configuration.PersistableConfiguration) Autowired(org.springframework.beans.factory.annotation.Autowired) Collectors(java.util.stream.Collectors) ServiceException(com.salesmanager.core.business.exception.ServiceException) PaymentService(com.salesmanager.core.business.services.payments.PaymentService) PaymentMethod(com.salesmanager.core.model.payments.PaymentMethod) List(java.util.List) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) IntegrationConfiguration(com.salesmanager.core.model.system.IntegrationConfiguration) Service(org.springframework.stereotype.Service) ReadableConfiguration(com.salesmanager.shop.model.configuration.ReadableConfiguration) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) Optional(java.util.Optional) ConfigurationsFacade(com.salesmanager.shop.store.controller.configurations.ConfigurationsFacade) ServiceException(com.salesmanager.core.business.exception.ServiceException) PaymentMethod(com.salesmanager.core.model.payments.PaymentMethod) ReadableConfiguration(com.salesmanager.shop.model.configuration.ReadableConfiguration) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 37 with ServiceException

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

the class PaymentConfigurationFacadeImpl method configurations.

@Override
public List<ReadableConfiguration> configurations(MerchantStore store) {
    try {
        List<PaymentMethod> methods = paymentService.getAcceptedPaymentMethods(store);
        List<ReadableConfiguration> configurations = methods.stream().map(m -> configuration(m.getInformations(), store)).collect(Collectors.toList());
        return configurations;
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Error while getting payment configurations", e);
    }
}
Also used : PersistableConfiguration(com.salesmanager.shop.model.configuration.PersistableConfiguration) Autowired(org.springframework.beans.factory.annotation.Autowired) Collectors(java.util.stream.Collectors) ServiceException(com.salesmanager.core.business.exception.ServiceException) PaymentService(com.salesmanager.core.business.services.payments.PaymentService) PaymentMethod(com.salesmanager.core.model.payments.PaymentMethod) List(java.util.List) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) IntegrationConfiguration(com.salesmanager.core.model.system.IntegrationConfiguration) Service(org.springframework.stereotype.Service) ReadableConfiguration(com.salesmanager.shop.model.configuration.ReadableConfiguration) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) Optional(java.util.Optional) ConfigurationsFacade(com.salesmanager.shop.store.controller.configurations.ConfigurationsFacade) ServiceException(com.salesmanager.core.business.exception.ServiceException) PaymentMethod(com.salesmanager.core.model.payments.PaymentMethod) ReadableConfiguration(com.salesmanager.shop.model.configuration.ReadableConfiguration) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 38 with ServiceException

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

the class ProductCommonFacadeImpl method deleteProduct.

@Override
public void deleteProduct(Long id, MerchantStore store) {
    Validate.notNull(id, "Product id cannot be null");
    Validate.notNull(store, "store cannot be null");
    Product p = productService.getById(id);
    if (p == null) {
        throw new ResourceNotFoundException("Product with id [" + id + " not found");
    }
    if (p.getMerchantStore().getId().intValue() != store.getId().intValue()) {
        throw new ResourceNotFoundException("Product with id [" + id + " not found for store [" + store.getCode() + "]");
    }
    try {
        productService.delete(p);
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Error while deleting ptoduct with id [" + id + "]", e);
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) 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) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 39 with ServiceException

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

the class UserFacadeImpl method delete.

@Override
public void delete(Long id, String merchant) {
    Validate.notNull(id, "User id cannot be null");
    try {
        User user = userService.findByStore(id, merchant);
        if (user == null) {
            throw new ServiceRuntimeException("Cannot find user [" + id + "]");
        }
        // cannot delete superadmin
        if (user.getGroups().contains(Constants.GROUP_SUPERADMIN)) {
            throw new ServiceRuntimeException("Cannot delete superadmin user [" + id + "]");
        }
        userService.delete(user);
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Cannot find user [" + id + "]", e);
    }
}
Also used : ReadableUser(com.salesmanager.shop.model.user.ReadableUser) User(com.salesmanager.core.model.user.User) PersistableUser(com.salesmanager.shop.model.user.PersistableUser) ServiceException(com.salesmanager.core.business.exception.ServiceException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 40 with ServiceException

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

the class UserFacadeImpl method updateEnabled.

@Override
public void updateEnabled(MerchantStore store, PersistableUser user) {
    Validate.notNull(user, "User cannot be null");
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(user.getId(), "User.id cannot be null");
    try {
        User modelUser = userService.findByStore(user.getId(), store.getCode());
        if (modelUser == null) {
            throw new ResourceNotFoundException("User with id [" + user.getId() + "] not found for store [" + store.getCode() + "]");
        }
        modelUser.setActive(user.isActive());
        userService.saveOrUpdate(modelUser);
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Error while updating user enable flag", e);
    }
}
Also used : ReadableUser(com.salesmanager.shop.model.user.ReadableUser) User(com.salesmanager.core.model.user.User) PersistableUser(com.salesmanager.shop.model.user.PersistableUser) ServiceException(com.salesmanager.core.business.exception.ServiceException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Aggregations

ServiceException (com.salesmanager.core.business.exception.ServiceException)230 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)88 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)54 ArrayList (java.util.ArrayList)45 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)44 Language (com.salesmanager.core.model.reference.language.Language)38 List (java.util.List)36 Collectors (java.util.stream.Collectors)30 IOException (java.io.IOException)28 InputStream (java.io.InputStream)27 IntegrationConfiguration (com.salesmanager.core.model.system.IntegrationConfiguration)22 Autowired (org.springframework.beans.factory.annotation.Autowired)21 OutputContentFile (com.salesmanager.core.model.content.OutputContentFile)20 Product (com.salesmanager.core.model.catalog.product.Product)19 HashMap (java.util.HashMap)19 Map (java.util.Map)18 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)17 InputContentFile (com.salesmanager.core.model.content.InputContentFile)17 Optional (java.util.Optional)17 IntegrationModule (com.salesmanager.core.model.system.IntegrationModule)16