public ProcessState commit(final ProcessState next) throws ReportProcessingException {
    next.setInItemGroup(true);

    // fast forward to the end of the facts ..
    while (true) {
      final DefaultFlowController fc = next.getFlowController().performAdvance();
      final Group group = next.getReport().getGroup(next.getCurrentGroupIndex());
      final DefaultFlowController cfc = fc.performCommit();
      if (ProcessState.isLastItemInGroup(group, fc.getMasterRow(), cfc.getMasterRow())) {
        next.setFlowController(fc);
        next.setAdvanceHandler(PrintSummaryEndCrosstabColumnAxisHandler.HANDLER);
        break;
      } else {
        next.setFlowController(cfc);
        next.setAdvanceHandler(PrintSummaryProcessCrosstabFactHandler.HANDLER);
      }
    }

    next.setInItemGroup(false);
    return next;
  }
  /**
   * @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();
    }
  }