Search in sources :

Example 1 with ProductInstanceGroup

use of com.salesmanager.core.model.catalog.product.instance.ProductInstanceGroup 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 2 with ProductInstanceGroup

use of com.salesmanager.core.model.catalog.product.instance.ProductInstanceGroup 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 3 with ProductInstanceGroup

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

the class ProductInstanceGroupFacadeImpl method delete.

@Override
public void delete(Long productInstanceGroup, Long productId, MerchantStore store) {
    ProductInstanceGroup group = this.group(productInstanceGroup, store);
    if (group == null) {
        throw new ResourceNotFoundException("Product instance group [" + group.getId() + " not found for store [" + store.getCode() + "]");
    }
    try {
        // null all group from instances
        for (ProductInstance instance : group.getProductInstances()) {
            Optional<ProductInstance> p = productInstanceService.getById(instance.getId(), store);
            if (p.isEmpty()) {
                throw new ResourceNotFoundException("Product instance [" + instance.getId() + " not found for store [" + store.getCode() + "]");
            }
            instance.setProductInstanceGroup(null);
            productInstanceService.save(instance);
        }
        // now delete
        productInstanceGroupService.delete(group);
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Cannot remove 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) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ProductInstance(com.salesmanager.core.model.catalog.product.instance.ProductInstance) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 4 with ProductInstanceGroup

use of com.salesmanager.core.model.catalog.product.instance.ProductInstanceGroup 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 5 with ProductInstanceGroup

use of com.salesmanager.core.model.catalog.product.instance.ProductInstanceGroup 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)6 PersistableProductInstanceGroup (com.salesmanager.shop.model.catalog.product.product.instanceGroup.PersistableProductInstanceGroup)6 ServiceException (com.salesmanager.core.business.exception.ServiceException)4 ReadableProductInstanceGroup (com.salesmanager.shop.model.catalog.product.product.instanceGroup.ReadableProductInstanceGroup)4 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)4 ProductInstanceImage (com.salesmanager.core.model.catalog.product.instance.ProductInstanceImage)3 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)3 ProductInstance (com.salesmanager.core.model.catalog.product.instance.ProductInstance)2 InputContentFile (com.salesmanager.core.model.content.InputContentFile)1 InputStream (java.io.InputStream)1