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

The following examples show how to use org.activiti.engine.impl.persistence.entity.ExecutionEntity#getExecutions() . 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: AbstractEventHandler.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected void dispatchExecutionCancelled(EventSubscriptionEntity eventSubscription, ExecutionEntity execution, CommandContext commandContext) {
  // subprocesses
  for (ExecutionEntity subExecution : execution.getExecutions()) {
    dispatchExecutionCancelled(eventSubscription, subExecution, commandContext);
  }

  // call activities
  ExecutionEntity subProcessInstance = commandContext.getExecutionEntityManager().findSubProcessInstanceBySuperExecutionId(execution.getId());
  if (subProcessInstance != null) {
    dispatchExecutionCancelled(eventSubscription, subProcessInstance, commandContext);
  }

  // activity with message/signal boundary events
  FlowElement flowElement = execution.getCurrentFlowElement();
  if (flowElement instanceof BoundaryEvent) {
    BoundaryEvent boundaryEvent = (BoundaryEvent) flowElement;
    if (boundaryEvent.getAttachedToRef() != null) {
      dispatchActivityCancelled(eventSubscription, execution, boundaryEvent.getAttachedToRef(), commandContext);
    }
  }
}
 
Example 2
Source File: CompleteAdhocSubProcessCmd.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public Void execute(CommandContext commandContext) {
  ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager();
  ExecutionEntity execution = executionEntityManager.findById(executionId);
  if (execution == null) {
    throw new ActivitiObjectNotFoundException("No execution found for id '" + executionId + "'", ExecutionEntity.class);
  }

  if (execution.getCurrentFlowElement() instanceof AdhocSubProcess == false) {
    throw new ActivitiException("The current flow element of the requested execution is not an ad-hoc sub process");
  }

  List<? extends ExecutionEntity> childExecutions = execution.getExecutions();
  if (childExecutions.size() > 0) {
    throw new ActivitiException("Ad-hoc sub process has running child executions that need to be completed first");
  }

  ExecutionEntity outgoingFlowExecution = executionEntityManager.createChildExecution(execution.getParent());
  outgoingFlowExecution.setCurrentFlowElement(execution.getCurrentFlowElement());

  executionEntityManager.deleteExecutionAndRelatedData(execution, null, false);

  Context.getAgenda().planTakeOutgoingSequenceFlowsOperation(outgoingFlowExecution, true);

  return null;
}
 
Example 3
Source File: AbstractEventHandler.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected void dispatchExecutionCancelled(EventSubscriptionEntity eventSubscription, ExecutionEntity execution, CommandContext commandContext) {
    // subprocesses
    for (ExecutionEntity subExecution : execution.getExecutions()) {
        dispatchExecutionCancelled(eventSubscription, subExecution, commandContext);
    }

    // call activities
    ExecutionEntity subProcessInstance = commandContext.getExecutionEntityManager().findSubProcessInstanceBySuperExecutionId(execution.getId());
    if (subProcessInstance != null) {
        dispatchExecutionCancelled(eventSubscription, subProcessInstance, commandContext);
    }

    // activity with message/signal boundary events
    ActivityImpl activity = execution.getActivity();
    if (activity != null && activity.getActivityBehavior() != null) {
        dispatchActivityCancelled(eventSubscription, execution, activity, commandContext);
    }
}
 
Example 4
Source File: TimerExecuteNestedActivityJobHandler.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected void dispatchExecutionTimeOut(Job job, ExecutionEntity execution, CommandContext commandContext) {
    // subprocesses
    for (ExecutionEntity subExecution : execution.getExecutions()) {
        dispatchExecutionTimeOut(job, subExecution, commandContext);
    }

    // call activities
    ExecutionEntity subProcessInstance = commandContext.getExecutionEntityManager().findSubProcessInstanceBySuperExecutionId(execution.getId());
    if (subProcessInstance != null) {
        dispatchExecutionTimeOut(job, subProcessInstance, commandContext);
    }

    // activity with timer boundary event
    ActivityImpl activity = execution.getActivity();
    if (activity != null && activity.getActivityBehavior() != null) {
        dispatchActivityTimeOut(job, activity, execution, commandContext);
    }
}
 
