Search in sources :

Example 21 with ServiceException

use of com.salesmanager.core.business.exception.ServiceException in project shopizer by shopizer-ecommerce.

the class ImagesController method printImage.

/**
 * Exclusive method for dealing with product images
 * @param storeCode
 * @param productCode
 * @param imageName
 * @param extension
 * @param request
 * @return
 * @throws IOException
 */
@RequestMapping(value = "/static/products/{storeCode}/{productCode}/{imageSize}/{imageName}.{extension}", produces = { "image/gif", "image/jpg", "image/png", "application/octet-stream" })
@ResponseBody
public byte[] printImage(@PathVariable final String storeCode, @PathVariable final String productCode, @PathVariable final String imageSize, @PathVariable final String imageName, @PathVariable final String extension, HttpServletRequest request) throws IOException {
    // product image small
    // example small product image -> /static/products/DEFAULT/TB12345/SMALL/product1.jpg
    // example large product image -> /static/products/DEFAULT/TB12345/LARGE/product1.jpg
    /**
     * List of possible imageType
     */
    ProductImageSize size = ProductImageSize.SMALL;
    if (FileContentType.PRODUCTLG.name().equals(imageSize)) {
        size = ProductImageSize.LARGE;
    }
    OutputContentFile image = null;
    try {
        image = productImageService.getProductImage(storeCode, productCode, new StringBuilder().append(imageName).append(".").append(extension).toString(), size);
    } catch (ServiceException e) {
        LOGGER.error("Cannot retrieve image " + imageName, e);
    }
    if (image != null) {
        return image.getFile().toByteArray();
    } else {
        // empty image placeholder
        return tempImage;
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) OutputContentFile(com.salesmanager.core.model.content.OutputContentFile) ProductImageSize(com.salesmanager.core.model.catalog.product.file.ProductImageSize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 22 with ServiceException

use of com.salesmanager.core.business.exception.ServiceException in project shopizer by shopizer-ecommerce.

the class ReferenceController method zoneName.

@RequestMapping(value = "/shop/reference/zoneName")
@ResponseBody
public String zoneName(@RequestParam String zoneCode, HttpServletRequest request, HttpServletResponse response) {
    try {
        Language language = languageUtils.getRequestLanguage(request, response);
        if (language == null) {
            return zoneCode;
        }
        Map<String, Zone> zonesMap = zoneService.getZones(language);
        if (zonesMap != null) {
            Zone z = zonesMap.get(zoneCode);
            if (z != null) {
                return z.getName();
            }
        }
    } catch (ServiceException e) {
        LOGGER.error("Error while looking up zone " + zoneCode);
    }
    return SanitizeUtils.getSafeString(zoneCode);
}
Also used : Language(com.salesmanager.core.model.reference.language.Language) ServiceException(com.salesmanager.core.business.exception.ServiceException) Zone(com.salesmanager.core.model.reference.zone.Zone) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 23 with ServiceException

use of com.salesmanager.core.business.exception.ServiceException in project shopizer by shopizer-ecommerce.

the class ReferenceController method countryName.

@RequestMapping(value = "/shop/reference/countryName")
@ResponseBody
public String countryName(@RequestParam String countryCode, HttpServletRequest request, HttpServletResponse response) {
    try {
        Language language = languageUtils.getRequestLanguage(request, response);
        if (language == null) {
            return countryCode;
        }
        Map<String, Country> countriesMap = countryService.getCountriesMap(language);
        if (countriesMap != null) {
            Country c = countriesMap.get(countryCode);
            if (c != null) {
                return c.getName();
            }
        }
    } catch (ServiceException e) {
        LOGGER.error("Error while looking up country " + countryCode);
    }
    return StringEscapeUtils.escapeHtml4(countryCode);
}
Also used : Language(com.salesmanager.core.model.reference.language.Language) ServiceException(com.salesmanager.core.business.exception.ServiceException) Country(com.salesmanager.core.model.reference.country.Country) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 24 with ServiceException

use of com.salesmanager.core.business.exception.ServiceException 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 25 with ServiceException

use of com.salesmanager.core.business.exception.ServiceException 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)

Aggregations

ServiceException (com.salesmanager.core.business.exception.ServiceException)230 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)88 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)54 ArrayList (java.util.ArrayList)45 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)44 Language (com.salesmanager.core.model.reference.language.Language)38 List (java.util.List)36 Collectors (java.util.stream.Collectors)30 IOException (java.io.IOException)28 InputStream (java.io.InputStream)27 IntegrationConfiguration (com.salesmanager.core.model.system.IntegrationConfiguration)22 Autowired (org.springframework.beans.factory.annotation.Autowired)21 OutputContentFile (com.salesmanager.core.model.content.OutputContentFile)20 Product (com.salesmanager.core.model.catalog.product.Product)19 HashMap (java.util.HashMap)19 Map (java.util.Map)18 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)17 InputContentFile (com.salesmanager.core.model.content.InputContentFile)17 Optional (java.util.Optional)17 IntegrationModule (com.salesmanager.core.model.system.IntegrationModule)16