Search in sources :

Example 1 with PvmTransition

use of org.camunda.bpm.engine.impl.pvm.PvmTransition in project camunda-bpm-platform by camunda.

the class BpmnParse method validateExclusiveGateway.

public void validateExclusiveGateway(ActivityImpl activity) {
    if (activity.getOutgoingTransitions().size() == 0) {
        // TODO: double check if this is valid (I think in Activiti yes, since we
        // need start events we will need an end event as well)
        addError("Exclusive Gateway '" + activity.getId() + "' has no outgoing sequence flows.", null);
    } else if (activity.getOutgoingTransitions().size() == 1) {
        PvmTransition flow = activity.getOutgoingTransitions().get(0);
        Condition condition = (Condition) flow.getProperty(BpmnParse.PROPERTYNAME_CONDITION);
        if (condition != null) {
            addError("Exclusive Gateway '" + activity.getId() + "' has only one outgoing sequence flow ('" + flow.getId() + "'). This is not allowed to have a condition.", null);
        }
    } else {
        String defaultSequenceFlow = (String) activity.getProperty("default");
        boolean hasDefaultFlow = defaultSequenceFlow != null && defaultSequenceFlow.length() > 0;
        ArrayList<PvmTransition> flowsWithoutCondition = new ArrayList<PvmTransition>();
        for (PvmTransition flow : activity.getOutgoingTransitions()) {
            Condition condition = (Condition) flow.getProperty(BpmnParse.PROPERTYNAME_CONDITION);
            boolean isDefaultFlow = flow.getId() != null && flow.getId().equals(defaultSequenceFlow);
            boolean hasConditon = condition != null;
            if (!hasConditon && !isDefaultFlow) {
                flowsWithoutCondition.add(flow);
            }
            if (hasConditon && isDefaultFlow) {
                addError("Exclusive Gateway '" + activity.getId() + "' has outgoing sequence flow '" + flow.getId() + "' which is the default flow but has a condition too.", null);
            }
        }
        if (hasDefaultFlow || flowsWithoutCondition.size() > 1) {
            // this is an error
            for (PvmTransition flow : flowsWithoutCondition) {
                addError("Exclusive Gateway '" + activity.getId() + "' has outgoing sequence flow '" + flow.getId() + "' without condition which is not the default flow.", null);
            }
        } else if (flowsWithoutCondition.size() == 1) {
            // Havinf no default and exactly one flow without condition this is
            // considered the default one now (to not break backward compatibility)
            PvmTransition flow = flowsWithoutCondition.get(0);
            addWarning("Exclusive Gateway '" + activity.getId() + "' has outgoing sequence flow '" + flow.getId() + "' without condition which is not the default flow. We assume it to be the default flow, but it is bad modeling practice, better set the default flow in your gateway.", null);
        }
    }
}
Also used : ScriptCondition(org.camunda.bpm.engine.impl.scripting.ScriptCondition) Condition(org.camunda.bpm.engine.impl.Condition) PvmTransition(org.camunda.bpm.engine.impl.pvm.PvmTransition)

Example 2 with PvmTransition

use of org.camunda.bpm.engine.impl.pvm.PvmTransition in project camunda-bpm-platform by camunda.

the class ExclusiveGatewayActivityBehavior method doLeave.

