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);
}
}
}
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());
}
}
}
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;
}
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());
}
}
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);
}
}
Aggregations