use of com.salesmanager.shop.store.api.exception.OperationNotAllowedException in project shopizer by shopizer-ecommerce.
the class ProductOptionSetFacadeImpl method create.
@Override
public void create(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");
if (this.exists(optionSet.getCode(), store)) {
throw new OperationNotAllowedException("Option set with code [" + optionSet.getCode() + "] already exist");
}
ProductOptionSet opt = persistableProductOptionSetMapper.convert(optionSet, store, language);
try {
opt.setStore(store);
productOptionSetService.create(opt);
} catch (ServiceException e) {
throw new ServiceRuntimeException("Exception while creating ProductOptionSet", e);
}
}
use of com.salesmanager.shop.store.api.exception.OperationNotAllowedException in project shopizer by shopizer-ecommerce.
the class ProductTypeFacadeImpl method save.
@Override
public Long save(PersistableProductType type, MerchantStore store, Language language) {
Validate.notNull(type, "ProductType cannot be null");
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(type.getCode(), "ProductType code cannot be empty");
try {
if (this.exists(type.getCode(), store, language)) {
throw new OperationNotAllowedException("Product type [" + type.getCode() + "] already exist for store [" + store.getCode() + "]");
}
ProductType model = persistableProductTypeMapper.convert(type, store, language);
model.setMerchantStore(store);
ProductType saved = productTypeService.saveOrUpdate(model);
return saved.getId();
} catch (Exception e) {
throw new ServiceRuntimeException("An exception occured while saving product type", e);
}
}
use of com.salesmanager.shop.store.api.exception.OperationNotAllowedException in project shopizer by shopizer-ecommerce.
the class ProductItemsFacadeImpl method addItemToGroup.
@Override
public ReadableProductList addItemToGroup(Product product, String group, MerchantStore store, Language language) {
Validate.notNull(product, "Product must not be null");
Validate.notNull(group, "group must not be null");
// check if product is already in group
List<ProductRelationship> existList = null;
try {
existList = productRelationshipService.getByGroup(store, group).stream().filter(prod -> prod.getRelatedProduct() != null && (product.getId().longValue() == prod.getRelatedProduct().getId())).collect(Collectors.toList());
} catch (ServiceException e) {
throw new ServiceRuntimeException("ExceptionWhile getting product group [" + group + "]", e);
}
if (existList.size() > 0) {
throw new OperationNotAllowedException("Product with id [" + product.getId() + "] is already in the group");
}
ProductRelationship relationship = new ProductRelationship();
relationship.setActive(true);
relationship.setCode(group);
relationship.setStore(store);
relationship.setRelatedProduct(product);
try {
productRelationshipService.saveOrUpdate(relationship);
return listItemsByGroup(group, store, language);
} catch (Exception e) {
throw new ServiceRuntimeException("ExceptionWhile getting product group [" + group + "]", e);
}
}
use of com.salesmanager.shop.store.api.exception.OperationNotAllowedException in project shopizer by shopizer-ecommerce.
the class ShippingFacadeImpl method createPackage.
@Override
public void createPackage(PackageDetails packaging, MerchantStore store) {
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(packaging, "PackageDetails cannot be null");
ShippingConfiguration config = getDbConfig(store);
if (this.packageExists(config, packaging)) {
throw new OperationNotAllowedException("Package with unique code [" + packaging.getCode() + "] already exist");
}
com.salesmanager.core.model.shipping.Package pack = toPackage(packaging);
// need to check if code exists
config.getPackages().add(pack);
this.saveShippingConfiguration(config, store);
}
use of com.salesmanager.shop.store.api.exception.OperationNotAllowedException in project shopizer by shopizer-ecommerce.
the class ProductFacadeV2Impl 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);
List<ProductAttribute> attributes = null;
if (!CollectionUtils.isEmpty(priceRequest.getOptions())) {
List<Long> attrinutesIds = priceRequest.getOptions().stream().map(p -> p.getId()).collect(Collectors.toList());
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 + "]");
}
}
}
if (!StringUtils.isBlank(priceRequest.getSku())) {
// change default availability with sku (instance availability)
List<ProductAvailability> availabilityList = productAvailabilityService.getBySku(priceRequest.getSku(), store);
if (CollectionUtils.isNotEmpty(availabilityList)) {
model.setAvailabilities(new HashSet(availabilityList));
}
}
FinalPrice price;
// attributes can be null;
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);
}
}
Aggregations