Search in sources :

Example 11 with ResourceNotFoundException

use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.

the class ProductInventoryFacadeImpl method update.

@Override
public void update(Long productId, PersistableInventory inventory, MerchantStore store, Language language) {
    Validate.notNull(productId, "Product id cannot be null");
    Validate.notNull(inventory, "Inventory cannot be null");
    Validate.notNull(store, "MerchantStore cannot be null");
    Product product = getProductById(productId);
    ProductAvailability availability = getAvailabilityById(store, inventory.getId());
    if (availability.getProduct().getId().longValue() != productId) {
        throw new ResourceNotFoundException("Availability with id [" + inventory.getId() + "] not found for product id [" + productId + "]");
    }
    inventory.setProductId(product.getId());
    availability = productInventoryMapper.merge(inventory, availability, store, language);
    availability.setProduct(product);
    availability.setMerchantStore(store);
    saveOrUpdate(availability);
}
Also used : ProductAvailability(com.salesmanager.core.model.catalog.product.availability.ProductAvailability) Product(com.salesmanager.core.model.catalog.product.Product) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException)

Example 12 with ResourceNotFoundException

use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.

the class ProductOptionFacadeImpl method saveAttribute.

@Override
public ReadableProductAttributeEntity saveAttribute(Long productId, PersistableProductAttribute attribute, MerchantStore store, Language language) {
    Validate.notNull(productId, "Product id cannot be null");
    Validate.notNull(attribute, "ProductAttribute cannot be null");
    Validate.notNull(attribute.getOption(), "ProductAttribute option cannot be null");
    Validate.notNull(attribute.getOptionValue(), "ProductAttribute option value cannot be null");
    Validate.notNull(store, "Store cannot be null");
    attribute.setProductId(productId);
    ProductAttribute attr = new ProductAttribute();
    if (attribute.getId() != null && attribute.getId().longValue() > 0) {
        attr = productAttributeService.getById(attribute.getId());
        if (attr == null) {
            throw new ResourceNotFoundException("Product attribute [" + attribute.getId() + "] not found");
        }
        if (productId != attr.getProduct().getId().longValue()) {
            throw new ResourceNotFoundException("Product attribute [" + attribute.getId() + "] not found for product [" + productId + "]");
        }
    }
    attr = persistableProductAttributeMapper.merge(attribute, attr, store, language);
    try {
        productAttributeService.saveOrUpdate(attr);
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Exception while saving ProductAttribute", e);
    }
    // refresh
    attr = productAttributeService.getById(attr.getId());
    ReadableProductAttributeEntity readable = readableProductAttributeMapper.convert(attr, store, language);
    return readable;
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) ProductAttribute(com.salesmanager.core.model.catalog.product.attribute.ProductAttribute) PersistableProductAttribute(com.salesmanager.shop.model.catalog.product.attribute.PersistableProductAttribute) ReadableProductAttributeEntity(com.salesmanager.shop.model.catalog.product.attribute.api.ReadableProductAttributeEntity) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 13 with ResourceNotFoundException

use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.

the class ProductOptionFacadeImpl method getOptionValue.

@Override
public ReadableProductOptionValueEntity getOptionValue(Long optionValueId, MerchantStore store, Language language) {
    Validate.notNull(optionValueId, "OptionValue id cannot be null");
    Validate.notNull(store, "Store cannot be null");
    ProductOptionValue optionValue = productOptionValueService.getById(store, optionValueId);
    if (optionValue == null) {
        throw new ResourceNotFoundException("OptionValue id [" + optionValueId + "] not found");
    }
    return readableOptionValueMapper.convert(optionValue, store, language);
}
Also used : ProductOptionValue(com.salesmanager.core.model.catalog.product.attribute.ProductOptionValue) PersistableProductOptionValue(com.salesmanager.shop.model.catalog.product.attribute.PersistableProductOptionValue) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException)

Example 14 with ResourceNotFoundException

use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.

the class TaxFacadeImpl method taxRateById.

// get by id
private TaxRate taxRateById(Long id, MerchantStore store, Language language) {
    Validate.notNull(id, "TaxRate id cannot be null");
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(store.getCode(), "MerchantStore code cannot be null");
    try {
        TaxRate model = taxRateService.getById(id, store);
        if (model == null) {
            throw new ResourceNotFoundException("TaxRate not found [" + id + "]");
        }
        return model;
    } catch (Exception e) {
        LOGGER.error("Error while getting taxRate [" + id + "] for store [" + store.getCode() + "]", e);
        throw new ServiceRuntimeException("Error while getting taxRate [" + id + "] for store [" + store.getCode() + "]", e);
    }
}
Also used : TaxRate(com.salesmanager.core.model.tax.taxrate.TaxRate) ReadableTaxRate(com.salesmanager.shop.model.tax.ReadableTaxRate) PersistableTaxRate(com.salesmanager.shop.model.tax.PersistableTaxRate) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) 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) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 15 with ResourceNotFoundException

use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.

the class ProductCommonFacadeImpl method deleteProduct.

@Override
public void deleteProduct(Long id, MerchantStore store) {
    Validate.notNull(id, "Product id cannot be null");
    Validate.notNull(store, "store cannot be null");
    Product p = productService.getById(id);
    if (p == null) {
        throw new ResourceNotFoundException("Product with id [" + id + " not found");
    }
    if (p.getMerchantStore().getId().intValue() != store.getId().intValue()) {
        throw new ResourceNotFoundException("Product with id [" + id + " not found for store [" + store.getCode() + "]");
    }
    try {
        productService.delete(p);
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Error while deleting ptoduct with id [" + id + "]", e);
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) PersistableProduct(com.salesmanager.shop.model.catalog.product.PersistableProduct) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) Product(com.salesmanager.core.model.catalog.product.Product) LightPersistableProduct(com.salesmanager.shop.model.catalog.product.LightPersistableProduct) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Aggregations

ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)108 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)77 ServiceException (com.salesmanager.core.business.exception.ServiceException)62 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)22 UnauthorizedException (com.salesmanager.shop.store.api.exception.UnauthorizedException)22 Product (com.salesmanager.core.model.catalog.product.Product)21 Language (com.salesmanager.core.model.reference.language.Language)19 List (java.util.List)19 Collectors (java.util.stream.Collectors)19 ApiImplicitParams (io.swagger.annotations.ApiImplicitParams)17 ArrayList (java.util.ArrayList)17 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)16 OperationNotAllowedException (com.salesmanager.shop.store.api.exception.OperationNotAllowedException)15 Autowired (org.springframework.beans.factory.annotation.Autowired)15 ConversionException (com.salesmanager.core.business.exception.ConversionException)13 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)13 Inject (javax.inject.Inject)12 Optional (java.util.Optional)11 Service (org.springframework.stereotype.Service)11 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)11