Search in sources :

Example 21 with ResourceNotFoundException

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

the class ProductOptionSetFacadeImpl method update.

@Override
public void update(Long id, 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");
    ProductOptionSet opt = productOptionSetService.getById(store, id, language);
    if (opt == null) {
        throw new ResourceNotFoundException("ProductOptionSet not found for id [" + id + "] and store [" + store.getCode() + "]");
    }
    optionSet.setId(id);
    optionSet.setCode(opt.getCode());
    ProductOptionSet model = persistableProductOptionSetMapper.convert(optionSet, store, language);
    try {
        model.setStore(store);
        productOptionSetService.save(model);
    } 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) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 22 with ResourceNotFoundException

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

the class ProductTypeFacadeImpl method delete.

@Override
public void delete(Long id, MerchantStore store, Language language) {
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(id, "id cannot be empty");
    try {
        ProductType t = productTypeService.getById(id, store, language);
        if (t == null) {
            throw new ResourceNotFoundException("Product type [" + id + "] does not exist for store [" + store.getCode() + "]");
        }
        productTypeService.delete(t);
    } 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) 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) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 23 with ResourceNotFoundException

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

the class ProductTypeFacadeImpl method get.

@Override
public ReadableProductType get(MerchantStore store, String code, Language language) {
    ProductType t;
    try {
        t = productTypeService.getByCode(code, store, language);
    } catch (ServiceException e) {
        throw new RuntimeException("An exception occured while getting product type [" + code + "] for merchant store [" + store.getCode() + "]", e);
    }
    if (t == null) {
        throw new ResourceNotFoundException("Product type [" + code + "] not found for merchant [" + store.getCode() + "]");
    }
    ReadableProductType readableType = readableProductTypeMapper.convert(t, store, language);
    return readableType;
}
Also used : ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ServiceException(com.salesmanager.core.business.exception.ServiceException) 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) ReadableProductType(com.salesmanager.shop.model.catalog.product.type.ReadableProductType) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException)

Example 24 with ResourceNotFoundException

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

the class ProductVariationFacadeImpl method delete.

@Override
public void delete(Long variationId, MerchantStore store) {
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(variationId, "variationId cannot be null");
    ProductVariation opt = productVariationService.getById(variationId);
    if (opt == null) {
        throw new ResourceNotFoundException("ProductVariation not found for id [" + variationId + "] and store [" + store.getCode() + "]");
    }
    if (!opt.getMerchantStore().getCode().equals(store.getCode())) {
        throw new ResourceNotFoundException("ProductVariation not found for id [" + variationId + "] and store [" + store.getCode() + "]");
    }
    try {
        productVariationService.delete(opt);
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Exception while deleting ProductVariation", e);
    }
}
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) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 25 with ResourceNotFoundException

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

the class PersistableProductInstanceMapper method merge.

@Override
public ProductInstance merge(PersistableProductInstance source, ProductInstance destination, MerchantStore store, Language language) {
    // 
    Long productVariant = source.getVariant();
    Long productVariantValue = source.getVariantValue();
    Optional<ProductVariation> variant = productVariationService.getById(store, productVariant);
    Optional<ProductVariation> variantValue = productVariationService.getById(store, productVariantValue);
    if (variant.isEmpty()) {
        throw new ResourceNotFoundException("ProductVariant [" + productVariant + "] + not found for store [" + store.getCode() + "]");
    }
    destination.setVariant(variant.get());
    if (variantValue.isEmpty()) {
        throw new ResourceNotFoundException("ProductVariant [" + productVariantValue + "] + not found for store [" + store.getCode() + "]");
    }
    destination.setVariantValue(variantValue.get());
    destination.setCode(variant.get().getCode() + ":" + variantValue.get().getCode());
    destination.setAvailable(source.isAvailable());
    destination.setDefaultSelection(source.isDefaultSelection());
    destination.setSku(source.getSku());
    if (StringUtils.isBlank(source.getDateAvailable())) {
        source.setDateAvailable(DateUtil.formatDate(new Date()));
    }
    if (source.getDateAvailable() != null) {
        try {
            destination.setDateAvailable(DateUtil.getDate(source.getDateAvailable()));
        } catch (Exception e) {
            throw new ServiceRuntimeException("Cant format date [" + source.getDateAvailable() + "]");
        }
    }
    destination.setSortOrder(source.getSortOrder());
    Product product = productService.getById(source.getProductId());
    if (product == null) {
        throw new ResourceNotFoundException("Product [" + source.getId() + "] + not found for store [" + store.getCode() + "]");
    }
    if (product.getMerchantStore().getId() != store.getId()) {
        throw new ResourceNotFoundException("Product [" + source.getId() + "] + not found for store [" + store.getCode() + "]");
    }
    destination.setProduct(product);
    return destination;
}
Also used : ProductVariation(com.salesmanager.core.model.catalog.product.variation.ProductVariation) Product(com.salesmanager.core.model.catalog.product.Product) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Date(java.util.Date) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) 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