use of com.salesmanager.shop.store.api.exception.OperationNotAllowedException in project shopizer by shopizer-ecommerce.
the class ProductVariationFacadeImpl method create.
@Override
public Long create(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");
if (this.exists(var.getCode(), store)) {
throw new OperationNotAllowedException("Option set with code [" + var.getCode() + "] already exist");
}
ProductVariation p = persistableProductVariationMapper.convert(var, store, language);
p.setMerchantStore(store);
try {
productVariationService.saveOrUpdate(p);
} catch (ServiceException e) {
throw new ServiceRuntimeException("Exception while creating ProductOptionSet", e);
}
return p.getId();
}
use of com.salesmanager.shop.store.api.exception.OperationNotAllowedException in project shopizer by shopizer-ecommerce.
the class ProductFacadeImpl method getProductPrice.
@Override
public ReadableProductPrice getProductPrice(Long id, ProductPriceRequest priceRequest, MerchantStore store, Language language) {
Validate.notNull(id, "Product id cannot be null");
Validate.notNull(priceRequest, "Product price request cannot be null");
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(language, "Language cannot be null");
try {
Product model = productService.findOne(id, store);
// TODO check if null
List<Long> attrinutesIds = priceRequest.getOptions().stream().map(p -> p.getId()).collect(Collectors.toList());
List<ProductAttribute> attributes = productAttributeService.getByAttributeIds(store, model, attrinutesIds);
for (ProductAttribute attribute : attributes) {
if (attribute.getProduct().getId().longValue() != id.longValue()) {
// throw unauthorized
throw new OperationNotAllowedException("Attribute with id [" + attribute.getId() + "] is not attached to product id [" + id + "]");
}
}
FinalPrice price;
price = pricingService.calculateProductPrice(model, attributes);
ReadableProductPrice readablePrice = new ReadableProductPrice();
ReadableFinalPricePopulator populator = new ReadableFinalPricePopulator();
populator.setPricingService(pricingService);
return populator.populate(price, readablePrice, store, language);
} catch (Exception e) {
throw new ServiceRuntimeException("An error occured while getting product price", e);
}
}
use of com.salesmanager.shop.store.api.exception.OperationNotAllowedException 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.OperationNotAllowedException in project shopizer by shopizer-ecommerce.
the class CatalogFacadeImpl method saveCatalog.
@Override
public ReadableCatalog saveCatalog(PersistableCatalog catalog, MerchantStore store, Language language) {
Validate.notNull(catalog, "Catalog cannot be null");
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(language, "Language cannot be null");
Catalog catalogToSave = persistableCatalogMapper.convert(catalog, store, language);
boolean existByCode = uniqueCatalog(catalog.getCode(), store);
if (existByCode) {
throw new OperationNotAllowedException("Catalog [" + catalog.getCode() + "] already exists");
}
catalogService.saveOrUpdate(catalogToSave, store);
Catalog savedCatalog = catalogService.getByCode(catalogToSave.getCode(), store).get();
return readableCatalogMapper.convert(savedCatalog, store, language);
}
Aggregations