org.activiti.engine.impl.Condition Java Examples

The following examples show how to use org.activiti.engine.impl.Condition. 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: ConditionUtil.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public static boolean hasTrueCondition(SequenceFlow sequenceFlow, DelegateExecution execution) {
  String conditionExpression = null;
  if (Context.getProcessEngineConfiguration().isEnableProcessDefinitionInfoCache()) {
    ObjectNode elementProperties = Context.getBpmnOverrideElementProperties(sequenceFlow.getId(), execution.getProcessDefinitionId());
    conditionExpression = getActiveValue(sequenceFlow.getConditionExpression(), DynamicBpmnConstants.SEQUENCE_FLOW_CONDITION, elementProperties);
  } else {
    conditionExpression = sequenceFlow.getConditionExpression();
  }
  
  if (StringUtils.isNotEmpty(conditionExpression)) {

    Expression expression = Context.getProcessEngineConfiguration().getExpressionManager().createExpression(conditionExpression);
    Condition condition = new UelExpressionCondition(expression);
    if (condition.evaluate(sequenceFlow.getId(), execution)) {
      return true;
    }

    return false;

  } else {
    return true;
  }

}
 
Example #2
Source File: TakeOutgoingSequenceFlowsOperation.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
protected void handleAdhocSubProcess(FlowNode flowNode) {
  boolean completeAdhocSubProcess = false;
  AdhocSubProcess adhocSubProcess = (AdhocSubProcess) flowNode.getParentContainer();
  if (adhocSubProcess.getCompletionCondition() != null) {
    Expression expression = Context.getProcessEngineConfiguration().getExpressionManager().createExpression(adhocSubProcess.getCompletionCondition());
    Condition condition = new UelExpressionCondition(expression);
    if (condition.evaluate(adhocSubProcess.getId(), execution)) {
      completeAdhocSubProcess = true;
    }
  }

  if (flowNode.getOutgoingFlows().size() > 0) {
    leaveFlowNode(flowNode);
  } else {
    commandContext.getExecutionEntityManager().deleteExecutionAndRelatedData(execution, null, false);
  }

  if (completeAdhocSubProcess) {
    boolean endAdhocSubProcess = true;
    if (adhocSubProcess.isCancelRemainingInstances() == false) {
      List<ExecutionEntity> childExecutions = commandContext.getExecutionEntityManager().findChildExecutionsByParentExecutionId(execution.getParentId());
      for (ExecutionEntity executionEntity : childExecutions) {
        if (executionEntity.getId().equals(execution.getId()) == false) {
          endAdhocSubProcess = false;
          break;
        }
      }
    }

    if (endAdhocSubProcess) {
      Context.getAgenda().planEndExecutionOperation(execution.getParent());
    }
  }
}
 
Example #3
Source File: SequenceFlowParseHandler.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
protected void executeParse(BpmnParse bpmnParse, SequenceFlow sequenceFlow) {

    ScopeImpl scope = bpmnParse.getCurrentScope();

    ActivityImpl sourceActivity = scope.findActivity(sequenceFlow.getSourceRef());
    ActivityImpl destinationActivity = scope.findActivity(sequenceFlow.getTargetRef());

    Expression skipExpression;
    if (StringUtils.isNotEmpty(sequenceFlow.getSkipExpression())) {
        ExpressionManager expressionManager = bpmnParse.getExpressionManager();
        skipExpression = expressionManager.createExpression(sequenceFlow.getSkipExpression());
    } else {
        skipExpression = null;
    }

    TransitionImpl transition = sourceActivity.createOutgoingTransition(sequenceFlow.getId(), skipExpression);
    bpmnParse.getSequenceFlows().put(sequenceFlow.getId(), transition);
    transition.setProperty("name", sequenceFlow.getName());
    transition.setProperty("documentation", sequenceFlow.getDocumentation());
    transition.setDestination(destinationActivity);

    if (StringUtils.isNotEmpty(sequenceFlow.getConditionExpression())) {
        Condition expressionCondition = new UelExpressionCondition(sequenceFlow.getConditionExpression());
        transition.setProperty(PROPERTYNAME_CONDITION_TEXT, sequenceFlow.getConditionExpression());
        transition.setProperty(PROPERTYNAME_CONDITION, expressionCondition);
    }

    createExecutionListenersOnTransition(bpmnParse, sequenceFlow.getExecutionListeners(), transition);

}
 