Example 5
Source File: TerminateEndEventActivityBehavior.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected List<ExecutionEntity> orderExecutionsRootToLeaf(ExecutionEntity rootExecution, List<ExecutionEntity> orderedExecutions) {
    orderedExecutions.add(rootExecution);

    // Children
    if (rootExecution.getExecutions() != null && rootExecution.getExecutions().size() > 0) {
        for (ExecutionEntity childExecution : rootExecution.getExecutions()) {
            orderExecutionsRootToLeaf(childExecution, orderedExecutions);
        }
    }

    // Called process instances (subprocess)
    if (rootExecution.getSubProcessInstance() != null) {
        orderExecutionsRootToLeaf(rootExecution.getSubProcessInstance(), orderedExecutions);
    }

    return orderedExecutions;
}
 
Example 6
Source File: CounterSignCmd.java    From lemon with Apache License 2.0 6 votes vote down vote up
/**
 * <li>给串行实例集合中添加一个审批人
 */
private void addSequentialInstance() {
    ExecutionEntity execution = getActivieExecutions().get(0);

    if (getActivity().getProperty("type").equals("subProcess")) {
        if (!execution.isActive()
                && execution.isEnded()
                && ((execution.getExecutions() == null) || (execution
                        .getExecutions().size() == 0))) {
            execution.setActive(true);
        }
    }

    Collection<String> col = (Collection<String>) execution
            .getVariable(collectionVariableName);
    col.add(assignee);
    execution.setVariable(collectionVariableName, col);
    setLoopVariable(execution, "nrOfInstances",
            (Integer) execution.getVariableLocal("nrOfInstances") + 1);
}
 
Example 7
Source File: ExecutionTreeUtil.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected static void collectChildExecutions(ExecutionEntity rootExecutionEntity, List<ExecutionEntity> allExecutions) {
  for (ExecutionEntity childExecutionEntity : rootExecutionEntity.getExecutions()) {
    allExecutions.add(childExecutionEntity);
    collectChildExecutions(childExecutionEntity, allExecutions);
  }
  
  if (rootExecutionEntity.getSubProcessInstance() != null) {
    allExecutions.add(rootExecutionEntity.getSubProcessInstance());
    collectChildExecutions(rootExecutionEntity.getSubProcessInstance(), allExecutions);
  }
}
 
Example 8
Source File: TakeOutgoingSequenceFlowsOperation.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected boolean allChildExecutionsEnded(ExecutionEntity parentExecutionEntity, ExecutionEntity executionEntityToIgnore) {
  for (ExecutionEntity childExecutionEntity : parentExecutionEntity.getExecutions()) {
    if (executionEntityToIgnore == null || !executionEntityToIgnore.getId().equals(childExecutionEntity.getId())) {
      if (!childExecutionEntity.isEnded()) {
        return false;
      }
      if (childExecutionEntity.getExecutions() != null && childExecutionEntity.getExecutions().size() > 0) {
        if (!allChildExecutionsEnded(childExecutionEntity, executionEntityToIgnore)) {
          return false;
        }
      }
    }
  }
  return true;
}
 
Example 9
Source File: EndExecutionOperation.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected boolean allChildExecutionsEnded(ExecutionEntity parentExecutionEntity, ExecutionEntity executionEntityToIgnore) {
  for (ExecutionEntity childExecutionEntity : parentExecutionEntity.getExecutions()) {
    if (executionEntityToIgnore == null || !executionEntityToIgnore.getId().equals(childExecutionEntity.getId())) {
      if (!childExecutionEntity.isEnded()) {
        return false;
      }
      if (childExecutionEntity.getExecutions() != null && childExecutionEntity.getExecutions().size() > 0) {
        if (!allChildExecutionsEnded(childExecutionEntity, executionEntityToIgnore)) {
          return false;
        }
      }
    }
  }
  return true;
}
 
Example 10
Source File: FindActiveActivityIdsCmd.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void collectActiveActivityIds(ExecutionEntity executionEntity, List<String> activeActivityIds) {
  if (executionEntity.isActive() && executionEntity.getActivityId() != null) {
    activeActivityIds.add(executionEntity.getActivityId());
  }
  
  for (ExecutionEntity childExecution : executionEntity.getExecutions()) {
    collectActiveActivityIds(childExecution, activeActivityIds);
  }
}
 
