Java Code Examples for org.activiti.engine.impl.persistence.entity.ExecutionEntity#isScope()

The following examples show how to use org.activiti.engine.impl.persistence.entity.ExecutionEntity#isScope() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TakeOutgoingSequenceFlowsOperation.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
/**
 * @param executionEntityToIgnore The execution entity which we can ignore to be ended,
 * as it's the execution currently being handled in this operation.
 */
protected ExecutionEntity findNextParentScopeExecutionWithAllEndedChildExecutions(ExecutionEntity executionEntity, ExecutionEntity executionEntityToIgnore) {
  if (executionEntity.getParentId() != null) {
    ExecutionEntity scopeExecutionEntity = executionEntity.getParent();

    // Find next scope
    while (!scopeExecutionEntity.isScope() || !scopeExecutionEntity.isProcessInstanceType()) {
      scopeExecutionEntity = scopeExecutionEntity.getParent();
    }

    // Return when all child executions for it are ended
    if (allChildExecutionsEnded(scopeExecutionEntity, executionEntityToIgnore)) {
      return scopeExecutionEntity;
    }

  }
  return null;
}
 
Example 2
Source File: AbstractEventHandler.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void dispatchActivityCancelledForChildExecution(EventSubscriptionEntity eventSubscription,
    ExecutionEntity parentExecutionEntity, ExecutionEntity boundaryEventExecution, CommandContext commandContext) {

  List<ExecutionEntity> executionEntities = commandContext.getExecutionEntityManager().findChildExecutionsByParentExecutionId(parentExecutionEntity.getId());
  for (ExecutionEntity childExecution : executionEntities) {

    if (!boundaryEventExecution.getId().equals(childExecution.getId())
        && childExecution.getCurrentFlowElement() != null
        && childExecution.getCurrentFlowElement() instanceof FlowNode) {

      FlowNode flowNode = (FlowNode) childExecution.getCurrentFlowElement();
      commandContext.getEventDispatcher().dispatchEvent(
          ActivitiEventBuilder.createActivityCancelledEvent(flowNode.getId(), flowNode.getName(), childExecution.getId(),
              childExecution.getProcessInstanceId(), childExecution.getProcessDefinitionId(),
              parseActivityType(flowNode), eventSubscription));

      if (childExecution.isScope()) {
        dispatchActivityCancelledForChildExecution(eventSubscription, childExecution, boundaryEventExecution, commandContext);
      }

    }

  }

}
 
Example 3
Source File: GatewayActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void lockFirstParentScope(DelegateExecution execution) {
  
  ExecutionEntityManager executionEntityManager = Context.getCommandContext().getExecutionEntityManager();
  
  boolean found = false;
  ExecutionEntity parentScopeExecution = null;
  ExecutionEntity currentExecution = (ExecutionEntity) execution;
  while (!found && currentExecution != null && currentExecution.getParentId() != null) {
    parentScopeExecution = executionEntityManager.findById(currentExecution.getParentId());
    if (parentScopeExecution != null && parentScopeExecution.isScope()) {
      found = true;
    }
    currentExecution = parentScopeExecution;
  }
  
  parentScopeExecution.forceUpdate();
}
 
Example 4
Source File: ParallelMultiInstanceBehavior.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void lockFirstParentScope(DelegateExecution execution) {

    ExecutionEntityManager executionEntityManager = Context.getCommandContext().getExecutionEntityManager();

    boolean found = false;
    ExecutionEntity parentScopeExecution = null;
    ExecutionEntity currentExecution = (ExecutionEntity) execution;
    while (!found && currentExecution != null && currentExecution.getParentId() != null) {
      parentScopeExecution = executionEntityManager.findById(currentExecution.getParentId());
      if (parentScopeExecution != null && parentScopeExecution.isScope()) {
        found = true;
      }
      currentExecution = parentScopeExecution;
    }

    parentScopeExecution.forceUpdate();
  }
 
Example 5
Source File: AbstractOperation.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the first parent execution of the provided execution that is a scope.
 */
protected ExecutionEntity findFirstParentScopeExecution(ExecutionEntity executionEntity) {
  ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager();
  ExecutionEntity parentScopeExecution = null;
  ExecutionEntity currentlyExaminedExecution = executionEntityManager.findById(executionEntity.getParentId());
  while (currentlyExaminedExecution != null && parentScopeExecution == null) {
    if (currentlyExaminedExecution.isScope()) {
      parentScopeExecution = currentlyExaminedExecution;
    } else {
      currentlyExaminedExecution = executionEntityManager.findById(currentlyExaminedExecution.getParentId());
    }
  }
  return parentScopeExecution;
}
 