/**
 * 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 overriden 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
public void doLeave(ActivityExecution execution) {
    LOG.leavingActivity(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();
        Condition condition = (Condition) seqFlow.getProperty(BpmnParse.PROPERTYNAME_CONDITION);
        if ((condition == null && (defaultSequenceFlow == null || !defaultSequenceFlow.equals(seqFlow.getId()))) || (condition != null && condition.evaluate(execution))) {
            LOG.outgoingSequenceFlowSelected(seqFlow.getId());
            outgoingSeqFlow = seqFlow;
        }
    }
    if (outgoingSeqFlow != null) {
        execution.leaveActivityViaTransition(outgoingSeqFlow);
    } 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 {
            // No sequence flow could be found, not even a default one
            throw LOG.stuckExecutionException(execution.getActivity().getId());
        }
    }
}
Also used : Condition(org.camunda.bpm.engine.impl.Condition) PvmTransition(org.camunda.bpm.engine.impl.pvm.PvmTransition)

Example 3 with PvmTransition

use of org.camunda.bpm.engine.impl.pvm.PvmTransition in project camunda-bpm-platform by camunda.

the class InclusiveGatewayActivityBehavior method isReachable.

protected boolean isReachable(PvmActivity srcActivity, PvmActivity targetActivity, Set<PvmActivity> visitedActivities) {
    if (srcActivity.equals(targetActivity)) {
        return true;
    }
    // To avoid infinite looping, we must capture every node we visit and
    // check before going further in the graph if we have already visited the node.
    visitedActivities.add(srcActivity);
    List<PvmTransition> outgoingTransitions = srcActivity.getOutgoingTransitions();
    if (outgoingTransitions.isEmpty()) {
        ScopeImpl flowScope = srcActivity.getFlowScope();
        if (flowScope == null || !(flowScope instanceof PvmActivity)) {
            return false;
        }
        return isReachable((PvmActivity) flowScope, targetActivity, visitedActivities);
    } else {
        for (PvmTransition pvmTransition : outgoingTransitions) {
            PvmActivity destinationActivity = pvmTransition.getDestination();
            if (destinationActivity != null && !visitedActivities.contains(destinationActivity)) {
                boolean reachable = isReachable(destinationActivity, targetActivity, visitedActivities);
                // If false, we should investigate other paths, and not yet return the result
                if (reachable) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : ScopeImpl(org.camunda.bpm.engine.impl.pvm.process.ScopeImpl) PvmTransition(org.camunda.bpm.engine.impl.pvm.PvmTransition) PvmActivity(org.camunda.bpm.engine.impl.pvm.PvmActivity)

Example 4 with PvmTransition

use of org.camunda.bpm.engine.impl.pvm.PvmTransition in project camunda-bpm-platform by camunda.

the class InclusiveGatewayActivityBehavior method execute.

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());
    }
}
Also used : Condition(org.camunda.bpm.engine.impl.Condition) ArrayList(java.util.ArrayList) ActivityExecution(org.camunda.bpm.engine.impl.pvm.delegate.ActivityExecution) PvmActivity(org.camunda.bpm.engine.impl.pvm.PvmActivity) PvmTransition(org.camunda.bpm.engine.impl.pvm.PvmTransition)

Example 5 with PvmTransition

use of org.camunda.bpm.engine.impl.pvm.PvmTransition in project camunda-bpm-platform by camunda.

the class ParallelGatewayActivityBehavior method execute.

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);
    }
}
Also used : ActivityExecution(org.camunda.bpm.engine.impl.pvm.delegate.ActivityExecution) PvmActivity(org.camunda.bpm.engine.impl.pvm.PvmActivity) PvmTransition(org.camunda.bpm.engine.impl.pvm.PvmTransition)

Aggregations

PvmTransition (org.camunda.bpm.engine.impl.pvm.PvmTransition)19 PvmActivity (org.camunda.bpm.engine.impl.pvm.PvmActivity)7 ActivityExecution (org.camunda.bpm.engine.impl.pvm.delegate.ActivityExecution)5 Condition (org.camunda.bpm.engine.impl.Condition)4 ArrayList (java.util.ArrayList)3 ActivityImpl (org.camunda.bpm.engine.impl.pvm.process.ActivityImpl)3 TransitionImpl (org.camunda.bpm.engine.impl.pvm.process.TransitionImpl)3 PvmExecutionImpl (org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl)3 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)2 CommandContext (org.camunda.bpm.engine.impl.interceptor.CommandContext)2 CommandExecutor (org.camunda.bpm.engine.impl.interceptor.CommandExecutor)2 ProcessDefinitionEntity (org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity)2 Deployment (org.camunda.bpm.engine.test.Deployment)2 List (java.util.List)1 RepositoryServiceImpl (org.camunda.bpm.engine.impl.RepositoryServiceImpl)1 AsyncContinuationConfiguration (org.camunda.bpm.engine.impl.jobexecutor.AsyncContinuationJobHandler.AsyncContinuationConfiguration)1 ReadOnlyProcessDefinition (org.camunda.bpm.engine.impl.pvm.ReadOnlyProcessDefinition)1 ModificationObserverBehavior (org.camunda.bpm.engine.impl.pvm.delegate.ModificationObserverBehavior)1 ScopeImpl (org.camunda.bpm.engine.impl.pvm.process.ScopeImpl)1 ExecutionStartContext (org.camunda.bpm.engine.impl.pvm.runtime.ExecutionStartContext)1