Example 11
Source File: ErrorPropagation.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
protected static void executeEventHandler(Event event, ExecutionEntity parentExecution, ExecutionEntity currentExecution, String errorId) {
  if (Context.getProcessEngineConfiguration() != null && Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
    BpmnModel bpmnModel = ProcessDefinitionUtil.getBpmnModel(parentExecution.getProcessDefinitionId());
    if (bpmnModel != null) {

      String errorCode = bpmnModel.getErrors().get(errorId);
      if (errorCode == null) {
        errorCode = errorId;
      }

      Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
        ActivitiEventBuilder.createErrorEvent(ActivitiEventType.ACTIVITY_ERROR_RECEIVED, event.getId(), errorId, errorCode, parentExecution.getId(),
            parentExecution.getProcessInstanceId(), parentExecution.getProcessDefinitionId()));
    }
  }

  if (event instanceof StartEvent) {
    ExecutionEntityManager executionEntityManager = Context.getCommandContext().getExecutionEntityManager();

    if (currentExecution.getParentId().equals(parentExecution.getId()) == false) {
      Context.getAgenda().planDestroyScopeOperation(currentExecution);
    } else {
      executionEntityManager.deleteExecutionAndRelatedData(currentExecution, null, false);
    }

    ExecutionEntity eventSubProcessExecution = executionEntityManager.createChildExecution(parentExecution);
    eventSubProcessExecution.setCurrentFlowElement(event);
    Context.getAgenda().planContinueProcessOperation(eventSubProcessExecution);

  } else {
    ExecutionEntity boundaryExecution = null;
    List<? extends ExecutionEntity> childExecutions = parentExecution.getExecutions();
    for (ExecutionEntity childExecution : childExecutions) {
      if (childExecution.getActivityId().equals(event.getId())) {
        boundaryExecution = childExecution;
      }
    }

    Context.getAgenda().planTriggerExecutionOperation(boundaryExecution);
  }
}
 
Example 12
Source File: BoundaryEventActivityBehavior.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void execute(DelegateExecution execution) {
    ExecutionEntity executionEntity = (ExecutionEntity) execution;
    ActivityImpl boundaryActivity = executionEntity.getProcessDefinition().findActivity(activityId);
    ActivityImpl interruptedActivity = executionEntity.getActivity();

    List<PvmTransition> outgoingTransitions = boundaryActivity.getOutgoingTransitions();
    List<ExecutionEntity> interruptedExecutions = null;

    if (interrupting) {

        // Call activity
        if (executionEntity.getSubProcessInstance() != null) {
            executionEntity.getSubProcessInstance().deleteCascade(executionEntity.getDeleteReason());
        } else {
            Context.getCommandContext().getHistoryManager().recordActivityEnd(executionEntity);
        }

        executionEntity.setActivity(boundaryActivity);

        interruptedExecutions = new ArrayList<>(executionEntity.getExecutions());
        for (ExecutionEntity interruptedExecution : interruptedExecutions) {
            interruptedExecution.deleteCascade("interrupting boundary event '" + executionEntity.getActivity().getId() + "' fired");
        }

        executionEntity.takeAll(outgoingTransitions, (List) interruptedExecutions);
    } else {
        // non interrupting event, introduced with BPMN 2.0, we need to create a new execution in this case

        // create a new execution and move it out from the timer activity
        ExecutionEntity concurrentRoot = executionEntity.getParent().isConcurrent() ? executionEntity.getParent() : executionEntity;
        ExecutionEntity outgoingExecution = concurrentRoot.createExecution();

        outgoingExecution.setActive(true);
        outgoingExecution.setScope(false);
        outgoingExecution.setConcurrent(true);

        outgoingExecution.takeAll(outgoingTransitions, Collections.EMPTY_LIST);
        outgoingExecution.remove();
        // now we have to move the execution back to the real activity
        // since the execution stays there (non interrupting) and it was
        // set to the boundary event before
        executionEntity.setActivity(interruptedActivity);
    }
}