Search in sources :

Example 1 with JREmptyDataSource

use of net.sf.jasperreports.engine.JREmptyDataSource in project opennms by OpenNMS.

the class JasperReportService method runAndRender.

/**
     * {@inheritDoc}
     */
@Override
public void runAndRender(final Map<String, Object> reportParms, final String reportId, final ReportFormat format, final OutputStream outputStream) throws ReportException {
    try {
        Logging.withPrefix(LOG4J_CATEGORY, new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                final JasperReport jasperReport = getJasperReport(reportId);
                final Map<String, Object> jrReportParms = buildJRparameters(reportParms, jasperReport.getParameters());
                jrReportParms.putAll(buildSubreport(reportId, jasperReport));
                if ("jdbc".equalsIgnoreCase(m_globalReportRepository.getEngine(reportId))) {
                    final DBUtils db = new DBUtils();
                    try {
                        final Connection connection = DataSourceFactory.getInstance().getConnection();
                        db.watch(connection);
                        final JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, jrReportParms, connection);
                        exportReport(format, jasperPrint, outputStream);
                    } finally {
                        db.cleanUp();
                    }
                } else if ("null".equalsIgnoreCase(m_globalReportRepository.getEngine(reportId))) {
                    final JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, jrReportParms, new JREmptyDataSource());
                    exportReport(format, jasperPrint, outputStream);
                }
                return null;
            }
        });
    } catch (final Exception e) {
        if (e instanceof ReportException)
            throw (ReportException) e;
        throw new ReportException("Failed to run Jasper report " + reportId, e);
    }
}
Also used : JREmptyDataSource(net.sf.jasperreports.engine.JREmptyDataSource) JasperPrint(net.sf.jasperreports.engine.JasperPrint) DBUtils(org.opennms.core.utils.DBUtils) Connection(java.sql.Connection) ReportException(org.opennms.api.reporting.ReportException) JasperReport(net.sf.jasperreports.engine.JasperReport) Map(java.util.Map) HashMap(java.util.HashMap) ReportException(org.opennms.api.reporting.ReportException) JRException(net.sf.jasperreports.engine.JRException)

Aggregations

Connection (java.sql.Connection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 JREmptyDataSource (net.sf.jasperreports.engine.JREmptyDataSource)1 JRException (net.sf.jasperreports.engine.JRException)1 JasperPrint (net.sf.jasperreports.engine.JasperPrint)1 JasperReport (net.sf.jasperreports.engine.JasperReport)1 ReportException (org.opennms.api.reporting.ReportException)1 DBUtils (org.opennms.core.utils.DBUtils)1