Search in sources :

Example 16 with ResourceNotFoundException

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

Example 17 with ResourceNotFoundException

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

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

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

the class ProductOptionFacadeImpl method getAttribute.

@Override
public ReadableProductAttributeEntity getAttribute(Long productId, Long attributeId, MerchantStore store, Language language) {
    ProductAttribute attr = productAttributeService.getById(attributeId);
    if (attr == null) {
        throw new ResourceNotFoundException("ProductAttribute not found for [" + attributeId + "] and store [" + store.getCode() + "]");
    }
    if (attr.getProduct().getId().longValue() != productId) {
        throw new ResourceNotFoundException("ProductAttribute not found for [" + attributeId + "] and product [" + productId + "]");
    }
    if (attr.getProduct().getMerchantStore().getId().intValue() != store.getId().intValue()) {
        throw new ResourceNotFoundException("ProductAttribute not found for [" + attributeId + "] and product [" + productId + "] and store [" + store.getCode() + "]");
    }
    ReadableProductAttributeEntity readable = readableProductAttributeMapper.convert(attr, store, language);
    return readable;
}
Also used : ProductAttribute(com.salesmanager.core.model.catalog.product.attribute.ProductAttribute) PersistableProductAttribute(com.salesmanager.shop.model.catalog.product.attribute.PersistableProductAttribute) ReadableProductAttributeEntity(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductAttributeEntity) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException)

Example 20 with ResourceNotFoundException

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

ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)108 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)77 ServiceException (com.salesmanager.core.business.exception.ServiceException)62 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)22 UnauthorizedException (com.salesmanager.shop.store.api.exception.UnauthorizedException)22 Product (com.salesmanager.core.model.catalog.product.Product)21 Language (com.salesmanager.core.model.reference.language.Language)19 List (java.util.List)19 Collectors (java.util.stream.Collectors)19 ApiImplicitParams (io.swagger.annotations.ApiImplicitParams)17 ArrayList (java.util.ArrayList)17 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)16 OperationNotAllowedException (com.salesmanager.shop.store.api.exception.OperationNotAllowedException)15 Autowired (org.springframework.beans.factory.annotation.Autowired)15 ConversionException (com.salesmanager.core.business.exception.ConversionException)13 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)13 Inject (javax.inject.Inject)12 Optional (java.util.Optional)11 Service (org.springframework.stereotype.Service)11 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)11