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));
}
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);
}
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);
}
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()));
}
}
}
Aggregations