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