Search in sources :

Example 71 with ResourceNotFoundException

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

the class ProductInventoryFacadeImpl method get.

@Override
public ReadableInventory get(Long productId, String child, Language language) {
    Product product = getProductById(productId);
    MerchantStore store = getMerchantStore(child);
    if (isStoreParentNotExist(store) || store.getParent().getId().equals(product.getMerchantStore().getId())) {
        throw new ResourceNotFoundException("MerchantStore [" + child + "] is not a store of retailer [" + store.getCode() + "]");
    }
    ProductAvailability availability = productAvailabilityService.getByStore(product, store).orElseThrow(() -> new ResourceNotFoundException("Inventory with not found"));
    return this.readableInventory(availability, store, language);
}
Also used : ProductAvailability(com.salesmanager.core.model.catalog.product.availability.ProductAvailability) Product(com.salesmanager.core.model.catalog.product.Product) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore)

Example 72 with ResourceNotFoundException

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

the class ProductOptionFacadeImpl method getOption.

@Override
public ReadableProductOptionEntity getOption(Long optionId, MerchantStore store, Language language) {
    Validate.notNull(optionId, "Option id cannot be null");
    Validate.notNull(store, "Store cannot be null");
    ProductOption option = productOptionService.getById(store, optionId);
    if (option == null) {
        throw new ResourceNotFoundException("Option id [" + optionId + "] not found");
    }
    return readableMapper.convert(option, store, language);
}
Also used : ProductOption(com.salesmanager.core.model.catalog.product.attribute.ProductOption) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException)

Example 73 with ResourceNotFoundException

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

the class ProductOptionFacadeImpl method deleteAttribute.

@Override
public void deleteAttribute(Long productId, Long attributeId, MerchantStore store) {
    try {
        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() + "]");
        }
        productAttributeService.delete(attr);
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("An exception occured while deleting ProductAttribute [" + attributeId + "]", e);
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) ProductAttribute(com.salesmanager.core.model.catalog.product.attribute.ProductAttribute) PersistableProductAttribute(com.salesmanager.shop.model.catalog.product.attribute.PersistableProductAttribute) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 74 with ResourceNotFoundException

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

the class ProductOptionFacadeImpl method saveOption.

@Override
public ReadableProductOptionEntity saveOption(PersistableProductOptionEntity option, MerchantStore store, Language language) {
    Validate.notNull(option, "ProductOption cannot be null");
    Validate.notNull(store, "MerchantStore cannot be null");
    ProductOption optionModel = new ProductOption();
    if (option.getId() != null && option.getId().longValue() > 0) {
        optionModel = productOptionService.getById(store, option.getId());
        if (optionModel == null) {
            throw new ResourceNotFoundException("ProductOption not found for if [" + option.getId() + "] and store [" + store.getCode() + "]");
        }
    }
    optionModel = persistableeMapper.merge(option, optionModel, store, language);
    try {
        productOptionService.saveOrUpdate(optionModel);
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("An exception occured while saving ProductOption", e);
    }
    optionModel = productOptionService.getById(store, optionModel.getId());
    ReadableProductOptionEntity readable = readableMapper.convert(optionModel, store, language);
    return readable;
}
Also used : ProductOption(com.salesmanager.core.model.catalog.product.attribute.ProductOption) ServiceException(com.salesmanager.core.business.exception.ServiceException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ReadableProductOptionEntity(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductOptionEntity) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 75 with ResourceNotFoundException

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

the class ProductOptionFacadeImpl method addOptionValueImage.

@Override
public void addOptionValueImage(MultipartFile image, Long optionValueId, MerchantStore store, Language language) {
    Validate.notNull(optionValueId, "OptionValueId must not be null");
    Validate.notNull(image, "Image must not be null");
    // get option value
    ProductOptionValue value = productOptionValueService.getById(store, optionValueId);
    if (value == null) {
        throw new ResourceNotFoundException("Product option value [" + optionValueId + "] not found");
    }
    try {
        String imageName = image.getOriginalFilename();
        InputStream inputStream = image.getInputStream();
        InputContentFile cmsContentImage = new InputContentFile();
        cmsContentImage.setFileName(imageName);
        cmsContentImage.setMimeType(image.getContentType());
        cmsContentImage.setFile(inputStream);
        contentService.addOptionImage(store.getCode(), cmsContentImage);
        value.setProductOptionValueImage(imageName);
        productOptionValueService.saveOrUpdate(value);
    } catch (Exception e) {
        throw new ServiceRuntimeException("Exception while adding 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) InputContentFile(com.salesmanager.core.model.content.InputContentFile) InputStream(java.io.InputStream) 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)

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