Example #4
Source File: InclusiveGatewayActivityBehavior.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(DelegateExecution execution) {
    ActivityExecution activityExecution = (ActivityExecution) execution;
    activityExecution.inactivate();
    lockConcurrentRoot(activityExecution);

    PvmActivity activity = activityExecution.getActivity();
    if (!activeConcurrentExecutionsExist(activityExecution)) {

        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("inclusive gateway '{}' activates", activity.getId());
        }

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

        for (PvmTransition outgoingTransition : activityExecution.getActivity().getOutgoingTransitions()) {

            Expression skipExpression = outgoingTransition.getSkipExpression();
            if (!SkipExpressionUtil.isSkipExpressionEnabled(activityExecution, skipExpression)) {
                if (defaultSequenceFlow == null || !outgoingTransition.getId().equals(defaultSequenceFlow)) {
                    Condition condition = (Condition) outgoingTransition.getProperty(BpmnParse.PROPERTYNAME_CONDITION);
                    if (condition == null || condition.evaluate(outgoingTransition.getId(), execution)) {
                        transitionsToTake.add(outgoingTransition);
                    }
                }
            } else if (SkipExpressionUtil.shouldSkipFlowElement(activityExecution, skipExpression)) {
                transitionsToTake.add(outgoingTransition);
            }
        }

        if (!transitionsToTake.isEmpty()) {
            activityExecution.takeAll(transitionsToTake, joinedExecutions);

        } else {

            if (defaultSequenceFlow != null) {
                PvmTransition defaultTransition = activityExecution.getActivity().findOutgoingTransition(defaultSequenceFlow);
                if (defaultTransition != null) {
                    activityExecution.take(defaultTransition);
                } else {
                    throw new ActivitiException("Default sequence flow '"
                            + defaultSequenceFlow + "' could not be not found");
                }
            } else {
                // No sequence flow could be found, not even a default one
                throw new ActivitiException(
                        "No outgoing sequence flow of the inclusive gateway '"
                                + activityExecution.getActivity().getId()
                                + "' could be selected for continuing the process");
            }
        }

    } else {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Inclusive gateway '{}' does not activate", activity.getId());
        }
    }
}
 
Example #5
Source File: ExclusiveGatewayActivityBehavior.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
/**
 * The default behaviour of BPMN, taking every outgoing sequence flow (where the condition evaluates to true), is not valid for an exclusive gateway.
 * 
 * Hence, this behaviour is overridden and replaced by the correct behavior: selecting the first sequence flow which condition evaluates to true (or which hasn't got a condition) and leaving the
 * activity through that sequence flow.
 * 
 * If no sequence flow is selected (ie all conditions evaluate to false), then the default sequence flow is taken (if defined).
 */
