Search in sources :

Example 11 with OperationNotAllowedException

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

Example 12 with OperationNotAllowedException

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);
    }
}
Also used : ProductService(com.salesmanager.core.business.services.catalog.product.ProductService) ProductFacade(com.salesmanager.shop.store.controller.product.facade.ProductFacade) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Language(com.salesmanager.core.model.reference.language.Language) PersistableProduct(com.salesmanager.shop.model.catalog.product.PersistableProduct) ReadableFinalPricePopulator(com.salesmanager.shop.populator.catalog.ReadableFinalPricePopulator) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) FinalPrice(com.salesmanager.core.model.catalog.product.price.FinalPrice) 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) Page(org.springframework.data.domain.Page) 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) ConversionException(com.salesmanager.core.business.exception.ConversionException) Comparator(java.util.Comparator) ReadableProductList(com.salesmanager.shop.model.catalog.product.ReadableProductList) PersistableProduct(com.salesmanager.shop.model.catalog.product.PersistableProduct) 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) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ConversionException(com.salesmanager.core.business.exception.ConversionException) FinalPrice(com.salesmanager.core.model.catalog.product.price.FinalPrice) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 13 with OperationNotAllowedException

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);
    }
}
Also used : Category(com.salesmanager.core.model.catalog.category.Category) ReadableCategory(com.salesmanager.shop.model.catalog.category.ReadableCategory) PersistableCategory(com.salesmanager.shop.model.catalog.category.PersistableCategory) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) 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) UnauthorizedException(com.salesmanager.shop.store.api.exception.UnauthorizedException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ConversionException(com.salesmanager.core.business.exception.ConversionException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 14 with OperationNotAllowedException

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

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