use of com.salesmanager.core.model.content.FileContentType in project shopizer by shopizer-ecommerce.
the class ShoppingOrderDownloadController method downloadFile.
/**
* Virtual product(s) download link
* @param id
* @param model
* @param request
* @param response
* @return
* @throws Exception
*/
@PreAuthorize("hasRole('AUTH_CUSTOMER')")
@RequestMapping("/download/{orderId}/{id}.html")
@ResponseBody
public byte[] downloadFile(@PathVariable Long orderId, @PathVariable Long id, Model model, HttpServletRequest request, HttpServletResponse response) throws Exception {
MerchantStore store = (MerchantStore) request.getAttribute(Constants.MERCHANT_STORE);
FileContentType fileType = FileContentType.PRODUCT_DIGITAL;
// get customer and check order
Order order = orderService.getById(orderId);
if (order == null) {
LOGGER.warn("Order is null for id " + orderId);
response.sendError(404, "Image not found");
return null;
}
// order belongs to customer
Customer customer = (Customer) super.getSessionAttribute(Constants.CUSTOMER, request);
if (customer == null) {
response.sendError(404, "Image not found");
return null;
}
// get it from OrderProductDownlaod
String fileName = null;
OrderProductDownload download = orderProductDownloadService.getById(id);
if (download == null) {
LOGGER.warn("OrderProductDownload is null for id " + id);
response.sendError(404, "Image not found");
return null;
}
fileName = download.getOrderProductFilename();
// needs to query the new API
OutputContentFile file = contentService.getContentFile(store.getCode(), fileType, fileName);
if (file != null) {
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
return file.getFile().toByteArray();
} else {
LOGGER.warn("Image not found for OrderProductDownload id " + id);
response.sendError(404, "Image not found");
return null;
}
// product image
// example -> /download/12345/120.html
}
use of com.salesmanager.core.model.content.FileContentType in project shopizer by shopizer-ecommerce.
the class ImagesController method printImage.
/**
* Logo, content image
* @param storeId
* @param imageType (LOGO, CONTENT, IMAGE)
* @param imageName
* @return
* @throws IOException
* @throws ServiceException
*/
@RequestMapping("/static/files/{storeCode}/{imageType}/{imageName}.{extension}")
@ResponseBody
public byte[] printImage(@PathVariable final String storeCode, @PathVariable final String imageType, @PathVariable final String imageName, @PathVariable final String extension) throws IOException, ServiceException {
// example -> /static/files/DEFAULT/CONTENT/myImage.png
FileContentType imgType = null;
if (FileContentType.LOGO.name().equals(imageType)) {
imgType = FileContentType.LOGO;
}
if (FileContentType.IMAGE.name().equals(imageType)) {
imgType = FileContentType.IMAGE;
}
if (FileContentType.PROPERTY.name().equals(imageType)) {
imgType = FileContentType.PROPERTY;
}
OutputContentFile image = contentService.getContentFile(storeCode, imgType, new StringBuilder().append(imageName).append(".").append(extension).toString());
if (image != null) {
return image.getFile().toByteArray();
} else {
return tempImage;
}
}
use of com.salesmanager.core.model.content.FileContentType in project shopizer by shopizer-ecommerce.
the class FilesController method downloadProduct.
/**
* Requires admin with roles admin, superadmin or product
* @param storeCode
* @param fileName
* @param extension
* @param request
* @param response
* @return
* @throws Exception
*/
@PreAuthorize("hasRole('PRODUCTS')")
@RequestMapping("/admin/files/downloads/{storeCode}/{fileName}.{extension}")
@ResponseBody
public byte[] downloadProduct(@PathVariable final String storeCode, @PathVariable final String fileName, @PathVariable final String extension, HttpServletRequest request, HttpServletResponse response) throws Exception {
FileContentType fileType = FileContentType.PRODUCT_DIGITAL;
String fileNameAndExtension = new StringBuilder().append(fileName).append(".").append(extension).toString();
// needs to query the new API
OutputContentFile file = contentService.getContentFile(storeCode, fileType, fileNameAndExtension);
if (file != null) {
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileNameAndExtension + "\"");
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.FileContentType in project shopizer by shopizer-ecommerce.
the class ContentFacadeImpl method addContentFile.
@Override
public void addContentFile(ContentFile file, String merchantStoreCode) {
try {
byte[] payload = file.getFile();
String fileName = file.getName();
try (InputStream targetStream = new ByteArrayInputStream(payload)) {
String type = file.getContentType().split(FILE_CONTENT_DELIMETER)[0];
FileContentType fileType = getFileContentType(type);
InputContentFile cmsContent = new InputContentFile();
cmsContent.setFileName(fileName);
cmsContent.setMimeType(file.getContentType());
cmsContent.setFile(targetStream);
cmsContent.setFileContentType(fileType);
contentService.addContentFile(merchantStoreCode, cmsContent);
}
} catch (ServiceException | IOException e) {
throw new ServiceRuntimeException(e);
}
}
use of com.salesmanager.core.model.content.FileContentType in project shopizer by shopizer-ecommerce.
the class ContentFacadeImpl method delete.
@Override
public void delete(MerchantStore store, String fileName, String fileType) {
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(fileName, "File name cannot be null");
try {
FileContentType t = FileContentType.valueOf(fileType);
contentService.removeFile(store.getCode(), t, fileName);
} catch (ServiceException e) {
throw new ServiceRuntimeException(e);
}
}
Aggregations