Search in sources :

Example 16 with ServiceRuntimeException

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

the class UserFacadeImpl method create.

@Override
public ReadableUser create(PersistableUser user, MerchantStore store) {
    Validate.notNull(store, "MerchantStore must not be null");
    Validate.notNull(user, "User must not be null");
    Validate.notNull(user.getUserName(), "Username must not be null");
    try {
        // check if user exists
        User tempUser = userService.getByUserName(user.getUserName(), store.getCode());
        if (tempUser != null) {
            throw new ServiceRuntimeException("User [" + user.getUserName() + "] already exists for store [" + store.getCode() + "]");
        }
        /**
         * validate password
         */
        if (!securityFacade.matchRawPasswords(user.getPassword(), user.getRepeatPassword())) {
            throw new ServiceRuntimeException("Passwords dos not match, make sure password and repeat password are equals");
        }
        /**
         * Validate new password
         */
        if (!securityFacade.validateUserPassword(user.getPassword())) {
            throw new ServiceRuntimeException("New password does not apply to format policy");
        }
        String newPasswordEncoded = securityFacade.encodePassword(user.getPassword());
        User userModel = new User();
        userModel = converPersistabletUserToUser(store, languageService.defaultLanguage(), userModel, user);
        if (CollectionUtils.isEmpty(userModel.getGroups())) {
            throw new ServiceRuntimeException("No valid group groups associated with user " + user.getUserName());
        }
        userModel.setAdminPassword(newPasswordEncoded);
        userService.saveOrUpdate(userModel);
        // now build returned object
        User createdUser = userService.getById(userModel.getId());
        return convertUserToReadableUser(createdUser.getDefaultLanguage(), createdUser);
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Cannot create user " + user.getUserName() + " for store " + store.getCode(), 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 17 with ServiceRuntimeException

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

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

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

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

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