use of com.salesmanager.core.business.exception.ServiceException in project shopizer by shopizer-ecommerce.
the class GCPProductContentFileManager method getProductImage.
@Override
public OutputContentFile getProductImage(String merchantStoreCode, String productCode, String imageName, ProductImageSize size) throws ServiceException {
InputStream inputStream = null;
try {
Storage storage = StorageOptions.getDefaultInstance().getService();
String bucketName = bucketName();
if (!this.bucketExists(storage, bucketName)) {
return null;
}
Blob blob = storage.get(BlobId.of(bucketName, filePath(merchantStoreCode, productCode, size.name(), imageName)));
ReadChannel reader = blob.reader();
inputStream = Channels.newInputStream(reader);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
IOUtils.copy(inputStream, outputStream);
OutputContentFile ct = new OutputContentFile();
ct.setFile(outputStream);
ct.setFileName(blob.getName());
return ct;
} catch (final Exception e) {
LOGGER.error("Error while getting files", e);
throw new ServiceException(e);
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (Exception ignore) {
}
}
}
}
use of com.salesmanager.core.business.exception.ServiceException in project shopizer by shopizer-ecommerce.
the class CmsImageFileManagerImpl method addProductImage.
/**
* root -productFiles -merchant-id PRODUCT-ID(key) -> CacheAttribute(value) - image 1 - image 2 -
* image 3
*/
@Override
public void addProductImage(ProductImage productImage, ImageContentFile contentImage) throws ServiceException {
if (cacheManager.getTreeCache() == null) {
throw new ServiceException("CmsImageFileManagerInfinispan has a null cacheManager.getTreeCache()");
}
try {
// node
StringBuilder nodePath = new StringBuilder();
nodePath.append(productImage.getProduct().getMerchantStore().getCode()).append(Constants.SLASH).append(productImage.getProduct().getSku()).append(Constants.SLASH);
if (contentImage.getFileContentType().name().equals(FileContentType.PRODUCT.name())) {
nodePath.append(SMALL);
} else if (contentImage.getFileContentType().name().equals(FileContentType.PRODUCTLG.name())) {
nodePath.append(LARGE);
}
Node<String, Object> productNode = this.getNode(nodePath.toString());
InputStream isFile = contentImage.getFile();
ByteArrayOutputStream output = new ByteArrayOutputStream();
IOUtils.copy(isFile, output);
// object for a given product containing all images
productNode.put(contentImage.getFileName(), output.toByteArray());
} catch (Exception e) {
throw new ServiceException(e);
}
}
use of com.salesmanager.core.business.exception.ServiceException in project shopizer by shopizer-ecommerce.
the class CmsImageFileManagerImpl method removeImages.
@SuppressWarnings("unchecked")
@Override
public void removeImages(final String merchantStoreCode) throws ServiceException {
if (cacheManager.getTreeCache() == null) {
throw new ServiceException("CmsImageFileManagerInfinispan has a null cacheManager.getTreeCache()");
}
try {
final StringBuilder merchantPath = new StringBuilder();
merchantPath.append(getRootName()).append(merchantStoreCode);
cacheManager.getTreeCache().getRoot().remove(merchantPath.toString());
} catch (Exception e) {
throw new ServiceException(e);
} finally {
}
}
use of com.salesmanager.core.business.exception.ServiceException in project shopizer by shopizer-ecommerce.
the class CmsImageFileManagerImpl method getImages.
@Override
public List<OutputContentFile> getImages(final String merchantStoreCode, FileContentType imageContentType) throws ServiceException {
if (cacheManager.getTreeCache() == null) {
throw new ServiceException("CmsImageFileManagerInfinispan has a null cacheManager.getTreeCache()");
}
List<OutputContentFile> images = new ArrayList<OutputContentFile>();
FileNameMap fileNameMap = URLConnection.getFileNameMap();
try {
StringBuilder nodePath = new StringBuilder();
nodePath.append(merchantStoreCode);
Node<String, Object> merchantNode = this.getNode(nodePath.toString());
Set<Node<String, Object>> childs = merchantNode.getChildren();
// TODO image sizes
for (Node<String, Object> node : childs) {
for (String key : node.getKeys()) {
byte[] imageBytes = (byte[]) merchantNode.get(key);
OutputContentFile contentImage = new OutputContentFile();
InputStream input = new ByteArrayInputStream(imageBytes);
ByteArrayOutputStream output = new ByteArrayOutputStream();
IOUtils.copy(input, output);
String contentType = fileNameMap.getContentTypeFor(key);
contentImage.setFile(output);
contentImage.setMimeType(contentType);
contentImage.setFileName(key);
images.add(contentImage);
}
}
} catch (Exception e) {
throw new ServiceException(e);
} finally {
}
return images;
}
use of com.salesmanager.core.business.exception.ServiceException in project shopizer by shopizer-ecommerce.
the class CmsImageFileManagerImpl method removeProductImages.
@Override
public void removeProductImages(Product product) throws ServiceException {
if (cacheManager.getTreeCache() == null) {
throw new ServiceException("CmsImageFileManagerInfinispan has a null cacheManager.getTreeCache()");
}
try {
StringBuilder nodePath = new StringBuilder();
nodePath.append(product.getMerchantStore().getCode());
Node<String, Object> merchantNode = this.getNode(nodePath.toString());
merchantNode.remove(product.getSku());
} catch (Exception e) {
throw new ServiceException(e);
} finally {
}
}
Aggregations