Search in sources :

Example 6 with ResourceNotFoundException

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

the class ProductInstanceFacadeImpl method list.

@Override
public ReadableEntityList<ReadableProductInstance> list(Long productId, MerchantStore store, Language language, int page, int count) {
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(productId, "Product id cannot be null");
    Product product = productFacade.getProduct(productId, store);
    if (product == null) {
        throw new ResourceNotFoundException("Product with id [" + productId + "] not found for store [" + store.getCode() + "]");
    }
    Page<ProductInstance> instances = productInstanceService.getByProductId(store, product, language, page, count);
    List<ReadableProductInstance> readableInstances = instances.stream().map(rp -> this.readableProductInstanceMapper.convert(rp, store, language)).collect(Collectors.toList());
    return createReadableList(instances, readableInstances);
}
Also used : ReadableEntityUtil.createReadableList(com.salesmanager.shop.util.ReadableEntityUtil.createReadableList) Arrays(java.util.Arrays) 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) ProductInstanceFacade(com.salesmanager.shop.store.controller.product.facade.ProductInstanceFacade) ServiceException(com.salesmanager.core.business.exception.ServiceException) Language(com.salesmanager.core.model.reference.language.Language) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ProductVariationService(com.salesmanager.core.business.services.catalog.product.variation.ProductVariationService) ProductInstanceService(com.salesmanager.core.business.services.catalog.product.instance.ProductInstanceService) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) Product(com.salesmanager.core.model.catalog.product.Product) ProductVariation(com.salesmanager.core.model.catalog.product.variation.ProductVariation) ConstraintException(com.salesmanager.shop.store.api.exception.ConstraintException) PersistableProductInstanceMapper(com.salesmanager.shop.mapper.catalog.product.PersistableProductInstanceMapper) Page(org.springframework.data.domain.Page) ProductInstance(com.salesmanager.core.model.catalog.product.instance.ProductInstance) Collectors(java.util.stream.Collectors) ProductCommonFacade(com.salesmanager.shop.store.controller.product.facade.ProductCommonFacade) List(java.util.List) Component(org.springframework.stereotype.Component) Validate(org.apache.commons.lang3.Validate) PersistableProductInstance(com.salesmanager.shop.model.catalog.product.product.instance.PersistableProductInstance) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) Optional(java.util.Optional) ReadableProductInstanceMapper(com.salesmanager.shop.mapper.catalog.product.ReadableProductInstanceMapper) ReadableEntityList(com.salesmanager.shop.model.entity.ReadableEntityList) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) Product(com.salesmanager.core.model.catalog.product.Product) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ReadableProductInstance(com.salesmanager.shop.model.catalog.product.product.instance.ReadableProductInstance) ProductInstance(com.salesmanager.core.model.catalog.product.instance.ProductInstance) PersistableProductInstance(com.salesmanager.shop.model.catalog.product.product.instance.PersistableProductInstance) ReadableProductInstance(com.salesmanager.shop.model.catalog.product.product.instance.ReadableProductInstance)

Example 7 with ResourceNotFoundException

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

the class ProductInstanceFacadeImpl method update.

@Override
public void update(Long instanceId, PersistableProductInstance productInstance, Long productId, MerchantStore store, Language language) {
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(productInstance, "ProductInstance cannot be null");
    Validate.notNull(productId, "Product id cannot be null");
    Validate.notNull(instanceId, "Product instance id cannot be null");
    Optional<ProductInstance> instanceModel = this.getProductInstance(instanceId, productId, store);
    if (instanceModel.isEmpty()) {
        throw new ResourceNotFoundException("ProductInstance with id [" + instanceId + "] not found for store [" + store.getCode() + "] and productId [" + productId + "]");
    }
    ProductInstance mergedModel = persistableProductInstanceMapper.merge(productInstance, instanceModel.get(), store, language);
    try {
        productInstanceService.save(mergedModel);
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Cannot save product instance for store [" + store.getCode() + "] and productId [" + productId + "]", e);
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ReadableProductInstance(com.salesmanager.shop.model.catalog.product.product.instance.ReadableProductInstance) ProductInstance(com.salesmanager.core.model.catalog.product.instance.ProductInstance) PersistableProductInstance(com.salesmanager.shop.model.catalog.product.product.instance.PersistableProductInstance) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 8 with ResourceNotFoundException

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

the class ProductInstanceFacadeImpl method delete.

@Override
public void delete(Long productInstance, Long productId, MerchantStore store) {
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(productInstance, "ProductInstance id cannot be null");
    Validate.notNull(productId, "Product id cannot be null");
    Optional<ProductInstance> instanceModel = this.getProductInstance(productInstance, productId, store);
    if (instanceModel.isEmpty()) {
        throw new ResourceNotFoundException("ProductInstance with id [" + productInstance + "] not found for store [" + store.getCode() + "] and productId [" + productId + "]");
    }
    try {
        productInstanceService.delete(instanceModel.get());
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Cannot delete product instance [" + productInstance + "]  for store [" + store.getCode() + "] and productId [" + productId + "]", e);
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ReadableProductInstance(com.salesmanager.shop.model.catalog.product.product.instance.ReadableProductInstance) ProductInstance(com.salesmanager.core.model.catalog.product.instance.ProductInstance) PersistableProductInstance(com.salesmanager.shop.model.catalog.product.product.instance.PersistableProductInstance) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 9 with ResourceNotFoundException

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

the class ProductInstanceGroupFacadeImpl method delete.

@Override
public void delete(Long productInstanceGroup, Long productId, MerchantStore store) {
    ProductInstanceGroup group = this.group(productInstanceGroup, store);
    if (group == null) {
        throw new ResourceNotFoundException("Product instance group [" + group.getId() + " not found for store [" + store.getCode() + "]");
    }
    try {
        // null all group from instances
        for (ProductInstance instance : group.getProductInstances()) {
            Optional<ProductInstance> p = productInstanceService.getById(instance.getId(), store);
            if (p.isEmpty()) {
                throw new ResourceNotFoundException("Product instance [" + instance.getId() + " not found for store [" + store.getCode() + "]");
            }
            instance.setProductInstanceGroup(null);
            productInstanceService.save(instance);
        }
        // now delete
        productInstanceGroupService.delete(group);
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Cannot remove product instance group [" + productInstanceGroup + "] for store [" + store.getCode() + "]");
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) ProductInstanceGroup(com.salesmanager.core.model.catalog.product.instance.ProductInstanceGroup) ReadableProductInstanceGroup(com.salesmanager.shop.model.catalog.product.product.instanceGroup.ReadableProductInstanceGroup) PersistableProductInstanceGroup(com.salesmanager.shop.model.catalog.product.product.instanceGroup.PersistableProductInstanceGroup) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ProductInstance(com.salesmanager.core.model.catalog.product.instance.ProductInstance) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 10 with ResourceNotFoundException

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

the class ProductInventoryFacadeImpl method get.

@Override
public ReadableInventory get(Long productId, Long inventoryId, MerchantStore store, Language language) {
    Product product = getProductById(productId);
    if (product.getMerchantStore().getId().intValue() != store.getId().intValue()) {
        throw new ResourceNotFoundException("Product with id [" + productId + "] not found for store [" + store.getCode() + "]");
    }
    ProductAvailability availability = productAvailabilityService.getByInventoryId(productId, inventoryId, store).orElseThrow(() -> new ResourceNotFoundException("Inventory with id [" + inventoryId + "] not found"));
    return readableInventoryMapper.convert(availability, store, language);
}
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)

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