Java Code Examples for org.activiti.engine.impl.pvm.delegate.ActivityExecution#take()

The following examples show how to use org.activiti.engine.impl.pvm.delegate.ActivityExecution#take() . 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: While.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public void execute(DelegateExecution execution) {
    ActivityExecution activityExecution = (ActivityExecution) execution;
    PvmTransition more = activityExecution.getActivity().findOutgoingTransition("more");
    PvmTransition done = activityExecution.getActivity().findOutgoingTransition("done");

    Integer value = (Integer) execution.getVariable(variableName);

    if (value == null) {
        execution.setVariable(variableName, from);
        activityExecution.take(more);

    } else {
        value = value + 1;

        if (value < to) {
            execution.setVariable(variableName, value);
            activityExecution.take(more);

        } else {
            activityExecution.take(done);
        }
    }
}
 
Example 2
Source File: Decision.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public void execute(DelegateExecution execution) {
    PvmTransition transition;
    ActivityExecution activityExecution = (ActivityExecution) execution;
    String creditRating = (String) execution.getVariable("creditRating");
    if (creditRating.equals("AAA+")) {
        transition = activityExecution.getActivity().findOutgoingTransition("wow");
    } else if (creditRating.equals("Aaa-")) {
        transition = activityExecution.getActivity().findOutgoingTransition("nice");
    } else {
        transition = activityExecution.getActivity().findOutgoingTransition("default");
    }

    activityExecution.take(transition);
}
 
Example 3
Source File: ThrowsExceptionBehavior.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public void execute(DelegateExecution execution) {
    ActivityExecution activityExecution = (ActivityExecution) execution;
    String var = (String) execution.getVariable("var");

    PvmTransition transition;
    try {
        executeLogic(var);
        transition = activityExecution.getActivity().findOutgoingTransition("no-exception");
    } catch (Exception e) {
        transition = activityExecution.getActivity().findOutgoingTransition("exception");
    }
    activityExecution.take(transition);
}
 
Example 4
Source File: Automatic.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public void execute(DelegateExecution execution) {
    ActivityExecution activityExecution = (ActivityExecution) execution;
    List<PvmTransition> outgoingTransitions = activityExecution.getActivity().getOutgoingTransitions();
    if (outgoingTransitions.isEmpty()) {
        activityExecution.end();
    } else {
        activityExecution.take(outgoingTransitions.get(0));
    }
}
 
Example 5
Source File: Automatic.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
public void execute(ActivityExecution execution) throws Exception {
    List<PvmTransition> outgoingTransitions = execution.getActivity().getOutgoingTransitions();
    if (outgoingTransitions.isEmpty()) {
        execution.end();
        System.out.println("流程已结束,结束节点:" + execution.getActivity().getId());
    } else {
        System.out.println("自动节点:" + execution.getActivity().getId());
        execution.take(outgoingTransitions.get(0));
    }
}
 
Example 6
Source File: WaitState.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
public void signal(ActivityExecution execution, String signalName, Object signalData) throws Exception {
    PvmActivity activity = execution.getActivity();
    System.out.println("触发活动" + activity.getId());

    PvmTransition transition = activity.getOutgoingTransitions().get(0);
    execution.take(transition);
}
 
Example 7
Source File: Automatic.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public void execute(DelegateExecution execution) {
    ActivityExecution activityExecution = (ActivityExecution) execution;
    PvmTransition defaultOutgoingTransition = activityExecution.getActivity().getOutgoingTransitions().get(0);
    activityExecution.take(defaultOutgoingTransition);
}
 
Example 8
Source File: WaitState.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public void signal(ActivityExecution execution, String signalName, Object event) {
    PvmTransition transition = findTransition(execution, signalName);
    execution.take(transition);
}
 
Example 9
Source File: WaitState.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public void signal(ActivityExecution execution, String signalName, Object signalData) throws Exception {
    PvmTransition transition = execution.getActivity().getOutgoingTransitions().get(0);
    execution.take(transition);
}
 
Example 10
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 11
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 12
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");
                }
            }

        }
    }
}