use of com.salesmanager.shop.store.api.exception.ServiceRuntimeException 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);
}
}
use of com.salesmanager.shop.store.api.exception.ServiceRuntimeException in project shopizer by shopizer-ecommerce.
the class ProductOptionFacadeImpl method createAttributes.
@Override
public List<CodeEntity> createAttributes(List<PersistableProductAttribute> attributes, Long productId, MerchantStore store) {
Validate.notNull(productId, "Product id must not be null");
Validate.notNull(store, "Merchant cannot be null");
// convert to model
List<ProductAttribute> modelAttributes = attributes.stream().map(attr -> persistableProductAttributeMapper.convert(attr, store, null)).collect(Collectors.toList());
try {
productAttributeService.saveAll(modelAttributes);
// save to a product
Product product = this.product(productId, store);
product.getAttributes().addAll(modelAttributes);
productService.save(product);
} catch (ServiceException e) {
throw new ServiceRuntimeException("Exception while saving product with attributes", e);
}
return modelAttributes.stream().map(e -> codeEntity(e)).collect(Collectors.toList());
}
use of com.salesmanager.shop.store.api.exception.ServiceRuntimeException in project shopizer by shopizer-ecommerce.
the class ProductOptionFacadeImpl method deleteAttribute.
@Override
public void deleteAttribute(Long productId, Long attributeId, MerchantStore store) {
try {
ProductAttribute attr = productAttributeService.getById(attributeId);
if (attr == null) {
throw new ResourceNotFoundException("ProductAttribute not found for [" + attributeId + "] and store [" + store.getCode() + "]");
}
if (attr.getProduct().getId().longValue() != productId) {
throw new ResourceNotFoundException("ProductAttribute not found for [" + attributeId + "] and product [" + productId + "]");
}
if (attr.getProduct().getMerchantStore().getId().intValue() != store.getId().intValue()) {
throw new ResourceNotFoundException("ProductAttribute not found for [" + attributeId + "] and product [" + productId + "] and store [" + store.getCode() + "]");
}
productAttributeService.delete(attr);
} catch (ServiceException e) {
throw new ServiceRuntimeException("An exception occured while deleting ProductAttribute [" + attributeId + "]", e);
}
}
use of com.salesmanager.shop.store.api.exception.ServiceRuntimeException in project shopizer by shopizer-ecommerce.
the class ProductOptionFacadeImpl method saveOption.
@Override
public ReadableProductOptionEntity saveOption(PersistableProductOptionEntity option, MerchantStore store, Language language) {
Validate.notNull(option, "ProductOption cannot be null");
Validate.notNull(store, "MerchantStore cannot be null");
ProductOption optionModel = new ProductOption();
if (option.getId() != null && option.getId().longValue() > 0) {
optionModel = productOptionService.getById(store, option.getId());
if (optionModel == null) {
throw new ResourceNotFoundException("ProductOption not found for if [" + option.getId() + "] and store [" + store.getCode() + "]");
}
}
optionModel = persistableeMapper.merge(option, optionModel, store, language);
try {
productOptionService.saveOrUpdate(optionModel);
} catch (ServiceException e) {
throw new ServiceRuntimeException("An exception occured while saving ProductOption", e);
}
optionModel = productOptionService.getById(store, optionModel.getId());
ReadableProductOptionEntity readable = readableMapper.convert(optionModel, store, language);
return readable;
}
use of com.salesmanager.shop.store.api.exception.ServiceRuntimeException in project shopizer by shopizer-ecommerce.
the class ProductOptionFacadeImpl method getAttributesList.
@Override
public ReadableProductAttributeList getAttributesList(Long productId, MerchantStore store, Language language, int page, int count) {
try {
Product product = this.product(productId, store);
ReadableProductAttributeList attrList = new ReadableProductAttributeList();
Page<ProductAttribute> attr = null;
if (language != null) {
// all entry
// attributes = productAttributeService.getByProductId(store, product, language);
attr = productAttributeService.getByProductId(store, product, language, page, count);
attrList.setRecordsTotal(attr.getTotalElements());
attrList.setNumber(attr.getSize());
attrList.setTotalPages(attr.getTotalPages());
} else {
attr = productAttributeService.getByProductId(store, product, page, count);
attrList.setRecordsTotal(attr.getTotalElements());
attrList.setNumber(attr.getSize());
attrList.setTotalPages(attr.getTotalPages());
}
List<ReadableProductAttributeEntity> values = attr.getContent().stream().map(attribute -> readableProductAttributeMapper.convert(attribute, store, language)).collect(Collectors.toList());
attrList.setAttributes(values);
return attrList;
} catch (ServiceException e) {
throw new ServiceRuntimeException("Error while getting attributes", e);
}
}
Aggregations