Search in sources :

Example 1 with JasperTemplate

use of org.openlmis.stockmanagement.domain.JasperTemplate in project openlmis-stockmanagement by OpenLMIS.

the class PhysicalInventoryController method print.

/**
 * Print out physical inventory as a PDF file.
 *
 * @param id The UUID of the stock event to print
 * @param format The report format
 * @return ResponseEntity with the "#200 OK" HTTP response status and PDF file on success, or
 *     ResponseEntity containing the error description status.
 */
@GetMapping(value = ID_PATH_VARIABLE, params = "format")
@ResponseBody
public ModelAndView print(@PathVariable("id") UUID id, @RequestParam String format) throws JasperReportViewException {
    checkPermission(id);
    checkFormat(format.toLowerCase());
    JasperTemplate printTemplate = templateService.getByName(PRINT_PI);
    if (printTemplate == null) {
        throw new ValidationMessageException(new Message(ERROR_REPORTING_TEMPLATE_NOT_FOUND_WITH_NAME, PRINT_PI));
    }
    JasperReportsMultiFormatView jasperView = jasperReportService.getJasperReportsView(printTemplate);
    return new ModelAndView(jasperView, getParams(id, format));
}
Also used : Message(org.openlmis.stockmanagement.util.Message) ValidationMessageException(org.openlmis.stockmanagement.exception.ValidationMessageException) ModelAndView(org.springframework.web.servlet.ModelAndView) JasperReportsMultiFormatView(org.springframework.web.servlet.view.jasperreports.JasperReportsMultiFormatView) JasperTemplate(org.openlmis.stockmanagement.domain.JasperTemplate) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with JasperTemplate

use of org.openlmis.stockmanagement.domain.JasperTemplate in project openlmis-stockmanagement by OpenLMIS.

the class JasperTemplateService method validateFileAndSaveTemplate.

/**
 * Validate ".jrmxl" file and insert if template not exist.
 * If this name of template already exist, remove older template and insert new.
 */
public void validateFileAndSaveTemplate(JasperTemplate template, MultipartFile file) {
    JasperTemplate templateTmp = templateRepository.findByName(template.getName());
    if (templateTmp != null) {
        templateRepository.removeAndFlush(templateTmp);
    }
    validateFileAndSetData(template, file);
    templateRepository.save(template);
}
Also used : JasperTemplate(org.openlmis.stockmanagement.domain.JasperTemplate)

Example 3 with JasperTemplate

use of org.openlmis.stockmanagement.domain.JasperTemplate in project openlmis-stockmanagement by OpenLMIS.

the class PhysicalInventoryTemplateController method saveTemplate.

/**
 * Add Physical Inventory report templates with ".jrxml" format(extension) to database, remove
 * older one if already exists.
 *
 * @param file File in ".jrxml" format to add or upload.
 */
@PostMapping
@ResponseStatus(HttpStatus.OK)
public void saveTemplate(@RequestPart("file") MultipartFile file) {
    LOGGER.debug("Checking right to create Physical Inventory template");
    permissionService.canManageSystemSettings();
    JasperTemplate template = new JasperTemplate(PRINT_PI, null, CONSISTENCY_REPORT, DESCRIPTION_PI);
    templateService.validateFileAndSaveTemplate(template, file);
}
Also used : JasperTemplate(org.openlmis.stockmanagement.domain.JasperTemplate) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus)

Example 4 with JasperTemplate

use of org.openlmis.stockmanagement.domain.JasperTemplate in project openlmis-stockmanagement by OpenLMIS.

the class PhysicalInventoryTemplateController method downloadXmlTemplate.

/**
 * Download report template with ".jrxml" format(extension) for Physical Inventory from database.
 *
 * @param response HttpServletResponse object.
 */
@GetMapping
@ResponseBody
public void downloadXmlTemplate(HttpServletResponse response) throws IOException {
    LOGGER.debug("Checking right to view Physical Inventory template");
    permissionService.canManageSystemSettings();
    JasperTemplate piPrintTemplate = templateService.getByName(PRINT_PI);
    if (piPrintTemplate == null) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND, "Physical Inventory template does not exist.");
    } else {
        response.setContentType("application/xml");
        response.addHeader("Content-Disposition", "attachment; filename=piPrint" + ".jrxml");
        File file = templateService.convertJasperToXml(piPrintTemplate);
        try (InputStream fis = new FileInputStream(file);
            InputStream bis = new BufferedInputStream(fis)) {
            IOUtils.copy(bis, response.getOutputStream());
            response.flushBuffer();
        } catch (IOException ex) {
            throw new ValidationMessageException(ex, new Message(ERROR_IO, ex.getMessage()));
        }
    }
}
Also used : Message(org.openlmis.stockmanagement.util.Message) BufferedInputStream(java.io.BufferedInputStream) ValidationMessageException(org.openlmis.stockmanagement.exception.ValidationMessageException) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile) JasperTemplate(org.openlmis.stockmanagement.domain.JasperTemplate) FileInputStream(java.io.FileInputStream) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

JasperTemplate (org.openlmis.stockmanagement.domain.JasperTemplate)4 ValidationMessageException (org.openlmis.stockmanagement.exception.ValidationMessageException)2 Message (org.openlmis.stockmanagement.util.Message)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 BufferedInputStream (java.io.BufferedInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)1 MultipartFile (org.springframework.web.multipart.MultipartFile)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1 JasperReportsMultiFormatView (org.springframework.web.servlet.view.jasperreports.JasperReportsMultiFormatView)1