@TransactionAttribute(
      TransactionAttributeType.SUPPORTS) // Never begin a transaction for report rendering
  @RolesAllowed({org.nightlabs.jfire.reporting.RoleConstants.renderReport_roleID})
  @Override
  public void processScheduledReport(TaskID taskID) throws Exception {

    PersistenceManager pm = createPersistenceManager();
    try {
      if (logger.isDebugEnabled())
        logger.debug("processScheduledReport started, determine parameters");
      Task task = (Task) pm.getObjectById(taskID);
      ScheduledReport scheduledReport = (ScheduledReport) task.getParam();
      if (logger.isDebugEnabled())
        logger.debug(
            "processScheduledReport have "
                + ScheduledReport.describeScheduledReport(scheduledReport));
      RenderReportRequest renderReportRequest = scheduledReport.getRenderReportRequest();
      if (renderReportRequest == null) {
        throw new RenderReportException(
            "Can not render ScheduledReport as the RenderReportRequest is not set. "
                + ScheduledReport.describeScheduledReport(scheduledReport));
      }
      ReportRegistryItemID reportLayoutID = scheduledReport.getReportLayoutID();
      if (reportLayoutID == null) {
        throw new RenderReportException(
            "Can not render ScheduledReport as no ReportLayout is set for it. "
                + ScheduledReport.describeScheduledReport(scheduledReport));
      }
      if (logger.isDebugEnabled())
        logger.debug("processScheduledReport have reportLayoutID " + reportLayoutID);

      Map<String, Object> newParams =
          convertScheduledReportParams(scheduledReport, renderReportRequest);
      renderReportRequest.setParameters(newParams);

      IScheduledReportDeliveryDelegate deliveryDelegate = scheduledReport.getDeliveryDelegate();
      if (deliveryDelegate == null) {
        throw new IllegalStateException(
            "Can not render ScheduledReport as no ScheduledReportDeliveryDelegate is set for it. "
                + ScheduledReport.describeScheduledReport(scheduledReport));
      }
      if (logger.isDebugEnabled())
        logger.debug("processScheduledReport have deliveryDelegate " + deliveryDelegate);

      renderReportRequest.setReportRegistryItemID(reportLayoutID);

      if (logger.isDebugEnabled())
        logger.debug("processScheduledReport rendering ReportLayout " + reportLayoutID);
      RenderedReportLayout renderedReportLayout =
          ReportLayoutRendererUtil.renderReport(pm, renderReportRequest);

      if (logger.isDebugEnabled())
        logger.debug("processScheduledReport delivering rendered report.");
      deliveryDelegate.deliverReportOutput(scheduledReport, renderedReportLayout);

    } finally {
      pm.close();
    }
  }
Ejemplo n.º 2
0
  /**
   * Prints the given report (registryItemID) with the given parameters. The {@link ReportUseCase}
   * for the given report will be searched and used for printing.
   *
   * @param registryItemID The id of the report to print.
   * @param params The parameters to use to render the report.
   * @param monitor The monitor to report progress to.
   * @throws PrinterException If an error occurs while printing.
   */
  public void printWithParams(
      ReportRegistryItemID registryItemID, Map<String, Object> params, ProgressMonitor monitor)
      throws PrinterException {
    monitor.beginTask(
        Messages.getString(
            "org.nightlabs.jfire.reporting.ui.layout.action.print.AbstractPrintReportLayoutAction.task.printingReportLayout"),
        6); //$NON-NLS-1$
    String useCaseID = getReportUseCaseID(registryItemID, params);
    if (useCaseID == null) {
      // Try to lookup the UseCase by the reportLayoutType
      ReportUseCase useCase =
          ReportUseCaseRegistry.sharedInstance()
              .getReportUseCaseByLayoutType(registryItemID.reportRegistryItemType);
      if (useCase != null) useCaseID = useCase.getId();
    }
    if (useCaseID == null) {
      // if no usecase found till now, try to find the default/fallback one
      ReportUseCase useCase =
          ReportUseCaseRegistry.sharedInstance()
              .getReportUseCase(ReportingPlugin.DEFAULT_REPORT_USE_CASE_ID);
      if (useCase == null) {
        throw new PrinterException(
            "No useCaseID could be found. A usecase for the type "
                + registryItemID.reportRegistryItemType
                + " could not be found and also the default/fallback usecase seems not to be registered."); //$NON-NLS-1$ //$NON-NLS-2$
      }
      useCaseID = useCase.getId();
    }

    RenderReportRequest renderRequest = new RenderReportRequest();
    renderRequest.setReportRegistryItemID(registryItemID);
    renderRequest.setParameters(params);
    Locale requestLocale =
        getRenderRequestLocale(registryItemID, params, new SubProgressMonitor(monitor, 1));
    if (requestLocale != null) {
      renderRequest.setLocale(requestLocale);
    } else {
      renderRequest.setLocale(Locale.getDefault());
    }
    PrintReportLayoutUtil.printReportLayoutWithDefaultFormat(
        renderRequest, useCaseID, new SubProgressMonitor(monitor, 5));
    monitor.done();
  }