Search in sources :

Example 1 with JasperReportsMultiFormatView

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));
}
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 JasperReportsMultiFormatView

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;
}
Also used : JasperReportsMultiFormatView(org.springframework.web.servlet.view.jasperreports.JasperReportsMultiFormatView)

Example 3 with JasperReportsMultiFormatView

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;
}
Also used : JasperReportsMultiFormatView(org.springframework.web.servlet.view.jasperreports.JasperReportsMultiFormatView)

Example 4 with JasperReportsMultiFormatView

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);
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) EntityNotFoundException(org.motechproject.mots.exception.EntityNotFoundException) JasperReportsMultiFormatView(org.springframework.web.servlet.view.jasperreports.JasperReportsMultiFormatView) JasperTemplate(org.motechproject.mots.domain.JasperTemplate) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

JasperReportsMultiFormatView (org.springframework.web.servlet.view.jasperreports.JasperReportsMultiFormatView)4 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 ModelAndView (org.springframework.web.servlet.ModelAndView)2 JasperTemplate (org.motechproject.mots.domain.JasperTemplate)1 EntityNotFoundException (org.motechproject.mots.exception.EntityNotFoundException)1 JasperTemplate (org.openlmis.stockmanagement.domain.JasperTemplate)1 ValidationMessageException (org.openlmis.stockmanagement.exception.ValidationMessageException)1 Message (org.openlmis.stockmanagement.util.Message)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1