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() + "]");
}
}
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;
}
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() + "]");
}
}
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;
}
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);
}
}
Aggregations