Java Code Examples for org.camunda.bpm.engine.impl.pvm.delegate.ActivityExecution#leaveActivityViaTransitions()

The following examples show how to use org.camunda.bpm.engine.impl.pvm.delegate.ActivityExecution#leaveActivityViaTransitions() . 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: ParallelGatewayActivityBehavior.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void execute(ActivityExecution execution) throws Exception {

    // Join
    PvmActivity activity = execution.getActivity();
    List<PvmTransition> outgoingTransitions = execution.getActivity().getOutgoingTransitions();

    execution.inactivate();
    lockConcurrentRoot(execution);

    List<ActivityExecution> joinedExecutions = execution.findInactiveConcurrentExecutions(activity);
    int nbrOfExecutionsToJoin = execution.getActivity().getIncomingTransitions().size();
    int nbrOfExecutionsJoined = joinedExecutions.size();

    if (nbrOfExecutionsJoined==nbrOfExecutionsToJoin) {

      // Fork
      LOG.activityActivation(activity.getId(), nbrOfExecutionsJoined, nbrOfExecutionsToJoin);
      execution.leaveActivityViaTransitions(outgoingTransitions, joinedExecutions);

    } else {
      LOG.noActivityActivation(activity.getId(), nbrOfExecutionsJoined, nbrOfExecutionsToJoin);
    }
  }
 
Example 2
Source File: ParallelGateway.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void execute(ActivityExecution execution) {
  PvmActivity activity = execution.getActivity();

  List<PvmTransition> outgoingTransitions = execution.getActivity().getOutgoingTransitions();

  execution.inactivate();

  List<ActivityExecution> joinedExecutions = execution.findInactiveConcurrentExecutions(activity);

  int nbrOfExecutionsToJoin = execution.getActivity().getIncomingTransitions().size();
  int nbrOfExecutionsJoined = joinedExecutions.size();

  if (nbrOfExecutionsJoined==nbrOfExecutionsToJoin) {
    LOG.debug("parallel gateway '"+activity.getId()+"' activates: "+nbrOfExecutionsJoined+" of "+nbrOfExecutionsToJoin+" joined");
    execution.leaveActivityViaTransitions(outgoingTransitions, joinedExecutions);

  } else {
    LOG.debug("parallel gateway '"+activity.getId()+"' does not activate: "+nbrOfExecutionsJoined+" of "+nbrOfExecutionsToJoin+" joined");
  }
}
 
Example 3
Source File: EventScopeCreatingSubprocess.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void complete(ActivityExecution execution) {

    ActivityExecution outgoingExecution = execution.getParent().createExecution();
    outgoingExecution.setConcurrent(false);
    outgoingExecution.setActivity(execution.getActivity());

    // eventscope execution
    execution.setConcurrent(false);
    execution.setActive(false);
    ((PvmExecutionImpl)execution).setEventScope(true);

    List<PvmTransition> outgoingTransitions = execution.getActivity().getOutgoingTransitions();
    if(outgoingTransitions.isEmpty()) {
      outgoingExecution.end(true);
    }else {
      outgoingExecution.leaveActivityViaTransitions(outgoingTransitions, Collections.EMPTY_LIST);
    }
  }
 
Example 4
Source File: EmbeddedSubProcess.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void complete(ActivityExecution execution) {
  List<PvmTransition> outgoingTransitions = execution.getActivity().getOutgoingTransitions();
  if(outgoingTransitions.isEmpty()) {
    execution.end(true);
  }else {
    execution.leaveActivityViaTransitions(outgoingTransitions, Collections.EMPTY_LIST);
  }
}
 
