use of org.springframework.web.servlet.view.jasperreports.JasperReportsMultiFormatView 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.springframework.web.servlet.view.jasperreports.JasperReportsMultiFormatView in project openlmis-stockmanagement by OpenLMIS.
the class JasperReportService method getJasperReportsView.
/**
* Create Jasper Report View.
* Create Jasper Report (".jasper" file) from bytes from Template entity.
* Set 'Jasper' exporter parameters, JDBC data source, web application context, url to file.
*
* @param jasperTemplate template that will be used to create a view
* @return created jasper view.
* @throws JasperReportViewException if there will be any problem with creating the view.
*/
public JasperReportsMultiFormatView getJasperReportsView(JasperTemplate jasperTemplate) throws JasperReportViewException {
JasperReportsMultiFormatView jasperView = new JasperReportsMultiFormatView();
jasperView.setJdbcDataSource(replicationDataSource);
jasperView.setUrl(getReportUrlForReportData(jasperTemplate));
jasperView.setApplicationContext(appContext);
return jasperView;
}
use of org.springframework.web.servlet.view.jasperreports.JasperReportsMultiFormatView in project mots by motech-implementations.
the class JasperReportsViewService method getJasperReportsView.
/**
* Create Jasper Report View.
* Create Jasper Report (".jasper" file) from bytes from Template entity.
* Set 'Jasper' exporter parameters, JDBC data source, web application context, url to file.
*
* @param jasperTemplate template that will be used to create a view
* @param request it is used to take web application context
* @return created jasper view.
* @throws JasperReportViewException if there will be any problem with creating the view.
*/
public JasperReportsMultiFormatView getJasperReportsView(JasperTemplate jasperTemplate, HttpServletRequest request) throws JasperReportViewException {
JasperReportsMultiFormatView jasperView = new JasperReportsMultiFormatView();
setExportParams(jasperView);
setFormatMappings(jasperView);
jasperView.setUrl(getReportUrlForReportData(jasperTemplate));
jasperView.setJdbcDataSource(replicationDataSource);
if (getApplicationContext(request) != null) {
jasperView.setApplicationContext(getApplicationContext(request));
}
return jasperView;
}
use of org.springframework.web.servlet.view.jasperreports.JasperReportsMultiFormatView in project mots by motech-implementations.
the class JasperTemplateController method generateReport.
/**
* Generate a report based on the template, the format and the request parameters.
*
* @param request request (to get the request parameters)
* @param templateId report template ID
* @param format report format to generate, default is PDF
* @return the generated report
*/
@RequestMapping(value = "/{id}/{format}", method = RequestMethod.GET)
@ResponseBody
public ModelAndView generateReport(HttpServletRequest request, @PathVariable("id") UUID templateId, @PathVariable("format") String format) throws JasperReportViewException {
JasperTemplate template = jasperTemplateRepository.findOne(templateId);
if (template == null) {
throw new EntityNotFoundException(ERROR_JASPER_TEMPLATE_NOT_FOUND, templateId);
}
Map<String, Object> map = jasperTemplateService.mapRequestParametersToTemplate(request, template);
map.put("format", format);
JasperReportsMultiFormatView jasperView = jasperReportsViewService.getJasperReportsView(template, request);
String fileName = template.getName().replaceAll("\\s+", "_");
String contentDisposition = "inline; filename=" + fileName + "." + format;
jasperView.getContentDispositionMappings().setProperty(format, contentDisposition.toLowerCase(Locale.ENGLISH));
return new ModelAndView(jasperView, map);
}
Aggregations