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;
}
}
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);
}
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);
}
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);
}
}
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);
}
}
Aggregations