Search in sources :

Example 91 with ServiceRuntimeException

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

the class ProductInstanceGroupFacadeImpl method removeImage.

@Override
public void removeImage(Long imageId, Long productInstanceGroupId, MerchantStore store) {
    Validate.notNull(productInstanceGroupId, "productInstanceGroupId must not be null");
    Validate.notNull(store, "MerchantStore must not be null");
    ProductInstanceImage image = productInstanceImageService.getById(imageId);
    if (image == null) {
        throw new ResourceNotFoundException("ProductInstanceImage [" + imageId + "] was not found");
    }
    ProductInstanceGroup group = this.group(productInstanceGroupId, store);
    try {
        contentService.removeFile(Constants.SLASH + store.getCode() + Constants.SLASH + productInstanceGroupId, FileContentType.INSTANCE, image.getProductImage());
        group.getImages().removeIf(i -> (i.getId() == image.getId()));
        // update productinstanceroup
        productInstanceGroupService.update(group);
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("An exception occured while removing instance image [" + imageId + "]", e);
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) ProductInstanceImage(com.salesmanager.core.model.catalog.product.instance.ProductInstanceImage) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ProductInstanceGroup(com.salesmanager.core.model.catalog.product.instance.ProductInstanceGroup) ReadableProductInstanceGroup(com.salesmanager.shop.model.catalog.product.product.instanceGroup.ReadableProductInstanceGroup) PersistableProductInstanceGroup(com.salesmanager.shop.model.catalog.product.product.instanceGroup.PersistableProductInstanceGroup) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 92 with ServiceRuntimeException

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

the class ProductOptionFacadeImpl method createAttributes.

@Override
public List<CodeEntity> createAttributes(List<PersistableProductAttribute> attributes, Long productId, MerchantStore store) {
    Validate.notNull(productId, "Product id must not be null");
    Validate.notNull(store, "Merchant cannot be null");
    // convert to model
    List<ProductAttribute> modelAttributes = attributes.stream().map(attr -> persistableProductAttributeMapper.convert(attr, store, null)).collect(Collectors.toList());
    try {
        productAttributeService.saveAll(modelAttributes);
        // save to a product
        Product product = this.product(productId, store);
        product.getAttributes().addAll(modelAttributes);
        productService.save(product);
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Exception while saving product with attributes", e);
    }
    return modelAttributes.stream().map(e -> codeEntity(e)).collect(Collectors.toList());
}
Also used : NotImplementedException(org.apache.commons.lang3.NotImplementedException) ProductService(com.salesmanager.core.business.services.catalog.product.ProductService) ReadableProductAttributeList(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductAttributeList) ReadableProductOptionValueEntity(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductOptionValueEntity) Autowired(org.springframework.beans.factory.annotation.Autowired) ProductOptionValueService(com.salesmanager.core.business.services.catalog.product.attribute.ProductOptionValueService) ServiceException(com.salesmanager.core.business.exception.ServiceException) Language(com.salesmanager.core.model.reference.language.Language) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ReadableProductOptionList(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductOptionList) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Service(org.springframework.stereotype.Service) ReadableProductAttributeMapper(com.salesmanager.shop.mapper.catalog.ReadableProductAttributeMapper) ProductOption(com.salesmanager.core.model.catalog.product.attribute.ProductOption) FileContentType(com.salesmanager.core.model.content.FileContentType) ProductAttributeService(com.salesmanager.core.business.services.catalog.product.attribute.ProductAttributeService) PersistableProductAttributeMapper(com.salesmanager.shop.mapper.catalog.PersistableProductAttributeMapper) ProductOptionFacade(com.salesmanager.shop.store.controller.product.facade.ProductOptionFacade) ProductAttribute(com.salesmanager.core.model.catalog.product.attribute.ProductAttribute) Validate(org.jsoup.helper.Validate) Product(com.salesmanager.core.model.catalog.product.Product) ReadableProductOptionMapper(com.salesmanager.shop.mapper.catalog.ReadableProductOptionMapper) ProductOptionValue(com.salesmanager.core.model.catalog.product.attribute.ProductOptionValue) PersistableProductOptionEntity(com.salesmanager.shop.model.catalog.product.attribute.api.PersistableProductOptionEntity) CodeEntity(com.salesmanager.shop.model.entity.CodeEntity) PersistableProductAttribute(com.salesmanager.shop.model.catalog.product.attribute.PersistableProductAttribute) PersistableProductOptionValue(com.salesmanager.shop.model.catalog.product.attribute.PersistableProductOptionValue) Page(org.springframework.data.domain.Page) InputContentFile(com.salesmanager.core.model.content.InputContentFile) Collectors(java.util.stream.Collectors) ContentService(com.salesmanager.core.business.services.content.ContentService) ReadableProductOptionValueList(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductOptionValueList) List(java.util.List) PersistableProductOptionMapper(com.salesmanager.shop.mapper.catalog.PersistableProductOptionMapper) ReadableProductOptionValueMapper(com.salesmanager.shop.mapper.catalog.ReadableProductOptionValueMapper) ReadableProductAttributeEntity(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductAttributeEntity) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) MultipartFile(org.springframework.web.multipart.MultipartFile) ProductOptionService(com.salesmanager.core.business.services.catalog.product.attribute.ProductOptionService) PersistableProductOptionValueMapper(com.salesmanager.shop.mapper.catalog.PersistableProductOptionValueMapper) ReadableProductOptionEntity(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductOptionEntity) InputStream(java.io.InputStream) ServiceException(com.salesmanager.core.business.exception.ServiceException) Product(com.salesmanager.core.model.catalog.product.Product) ProductAttribute(com.salesmanager.core.model.catalog.product.attribute.ProductAttribute) PersistableProductAttribute(com.salesmanager.shop.model.catalog.product.attribute.PersistableProductAttribute) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 93 with ServiceRuntimeException

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

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

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

