Search in sources :

Example 16 with JasperPrint

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);
        }
    }
}
Also used : Report(org.hisp.dhis.report.Report) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) JasperPrint(net.sf.jasperreports.engine.JasperPrint) Period(org.hisp.dhis.period.Period) DateTime(org.joda.time.DateTime)

Example 17 with JasperPrint

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);
}
Also used : StringWriter(java.io.StringWriter) JasperPrint(net.sf.jasperreports.engine.JasperPrint) JasperReport(net.sf.jasperreports.engine.JasperReport)

Aggregations

JasperPrint (net.sf.jasperreports.engine.JasperPrint)17 JasperReport (net.sf.jasperreports.engine.JasperReport)9 JRException (net.sf.jasperreports.engine.JRException)8 File (java.io.File)5 Connection (java.sql.Connection)5 HashMap (java.util.HashMap)5 IOException (java.io.IOException)4 SQLException (java.sql.SQLException)4 PrismObject (com.evolveum.midpoint.prism.PrismObject)2 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2 FileInputStream (java.io.FileInputStream)2 ClassicLayoutManager (ar.com.fdvs.dj.core.layout.ClassicLayoutManager)1 AutoText (ar.com.fdvs.dj.domain.AutoText)1 DJGroupLabel (ar.com.fdvs.dj.domain.DJGroupLabel)1 DynamicReport (ar.com.fdvs.dj.domain.DynamicReport)1 Style (ar.com.fdvs.dj.domain.Style)1 ColumnBuilder (ar.com.fdvs.dj.domain.builders.ColumnBuilder)1 DynamicReportBuilder (ar.com.fdvs.dj.domain.builders.DynamicReportBuilder)1 GroupBuilder (ar.com.fdvs.dj.domain.builders.GroupBuilder)1 DJGroup (ar.com.fdvs.dj.domain.entities.DJGroup)1