Example 6
Source File: TakeOutgoingSequenceFlowsOperation.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void cleanupCompensation() {

    // The compensation is at the end here. Simply stop the execution.

    commandContext.getHistoryManager().recordActivityEnd(execution, null);
    commandContext.getExecutionEntityManager().deleteExecutionAndRelatedData(execution, null, false);

    ExecutionEntity parentExecutionEntity = execution.getParent();
    if (parentExecutionEntity.isScope() && !parentExecutionEntity.isProcessInstanceType()) {

      if (allChildExecutionsEnded(parentExecutionEntity, null)) {

        // Go up the hierarchy to check if the next scope is ended too.
        // This could happen if only the compensation activity is still active, but the
        // main process is already finished.

        ExecutionEntity executionEntityToEnd = parentExecutionEntity;
        ExecutionEntity scopeExecutionEntity = findNextParentScopeExecutionWithAllEndedChildExecutions(parentExecutionEntity, parentExecutionEntity);
        while (scopeExecutionEntity != null) {
          executionEntityToEnd = scopeExecutionEntity;
          scopeExecutionEntity = findNextParentScopeExecutionWithAllEndedChildExecutions(scopeExecutionEntity, parentExecutionEntity);
        }

        if (executionEntityToEnd.isProcessInstanceType()) {
          Context.getAgenda().planEndExecutionOperation(executionEntityToEnd);
        } else {
          Context.getAgenda().planDestroyScopeOperation(executionEntityToEnd);
        }

      }
    }
  }
 
Example 7
Source File: BoundaryEventActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void executeInterruptingBehavior(ExecutionEntity executionEntity, CommandContext commandContext) {

    // The destroy scope operation will look for the parent execution and
    // destroy the whole scope, and leave the boundary event using this parent execution.
    //
    // The take outgoing seq flows operation below (the non-interrupting else clause) on the other hand uses the
    // child execution to leave, which keeps the scope alive.
    // Which is what we need here.

    ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager();
    ExecutionEntity attachedRefScopeExecution = executionEntityManager.findById(executionEntity.getParentId());

    ExecutionEntity parentScopeExecution = null;
    ExecutionEntity currentlyExaminedExecution = executionEntityManager.findById(attachedRefScopeExecution.getParentId());
    while (currentlyExaminedExecution != null && parentScopeExecution == null) {
      if (currentlyExaminedExecution.isScope()) {
        parentScopeExecution = currentlyExaminedExecution;
      } else {
        currentlyExaminedExecution = executionEntityManager.findById(currentlyExaminedExecution.getParentId());
      }
    }

    if (parentScopeExecution == null) {
      throw new ActivitiException("Programmatic error: no parent scope execution found for boundary event");
    }

    deleteChildExecutions(attachedRefScopeExecution, executionEntity, commandContext);

    // set new parent for boundary event execution
    executionEntity.setParent(parentScopeExecution);

    Context.getAgenda().planTakeOutgoingSequenceFlowsOperation(executionEntity, true);
  }
 
Example 8
Source File: BoundaryEventActivityBehavior.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void executeNonInterruptingBehavior(ExecutionEntity executionEntity, CommandContext commandContext) {

    // Non-interrupting: the current execution is given the first parent
    // scope (which isn't its direct parent)
    //
    // Why? Because this execution does NOT have anything to do with
    // the current parent execution (the one where the boundary event is on): when it is deleted or whatever,
    // this does not impact this new execution at all, it is completely independent in that regard.

    // Note: if the parent of the parent does not exists, this becomes a concurrent execution in the process instance!

    ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager();

    ExecutionEntity parentExecutionEntity = executionEntityManager.findById(executionEntity.getParentId());

    ExecutionEntity scopeExecution = null;
    ExecutionEntity currentlyExaminedExecution = executionEntityManager.findById(parentExecutionEntity.getParentId());
    while (currentlyExaminedExecution != null && scopeExecution == null) {
      if (currentlyExaminedExecution.isScope()) {
        scopeExecution = currentlyExaminedExecution;
      } else {
        currentlyExaminedExecution = executionEntityManager.findById(currentlyExaminedExecution.getParentId());
      }
    }

    if (scopeExecution == null) {
      throw new ActivitiException("Programmatic error: no parent scope execution found for boundary event");
    }

    ExecutionEntity nonInterruptingExecution = executionEntityManager.createChildExecution(scopeExecution);
    nonInterruptingExecution.setCurrentFlowElement(executionEntity.getCurrentFlowElement());

    Context.getAgenda().planTakeOutgoingSequenceFlowsOperation(nonInterruptingExecution, true);
  }
 
Example 9
Source File: ErrorPropagation.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
private static ActivityExecution getSuperExecution(ActivityExecution execution) {
    ExecutionEntity executionEntity = (ExecutionEntity) execution;
    ExecutionEntity superExecution = executionEntity.getProcessInstance().getSuperExecution();
    if (superExecution != null && !superExecution.isScope()) {
        return superExecution.getParent();
    }
    return superExecution;
}