Search in sources :

Example 6 with ReportException

use of com.qcadoo.report.api.ReportException in project qcadoo by qcadoo.

the class ReportController method generateReportForEntity.

@RequestMapping(value = "generateReportForEntity/{templatePlugin}/{templateName}", method = RequestMethod.GET)
public void generateReportForEntity(@PathVariable("templatePlugin") final String templatePlugin, @PathVariable("templateName") final String templateName, @RequestParam("id") final List<Long> entityIds, @RequestParam("additionalArgs") final String requestAdditionalArgs, final HttpServletRequest request, final HttpServletResponse response, final Locale locale) throws ReportException {
    ReportService.ReportType reportType = getReportType(request);
    Map<String, String> additionalArgs = convertJsonStringToMap(requestAdditionalArgs);
    response.setContentType(reportType.getMimeType());
    try {
        int bytes = copy(new ByteArrayInputStream(reportService.generateReportForEntity(templatePlugin, templateName, reportType, entityIds, additionalArgs, locale)), response.getOutputStream());
        response.setContentLength(bytes);
    } catch (IOException e) {
        throw new ReportException(ReportException.Type.ERROR_WHILE_COPYING_REPORT_TO_RESPONSE, e);
    }
    disableCache(response);
}
Also used : ReportService(com.qcadoo.report.api.ReportService) ByteArrayInputStream(java.io.ByteArrayInputStream) ReportException(com.qcadoo.report.api.ReportException) IOException(java.io.IOException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ReportException (com.qcadoo.report.api.ReportException)6 ByteArrayInputStream (java.io.ByteArrayInputStream)2 JRException (net.sf.jasperreports.engine.JRException)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ReportService (com.qcadoo.report.api.ReportService)1 ReportType (com.qcadoo.report.api.ReportService.ReportType)1 ReportFormatFactory (com.qcadoo.report.internal.util.ReportFormatFactory)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 HashMap (java.util.HashMap)1 ResourceBundle (java.util.ResourceBundle)1 JRExporter (net.sf.jasperreports.engine.JRExporter)1 JasperPrint (net.sf.jasperreports.engine.JasperPrint)1 JasperReport (net.sf.jasperreports.engine.JasperReport)1 ByteArrayOutputStream (org.apache.commons.io.output.ByteArrayOutputStream)1 Session (org.hibernate.Session)1 JDOMException (org.jdom.JDOMException)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1