use of net.sf.jasperreports.engine.JasperPrint in project dhis2-core by dhis2.
the class ReportController method getReport.
// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
private void getReport(HttpServletRequest request, HttpServletResponse response, String uid, String organisationUnitUid, String isoPeriod, Date date, String type, String contentType, boolean attachment) throws Exception {
Report report = reportService.getReport(uid);
if (report == null) {
throw new WebMessageException(WebMessageUtils.notFound("Report not found for identifier: " + uid));
}
if (organisationUnitUid == null && report.hasReportTable() && report.getReportTable().hasReportParams() && report.getReportTable().getReportParams().isOrganisationUnitSet()) {
organisationUnitUid = organisationUnitService.getRootOrganisationUnits().iterator().next().getUid();
}
if (report.isTypeHtml()) {
contextUtils.configureResponse(response, ContextUtils.CONTENT_TYPE_HTML, report.getCacheStrategy());
reportService.renderHtmlReport(response.getWriter(), uid, date, organisationUnitUid);
} else {
date = date != null ? date : new DateTime().minusMonths(1).toDate();
Period period = isoPeriod != null ? PeriodType.getPeriodFromIsoString(isoPeriod) : new MonthlyPeriodType().createPeriod(date);
String filename = CodecUtils.filenameEncode(report.getName()) + "." + type;
contextUtils.configureResponse(response, contentType, report.getCacheStrategy(), filename, attachment);
JasperPrint print = reportService.renderReport(response.getOutputStream(), uid, period, organisationUnitUid, type);
if ("html".equals(type)) {
request.getSession().setAttribute(BaseHttpServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, print);
}
}
}
use of net.sf.jasperreports.engine.JasperPrint in project dhis2-core by dhis2.
the class GridUtils method toJasperReport.
/**
* Writes a Jasper Reports representation of the given Grid to the given OutputStream.
*/
public static void toJasperReport(Grid grid, Map<String, Object> params, OutputStream out) throws Exception {
if (grid == null) {
return;
}
final StringWriter writer = new StringWriter();
render(grid, params, writer, JASPER_TEMPLATE);
String report = writer.toString();
JasperReport jasperReport = JasperCompileManager.compileReport(IOUtils.toInputStream(report, StandardCharsets.UTF_8));
JasperPrint print = JasperFillManager.fillReport(jasperReport, params, grid);
JasperExportManager.exportReportToPdfStream(print, out);
}
Aggregations