Search in sources :

Example 41 with ServiceException

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

the class UserFacadeImpl method resetPassword.

@Override
public void resetPassword(String password, String token, String store) {
    Validate.notNull(token, "ResetPassword token cannot be null");
    Validate.notNull(store, "Store code cannot be null");
    Validate.notNull(password, "New password cannot be null");
    // reverify
    User user = verifyUserLink(token, store);
    user.setAdminPassword(passwordEncoder.encode(password));
    try {
        userService.save(user);
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Error while saving user", 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 42 with ServiceException

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

the class UserFacadeImpl method findByUserName.

@Override
public ReadableUser findByUserName(String userName) {
    Validate.notNull(userName, "userName cannot be null");
    User user;
    try {
        user = userService.getByUserName(userName);
        if (user == null) {
            throw new ResourceNotFoundException("User [" + userName + "] not found");
        }
        return this.convertUserToReadableUser(user.getDefaultLanguage(), user);
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Error while getting user [" + userName + "]", 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)

Example 43 with ServiceException

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

the class AbstractCustomerServices method loadUserByUsername.

public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException, DataAccessException {
    Customer user = null;
    Collection<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
    try {
        LOGGER.debug("Loading user by user id: {}", userName);
        user = customerService.getByNick(userName);
        if (user == null) {
            // return null;
            throw new UsernameNotFoundException("User " + userName + " not found");
        }
        // required to login
        GrantedAuthority role = new SimpleGrantedAuthority(ROLE_PREFIX + Constants.PERMISSION_CUSTOMER_AUTHENTICATED);
        authorities.add(role);
        List<Integer> groupsId = new ArrayList<Integer>();
        List<Group> groups = user.getGroups();
        for (Group group : groups) {
            groupsId.add(group.getId());
        }
        if (CollectionUtils.isNotEmpty(groupsId)) {
            List<Permission> permissions = permissionService.getPermissions(groupsId);
            for (Permission permission : permissions) {
                GrantedAuthority auth = new SimpleGrantedAuthority(permission.getPermissionName());
                authorities.add(auth);
            }
        }
    } catch (ServiceException e) {
        LOGGER.error("Exception while querrying customer", e);
        throw new SecurityDataAccessException("Cannot authenticate customer", e);
    }
    return userDetails(userName, user, authorities);
}
Also used : UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) Group(com.salesmanager.core.model.user.Group) Customer(com.salesmanager.core.model.customer.Customer) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) GrantedAuthority(org.springframework.security.core.GrantedAuthority) SecurityDataAccessException(com.salesmanager.shop.admin.security.SecurityDataAccessException) ArrayList(java.util.ArrayList) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) ServiceException(com.salesmanager.core.business.exception.ServiceException) Permission(com.salesmanager.core.model.user.Permission)

Example 44 with ServiceException

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

the class ProductOptionFacadeImpl method saveOptionValue.

@Override
public ReadableProductOptionValueEntity saveOptionValue(PersistableProductOptionValue optionValue, MerchantStore store, Language language) {
    Validate.notNull(optionValue, "Option value code must not be null");
    Validate.notNull(store, "Store code must not be null");
    ProductOptionValue value = new ProductOptionValue();
    if (optionValue.getId() != null && optionValue.getId().longValue() > 0) {
        value = productOptionValueService.getById(store, optionValue.getId());
        if (value == null) {
            throw new ResourceNotFoundException("ProductOptionValue [" + optionValue.getId() + "] does not exists for store [" + store.getCode() + "]");
        }
    }
    value = persistableOptionValueMapper.merge(optionValue, value, store, language);
    try {
        productOptionValueService.saveOrUpdate(value);
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Exception while saving option value", e);
    }
    ProductOptionValue optValue = productOptionValueService.getById(store, value.getId());
    // convert to readable
    ReadableProductOptionValueEntity readableProductOptionValue = new ReadableProductOptionValueEntity();
    readableProductOptionValue = readableOptionValueMapper.merge(optValue, readableProductOptionValue, store, language);
    return readableProductOptionValue;
}
Also used : ProductOptionValue(com.salesmanager.core.model.catalog.product.attribute.ProductOptionValue) PersistableProductOptionValue(com.salesmanager.shop.model.catalog.product.attribute.PersistableProductOptionValue) ServiceException(com.salesmanager.core.business.exception.ServiceException) ReadableProductOptionValueEntity(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductOptionValueEntity) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 45 with ServiceException

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

the class ProductOptionSetFacadeImpl method delete.

@Override
public void delete(Long id, MerchantStore store) {
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(id, "id cannot be null");
    ProductOptionSet opt = productOptionSetService.getById(id);
    if (opt == null) {
        throw new ResourceNotFoundException("ProductOptionSet not found for id [" + id + "] and store [" + store.getCode() + "]");
    }
    if (!opt.getStore().getCode().equals(store.getCode())) {
        throw new ResourceNotFoundException("ProductOptionSet not found for id [" + id + "] and store [" + store.getCode() + "]");
    }
    try {
        productOptionSetService.delete(opt);
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Exception while deleting ProductOptionSet", e);
    }
}
Also used : ProductOptionSet(com.salesmanager.core.model.catalog.product.attribute.ProductOptionSet) PersistableProductOptionSet(com.salesmanager.shop.model.catalog.product.attribute.optionset.PersistableProductOptionSet) ReadableProductOptionSet(com.salesmanager.shop.model.catalog.product.attribute.optionset.ReadableProductOptionSet) 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