use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class ProductInventoryFacadeImpl method get.
@Override
public ReadableInventory get(Long productId, String child, Language language) {
Product product = getProductById(productId);
MerchantStore store = getMerchantStore(child);
if (isStoreParentNotExist(store) || store.getParent().getId().equals(product.getMerchantStore().getId())) {
throw new ResourceNotFoundException("MerchantStore [" + child + "] is not a store of retailer [" + store.getCode() + "]");
}
ProductAvailability availability = productAvailabilityService.getByStore(product, store).orElseThrow(() -> new ResourceNotFoundException("Inventory with not found"));
return this.readableInventory(availability, store, language);
}
use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class ProductOptionFacadeImpl method getOption.
@Override
public ReadableProductOptionEntity getOption(Long optionId, MerchantStore store, Language language) {
Validate.notNull(optionId, "Option id cannot be null");
Validate.notNull(store, "Store cannot be null");
ProductOption option = productOptionService.getById(store, optionId);
if (option == null) {
throw new ResourceNotFoundException("Option id [" + optionId + "] not found");
}
return readableMapper.convert(option, store, language);
}
use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException 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.ResourceNotFoundException 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.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class ProductOptionFacadeImpl method addOptionValueImage.
@Override
public void addOptionValueImage(MultipartFile image, Long optionValueId, MerchantStore store, Language language) {
Validate.notNull(optionValueId, "OptionValueId must not be null");
Validate.notNull(image, "Image must not be null");
// get option value
ProductOptionValue value = productOptionValueService.getById(store, optionValueId);
if (value == null) {
throw new ResourceNotFoundException("Product option value [" + optionValueId + "] not found");
}
try {
String imageName = image.getOriginalFilename();
InputStream inputStream = image.getInputStream();
InputContentFile cmsContentImage = new InputContentFile();
cmsContentImage.setFileName(imageName);
cmsContentImage.setMimeType(image.getContentType());
cmsContentImage.setFile(inputStream);
contentService.addOptionImage(store.getCode(), cmsContentImage);
value.setProductOptionValueImage(imageName);
productOptionValueService.saveOrUpdate(value);
} catch (Exception e) {
throw new ServiceRuntimeException("Exception while adding option value image", e);
}
return;
}
Aggregations