use of com.salesmanager.core.model.content.OutputContentFile in project shopizer by shopizer-ecommerce.
the class CmsStaticContentFileManagerImpl method getFiles.
@Override
public List<OutputContentFile> getFiles(final String merchantStoreCode, Optional<String> path, final FileContentType staticContentType) throws ServiceException {
if (cacheManager.getTreeCache() == null) {
throw new ServiceException("CmsStaticContentFileManagerInfinispan has a null cacheManager.getTreeCache()");
}
List<OutputContentFile> images = new ArrayList<OutputContentFile>();
try {
FileNameMap fileNameMap = URLConnection.getFileNameMap();
String nodePath = this.getNodePath(merchantStoreCode, staticContentType);
final Node<String, Object> merchantNode = this.getNode(nodePath);
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 (final Exception e) {
LOGGER.error("Error while fetching file for {} merchant ", merchantStoreCode);
throw new ServiceException(e);
}
return images;
}
use of com.salesmanager.core.model.content.OutputContentFile in project shopizer by shopizer-ecommerce.
the class CmsStaticContentFileManagerImpl method getFile.
/**
* Method to return static data for given Merchant store based on the file
* name. Content data will be searched in underlying Infinispan cache tree
* and {@link OutputStaticContentData} will be returned on finding an
* associated file. In case of no file, null be returned.
*
* @param store
* Merchant store
* @param contentFileName
* name of file being requested
* @return {@link OutputStaticContentData}
* @throws ServiceException
*/
@Override
public OutputContentFile getFile(final String merchantStoreCode, Optional<String> path, final FileContentType fileContentType, final String contentFileName) throws ServiceException {
if (cacheManager.getTreeCache() == null) {
throw new ServiceException("CmsStaticContentFileManagerInfinispan has a null cacheManager.getTreeCache()");
}
OutputContentFile outputStaticContentData = new OutputContentFile();
InputStream input = null;
try {
String nodePath = this.getNodePath(merchantStoreCode, fileContentType);
final Node<String, Object> merchantNode = this.getNode(nodePath);
final byte[] fileBytes = (byte[]) merchantNode.get(contentFileName);
if (fileBytes == null) {
LOGGER.warn("file byte is null, no file found");
return null;
}
input = new ByteArrayInputStream(fileBytes);
final ByteArrayOutputStream output = new ByteArrayOutputStream();
IOUtils.copy(input, output);
outputStaticContentData.setFile(output);
outputStaticContentData.setMimeType(URLConnection.getFileNameMap().getContentTypeFor(contentFileName));
outputStaticContentData.setFileName(contentFileName);
outputStaticContentData.setFileContentType(fileContentType);
} catch (final Exception e) {
LOGGER.error("Error while fetching file for {} merchant ", merchantStoreCode);
throw new ServiceException(e);
}
return outputStaticContentData;
}
use of com.salesmanager.core.model.content.OutputContentFile in project shopizer by shopizer-ecommerce.
the class ContentAssetsManager method getOutputContentFile.
default OutputContentFile getOutputContentFile(byte[] byteArray) {
ByteArrayOutputStream baos = new ByteArrayOutputStream(byteArray.length);
baos.write(byteArray, 0, byteArray.length);
OutputContentFile ct = new OutputContentFile();
ct.setFile(baos);
return ct;
}
use of com.salesmanager.core.model.content.OutputContentFile in project shopizer by shopizer-ecommerce.
the class S3StaticContentAssetsManagerImpl method getFiles.
@Override
public List<OutputContentFile> getFiles(String merchantStoreCode, Optional<String> folderPath, FileContentType fileContentType) throws ServiceException {
try {
// get buckets
String bucketName = bucketName();
ListObjectsV2Request listObjectsRequest = new ListObjectsV2Request().withBucketName(bucketName).withPrefix(nodePath(merchantStoreCode, fileContentType));
List<OutputContentFile> files = null;
final AmazonS3 s3 = s3Client();
ListObjectsV2Result results = s3.listObjectsV2(listObjectsRequest);
List<S3ObjectSummary> objects = results.getObjectSummaries();
for (S3ObjectSummary os : objects) {
if (files == null) {
files = new ArrayList<OutputContentFile>();
}
String mimetype = URLConnection.guessContentTypeFromName(os.getKey());
if (!StringUtils.isBlank(mimetype)) {
S3Object o = s3.getObject(bucketName, os.getKey());
byte[] byteArray = IOUtils.toByteArray(o.getObjectContent());
ByteArrayOutputStream baos = new ByteArrayOutputStream(byteArray.length);
baos.write(byteArray, 0, byteArray.length);
OutputContentFile ct = new OutputContentFile();
ct.setFile(baos);
files.add(ct);
}
}
LOGGER.info("Content getFiles");
return files;
} catch (final Exception e) {
LOGGER.error("Error while getting files", e);
throw new ServiceException(e);
}
}
use of com.salesmanager.core.model.content.OutputContentFile in project shopizer by shopizer-ecommerce.
the class GCPStaticContentAssetsManagerImpl method getFiles.
@Override
public List<OutputContentFile> getFiles(String merchantStoreCode, Optional<String> folderPath, FileContentType fileContentType) throws ServiceException {
try {
List<String> fileNames = getFileNames(merchantStoreCode, folderPath, fileContentType);
List<OutputContentFile> files = new ArrayList<OutputContentFile>();
for (String fileName : fileNames) {
files.add(getFile(merchantStoreCode, folderPath, fileContentType, fileName));
}
LOGGER.info("Content get file names");
return files;
} catch (Exception e) {
LOGGER.error("Error while getting file names", e);
throw new ServiceException(e);
}
}
Aggregations