Example 5
Source File: InclusiveGatewayActivityBehavior.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public void execute(ActivityExecution execution) throws Exception {

    execution.inactivate();
    lockConcurrentRoot(execution);

    PvmActivity activity = execution.getActivity();
    if (activatesGateway(execution, activity)) {

      LOG.activityActivation(activity.getId());

      List<ActivityExecution> joinedExecutions = execution.findInactiveConcurrentExecutions(activity);
      String defaultSequenceFlow = (String) execution.getActivity().getProperty("default");
      List<PvmTransition> transitionsToTake = new ArrayList<PvmTransition>();

      // find matching non-default sequence flows
      for (PvmTransition outgoingTransition : execution.getActivity().getOutgoingTransitions()) {
        if (defaultSequenceFlow == null || !outgoingTransition.getId().equals(defaultSequenceFlow)) {
          Condition condition = (Condition) outgoingTransition.getProperty(BpmnParse.PROPERTYNAME_CONDITION);
          if (condition == null || condition.evaluate(execution)) {
            transitionsToTake.add(outgoingTransition);
          }
        }
      }

      // if none found, add default flow
      if (transitionsToTake.isEmpty()) {
        if (defaultSequenceFlow != null) {
          PvmTransition defaultTransition = execution.getActivity().findOutgoingTransition(defaultSequenceFlow);
          if (defaultTransition == null) {
            throw LOG.missingDefaultFlowException(execution.getActivity().getId(), defaultSequenceFlow);
          }

          transitionsToTake.add(defaultTransition);

        } else {
          // No sequence flow could be found, not even a default one
          throw LOG.stuckExecutionException(execution.getActivity().getId());
        }
      }

      // take the flows found
      execution.leaveActivityViaTransitions(transitionsToTake, joinedExecutions);
    } else {
      LOG.noActivityActivation(activity.getId());
    }
  }
 
Example 6
Source File: BpmnActivityBehavior.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
/**
 * Actual implementation of leaving an activity.
 *
 * @param execution
 *          The current execution context
 * @param checkConditions
 *          Whether or not to check conditions before determining whether or
 *          not to take a transition.
 */
protected void performOutgoingBehavior(ActivityExecution execution,
        boolean checkConditions, List<ActivityExecution> reusableExecutions) {

  LOG.leavingActivity(execution.getActivity().getId());

  String defaultSequenceFlow = (String) execution.getActivity().getProperty("default");
  List<PvmTransition> transitionsToTake = new ArrayList<>();

  List<PvmTransition> outgoingTransitions = execution.getActivity().getOutgoingTransitions();
  for (PvmTransition outgoingTransition : outgoingTransitions) {
    if (defaultSequenceFlow == null || !outgoingTransition.getId().equals(defaultSequenceFlow)) {
      Condition condition = (Condition) outgoingTransition.getProperty(BpmnParse.PROPERTYNAME_CONDITION);
      if (condition == null || !checkConditions || condition.evaluate(execution)) {
        transitionsToTake.add(outgoingTransition);
      }
    }
  }

  if (transitionsToTake.size() == 1) {

    execution.leaveActivityViaTransition(transitionsToTake.get(0));

  } else if (transitionsToTake.size() >= 1) {

    if (reusableExecutions == null || reusableExecutions.isEmpty()) {
      execution.leaveActivityViaTransitions(transitionsToTake, Arrays.asList(execution));
    } else {
      execution.leaveActivityViaTransitions(transitionsToTake, reusableExecutions);
    }

  } else {

    if (defaultSequenceFlow != null) {
      PvmTransition defaultTransition = execution.getActivity().findOutgoingTransition(defaultSequenceFlow);
      if (defaultTransition != null) {
        execution.leaveActivityViaTransition(defaultTransition);
      } else {
        throw LOG.missingDefaultFlowException(execution.getActivity().getId(), defaultSequenceFlow);
      }

    } else if (!outgoingTransitions.isEmpty()) {
      throw LOG.missingConditionalFlowException(execution.getActivity().getId());

    } else {

      if (((ActivityImpl) execution.getActivity()).isCompensationHandler() && isAncestorCompensationThrowing(execution)) {

       execution.endCompensation();

      } else {
        LOG.missingOutgoingSequenceFlow(execution.getActivity().getId());
        execution.end(true);
      }
    }
  }
}
 
Example 7
Source File: ReusableSubProcess.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public void completed(ActivityExecution execution) throws Exception {
  List<PvmTransition> outgoingTransitions = execution.getActivity().getOutgoingTransitions();
  execution.leaveActivityViaTransitions(outgoingTransitions, null);
}