use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class ProductOptionSetFacadeImpl method update.
@Override
public void update(Long id, PersistableProductOptionSet optionSet, MerchantStore store, Language language) {
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(language, "Language cannot be null");
Validate.notNull(optionSet, "PersistableProductOptionSet cannot be null");
ProductOptionSet opt = productOptionSetService.getById(store, id, language);
if (opt == null) {
throw new ResourceNotFoundException("ProductOptionSet not found for id [" + id + "] and store [" + store.getCode() + "]");
}
optionSet.setId(id);
optionSet.setCode(opt.getCode());
ProductOptionSet model = persistableProductOptionSetMapper.convert(optionSet, store, language);
try {
model.setStore(store);
productOptionSetService.save(model);
} catch (ServiceException e) {
throw new ServiceRuntimeException("Exception while creating ProductOptionSet", e);
}
}
use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class ProductTypeFacadeImpl method delete.
@Override
public void delete(Long id, MerchantStore store, Language language) {
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(id, "id cannot be empty");
try {
ProductType t = productTypeService.getById(id, store, language);
if (t == null) {
throw new ResourceNotFoundException("Product type [" + id + "] does not exist for store [" + store.getCode() + "]");
}
productTypeService.delete(t);
} catch (Exception e) {
throw new ServiceRuntimeException("An exception occured while saving product type", e);
}
}
use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class ProductTypeFacadeImpl method get.
@Override
public ReadableProductType get(MerchantStore store, String code, Language language) {
ProductType t;
try {
t = productTypeService.getByCode(code, store, language);
} catch (ServiceException e) {
throw new RuntimeException("An exception occured while getting product type [" + code + "] for merchant store [" + store.getCode() + "]", e);
}
if (t == null) {
throw new ResourceNotFoundException("Product type [" + code + "] not found for merchant [" + store.getCode() + "]");
}
ReadableProductType readableType = readableProductTypeMapper.convert(t, store, language);
return readableType;
}
use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class ProductVariationFacadeImpl method delete.
@Override
public void delete(Long variationId, MerchantStore store) {
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(variationId, "variationId cannot be null");
ProductVariation opt = productVariationService.getById(variationId);
if (opt == null) {
throw new ResourceNotFoundException("ProductVariation not found for id [" + variationId + "] and store [" + store.getCode() + "]");
}
if (!opt.getMerchantStore().getCode().equals(store.getCode())) {
throw new ResourceNotFoundException("ProductVariation not found for id [" + variationId + "] and store [" + store.getCode() + "]");
}
try {
productVariationService.delete(opt);
} catch (ServiceException e) {
throw new ServiceRuntimeException("Exception while deleting ProductVariation", e);
}
}
use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class PersistableProductInstanceMapper method merge.
@Override
public ProductInstance merge(PersistableProductInstance source, ProductInstance destination, MerchantStore store, Language language) {
//
Long productVariant = source.getVariant();
Long productVariantValue = source.getVariantValue();
Optional<ProductVariation> variant = productVariationService.getById(store, productVariant);
Optional<ProductVariation> variantValue = productVariationService.getById(store, productVariantValue);
if (variant.isEmpty()) {
throw new ResourceNotFoundException("ProductVariant [" + productVariant + "] + not found for store [" + store.getCode() + "]");
}
destination.setVariant(variant.get());
if (variantValue.isEmpty()) {
throw new ResourceNotFoundException("ProductVariant [" + productVariantValue + "] + not found for store [" + store.getCode() + "]");
}
destination.setVariantValue(variantValue.get());
destination.setCode(variant.get().getCode() + ":" + variantValue.get().getCode());
destination.setAvailable(source.isAvailable());
destination.setDefaultSelection(source.isDefaultSelection());
destination.setSku(source.getSku());
if (StringUtils.isBlank(source.getDateAvailable())) {
source.setDateAvailable(DateUtil.formatDate(new Date()));
}
if (source.getDateAvailable() != null) {
try {
destination.setDateAvailable(DateUtil.getDate(source.getDateAvailable()));
} catch (Exception e) {
throw new ServiceRuntimeException("Cant format date [" + source.getDateAvailable() + "]");
}
}
destination.setSortOrder(source.getSortOrder());
Product product = productService.getById(source.getProductId());
if (product == null) {
throw new ResourceNotFoundException("Product [" + source.getId() + "] + not found for store [" + store.getCode() + "]");
}
if (product.getMerchantStore().getId() != store.getId()) {
throw new ResourceNotFoundException("Product [" + source.getId() + "] + not found for store [" + store.getCode() + "]");
}
destination.setProduct(product);
return destination;
}
Aggregations