@Override
protected void leave(ActivityExecution execution) {

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Leaving activity '{}'", execution.getActivity().getId());
    }

    PvmTransition outgoingSeqFlow = null;
    String defaultSequenceFlow = (String) execution.getActivity().getProperty("default");
    Iterator<PvmTransition> transitionIterator = execution.getActivity().getOutgoingTransitions().iterator();
    while (outgoingSeqFlow == null && transitionIterator.hasNext()) {
        PvmTransition seqFlow = transitionIterator.next();
        Expression skipExpression = seqFlow.getSkipExpression();

        if (!SkipExpressionUtil.isSkipExpressionEnabled(execution, skipExpression)) {
            Condition condition = (Condition) seqFlow.getProperty(BpmnParse.PROPERTYNAME_CONDITION);
            if ((condition == null && (defaultSequenceFlow == null || !defaultSequenceFlow.equals(seqFlow.getId())))
                    || (condition != null && condition.evaluate(seqFlow.getId(), execution))) {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Sequence flow '{}' selected as outgoing sequence flow.", seqFlow.getId());
                }
                outgoingSeqFlow = seqFlow;
            }
        } else if (SkipExpressionUtil.shouldSkipFlowElement(execution, skipExpression)) {
            outgoingSeqFlow = seqFlow;
        }
    }

    if (outgoingSeqFlow != null) {
        execution.take(outgoingSeqFlow);
    } else {

        if (defaultSequenceFlow != null) {
            PvmTransition defaultTransition = execution.getActivity().findOutgoingTransition(defaultSequenceFlow);
            if (defaultTransition != null) {
                execution.take(defaultTransition);
            } else {
                throw new ActivitiException("Default sequence flow '" + defaultSequenceFlow + "' not found");
            }
        } else {
            // No sequence flow could be found, not even a default one
            throw new ActivitiException("No outgoing sequence flow of the exclusive gateway '"
                    + execution.getActivity().getId() + "' could be selected for continuing the process");
        }
    }
}
 
Example #6
Source File: BpmnActivityBehavior.java    From flowable-engine 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.
 * @param throwExceptionIfExecutionStuck If true, an {@link ActivitiException} will be thrown in case no transition could be found to leave the activity.
 */
protected void performOutgoingBehavior(ActivityExecution execution,
                                       boolean checkConditions, boolean throwExceptionIfExecutionStuck, List<ActivityExecution> reusableExecutions) {

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Leaving activity '{}'", 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) {
        Expression skipExpression = outgoingTransition.getSkipExpression();

        if (!SkipExpressionUtil.isSkipExpressionEnabled(execution, skipExpression)) {
            if (defaultSequenceFlow == null || !outgoingTransition.getId().equals(defaultSequenceFlow)) {
                Condition condition = (Condition) outgoingTransition.getProperty(BpmnParse.PROPERTYNAME_CONDITION);
                if (condition == null || !checkConditions || condition.evaluate(outgoingTransition.getId(), execution)) {
                    transitionsToTake.add(outgoingTransition);
                }
            }

        } else if (SkipExpressionUtil.shouldSkipFlowElement(execution, skipExpression)) {
            transitionsToTake.add(outgoingTransition);
        }
    }

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

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

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

        execution.inactivate();
        if (reusableExecutions == null || reusableExecutions.isEmpty()) {
            execution.takeAll(transitionsToTake, Collections.singletonList(execution));
        } else {
            execution.takeAll(transitionsToTake, reusableExecutions);
        }

    } else {

        if (defaultSequenceFlow != null) {
            PvmTransition defaultTransition = execution.getActivity().findOutgoingTransition(defaultSequenceFlow);
            if (defaultTransition != null) {
                execution.take(defaultTransition);
            } else {
                throw new ActivitiException("Default sequence flow '" + defaultSequenceFlow + "' could not be not found");
            }
        } else {

            Object isForCompensation = execution.getActivity().getProperty(BpmnParse.PROPERTYNAME_IS_FOR_COMPENSATION);
            if (isForCompensation != null && (Boolean) isForCompensation) {
                if (execution instanceof ExecutionEntity) {
                    Context.getCommandContext().getHistoryManager().recordActivityEnd((ExecutionEntity) execution);
                }
                InterpretableExecution parentExecution = (InterpretableExecution) execution.getParent();
                ((InterpretableExecution) execution).remove();
                parentExecution.signal("compensationDone", null);

            } else {

                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("No outgoing sequence flow found for {}. Ending execution.", execution.getActivity().getId());
                }
                execution.end();

                if (throwExceptionIfExecutionStuck) {
                    throw new ActivitiException("No outgoing sequence flow of the inclusive gateway '" + execution.getActivity().getId()
                            + "' could be selected for continuing the process");
                }
            }

        }
    }
}