Search in sources :

Example 76 with ResourceNotFoundException

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

the class ProductOptionFacadeImpl method removeOptionValueImage.

@Override
public void removeOptionValueImage(Long optionValueId, MerchantStore store, Language language) {
    Validate.notNull(optionValueId, "OptionValueId must not be null");
    ProductOptionValue value = productOptionValueService.getById(store, optionValueId);
    if (value == null) {
        throw new ResourceNotFoundException("Product option value [" + optionValueId + "] not found");
    }
    try {
        contentService.removeFile(store.getCode(), FileContentType.PROPERTY, value.getProductOptionValueImage());
        value.setProductOptionValueImage(null);
        productOptionValueService.saveOrUpdate(value);
    } catch (Exception e) {
        throw new ServiceRuntimeException("Exception while removing option value image", e);
    }
    return;
}
Also used : ProductOptionValue(com.salesmanager.core.model.catalog.product.attribute.ProductOptionValue) PersistableProductOptionValue(com.salesmanager.shop.model.catalog.product.attribute.PersistableProductOptionValue) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) NotImplementedException(org.apache.commons.lang3.NotImplementedException) ServiceException(com.salesmanager.core.business.exception.ServiceException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 77 with ResourceNotFoundException

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

the class ProductOptionSetFacadeImpl method get.

@Override
public ReadableProductOptionSet get(Long id, MerchantStore store, Language language) {
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(language, "Language cannot be null");
    ProductOptionSet optionSet = productOptionSetService.getById(store, id, language);
    if (optionSet == null) {
        throw new ResourceNotFoundException("ProductOptionSet not found for id [" + id + "] and store [" + store.getCode() + "]");
    }
    return readableProductOptionSetMapper.convert(optionSet, store, language);
}
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) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException)

Example 78 with ResourceNotFoundException

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

the class ProductOptionSetFacadeImpl method list.

@Override
public List<ReadableProductOptionSet> list(MerchantStore store, Language language, String type) {
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(language, "Language cannot be null");
    Validate.notNull(type, "Product type cannot be null");
    // find product type by id
    ReadableProductType readable = productTypeFacade.get(store, type, language);
    if (readable == null) {
        throw new ResourceNotFoundException("Can't fing product type [" + type + "] fpr merchand [" + store.getCode() + "]");
    }
    List<ProductOptionSet> optionSets = productOptionSetService.getByProductType(readable.getId(), store, language);
    return optionSets.stream().map(opt -> this.convert(opt, store, language)).collect(Collectors.toList());
}
Also used : OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) ProductOptionSetFacade(com.salesmanager.shop.store.controller.product.facade.ProductOptionSetFacade) ProductOptionSet(com.salesmanager.core.model.catalog.product.attribute.ProductOptionSet) ReadableProductType(com.salesmanager.shop.model.catalog.product.type.ReadableProductType) Autowired(org.springframework.beans.factory.annotation.Autowired) Collectors(java.util.stream.Collectors) ProductOptionSetService(com.salesmanager.core.business.services.catalog.product.attribute.ProductOptionSetService) ServiceException(com.salesmanager.core.business.exception.ServiceException) Language(com.salesmanager.core.model.reference.language.Language) List(java.util.List) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) Validate(org.apache.commons.lang3.Validate) ReadableProductOptionSetMapper(com.salesmanager.shop.mapper.catalog.ReadableProductOptionSetMapper) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Service(org.springframework.stereotype.Service) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) PersistableProductOptionSet(com.salesmanager.shop.model.catalog.product.attribute.optionset.PersistableProductOptionSet) PersistableProductOptionSetMapper(com.salesmanager.shop.mapper.catalog.PersistableProductOptionSetMapper) ReadableProductOptionSet(com.salesmanager.shop.model.catalog.product.attribute.optionset.ReadableProductOptionSet) ProductTypeFacade(com.salesmanager.shop.store.controller.product.facade.ProductTypeFacade) 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) ReadableProductType(com.salesmanager.shop.model.catalog.product.type.ReadableProductType) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException)

Example 79 with ResourceNotFoundException

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

the class ProductTypeFacadeImpl method update.

@Override
public void update(PersistableProductType type, Long id, MerchantStore store, Language language) {
    Validate.notNull(type, "ProductType cannot be null");
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(id, "id cannot be empty");
    try {
        ProductType t = productTypeService.getById(id, store, language);
        if (t == null) {
            throw new ResourceNotFoundException("Product type [" + type.getCode() + "] does not exist for store [" + store.getCode() + "]");
        }
        type.setId(t.getId());
        type.setCode(t.getCode());
        ProductType model = persistableProductTypeMapper.merge(type, t, store, language);
        model.setMerchantStore(store);
        productTypeService.saveOrUpdate(model);
    } catch (Exception e) {
        throw new ServiceRuntimeException("An exception occured while saving product type", e);
    }
}
Also used : ReadableProductType(com.salesmanager.shop.model.catalog.product.type.ReadableProductType) ProductType(com.salesmanager.core.model.catalog.product.type.ProductType) PersistableProductType(com.salesmanager.shop.model.catalog.product.type.PersistableProductType) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) ServiceException(com.salesmanager.core.business.exception.ServiceException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 80 with ResourceNotFoundException

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

the class ProductTypeFacadeImpl method get.

@Override
public ReadableProductType get(MerchantStore store, Long id, Language language) {
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(id, "ProductType code cannot be empty");
    try {
        ProductType type = null;
        if (language == null) {
            type = productTypeService.getById(id, store);
        } else {
            type = productTypeService.getById(id, store, language);
        }
        if (type == null) {
            throw new ResourceNotFoundException("Product type [" + id + "] not found for store [" + store.getCode() + "]");
        }
        ReadableProductType readableType = readableProductTypeMapper.convert(type, store, language);
        return readableType;
    } catch (Exception e) {
        throw new ServiceRuntimeException("An exception occured while getting product type [" + id + "] not found for store [" + store.getCode() + "]", e);
    }
}
Also used : ReadableProductType(com.salesmanager.shop.model.catalog.product.type.ReadableProductType) ProductType(com.salesmanager.core.model.catalog.product.type.ProductType) PersistableProductType(com.salesmanager.shop.model.catalog.product.type.PersistableProductType) ReadableProductType(com.salesmanager.shop.model.catalog.product.type.ReadableProductType) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) ServiceException(com.salesmanager.core.business.exception.ServiceException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) 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