use of org.camunda.bpm.engine.impl.pvm.PvmActivity in project camunda-bpm-platform by camunda.
the class AbstractBpmnActivityBehavior method doLeave.
/**
* Subclasses that call leave() will first pass through this method, before
* the regular {@link FlowNodeActivityBehavior#leave(ActivityExecution)} is
* called.
*/
@Override
public void doLeave(ActivityExecution execution) {
PvmActivity currentActivity = execution.getActivity();
ActivityImpl compensationHandler = ((ActivityImpl) currentActivity).findCompensationHandler();
// subscription for compensation event subprocess is already created
if (compensationHandler != null && !isCompensationEventSubprocess(compensationHandler)) {
createCompensateEventSubscription(execution, compensationHandler);
}
super.doLeave(execution);
}
use of org.camunda.bpm.engine.impl.pvm.PvmActivity 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.PvmActivity 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.PvmActivity 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);
}
}
use of org.camunda.bpm.engine.impl.pvm.PvmActivity in project camunda-bpm-platform by camunda.
the class SetProcessDefinitionVersionCmd method validateAndSwitchVersionOfExecution.
protected void validateAndSwitchVersionOfExecution(CommandContext commandContext, ExecutionEntity execution, ProcessDefinitionEntity newProcessDefinition) {
// check that the new process definition version contains the current activity
if (execution.getActivity() != null) {
String activityId = execution.getActivity().getId();
PvmActivity newActivity = newProcessDefinition.findActivity(activityId);
if (newActivity == null) {
throw new ProcessEngineException("The new process definition " + "(key = '" + newProcessDefinition.getKey() + "') " + "does not contain the current activity " + "(id = '" + activityId + "') " + "of the process instance " + "(id = '" + processInstanceId + "').");
}
// clear cached activity so that outgoing transitions are refreshed
execution.setActivity(newActivity);
}
// switch the process instance to the new process definition version
execution.setProcessDefinition(newProcessDefinition);
// and change possible existing tasks (as the process definition id is stored there too)
List<TaskEntity> tasks = commandContext.getTaskManager().findTasksByExecutionId(execution.getId());
for (TaskEntity taskEntity : tasks) {
taskEntity.setProcessDefinitionId(newProcessDefinition.getId());
}
}
Aggregations