the class ProductOptionFacadeImpl method getAttributesList.

@Override
public ReadableProductAttributeList getAttributesList(Long productId, MerchantStore store, Language language, int page, int count) {
    try {
        Product product = this.product(productId, store);
        ReadableProductAttributeList attrList = new ReadableProductAttributeList();
        Page<ProductAttribute> attr = null;
        if (language != null) {
            // all entry
            // attributes = productAttributeService.getByProductId(store, product, language);
            attr = productAttributeService.getByProductId(store, product, language, page, count);
            attrList.setRecordsTotal(attr.getTotalElements());
            attrList.setNumber(attr.getSize());
            attrList.setTotalPages(attr.getTotalPages());
        } else {
            attr = productAttributeService.getByProductId(store, product, page, count);
            attrList.setRecordsTotal(attr.getTotalElements());
            attrList.setNumber(attr.getSize());
            attrList.setTotalPages(attr.getTotalPages());
        }
        List<ReadableProductAttributeEntity> values = attr.getContent().stream().map(attribute -> readableProductAttributeMapper.convert(attribute, store, language)).collect(Collectors.toList());
        attrList.setAttributes(values);
        return attrList;
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Error while getting attributes", e);
    }
}
Also used : NotImplementedException(org.apache.commons.lang3.NotImplementedException) ProductService(com.salesmanager.core.business.services.catalog.product.ProductService) ReadableProductAttributeList(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductAttributeList) ReadableProductOptionValueEntity(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductOptionValueEntity) Autowired(org.springframework.beans.factory.annotation.Autowired) ProductOptionValueService(com.salesmanager.core.business.services.catalog.product.attribute.ProductOptionValueService) ServiceException(com.salesmanager.core.business.exception.ServiceException) Language(com.salesmanager.core.model.reference.language.Language) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ReadableProductOptionList(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductOptionList) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Service(org.springframework.stereotype.Service) ReadableProductAttributeMapper(com.salesmanager.shop.mapper.catalog.ReadableProductAttributeMapper) ProductOption(com.salesmanager.core.model.catalog.product.attribute.ProductOption) FileContentType(com.salesmanager.core.model.content.FileContentType) ProductAttributeService(com.salesmanager.core.business.services.catalog.product.attribute.ProductAttributeService) PersistableProductAttributeMapper(com.salesmanager.shop.mapper.catalog.PersistableProductAttributeMapper) ProductOptionFacade(com.salesmanager.shop.store.controller.product.facade.ProductOptionFacade) ProductAttribute(com.salesmanager.core.model.catalog.product.attribute.ProductAttribute) Validate(org.jsoup.helper.Validate) Product(com.salesmanager.core.model.catalog.product.Product) ReadableProductOptionMapper(com.salesmanager.shop.mapper.catalog.ReadableProductOptionMapper) ProductOptionValue(com.salesmanager.core.model.catalog.product.attribute.ProductOptionValue) PersistableProductOptionEntity(com.salesmanager.shop.model.catalog.product.attribute.api.PersistableProductOptionEntity) CodeEntity(com.salesmanager.shop.model.entity.CodeEntity) PersistableProductAttribute(com.salesmanager.shop.model.catalog.product.attribute.PersistableProductAttribute) PersistableProductOptionValue(com.salesmanager.shop.model.catalog.product.attribute.PersistableProductOptionValue) Page(org.springframework.data.domain.Page) InputContentFile(com.salesmanager.core.model.content.InputContentFile) Collectors(java.util.stream.Collectors) ContentService(com.salesmanager.core.business.services.content.ContentService) ReadableProductOptionValueList(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductOptionValueList) List(java.util.List) PersistableProductOptionMapper(com.salesmanager.shop.mapper.catalog.PersistableProductOptionMapper) ReadableProductOptionValueMapper(com.salesmanager.shop.mapper.catalog.ReadableProductOptionValueMapper) ReadableProductAttributeEntity(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductAttributeEntity) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) MultipartFile(org.springframework.web.multipart.MultipartFile) ProductOptionService(com.salesmanager.core.business.services.catalog.product.attribute.ProductOptionService) PersistableProductOptionValueMapper(com.salesmanager.shop.mapper.catalog.PersistableProductOptionValueMapper) ReadableProductOptionEntity(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductOptionEntity) InputStream(java.io.InputStream) ServiceException(com.salesmanager.core.business.exception.ServiceException) ReadableProductAttributeList(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductAttributeList) Product(com.salesmanager.core.model.catalog.product.Product) 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) 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