use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class ProductVariationFacadeImpl method update.
@Override
public void update(Long variationId, PersistableProductVariation var, MerchantStore store, Language language) {
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(language, "Language cannot be null");
Validate.notNull(var, "PersistableProductVariation cannot be null");
Optional<ProductVariation> p = productVariationService.getById(store, variationId, language);
if (p.isEmpty()) {
throw new ResourceNotFoundException("ProductVariation not found for id [" + variationId + "] and store [" + store.getCode() + "]");
}
ProductVariation productVariant = p.get();
productVariant.setId(variationId);
productVariant.setCode(var.getCode());
ProductVariation model = persistableProductVariationMapper.merge(var, productVariant, store, language);
try {
model.setMerchantStore(store);
productVariationService.save(model);
} catch (ServiceException e) {
throw new ServiceRuntimeException("Exception while creating ProductVariation", e);
}
}
use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class ProductCommonFacadeImpl method getProduct.
@Override
public ReadableProduct getProduct(MerchantStore store, Long id, Language language) {
Product product = productService.findOne(id, store);
if (product == null) {
throw new ResourceNotFoundException("Product [" + id + "] not found");
}
if (product.getMerchantStore().getId() != store.getId()) {
throw new ResourceNotFoundException("Product [" + id + "] not found for store [" + store.getId() + "]");
}
ReadableProduct readableProduct = new ReadableProduct();
ReadableProductPopulator populator = new ReadableProductPopulator();
populator.setPricingService(pricingService);
populator.setimageUtils(imageUtils);
try {
readableProduct = populator.populate(product, readableProduct, store, language);
} catch (ConversionException e) {
throw new ConversionRuntimeException("Error converting product [" + id + "]", e);
}
return readableProduct;
}
use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class CategoryFacadeImpl method move.
@Override
public void move(Long child, Long parent, MerchantStore store) {
Validate.notNull(child, "Child category must not be null");
Validate.notNull(parent, "Parent category must not be null");
Validate.notNull(store, "Merhant must not be null");
try {
Category c = categoryService.getById(child, store.getId());
if (c == null) {
throw new ResourceNotFoundException("Category with id [" + child + "] for store [" + store.getCode() + "]");
}
if (parent.longValue() == -1) {
categoryService.addChild(null, c);
return;
}
Category p = categoryService.getById(parent, store.getId());
if (p == null) {
throw new ResourceNotFoundException("Category with id [" + parent + "] for store [" + store.getCode() + "]");
}
if (c.getParent() != null && c.getParent().getId() == parent) {
return;
}
if (c.getMerchantStore().getId().intValue() != store.getId().intValue()) {
throw new OperationNotAllowedException("Invalid identifiers for Merchant [" + c.getMerchantStore().getCode() + "]");
}
if (p.getMerchantStore().getId().intValue() != store.getId().intValue()) {
throw new OperationNotAllowedException("Invalid identifiers for Merchant [" + c.getMerchantStore().getCode() + "]");
}
p.getAuditSection().setModifiedBy("Api");
categoryService.addChild(p, c);
} catch (ResourceNotFoundException re) {
throw re;
} catch (OperationNotAllowedException oe) {
throw oe;
} catch (Exception e) {
throw new ServiceRuntimeException(e);
}
}
use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class ContentFacadeImpl method getContentFolder.
@Override
public ContentFolder getContentFolder(String folder, MerchantStore store) throws Exception {
try {
List<String> imageNames = Optional.ofNullable(contentService.getContentFilesNames(store.getCode(), FileContentType.IMAGE)).orElseThrow(() -> new ResourceNotFoundException("No Folder found for path : " + folder));
// images from CMS
List<ContentImage> contentImages = imageNames.stream().map(name -> convertToContentImage(name, store)).collect(Collectors.toList());
ContentFolder contentFolder = new ContentFolder();
if (!StringUtils.isBlank(folder)) {
contentFolder.setPath(URLEncoder.encode(folder, "UTF-8"));
}
contentFolder.getContent().addAll(contentImages);
return contentFolder;
} catch (ServiceException e) {
throw new ServiceRuntimeException("Error while getting folder " + e.getMessage(), e);
}
}
use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class ContentFacadeImpl method getContentPage.
@Override
public ReadableContentPage getContentPage(String code, MerchantStore store, Language language) {
Validate.notNull(code, "Content code cannot be null");
Validate.notNull(store, "MerchantStore cannot be null");
try {
Content content = null;
if (language == null) {
content = Optional.ofNullable(contentService.getByCode(code, store)).orElseThrow(() -> new ResourceNotFoundException("No page found : " + code));
} else {
content = Optional.ofNullable(contentService.getByCode(code, store, language)).orElseThrow(() -> new ResourceNotFoundException("No page found : " + code));
}
return convertContentToReadableContentPage(store, language, content);
} catch (ServiceException e) {
throw new ServiceRuntimeException("Error while getting page " + e.getMessage(), e);
}
}
Aggregations