Package org.pentaho.reporting.engine.classic.core.states

Examples of org.pentaho.reporting.engine.classic.core.states.ReportStateKey


    if (canvasProcessingId == null)
    {
      canvasProcessingId = box.getInstanceId();
    }

    final ReportStateKey stateKey = box.getStateKey();
    if (stateKey != null)
    {
      lastSeenStateKey = stateKey;
    }
View Full Code Here


    if (canvasProcessingId == null)
    {
      canvasProcessingId = box.getInstanceId();
    }

    final ReportStateKey stateKey = box.getStateKey();
    if (stateKey != null)
    {
      lastSeenStateKey = stateKey;
    }
View Full Code Here

    else
    {
      finishContexts.put(box.getInstanceId(), Boolean.TRUE);
    }

    final ReportStateKey stateKey = box.getStateKey();
    if (stateKey != null)
    {
      lastSeenStateKey = stateKey;
    }
View Full Code Here

  protected void processOtherNode(final RenderNode node)
  {
    if (node.getNodeType() == LayoutNodeTypes.TYPE_NODE_FINISHEDNODE)
    {
      final ReportStateKey stateKey = node.getStateKey();
      if (stateKey != null)
      {
        lastSeenStateKey = stateKey;
      }
    }
View Full Code Here

  private void updateStateKey(final RenderNode box)
  {
    final long y = box.getY();
    if (y < (pageEnd))
    {
      final ReportStateKey stateKey = box.getStateKey();
      if (stateKey != null)
      {
//        Log.debug ("Updating state key: " + stateKey);
        this.finalVisibleState = stateKey;
      }
View Full Code Here

  private boolean updateStateKeyDeep(final RenderBox box)
  {
    final long y = box.getY();
    if (y < (pageEnd))
    {
      final ReportStateKey stateKey = box.getStateKey();
      if (stateKey != null)
      {
//        Log.debug ("Deep: Updating state key: " + stateKey);
        this.finalVisibleState = stateKey;
        return true;
View Full Code Here

        if (processingStack == null)
        {
          processingStack = new FastStack();
        }
        final String[] columnSet = computeColumns(crosstabGroup);
        final ReportStateKey processKey = state.getProcessKey();
        final DataSchema dataSchema = getRuntime().getDataSchema();
        final DataAttributes tableAttributes = dataSchema.getTableAttributes();
        final DataAttributeContext context = new DefaultDataAttributeContext
            (getRuntime().getProcessingContext().getOutputProcessorMetaData(),
                getRuntime().getResourceBundleFactory().getLocale());

        final String mode = (String) tableAttributes.getMetaAttribute
            (MetaAttributeNames.Core.NAMESPACE, MetaAttributeNames.Core.CROSSTAB_MODE, String.class, context);
        if ("normalized".equals(mode))
        {
          processingStack.push(new OrderedMergeCrosstabSpecification(processKey, columnSet));
        }
        else
        {
          processingStack.push(new SortedMergeCrosstabSpecification(processKey, columnSet));
        }
        return;
      }

      if (processingStack == null || processingStack.isEmpty())
      {
        return;
      }

      final CrosstabSpecification csstate = (CrosstabSpecification) processingStack.peek();
      if (csstate == null)
      {
        return;
      }

      if (group instanceof CrosstabRowGroup)
      {
        if (group.getBody() instanceof CrosstabColumnGroupBody)
        {
          csstate.startRow();
        }
      }

      return;
    }

    if (results == null || processingStack == null || processingStack.isEmpty())
    {
      return;
    }

    // recall ..
    final Group group = event.getReport().getGroup(state.getCurrentGroupIndex());
    if (group instanceof CrosstabGroup)
    {
      final ReportStateKey processKey = state.getProcessKey();
      final CrosstabSpecification o = (CrosstabSpecification) results.get(processKey);
      if (o == null)
      {
        throw new IllegalStateException("Expected crosstab result, but got nothing at all");
      }
View Full Code Here

    return cs;
  }

  private static ReportStateKey createDummyKey()
  {
    return new ReportStateKey();
  }
View Full Code Here

      // First and last derive of a page must be a storage derivate - this clones everything and does
      // not rely on the more complicated transactional layouting ..
      ProcessState fallBackState = state.deriveForPagebreak();
      ProcessState globalState = state.deriveForStorage();

      ReportStateKey rollbackPageState = null;
      boolean isInRollBackMode = false;
      final boolean pagebreaksSupported = isPagebreaksSupported();

      int eventCount = 0;
      int lastRow = -1;
      while (!state.isFinish())
      {
        int logPageCount = outputProcessor.getLogicalPageCount();
        int physPageCount = outputProcessor.getPhysicalPageCount();

        checkInterrupted();
        if (lastRow != state.getCurrentDataItem())
        {
          lastRow = state.getCurrentDataItem();
          if (eventCount == 0)
          {
            if (isPagebreaksSupported() && fallBackState != null)
            {
              repaginationState.reuse(ReportProgressEvent.PAGINATING,
                  fallBackState.getCurrentDataItem(), fallBackState.getNumberOfRows(), fallBackState.getCurrentPage(),
                  fallBackState.getProgressLevel(), fallBackState.getProgressLevelCount());
            }
            else
            {
              repaginationState.reuse(ReportProgressEvent.PAGINATING,
                  state.getCurrentDataItem(), state.getNumberOfRows(), state.getCurrentPage(),
                  state.getProgressLevel(), state.getProgressLevelCount());
            }
            fireStateUpdate(repaginationState);
            eventCount += 1;
          }
          else
          {
            if (eventCount == eventTrigger)
            {
              eventCount = 0;
            }
            else
            {
              eventCount += 1;
            }
          }
        }

        // Do not try to layout on a artificial state. Those states are not valid on
        // generating page events and cannot be trusted.
        ProcessState realFallbackState = fallBackState;
        final ProcessState restoreState;
        if (pagebreaksSupported && state.isArtifcialState() == false)
        {
          restoreState = fallBackState;
          if (isInRollBackMode == false)
          {
            if (pageEventCount >= AbstractReportProcessor.COMMIT_RATE)
            {
              final OutputFunction outputFunction = state.getLayoutProcess().getOutputFunction();
              if (outputFunction.createRollbackInformation())
              {
                realFallbackState = state.deriveForPagebreak();
                if (AbstractReportProcessor.SHOW_ROLLBACKS)
                {
                  logger.debug("Paginate: Try to generate new fallback state after commit count reached: " + state.getProcessKey());
                }
                validate(state);
              }
              else
              {
                realFallbackState = null;
              }
            }
          }
        }
        else
        {
          restoreState = null;
        }

        final ProcessState nextState = state.advance();
        state.setErrorHandler(IgnoreEverythingReportErrorHandler.INSTANCE);
        state = nextState;
        validate(state);

        final ReportStateKey nextStateKey = state.getProcessKey();

        if (errorHandler.isErrorOccured() == true)
        {
          final List childExceptions = Arrays.asList(errorHandler.getErrors());
          errorHandler.clearErrors();
          final ReportEventException exception =
              new ReportEventException("Failed to dispatch an event.", childExceptions);
          if (failOnError)
          {
            throw exception;
          }
          else
          {
            AbstractReportProcessor.logger.error("Failed to dispatch an event.", exception);
          }
        }

        if (state.isArtifcialState())
        {
          if (AbstractReportProcessor.SHOW_ROLLBACKS)
          {
            logger.debug("Paginate: Silent commit as we are in an artificial state: " + state.getProcessKey());
          }
          state = state.commit();
          if (AbstractReportProcessor.SHOW_ROLLBACKS)
          {
            logger.debug("Paginate: Post Silent commit as we are in an artificial state: " + state.getProcessKey());
          }
          continue;
        }

        final OutputFunction outputFunction = state.getLayoutProcess().getOutputFunction();
        if (outputFunction instanceof DefaultOutputFunction == false)
        {
          state = state.commit();
          if (state.isFinish() && pageStates.size() == 1)
          {
            physicalMapping.add(0);
            logicalMapping.add(0);
          }
          continue;
        }

        final DefaultOutputFunction lm = (DefaultOutputFunction) outputFunction;
        final Renderer renderer = lm.getRenderer();
        pagebreakHandler.setReportState(state);

        boolean assertExpectPagebreak = false;
        if (isInRollBackMode)
        {
          // todo: Could be that we have to use the other key here..
          // was: state.getProcessKey()
          if (nextStateKey.equals(rollbackPageState))
          {
            // reached the border case. We have to insert a manual pagebreak here or at least
            // we have to force the renderer to end the page right now.
            if (AbstractReportProcessor.SHOW_ROLLBACKS)
            {
              AbstractReportProcessor.logger.debug(
                  "Paginate: Found real pagebreak position. This might be the last state we process: " + rollbackPageState);
              AbstractReportProcessor.logger.debug(
                  "Paginate:                                         : " + state.getProcessKey());
              if (restoreState != null)
              {
                AbstractReportProcessor.logger.debug(
                    "Paginate:                                         : " + restoreState.getProcessKey());
              }
              AbstractReportProcessor.logger.debug(
                  "Paginate: (Handler)                               : " + state.getAdvanceHandler());
            }
            assertExpectPagebreak = true;
            renderer.addPagebreak(state.getProcessKey());
          }
        }

        final Renderer.LayoutResult pagebreakEncountered = renderer.validatePages();
        if (AbstractReportProcessor.SHOW_ROLLBACKS)
        {
          AbstractReportProcessor.logger.debug("Validate Page returned " + pagebreakEncountered);
        }
        if (assertExpectPagebreak == true && pagebreakEncountered != Renderer.LayoutResult.LAYOUT_PAGEBREAK)
        {
          if (SHOW_ROLLBACKS)
          {
            AbstractReportProcessor.logger.debug("Paginate: Missed the pagebreak. This smells fishy!");
          }
        }

        if (pagebreakEncountered != Renderer.LayoutResult.LAYOUT_UNVALIDATABLE)
        {
          if (pagebreaksSupported && state.isArtifcialState() == false)
          {
            if (isInRollBackMode == false)
            {
              if (pageEventCount >= AbstractReportProcessor.COMMIT_RATE)
              {
                if (AbstractReportProcessor.SHOW_ROLLBACKS)
                {
                  logger.debug("Paginate: Try to apply new fallback state after commit count reached: " + state.getProcessKey());
                  logger.debug("Paginate:        : " + renderer.getLastStateKey());
                }

                fallBackState = realFallbackState;
                pageEventCount = 0;
              }
              else
              {
                pageEventCount += 1;
              }
            }
          }
        }

        if (pagebreakEncountered == Renderer.LayoutResult.LAYOUT_PAGEBREAK)
        {
          final ReportStateKey lastVisibleStateKey = renderer.getLastStateKey();
          if (isPagebreaksSupported() &&
              isInRollBackMode == false &&
              lastVisibleStateKey != null &&
              renderer.isOpen())
          {
            if (lastVisibleStateKey.equals(nextStateKey) == false)
            {
              // Roll back to the last known to be good position and process the states up to, but not
              // including the current state. This way, we can fire the page-events *before* this band
              // gets printed.
              rollbackPageState = lastVisibleStateKey;

              final ReportStateKey restoreStateProcessKey = restoreState.getProcessKey();
              if (AbstractReportProcessor.SHOW_ROLLBACKS)
              {
                AbstractReportProcessor.logger.debug(
                    "Paginate: Encountered bad break, need to roll-back: " + rollbackPageState);
                AbstractReportProcessor.logger.debug(
                    "Paginate:    Next StateKey                        : " + state.getProcessKey());
                AbstractReportProcessor.logger.debug(
                    "Paginate:    Restored Key                         : " + restoreStateProcessKey);
                AbstractReportProcessor.logger.debug(
                    "Paginate:    Position in event chain              : " + restoreState.getSequenceCounter());
              }
              if (lastVisibleStateKey.getSequenceCounter() < restoreStateProcessKey.getSequenceCounter())
              {
                if (AbstractReportProcessor.SHOW_ROLLBACKS)
                {
                  AbstractReportProcessor.logger.debug(
                      "Print: Fall back to start of page              : " + restoreStateProcessKey);
View Full Code Here

        eventTrigger = Math.min(maxRows, Math.max(maxRows / MAX_EVENTS_PER_RUN, MIN_ROWS_PER_EVENT));
      }

      final boolean pagebreaksSupported = isPagebreaksSupported();

      ReportStateKey rollbackPageState = null;

      ProcessState state = startState.deriveForStorage();
      ProcessState fallBackState = state.deriveForPagebreak();
      final ProcessState globalState = state.deriveForStorage();
      state.setErrorHandler(errorHandler);

      boolean isInRollBackMode = false;
      int lastRow = -1;
      int eventCount = 0;
      int pageEventCount = 0;
      while (!state.isFinish())
      {
        checkInterrupted();
        if (lastRow != state.getCurrentDataItem())
        {
          lastRow = state.getCurrentDataItem();
          if (eventCount == 0)
          {
            repaginationState.reuse(ReportProgressEvent.GENERATING_CONTENT,
                state.getCurrentDataItem(), maxRows, state.getCurrentPage(),
                state.getProgressLevel(), state.getProgressLevelCount());
            fireStateUpdate(repaginationState);
            eventCount += 1;
          }
          else
          {
            if (eventCount == eventTrigger)
            {
              eventCount = 0;
            }
            else
            {
              eventCount += 1;
            }
          }
        }

        ProcessState realFallbackState = fallBackState;
        final ProcessState restoreState;
        if (pagebreaksSupported && state.isArtifcialState() == false)
        {
          restoreState = fallBackState;
          if (isInRollBackMode == false)
          {
            if (pageEventCount >= AbstractReportProcessor.COMMIT_RATE)
            {
              final OutputFunction outputFunction = state.getLayoutProcess().getOutputFunction();
              if (outputFunction.createRollbackInformation())
              {
                if (AbstractReportProcessor.SHOW_ROLLBACKS)
                {
                  logger.debug("Print: Try to generate new fallback state after commit count reached: " + state.getProcessKey());
                }
                realFallbackState = state.deriveForPagebreak();
              }
              else
              {
                realFallbackState = null;
              }
            }
          }
        }
        else
        {
          restoreState = null;
        }

        final ProcessState nextState = state.advance();
        state.setErrorHandler(IgnoreEverythingReportErrorHandler.INSTANCE);
        state = nextState;

        final ReportStateKey nextStateKey = state.getProcessKey();

        if (errorHandler.isErrorOccured() == true)
        {
          final List childExceptions = Arrays.asList(errorHandler.getErrors());
          errorHandler.clearErrors();
          if (failOnError)
          {
            throw new ReportEventException("Failed to dispatch an event.", childExceptions);
          }
          else
          {
            final ReportEventException exception =
                new ReportEventException("Failed to dispatch an event.", childExceptions);
            AbstractReportProcessor.logger.error("Failed to dispatch an event.", exception);
          }
        }

        if (state.isArtifcialState())
        {
          if (AbstractReportProcessor.SHOW_ROLLBACKS)
          {
            logger.debug("Print: Silent commit as we are in an artificial state: " + state.getProcessKey());
          }
          state = state.commit();
          continue;
        }

        final OutputFunction outputFunction = state.getLayoutProcess().getOutputFunction();
        if (outputFunction instanceof DefaultOutputFunction == false)
        {
          if (AbstractReportProcessor.SHOW_ROLLBACKS)
          {
            logger.debug("Print: Silent commit as we are have no access to the renderer: " + state.getProcessKey());
          }
          state = state.commit();
          continue;
        }

        final DefaultOutputFunction lm = (DefaultOutputFunction) outputFunction;
        final Renderer renderer = lm.getRenderer();
        pagebreakHandler.setReportState(state);

        boolean assertExpectPagebreak = false;
        if (isInRollBackMode)
        {
          if (nextStateKey.equals(rollbackPageState))
          {
            // reached the border case. We have to insert a manual pagebreak here or at least
            // we have to force the renderer to end the page right now.
//            Log.debug ("HERE: Found real pagebreak position. This might be the last state we process.");
            assertExpectPagebreak = true;
            renderer.addPagebreak(state.getProcessKey());
          }
        }

        final Renderer.LayoutResult pagebreakEncountered = renderer.validatePages();
        if (assertExpectPagebreak == true && pagebreakEncountered != Renderer.LayoutResult.LAYOUT_PAGEBREAK)
        {
          if (SHOW_ROLLBACKS)
          {
            AbstractReportProcessor.logger.debug("Paginate: Missed the pagebreak. This smells fishy!");
          }
        }

        if (pagebreakEncountered == Renderer.LayoutResult.LAYOUT_UNVALIDATABLE)
        {
          if (pagebreaksSupported && state.isArtifcialState() == false)
          {
            if (isInRollBackMode == false)
            {
              if (pageEventCount >= AbstractReportProcessor.COMMIT_RATE)
              {
                if (AbstractReportProcessor.SHOW_ROLLBACKS)
                {
                  logger.debug("Paginate: Try to apply new fallback state after commit count reached: " + state.getProcessKey());
                }
                fallBackState = realFallbackState;
                pageEventCount = 0;
              }
              else
              {
                pageEventCount += 1;
              }
            }
          }
        }

        if (pagebreakEncountered == Renderer.LayoutResult.LAYOUT_PAGEBREAK)
        {
          final ReportStateKey lastVisibleStateKey = renderer.getLastStateKey();
          if (pagebreaksSupported &&
              isInRollBackMode == false &&
              renderer.isOpen() &&
              lastVisibleStateKey != null)
          {
            if (lastVisibleStateKey.equals(nextStateKey) == false)
            {
//              Log.debug ("HERE: Encountered bad break, need to roll-back");

              // Roll back to the last known to be good position and process the states up to, but not
              // including the current state. This way, we can fire the page-events *before* this band
              // gets printed.
              rollbackPageState = lastVisibleStateKey;

              final ReportStateKey restoreStateProcessKey = restoreState.getProcessKey();
              if (AbstractReportProcessor.SHOW_ROLLBACKS)
              {
                AbstractReportProcessor.logger.debug(
                    "Print: Encountered bad break, need to roll-back: " + rollbackPageState);
                AbstractReportProcessor.logger.debug(
                    "Print:                                         : " + state.getProcessKey());
                AbstractReportProcessor.logger.debug(
                    "Print:                                         : " + restoreStateProcessKey);
              }

              if (lastVisibleStateKey.getSequenceCounter() < restoreStateProcessKey.getSequenceCounter())
              {
                if (AbstractReportProcessor.SHOW_ROLLBACKS)
                {
                  AbstractReportProcessor.logger.debug(
                      "Print: Fall back to start of page              : " + restoreStateProcessKey);
View Full Code Here

TOP

Related Classes of org.pentaho.reporting.engine.classic.core.states.ReportStateKey

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.