コード例 #1
0
  private JasperPrint runAndRender(Report report) throws Exception, JRException {
    JasperPrint jasperPrint = new JasperPrint();

    JasperReport jasperReport =
        JasperCompileManager.compileReport(
            System.getProperty("opennms.home")
                + File.separator
                + "etc"
                + File.separator
                + "report-templates"
                + File.separator
                + report.getReportTemplate());

    if (report.getReportEngine().equals("jdbc")) {
      Connection connection = DataSourceFactory.getDataSource().getConnection();
      jasperPrint =
          JasperFillManager.fillReport(
              jasperReport, paramListToMap(report.getParameterCollection()), connection);
      connection.close();
    } else if (report.getReportEngine().equals("opennms")) {
      LogUtils.errorf(this, "Sorry the OpenNMS Data source engine is not yet available");
      jasperPrint = null;
    } else {
      LogUtils.errorf(this, "Unknown report engine: %s ", report.getReportEngine());
      jasperPrint = null;
    }

    return jasperPrint;
  }
コード例 #2
0
  /**
   * {@inheritDoc}
   *
   * @throws ReportRunException
   */
  public synchronized String runReport(Report report, String reportDirectory)
      throws ReportRunException {

    String outputFile = null;
    try {
      outputFile =
          generateReportName(reportDirectory, report.getReportName(), report.getReportFormat());
      JasperPrint print = runAndRender(report);
      outputFile = saveReport(print, report.getReportFormat(), outputFile);

    } catch (JRException e) {
      LogUtils.errorf(this, e, "Error running report: %s", e.getMessage());
      throw new ReportRunException("Caught JRException: " + e.getMessage());
    } catch (Throwable e) {
      LogUtils.errorf(this, e, "Unexpected exception: %s", e.getMessage());
      throw new ReportRunException(
          "Caught unexpected " + e.getClass().getName() + ": " + e.getMessage());
    }

    return outputFile;
  }