@Override public List<OutputContentFile> getImages(Product product) throws ServiceException { if (cacheManager.getTreeCache() == null) { throw new ServiceException( "CmsImageFileManagerInfinispan has a null cacheManager.getTreeCache()"); } List<OutputContentFile> images = new ArrayList<OutputContentFile>(); try { FileNameMap fileNameMap = URLConnection.getFileNameMap(); StringBuilder nodePath = new StringBuilder(); nodePath.append(product.getMerchantStore().getCode()); Node<String, Object> merchantNode = this.getNode(nodePath.toString()); if (merchantNode == null) { return null; } for (String key : merchantNode.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; }
@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 { } }