Search in sources :

Example 81 with ResourceNotFoundException

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

the class ProductVariationFacadeImpl method update.

@Override
public void update(Long variationId, 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");
    Optional<ProductVariation> p = productVariationService.getById(store, variationId, language);
    if (p.isEmpty()) {
        throw new ResourceNotFoundException("ProductVariation not found for id [" + variationId + "] and store [" + store.getCode() + "]");
    }
    ProductVariation productVariant = p.get();
    productVariant.setId(variationId);
    productVariant.setCode(var.getCode());
    ProductVariation model = persistableProductVariationMapper.merge(var, productVariant, store, language);
    try {
        model.setMerchantStore(store);
        productVariationService.save(model);
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Exception while creating 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 82 with ResourceNotFoundException

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

the class ProductCommonFacadeImpl method getProduct.

@Override
public ReadableProduct getProduct(MerchantStore store, Long id, Language language) {
    Product product = productService.findOne(id, store);
    if (product == null) {
        throw new ResourceNotFoundException("Product [" + id + "] not found");
    }
    if (product.getMerchantStore().getId() != store.getId()) {
        throw new ResourceNotFoundException("Product [" + id + "] not found for store [" + store.getId() + "]");
    }
    ReadableProduct readableProduct = new ReadableProduct();
    ReadableProductPopulator populator = new ReadableProductPopulator();
    populator.setPricingService(pricingService);
    populator.setimageUtils(imageUtils);
    try {
        readableProduct = populator.populate(product, readableProduct, store, language);
    } catch (ConversionException e) {
        throw new ConversionRuntimeException("Error converting product [" + id + "]", e);
    }
    return readableProduct;
}
Also used : ConversionException(com.salesmanager.core.business.exception.ConversionException) ReadableProductPopulator(com.salesmanager.shop.populator.catalog.ReadableProductPopulator) 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) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException)

Example 83 with ResourceNotFoundException

use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException 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 84 with ResourceNotFoundException

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

the class ContentFacadeImpl method getContentFolder.

@Override
public ContentFolder getContentFolder(String folder, MerchantStore store) throws Exception {
    try {
        List<String> imageNames = Optional.ofNullable(contentService.getContentFilesNames(store.getCode(), FileContentType.IMAGE)).orElseThrow(() -> new ResourceNotFoundException("No Folder found for path : " + folder));
        // images from CMS
        List<ContentImage> contentImages = imageNames.stream().map(name -> convertToContentImage(name, store)).collect(Collectors.toList());
        ContentFolder contentFolder = new ContentFolder();
        if (!StringUtils.isBlank(folder)) {
            contentFolder.setPath(URLEncoder.encode(folder, "UTF-8"));
        }
        contentFolder.getContent().addAll(contentImages);
        return contentFolder;
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Error while getting folder " + e.getMessage(), e);
    }
}
Also used : ContentDescription(com.salesmanager.core.model.content.ContentDescription) ContentFacade(com.salesmanager.shop.store.controller.content.facade.ContentFacade) LoggerFactory(org.slf4j.LoggerFactory) StringUtils(org.apache.commons.lang3.StringUtils) LanguageService(com.salesmanager.core.business.services.reference.language.LanguageService) ContentDescriptionEntity(com.salesmanager.shop.model.content.ContentDescriptionEntity) ArrayList(java.util.ArrayList) ServiceException(com.salesmanager.core.business.exception.ServiceException) PersistableContentBox(com.salesmanager.shop.model.content.box.PersistableContentBox) PersistableContentPage(com.salesmanager.shop.model.content.page.PersistableContentPage) Inject(javax.inject.Inject) Language(com.salesmanager.core.model.reference.language.Language) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ContentFile(com.salesmanager.shop.model.content.ContentFile) ReadableContentPageFull(com.salesmanager.shop.model.content.page.ReadableContentPageFull) ReadableContentPage(com.salesmanager.shop.model.content.page.ReadableContentPage) ByteArrayInputStream(java.io.ByteArrayInputStream) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Content(com.salesmanager.core.model.content.Content) ReadableContentFull(com.salesmanager.shop.model.content.ReadableContentFull) Qualifier(org.springframework.beans.factory.annotation.Qualifier) ContentType(com.salesmanager.core.model.content.ContentType) FileContentType(com.salesmanager.core.model.content.FileContentType) ReadableContentBox(com.salesmanager.shop.model.content.box.ReadableContentBox) Validate(org.jsoup.helper.Validate) OutputContentFile(com.salesmanager.core.model.content.OutputContentFile) Logger(org.slf4j.Logger) ConstraintException(com.salesmanager.shop.store.api.exception.ConstraintException) IOException(java.io.IOException) ImageFilePath(com.salesmanager.shop.utils.ImageFilePath) Page(org.springframework.data.domain.Page) InputContentFile(com.salesmanager.core.model.content.InputContentFile) Collectors(java.util.stream.Collectors) ContentService(com.salesmanager.core.business.services.content.ContentService) ContentFolder(com.salesmanager.shop.model.content.ContentFolder) ReadableContentBoxFull(com.salesmanager.shop.model.content.box.ReadableContentBoxFull) URLEncoder(java.net.URLEncoder) List(java.util.List) Component(org.springframework.stereotype.Component) ContentImage(com.salesmanager.shop.model.content.ContentImage) CollectionUtils(org.springframework.util.CollectionUtils) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) Optional(java.util.Optional) ReadableContentEntity(com.salesmanager.shop.model.content.ReadableContentEntity) FilePathUtils(com.salesmanager.shop.utils.FilePathUtils) InputStream(java.io.InputStream) ReadableEntityList(com.salesmanager.shop.model.entity.ReadableEntityList) ContentImage(com.salesmanager.shop.model.content.ContentImage) ContentFolder(com.salesmanager.shop.model.content.ContentFolder) ServiceException(com.salesmanager.core.business.exception.ServiceException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 85 with ResourceNotFoundException

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

the class ContentFacadeImpl method getContentPage.

@Override
public ReadableContentPage getContentPage(String code, MerchantStore store, Language language) {
    Validate.notNull(code, "Content code cannot be null");
    Validate.notNull(store, "MerchantStore cannot be null");
    try {
        Content content = null;
        if (language == null) {
            content = Optional.ofNullable(contentService.getByCode(code, store)).orElseThrow(() -> new ResourceNotFoundException("No page found : " + code));
        } else {
            content = Optional.ofNullable(contentService.getByCode(code, store, language)).orElseThrow(() -> new ResourceNotFoundException("No page found : " + code));
        }
        return convertContentToReadableContentPage(store, language, content);
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Error while getting page " + e.getMessage(), e);
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) Content(com.salesmanager.core.model.content.Content) 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