public List<ReportParameter> getAvailableParameters(Report report) throws ProviderException {
    List<ReportParameter> parameters = getReportParameters();

    Iterator<ReportParameter> iterator = parameters.iterator();
    while (iterator.hasNext()) {
      ReportParameter rp = iterator.next();

      Iterator<ReportParameterMap> reportIterator = report.getParameters().iterator();
      while (reportIterator.hasNext()) {
        ReportParameterMap rpMap = reportIterator.next();

        if (rp.getId().equals(rpMap.getReportParameter().getId())) {
          parameters.remove(rp);
          iterator = parameters.iterator();
        }
      }
    }

    return parameters;
  }
  public List<ReportParameter> getReportParameters(Report report, String type)
      throws ProviderException {
    List<ReportParameter> parameters = new ArrayList<ReportParameter>();

    List<ReportParameterMap> allParameters = report.getParameters();

    if (allParameters != null) {
      Iterator<ReportParameterMap> iterator = allParameters.iterator();

      while (iterator.hasNext()) {
        ReportParameterMap rpMap = iterator.next();

        if (rpMap.getReportParameter().getType().equals(type)) {
          parameters.add(rpMap.getReportParameter());
        }
      }
    }

    return parameters;
  }
  public static ReportEngine getReportEngine(
      Report report,
      DataSourceProvider dataSourceProvider,
      DirectoryProvider directoryProvider,
      PropertiesProvider propertiesProvider)
      throws ProviderException {
    ReportEngine reportEngine = null;
    if (report.isChartReport()) {
      reportEngine =
          new ChartReportEngine(dataSourceProvider, directoryProvider, propertiesProvider);
    } else if (report.isJXLSReport()) {
      reportEngine =
          new JXLSReportEngine(dataSourceProvider, directoryProvider, propertiesProvider);
    } else if (report.isBirtReport()) {
      reportEngine =
          new BirtReportEngine(dataSourceProvider, directoryProvider, propertiesProvider);
    } else if (report.isJasperReport()) {
      reportEngine =
          new JasperReportEngine(dataSourceProvider, directoryProvider, propertiesProvider);
    } else if (report.isQueryReport()) {
      reportEngine =
          new QueryReportEngine(dataSourceProvider, directoryProvider, propertiesProvider);
    } else if (report.isVelocityReport()) {
      reportEngine =
          new VelocityReportEngine(dataSourceProvider, directoryProvider, propertiesProvider);
    }

    if (reportEngine == null) {
      String message = report.getName() + " is invalid. Please verify report definition.";

      log.error(message);
      throw new ProviderException(message);
    }

    return reportEngine;
  }
示例#4
0
  public String execute() {
    // remove results of any previous query report from session
    ActionContext.getContext().getSession().remove(ORStatics.QUERY_REPORT_RESULTS);
    ActionContext.getContext().getSession().remove(ORStatics.QUERY_REPORT_PROPERTIES);

    ReportUser user =
        (ReportUser) ActionContext.getContext().getSession().get(ORStatics.REPORT_USER);

    report = (Report) ActionContext.getContext().getSession().get(ORStatics.REPORT);

    Map<String, Object> reportParameters = getReportParameterMap(user);

    ReportLog reportLog = new ReportLog(user, report, new Date());

    try {
      log.debug("Starting Query Report: " + report.getName());
      log.debug("Query: " + report.getQuery());

      reportLogProvider.insertReportLog(reportLog);

      ReportEngineInput input = new ReportEngineInput(report, reportParameters);

      if (report.isJFreeReport()) {
        JFreeReportEngine jfreeReportEngine =
            new JFreeReportEngine(dataSourceProvider, directoryProvider, propertiesProvider);

        ReportEngineOutput output = jfreeReportEngine.generateReport(input);

        html = new String(output.getContent());
      } else {
        QueryReportEngine queryReportEngine =
            new QueryReportEngine(dataSourceProvider, directoryProvider, propertiesProvider);

        QueryEngineOutput output = (QueryEngineOutput) queryReportEngine.generateReport(input);

        session.put(ORStatics.QUERY_REPORT_RESULTS, output.getResults());

        session.put(ORStatics.QUERY_REPORT_PROPERTIES, output.getProperties());
      }

      reportLog.setEndTime(new Date());
      reportLog.setStatus(ReportLog.STATUS_SUCCESS);
      reportLogProvider.updateReportLog(reportLog);

      log.debug("Finished Query Report: " + report.getName());
    } catch (Exception e) {

      addActionError(e.getMessage());

      log.error(e.getMessage());

      reportLog.setMessage(e.getMessage());
      reportLog.setStatus(ReportLog.STATUS_FAILURE);

      reportLog.setEndTime(new Date());

      try {
        reportLogProvider.updateReportLog(reportLog);
      } catch (Exception ex) {
        log.error("Unable to create ReportLog: " + ex.getMessage());
      }

      return ERROR;
    }

    if (report.isJFreeReport()) return ORStatics.JFREEREPORT_RESULT;

    return SUCCESS;
  }