use of com.salesmanager.core.model.content.OutputContentFile in project shopizer by shopizer-ecommerce.
the class ContentServiceImpl method renameFile.
@Override
public void renameFile(String merchantStoreCode, FileContentType fileContentType, Optional<String> path, String originalName, String newName) throws ServiceException {
OutputContentFile file = contentFileManager.getFile(merchantStoreCode, path, fileContentType, originalName);
if (file == null) {
throw new ServiceException("File name [" + originalName + "] not found for merchant [" + merchantStoreCode + "]");
}
ByteArrayOutputStream os = file.getFile();
InputStream is = new ByteArrayInputStream(os.toByteArray());
// remove file
contentFileManager.removeFile(merchantStoreCode, fileContentType, originalName, path);
// recreate file
InputContentFile inputFile = new InputContentFile();
inputFile.setFileContentType(fileContentType);
inputFile.setFileName(newName);
inputFile.setMimeType(file.getMimeType());
inputFile.setFile(is);
contentFileManager.addFile(merchantStoreCode, path, inputFile);
}
use of com.salesmanager.core.model.content.OutputContentFile in project shopizer by shopizer-ecommerce.
the class FilesController method downloadFile.
/**
* Serves static files (css, js ...) the repository is a single node by merchant
* @param storeCode
* @param extension
* @return
* @throws IOException
* @throws ServiceException
*/
@RequestMapping("/static/files/{storeCode}/{fileName}.{extension}")
@ResponseBody
public byte[] downloadFile(@PathVariable final String storeCode, @PathVariable final String fileName, @PathVariable final String extension, HttpServletRequest request, HttpServletResponse response) throws IOException, ServiceException {
// example -> /files/<store code>/myfile.css
FileContentType fileType = FileContentType.STATIC_FILE;
// needs to query the new API
OutputContentFile file = contentService.getContentFile(storeCode, fileType, new StringBuilder().append(fileName).append(".").append(extension).toString());
if (file != null) {
return file.getFile().toByteArray();
} else {
LOGGER.debug("File not found " + fileName + "." + extension);
response.sendError(404, Constants.FILE_NOT_FOUND);
return null;
}
}
use of com.salesmanager.core.model.content.OutputContentFile in project shopizer by shopizer-ecommerce.
the class ContentImagesTest method createStoreLogo.
// @Test
@Ignore
public void createStoreLogo() throws ServiceException, FileNotFoundException, IOException {
MerchantStore store = merchantService.getByCode(MerchantStore.DEFAULT_STORE);
final File file1 = new File("C:/doc/Hadoop.jpg");
if (!file1.exists() || !file1.canRead()) {
throw new ServiceException("Can't read" + file1.getAbsolutePath());
}
byte[] is = IOUtils.toByteArray(new FileInputStream(file1));
ByteArrayInputStream inputStream = new ByteArrayInputStream(is);
InputContentFile cmsContentImage = new InputContentFile();
cmsContentImage.setFileName(file1.getName());
cmsContentImage.setFile(inputStream);
// logo as a content
contentService.addLogo(store.getCode(), cmsContentImage);
store.setStoreLogo(file1.getName());
merchantService.update(store);
// query the store
store = merchantService.getByCode(MerchantStore.DEFAULT_STORE);
// get the logo
String logo = store.getStoreLogo();
OutputContentFile image = contentService.getContentFile(store.getCode(), FileContentType.LOGO, logo);
// print image
OutputStream outputStream = new FileOutputStream("C:/doc/logo-" + image.getFileName());
ByteArrayOutputStream baos = image.getFile();
baos.writeTo(outputStream);
// remove image
contentService.removeFile(store.getCode(), FileContentType.LOGO, store.getStoreLogo());
}
use of com.salesmanager.core.model.content.OutputContentFile in project shopizer by shopizer-ecommerce.
the class StaticContentTest method createImage.
@Test
public void createImage() throws ServiceException, FileNotFoundException, IOException {
MerchantStore store = merchantService.getByCode(MerchantStore.DEFAULT_STORE);
final File file1 = new File(IMAGE_FILE);
if (!file1.exists() || !file1.canRead()) {
throw new ServiceException("Can't read" + file1.getAbsolutePath());
}
final byte[] is = IOUtils.toByteArray(new FileInputStream(file1));
final ByteArrayInputStream inputStream = new ByteArrayInputStream(is);
final InputContentFile cmsContentImage = new InputContentFile();
cmsContentImage.setFileName(file1.getName());
cmsContentImage.setFile(inputStream);
cmsContentImage.setFileContentType(FileContentType.IMAGE);
// Add image
contentService.addContentFile(store.getCode(), cmsContentImage);
// get image
OutputContentFile image = contentService.getContentFile(store.getCode(), FileContentType.IMAGE, file1.getName());
// print image
OutputStream outputStream = new FileOutputStream(OUTPUT_FOLDER + image.getFileName());
ByteArrayOutputStream baos = image.getFile();
baos.writeTo(outputStream);
// remove image
contentService.removeFile(store.getCode(), FileContentType.IMAGE, file1.getName());
}
use of com.salesmanager.core.model.content.OutputContentFile in project shopizer by shopizer-ecommerce.
the class ProductTest method testViewImage.
private void testViewImage(Product product) throws Exception {
ProductImage productImage = product.getProductImage();
// get physical small image
OutputContentFile contentFile = productImageService.getProductImage(product.getMerchantStore().getCode(), product.getSku(), productImage.getProductImage(), ProductImageSize.SMALL);
Assert.assertNotNull(contentFile);
// get physical original image
contentFile = productImageService.getProductImage(product.getMerchantStore().getCode(), product.getSku(), productImage.getProductImage(), ProductImageSize.LARGE);
Assert.assertNotNull(contentFile);
}
Aggregations