Search in sources :

Example 1 with ProductInstanceImage

use of com.salesmanager.core.model.catalog.product.instance.ProductInstanceImage 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)

Example 2 with ProductInstanceImage

use of com.salesmanager.core.model.catalog.product.instance.ProductInstanceImage in project shopizer by shopizer-ecommerce.

the class PersistableProductIntanceGroupMapper method merge.

@Override
public ProductInstanceGroup merge(PersistableProductInstanceGroup source, ProductInstanceGroup destination, MerchantStore store, Language language) {
    Validate.notNull(source, "PersistableProductInstanceGroup cannot be null");
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(language, "Language cannot be null");
    Validate.notNull(source.getProductInstances(), "Product instances cannot be null");
    if (destination == null) {
        destination = new ProductInstanceGroup();
    }
    destination.setId(source.getId());
    List<ProductInstance> productInstances = productInstanceService.getByIds(source.getProductInstances(), store);
    for (ProductInstance p : productInstances) {
        p.setProductInstanceGroup(destination);
    }
    // images are not managed from this object
    if (source.getId() != null) {
        List<ProductInstanceImage> images = productInstanceImageService.listByProductInstanceGroup(source.getId(), store);
        destination.setImages(images);
    }
    destination.setMerchantStore(store);
    destination.setProductInstances(new HashSet<ProductInstance>(productInstances));
    return destination;
}
Also used : ProductInstanceImage(com.salesmanager.core.model.catalog.product.instance.ProductInstanceImage) ProductInstanceGroup(com.salesmanager.core.model.catalog.product.instance.ProductInstanceGroup) PersistableProductInstanceGroup(com.salesmanager.shop.model.catalog.product.product.instanceGroup.PersistableProductInstanceGroup) ProductInstance(com.salesmanager.core.model.catalog.product.instance.ProductInstance)

Example 3 with ProductInstanceImage

use of com.salesmanager.core.model.catalog.product.instance.ProductInstanceImage 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)

Aggregations

ProductInstanceGroup (com.salesmanager.core.model.catalog.product.instance.ProductInstanceGroup)3 ProductInstanceImage (com.salesmanager.core.model.catalog.product.instance.ProductInstanceImage)3 PersistableProductInstanceGroup (com.salesmanager.shop.model.catalog.product.product.instanceGroup.PersistableProductInstanceGroup)3 ServiceException (com.salesmanager.core.business.exception.ServiceException)2 ReadableProductInstanceGroup (com.salesmanager.shop.model.catalog.product.product.instanceGroup.ReadableProductInstanceGroup)2 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)2 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)2 ProductInstance (com.salesmanager.core.model.catalog.product.instance.ProductInstance)1 InputContentFile (com.salesmanager.core.model.content.InputContentFile)1 InputStream (java.io.InputStream)1