Search in sources :

Example 96 with ServiceRuntimeException

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

Example 97 with ServiceRuntimeException

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

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

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

Example 100 with ServiceRuntimeException

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

the class ProductTypeFacadeImpl method getByMerchant.

@Override
public ReadableProductTypeList getByMerchant(MerchantStore store, Language language, int count, int page) {
    Validate.notNull(store, "MerchantStore cannot be null");
    ReadableProductTypeList returnList = new ReadableProductTypeList();
    try {
        Page<ProductType> types = productTypeService.getByMerchant(store, language, page, count);
        if (types != null) {
            returnList.setList(types.getContent().stream().map(t -> readableProductTypeMapper.convert(t, store, language)).collect(Collectors.toList()));
            returnList.setTotalPages(types.getTotalPages());
            returnList.setRecordsTotal(types.getTotalElements());
            returnList.setRecordsFiltered(types.getSize());
        }
        return returnList;
    } catch (Exception e) {
        throw new ServiceRuntimeException("An exception occured while getting product types for merchant[ " + store.getCode() + "]", e);
    }
}
Also used : ReadableProductTypeList(com.salesmanager.shop.model.catalog.product.type.ReadableProductTypeList) 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) 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

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