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