use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class ProductInventoryFacadeImpl method update.
@Override
public void update(Long productId, PersistableInventory inventory, MerchantStore store, Language language) {
Validate.notNull(productId, "Product id cannot be null");
Validate.notNull(inventory, "Inventory cannot be null");
Validate.notNull(store, "MerchantStore cannot be null");
Product product = getProductById(productId);
ProductAvailability availability = getAvailabilityById(store, inventory.getId());
if (availability.getProduct().getId().longValue() != productId) {
throw new ResourceNotFoundException("Availability with id [" + inventory.getId() + "] not found for product id [" + productId + "]");
}
inventory.setProductId(product.getId());
availability = productInventoryMapper.merge(inventory, availability, store, language);
availability.setProduct(product);
availability.setMerchantStore(store);
saveOrUpdate(availability);
}
use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class ProductOptionFacadeImpl method saveAttribute.
@Override
public ReadableProductAttributeEntity saveAttribute(Long productId, PersistableProductAttribute attribute, MerchantStore store, Language language) {
Validate.notNull(productId, "Product id cannot be null");
Validate.notNull(attribute, "ProductAttribute cannot be null");
Validate.notNull(attribute.getOption(), "ProductAttribute option cannot be null");
Validate.notNull(attribute.getOptionValue(), "ProductAttribute option value cannot be null");
Validate.notNull(store, "Store cannot be null");
attribute.setProductId(productId);
ProductAttribute attr = new ProductAttribute();
if (attribute.getId() != null && attribute.getId().longValue() > 0) {
attr = productAttributeService.getById(attribute.getId());
if (attr == null) {
throw new ResourceNotFoundException("Product attribute [" + attribute.getId() + "] not found");
}
if (productId != attr.getProduct().getId().longValue()) {
throw new ResourceNotFoundException("Product attribute [" + attribute.getId() + "] not found for product [" + productId + "]");
}
}
attr = persistableProductAttributeMapper.merge(attribute, attr, store, language);
try {
productAttributeService.saveOrUpdate(attr);
} catch (ServiceException e) {
throw new ServiceRuntimeException("Exception while saving ProductAttribute", e);
}
// refresh
attr = productAttributeService.getById(attr.getId());
ReadableProductAttributeEntity readable = readableProductAttributeMapper.convert(attr, store, language);
return readable;
}
use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class ProductOptionFacadeImpl method getOptionValue.
@Override
public ReadableProductOptionValueEntity getOptionValue(Long optionValueId, MerchantStore store, Language language) {
Validate.notNull(optionValueId, "OptionValue id cannot be null");
Validate.notNull(store, "Store cannot be null");
ProductOptionValue optionValue = productOptionValueService.getById(store, optionValueId);
if (optionValue == null) {
throw new ResourceNotFoundException("OptionValue id [" + optionValueId + "] not found");
}
return readableOptionValueMapper.convert(optionValue, store, language);
}
use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class TaxFacadeImpl method taxRateById.
// get by id
private TaxRate taxRateById(Long id, MerchantStore store, Language language) {
Validate.notNull(id, "TaxRate id cannot be null");
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(store.getCode(), "MerchantStore code cannot be null");
try {
TaxRate model = taxRateService.getById(id, store);
if (model == null) {
throw new ResourceNotFoundException("TaxRate not found [" + id + "]");
}
return model;
} catch (Exception e) {
LOGGER.error("Error while getting taxRate [" + id + "] for store [" + store.getCode() + "]", e);
throw new ServiceRuntimeException("Error while getting taxRate [" + id + "] for store [" + store.getCode() + "]", e);
}
}
use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class ProductCommonFacadeImpl 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);
}
}
Aggregations