protected void inspect(final AbstractReportDefinition reportDefinition) {
    if (reportDefinition instanceof MasterReport) {
      final MasterReport mr = (MasterReport) reportDefinition;
      final ReportParameterDefinition parameters = mr.getParameterDefinition();
      final ParameterDefinitionEntry[] entries = parameters.getParameterDefinitions();
      for (int i = 0; i < entries.length; i++) {
        final ParameterDefinitionEntry entry = entries[i];
        inspectParameter(reportDefinition, parameters, entry);
      }
    }

    final CompoundDataFactory dataFactory =
        CompoundDataFactory.normalize(reportDefinition.getDataFactory(), false);
    final int size = dataFactory.size();
    for (int i = 0; i < size; i++) {
      inspectDataSource(reportDefinition, dataFactory);
    }

    final ExpressionCollection expressions = reportDefinition.getExpressions();
    final Expression[] expressionsArray = expressions.getExpressions();
    for (int i = 0; i < expressionsArray.length; i++) {
      final Expression expression = expressionsArray[i];
      inspectExpression(reportDefinition, expression);
    }

    inspectElement(reportDefinition);
    traverseSection(reportDefinition);
  }
Ejemplo n.º 2
0
  /**
   * @param model
   * @param dataFactory
   * @param reportTemplate
   * @param output
   * @return
   * @throws ReportException
   * @throws ReportProcessingException
   * @throws SaikuAdhocException
   * @throws IOException
   * @throws ResourceException
   */
  protected MasterReport processReport(SaikuMasterModel model)
      throws ReportException, ReportProcessingException, SaikuAdhocException, ResourceException,
          IOException {

    CachingDataFactory dataFactory = null;

    try {

      model.deriveModels();

      final MasterReport reportTemplate = model.getDerivedModels().getReportTemplate();

      final WizardSpecification wizardSpecification = model.getWizardSpecification();

      reportTemplate.setDataFactory(model.getDerivedModels().getCdaDataFactory());
      reportTemplate.setQuery(model.getDerivedModels().getSessionId());

      reportTemplate.setAttribute(
          AttributeNames.Wizard.NAMESPACE, "wizard-spec", wizardSpecification);

      final ProcessingContext processingContext = new DefaultProcessingContext();
      final DataSchemaDefinition definition = reportTemplate.getDataSchemaDefinition();

      final ReportParameterValues parameterValues =
          StateUtilities.computeParameterValueSet(reportTemplate, getReportParameterValues(model));

      final ParameterDefinitionEntry[] parameterDefinitions =
          reportTemplate.getParameterDefinition().getParameterDefinitions();

      final DefaultFlowController flowController =
          new DefaultFlowController(
              processingContext, definition, parameterValues, parameterDefinitions, false);

      ensureSaikuPreProcessorIsAdded(reportTemplate, model);
      ensureHasOverrideWizardFormatting(reportTemplate, flowController);

      dataFactory = new CachingDataFactory(reportTemplate.getDataFactory(), false);
      dataFactory.initialize(
          processingContext.getConfiguration(),
          processingContext.getResourceManager(),
          processingContext.getContentBase(),
          processingContext.getResourceBundleFactory());

      final DefaultFlowController postQueryFlowController =
          flowController.performQuery(
              dataFactory,
              reportTemplate.getQuery(),
              reportTemplate.getQueryLimit(),
              reportTemplate.getQueryTimeout(),
              flowController.getMasterRow().getResourceBundleFactory());

      reportTemplate.setAttribute(
          AttributeNames.Wizard.NAMESPACE, AttributeNames.Wizard.ENABLE, Boolean.TRUE);

      ReportPreProcessor processor = new SaikuAdhocPreProcessor();
      ((SaikuAdhocPreProcessor) processor).setSaikuMasterModel(model);
      MasterReport output = processor.performPreProcessing(reportTemplate, postQueryFlowController);
      output.setAttribute(
          AttributeNames.Wizard.NAMESPACE, AttributeNames.Wizard.ENABLE, Boolean.FALSE);

      output.setAttribute(
          AttributeNames.Wizard.NAMESPACE, AttributeNames.Wizard.ENABLE, Boolean.FALSE);

      TemplateUtils.mergePageSetup(model, output);

      return output;

    } finally {
      dataFactory.close();
    }
  }