Search in sources :

Example 6 with OperationNotAllowedException

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);
    }
}
Also used : ProductOptionSet(com.salesmanager.core.model.catalog.product.attribute.ProductOptionSet) PersistableProductOptionSet(com.salesmanager.shop.model.catalog.product.attribute.optionset.PersistableProductOptionSet) ReadableProductOptionSet(com.salesmanager.shop.model.catalog.product.attribute.optionset.ReadableProductOptionSet) ServiceException(com.salesmanager.core.business.exception.ServiceException) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 7 with OperationNotAllowedException

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);
    }
}
Also used : ReadableProductType(com.salesmanager.shop.model.catalog.product.type.ReadableProductType) ProductType(com.salesmanager.core.model.catalog.product.type.ProductType) PersistableProductType(com.salesmanager.shop.model.catalog.product.type.PersistableProductType) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) ServiceException(com.salesmanager.core.business.exception.ServiceException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 8 with OperationNotAllowedException

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);
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) ProductRelationship(com.salesmanager.core.model.catalog.product.relationship.ProductRelationship) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) ServiceException(com.salesmanager.core.business.exception.ServiceException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 9 with OperationNotAllowedException

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);
}
Also used : OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) ShippingConfiguration(com.salesmanager.core.model.shipping.ShippingConfiguration)

Example 10 with OperationNotAllowedException

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);
    }
}
Also used : ProductService(com.salesmanager.core.business.services.catalog.product.ProductService) ReadableProductInstance(com.salesmanager.shop.model.catalog.product.product.instance.ReadableProductInstance) Autowired(org.springframework.beans.factory.annotation.Autowired) ProductFacade(com.salesmanager.shop.store.controller.product.facade.ProductFacade) StringUtils(org.apache.commons.lang3.StringUtils) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Language(com.salesmanager.core.model.reference.language.Language) ReadableFinalPricePopulator(com.salesmanager.shop.populator.catalog.ReadableFinalPricePopulator) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) FinalPrice(com.salesmanager.core.model.catalog.product.price.FinalPrice) ProductInstanceService(com.salesmanager.core.business.services.catalog.product.instance.ProductInstanceService) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Service(org.springframework.stereotype.Service) Qualifier(org.springframework.beans.factory.annotation.Qualifier) PricingService(com.salesmanager.core.business.services.catalog.product.PricingService) CategoryService(com.salesmanager.core.business.services.catalog.category.CategoryService) ReadableProductPrice(com.salesmanager.shop.model.catalog.product.ReadableProductPrice) ProductAttributeService(com.salesmanager.core.business.services.catalog.product.attribute.ProductAttributeService) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) ProductAttribute(com.salesmanager.core.model.catalog.product.attribute.ProductAttribute) Product(com.salesmanager.core.model.catalog.product.Product) ProductCriteria(com.salesmanager.core.model.catalog.product.ProductCriteria) ProductPriceRequest(com.salesmanager.shop.model.catalog.product.ProductPriceRequest) ProductRelationshipService(com.salesmanager.core.business.services.catalog.product.relationship.ProductRelationshipService) ImageFilePath(com.salesmanager.shop.utils.ImageFilePath) ProductAvailabilityService(com.salesmanager.core.business.services.catalog.product.availability.ProductAvailabilityService) Page(org.springframework.data.domain.Page) ProductInstance(com.salesmanager.core.model.catalog.product.instance.ProductInstance) Collectors(java.util.stream.Collectors) Profile(org.springframework.context.annotation.Profile) List(java.util.List) LocaleUtils(com.salesmanager.shop.utils.LocaleUtils) Validate(org.apache.commons.lang3.Validate) ProductRelationship(com.salesmanager.core.model.catalog.product.relationship.ProductRelationship) ReadableProductPopulator(com.salesmanager.shop.populator.catalog.ReadableProductPopulator) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ProductRelationshipType(com.salesmanager.core.model.catalog.product.relationship.ProductRelationshipType) ReadableProductMapper(com.salesmanager.shop.mapper.catalog.ReadableProductMapper) ProductAvailability(com.salesmanager.core.model.catalog.product.availability.ProductAvailability) Comparator(java.util.Comparator) ReadableProductList(com.salesmanager.shop.model.catalog.product.ReadableProductList) ReadableProductInstanceMapper(com.salesmanager.shop.mapper.catalog.product.ReadableProductInstanceMapper) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) Product(com.salesmanager.core.model.catalog.product.Product) ProductAttribute(com.salesmanager.core.model.catalog.product.attribute.ProductAttribute) ReadableFinalPricePopulator(com.salesmanager.shop.populator.catalog.ReadableFinalPricePopulator) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) ReadableProductPrice(com.salesmanager.shop.model.catalog.product.ReadableProductPrice) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ProductAvailability(com.salesmanager.core.model.catalog.product.availability.ProductAvailability) HashSet(java.util.HashSet) FinalPrice(com.salesmanager.core.model.catalog.product.price.FinalPrice)

Aggregations

OperationNotAllowedException (com.salesmanager.shop.store.api.exception.OperationNotAllowedException)14 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)12 ServiceException (com.salesmanager.core.business.exception.ServiceException)10 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)6 CategoryService (com.salesmanager.core.business.services.catalog.category.CategoryService)4 PricingService (com.salesmanager.core.business.services.catalog.product.PricingService)4 ProductService (com.salesmanager.core.business.services.catalog.product.ProductService)4 ProductAttributeService (com.salesmanager.core.business.services.catalog.product.attribute.ProductAttributeService)4 ProductRelationshipService (com.salesmanager.core.business.services.catalog.product.relationship.ProductRelationshipService)4 Product (com.salesmanager.core.model.catalog.product.Product)4 ProductRelationship (com.salesmanager.core.model.catalog.product.relationship.ProductRelationship)4 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)4 Language (com.salesmanager.core.model.reference.language.Language)4 ReadableProduct (com.salesmanager.shop.model.catalog.product.ReadableProduct)4 ReadableProductPopulator (com.salesmanager.shop.populator.catalog.ReadableProductPopulator)4 ImageFilePath (com.salesmanager.shop.utils.ImageFilePath)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 Inject (javax.inject.Inject)4