use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class ProductInstanceFacadeImpl method list.
@Override
public ReadableEntityList<ReadableProductInstance> list(Long productId, MerchantStore store, Language language, int page, int count) {
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(productId, "Product id cannot be null");
Product product = productFacade.getProduct(productId, store);
if (product == null) {
throw new ResourceNotFoundException("Product with id [" + productId + "] not found for store [" + store.getCode() + "]");
}
Page<ProductInstance> instances = productInstanceService.getByProductId(store, product, language, page, count);
List<ReadableProductInstance> readableInstances = instances.stream().map(rp -> this.readableProductInstanceMapper.convert(rp, store, language)).collect(Collectors.toList());
return createReadableList(instances, readableInstances);
}
use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException 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.ResourceNotFoundException 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.ResourceNotFoundException 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.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class ProductInventoryFacadeImpl method get.
@Override
public ReadableInventory get(Long productId, Long inventoryId, MerchantStore store, Language language) {
Product product = getProductById(productId);
if (product.getMerchantStore().getId().intValue() != store.getId().intValue()) {
throw new ResourceNotFoundException("Product with id [" + productId + "] not found for store [" + store.getCode() + "]");
}
ProductAvailability availability = productAvailabilityService.getByInventoryId(productId, inventoryId, store).orElseThrow(() -> new ResourceNotFoundException("Inventory with id [" + inventoryId + "] not found"));
return readableInventoryMapper.convert(availability, store, language);
}
Aggregations