Search in sources :

Example 6 with FileContentType

use of com.salesmanager.core.model.content.FileContentType 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;
    }
}
Also used : OutputContentFile(com.salesmanager.core.model.content.OutputContentFile) FileContentType(com.salesmanager.core.model.content.FileContentType) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

FileContentType (com.salesmanager.core.model.content.FileContentType)6 OutputContentFile (com.salesmanager.core.model.content.OutputContentFile)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)4 ServiceException (com.salesmanager.core.business.exception.ServiceException)2 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 InputContentFile (com.salesmanager.core.model.content.InputContentFile)1 Customer (com.salesmanager.core.model.customer.Customer)1 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)1 Order (com.salesmanager.core.model.order.Order)1 OrderProductDownload (com.salesmanager.core.model.order.orderproduct.OrderProductDownload)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1