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;
}
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;
}
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);
}
}
Aggregations