Search in sources :

Example 1 with ServiceRuntimeException

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

the class ProductFacadeImpl method deleteProduct.

@Override
public void deleteProduct(Long id, MerchantStore store) {
    Validate.notNull(id, "Product id cannot be null");
    Validate.notNull(store, "store cannot be null");
    Product p = productService.getById(id);
    if (p == null) {
        throw new ResourceNotFoundException("Product with id [" + id + " not found");
    }
    if (p.getMerchantStore().getId().intValue() != store.getId().intValue()) {
        throw new ResourceNotFoundException("Product with id [" + id + " not found for store [" + store.getCode() + "]");
    }
    try {
        productService.delete(p);
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Error while deleting ptoduct with id [" + id + "]", e);
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) PersistableProduct(com.salesmanager.shop.model.catalog.product.PersistableProduct) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) Product(com.salesmanager.core.model.catalog.product.Product) LightPersistableProduct(com.salesmanager.shop.model.catalog.product.LightPersistableProduct) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 2 with ServiceRuntimeException

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

the class ProductInstanceFacadeImpl method update.

@Override
public void update(Long instanceId, PersistableProductInstance productInstance, Long productId, MerchantStore store, Language language) {
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(productInstance, "ProductInstance cannot be null");
    Validate.notNull(productId, "Product id cannot be null");
    Validate.notNull(instanceId, "Product instance id cannot be null");
    Optional<ProductInstance> instanceModel = this.getProductInstance(instanceId, productId, store);
    if (instanceModel.isEmpty()) {
        throw new ResourceNotFoundException("ProductInstance with id [" + instanceId + "] not found for store [" + store.getCode() + "] and productId [" + productId + "]");
    }
    ProductInstance mergedModel = persistableProductInstanceMapper.merge(productInstance, instanceModel.get(), store, language);
    try {
        productInstanceService.save(mergedModel);
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Cannot save product instance for store [" + store.getCode() + "] and productId [" + productId + "]", e);
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ReadableProductInstance(com.salesmanager.shop.model.catalog.product.product.instance.ReadableProductInstance) ProductInstance(com.salesmanager.core.model.catalog.product.instance.ProductInstance) PersistableProductInstance(com.salesmanager.shop.model.catalog.product.product.instance.PersistableProductInstance) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 3 with ServiceRuntimeException

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

the class ProductInstanceFacadeImpl method delete.

@Override
public void delete(Long productInstance, Long productId, MerchantStore store) {
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(productInstance, "ProductInstance id cannot be null");
    Validate.notNull(productId, "Product id cannot be null");
    Optional<ProductInstance> instanceModel = this.getProductInstance(productInstance, productId, store);
    if (instanceModel.isEmpty()) {
        throw new ResourceNotFoundException("ProductInstance with id [" + productInstance + "] not found for store [" + store.getCode() + "] and productId [" + productId + "]");
    }
    try {
        productInstanceService.delete(instanceModel.get());
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Cannot delete product instance [" + productInstance + "]  for store [" + store.getCode() + "] and productId [" + productId + "]", e);
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ReadableProductInstance(com.salesmanager.shop.model.catalog.product.product.instance.ReadableProductInstance) ProductInstance(com.salesmanager.core.model.catalog.product.instance.ProductInstance) PersistableProductInstance(com.salesmanager.shop.model.catalog.product.product.instance.PersistableProductInstance) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 4 with ServiceRuntimeException

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

the class ProductInstanceGroupFacadeImpl method update.

@Override
public void update(Long productInstanceGroup, PersistableProductInstanceGroup instance, MerchantStore store, Language language) {
    ProductInstanceGroup group = this.group(productInstanceGroup, store);
    instance.setId(productInstanceGroup);
    group = persistableProductIntanceGroupMapper.merge(instance, group, store, language);
    try {
        productInstanceGroupService.saveOrUpdate(group);
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Cannot save product instance group [" + productInstanceGroup + "] for store [" + store.getCode() + "]");
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) 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 5 with ServiceRuntimeException

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

the class ProductInstanceGroupFacadeImpl method addImage.

@Override
public void addImage(MultipartFile image, Long productOptionGroupId, MerchantStore store, Language language) {
    Validate.notNull(productOptionGroupId, "productOptionGroupId must not be null");
    Validate.notNull(image, "Image must not be null");
    Validate.notNull(store, "MerchantStore must not be null");
    // get option group
    ProductInstanceGroup group = this.group(productOptionGroupId, store);
    try {
        ProductInstanceImage instanceImage = new ProductInstanceImage();
        instanceImage.setProductImage(image.getOriginalFilename());
        instanceImage.setProductInstanceGroup(group);
        String imageName = image.getOriginalFilename();
        InputStream inputStream = image.getInputStream();
        InputContentFile cmsContentImage = new InputContentFile();
        cmsContentImage.setFileName(imageName);
        cmsContentImage.setMimeType(image.getContentType());
        cmsContentImage.setFile(inputStream);
        cmsContentImage.setPath(Constants.SLASH + store.getCode() + Constants.SLASH + productOptionGroupId);
        cmsContentImage.setFileContentType(FileContentType.INSTANCE);
        contentService.addContentFile(store.getCode(), cmsContentImage);
        group.getImages().add(instanceImage);
        productInstanceGroupService.save(group);
    } catch (Exception e) {
        throw new ServiceRuntimeException("Exception while adding instance group image", e);
    }
    return;
}
Also used : InputContentFile(com.salesmanager.core.model.content.InputContentFile) ProductInstanceImage(com.salesmanager.core.model.catalog.product.instance.ProductInstanceImage) InputStream(java.io.InputStream) 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) 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