Author: kukeltje
Date: 2009-07-30 16:33:16 -0400 (Thu, 30 Jul 2009)
New Revision: 5401
Modified:
jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/BpmnActivity.java
jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ExclusiveGatewayActivity.java
jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ExclusiveGatewayBinding.java
jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/parser/BindingsParser.java
jbpm4/trunk/modules/bpmn/src/test/java/org/jbpm/bpmn/flownodes/ExclusiveGatewayTest.java
jbpm4/trunk/modules/bpmn/src/test/java/org/jbpm/bpmn/flownodes/UserTaskTest.java
jbpm4/trunk/modules/bpmn/src/test/resources/org/jbpm/bpmn/flownodes/exclusiveGateway.bpmn.xml
Log:
Made default sequenceflow working on exclusiveGateway
Modified:
jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/BpmnActivity.java
===================================================================
---
jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/BpmnActivity.java 2009-07-30
20:26:44 UTC (rev 5400)
+++
jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/BpmnActivity.java 2009-07-30
20:33:16 UTC (rev 5401)
@@ -43,7 +43,7 @@
public abstract class BpmnActivity implements ActivityBehaviour {
private static final Log log = Log.getLog(BindingsParser.class.getName());
-
+
private static final long serialVersionUID = 1L;
private static final boolean FORK_ALLOWED = true;
@@ -53,19 +53,19 @@
protected void leaveBpmnActivity(ExecutionImpl execution) {
- proceedForkedIfAllowed(execution, FORK_ALLOWED, CONDITIONS_CHECKED);
+ proceedForkedIfAllowed(execution, FORK_ALLOWED, CONDITIONS_CHECKED, null);
}
- protected void leaveBpmnActivitySingle(ExecutionImpl execution) {
+ protected void leaveBpmnActivitySingle(ExecutionImpl execution, String default_) {
- proceedForkedIfAllowed(execution, FORK_DISALLOWED, CONDITIONS_CHECKED);
+ proceedForkedIfAllowed(execution, FORK_DISALLOWED, CONDITIONS_CHECKED, default_);
}
-
+
protected void leaveBpmnActivityAll(ExecutionImpl execution) {
- proceedForkedIfAllowed(execution, FORK_ALLOWED, CONDITIONS_IGNORED);
+ proceedForkedIfAllowed(execution, FORK_ALLOWED, CONDITIONS_IGNORED, null);
}
@@ -74,28 +74,40 @@
*
* Code copied basically from jPDL fork.
*/
- private void proceedForkedIfAllowed(ExecutionImpl execution, boolean forkAllowed,
boolean checkConditions) {
+ private void proceedForkedIfAllowed(ExecutionImpl execution, boolean forkAllowed,
boolean checkConditions, String default_) {
Activity activity = execution.getActivity();
-
+
// evaluate the conditions and find the transitions that should be forked
List<Transition> forkingTransitions = new ArrayList<Transition>();
List<Transition> outgoingTransitions = activity.getOutgoingTransitions();
for (Transition transition : outgoingTransitions) {
Condition condition = transition.getCondition();
- if ((condition == null) || (!checkConditions) || (condition.evaluate(execution)) )
{
+ // also ignore the default transition of the exclusive gateway
+ if (((condition == null) || (!checkConditions) || (condition.evaluate(execution)))
&& (!transition.getName().equals(default_))) {
forkingTransitions.add(transition);
}
}
- log.debug(forkingTransitions.size() + " out of "+
outgoingTransitions.size() + " selected for " + activity.getName());
-
+ log.debug(forkingTransitions.size() + " out of " +
outgoingTransitions.size() + " selected for " + activity.getName());
+
// if no outgoing transitions should be forked,
if (forkingTransitions.size() == 0) {
- // end this execution
- execution.end();
- // if there is exactly 1 transition to be taken, just use the incoming
- // execution
- } else if (forkingTransitions.size() == 1) {
+ if (default_ != null) { // take the default if it is there
+ for (Transition transition : outgoingTransitions) {
+ if (default_.equals(transition.getName())) {
+ // take it
+ execution.take(transition);
+ }
+ }
+ } else {
+ // end this execution
+ execution.end();
+ }
+ }
+
+ // if there is exactly 1 transition to be taken, just use the incoming
+ // execution
+ else if (forkingTransitions.size() == 1) {
execution.take(forkingTransitions.get(0));
// if there are more transitions
Modified:
jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ExclusiveGatewayActivity.java
===================================================================
---
jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ExclusiveGatewayActivity.java 2009-07-30
20:26:44 UTC (rev 5400)
+++
jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ExclusiveGatewayActivity.java 2009-07-30
20:33:16 UTC (rev 5401)
@@ -37,7 +37,7 @@
public class ExclusiveGatewayActivity extends BpmnActivity {
String gatewayDirection = "unspecified"; // is the default behaviour
- String default_ = null;
+ String default_;
private static final long serialVersionUID = 1L;
@@ -46,7 +46,7 @@
}
public void execute(ExecutionImpl execution) {
- leaveBpmnActivitySingle(execution);
+ leaveBpmnActivitySingle(execution, default_);
}
public String getGatewayDirection() {
Modified:
jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ExclusiveGatewayBinding.java
===================================================================
---
jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ExclusiveGatewayBinding.java 2009-07-30
20:26:44 UTC (rev 5400)
+++
jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/flownodes/ExclusiveGatewayBinding.java 2009-07-30
20:33:16 UTC (rev 5401)
@@ -43,12 +43,12 @@
public Object parse(Element element, Parse parse, Parser parser) {
super.parse(element);
-
+
String default_ = null;
- if (element.hasAttribute("default")) {
+ if (element.hasAttribute("default")) {
default_ = element.getAttribute("default");
}
-
+
boolean defaultExists = false;
List<Element> transitionElements = XmlUtil.elements((Element)
element.getParentNode(), "sequenceFlow");
@@ -63,15 +63,16 @@
if (elementId.equals(sourceRef)) {
outgoing++;
ce = XmlUtil.element(transitionElement, "conditionExpression");
-
- //TODO: Warn or error if CE is not of type tFormalExpression?
-
+
+ // TODO: Warn or error if CE is not of type tFormalExpression?
+
if (transitionElement.getAttribute("id").equals(default_)) {
defaultExists = true;
if (ce != null) {
// conditionExpression on the default sequenceflow SHALL be ignored
// according to the spec
- log.debug("Default sequenceFlow for " + elementName + " has
conditionExpressio(s). Ignoring them by removing them from the Document model");
+ log.debug("Default sequenceFlow (" + default_ + ") for
'" + elementName
+ + "' has conditionExpressio(s). Ignoring them by removing
them from the Document model");
transitionElement.removeChild(ce);
}
} else if (default_ != null && ce == null) {
@@ -88,8 +89,7 @@
valid = valid == false ? false : validGatewayDirection;
if (default_ != null && !defaultExists) {
- parse.addProblem("exclusiveGateway '" + elementName + "'
default sequenceFlow '" + default_
- + "' does not exist or is not related to this node",
element);
+ parse.addProblem("exclusiveGateway '" + elementName + "'
default sequenceFlow '" + default_ + "' does not exist or is not related
to this node", element);
valid = false;
}
Modified: jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/parser/BindingsParser.java
===================================================================
---
jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/parser/BindingsParser.java 2009-07-30
20:26:44 UTC (rev 5400)
+++
jbpm4/trunk/modules/bpmn/src/main/java/org/jbpm/bpmn/parser/BindingsParser.java 2009-07-30
20:33:16 UTC (rev 5401)
@@ -39,30 +39,30 @@
public class BindingsParser extends Parser {
private static final Log log = Log.getLog(BindingsParser.class.getName());
-
+
public Object parseDocumentElement(Element documentElement, Parse parse) {
List<Binding> bindings = new ArrayList<Binding>();
parse.setDocumentObject(bindings);
-
+
for (Element bindingElement : XmlUtil.elements(documentElement)) {
Binding binding = instantiateBinding(bindingElement, parse);
bindings.add(binding);
}
-
+
return bindings;
}
protected Binding instantiateBinding(Element bindingElement, Parse parse) {
String bindingClassName = XmlUtil.attribute(bindingElement, "binding",
true, parse);
-
- log.trace("adding bpmn binding "+bindingClassName);
-
- if (bindingClassName!=null) {
+
+ log.trace("adding bpmn binding " + bindingClassName);
+
+ if (bindingClassName != null) {
try {
- Class<?> bindingClass = ReflectUtil.loadClass(classLoader,
bindingClassName);
+ Class< ? > bindingClass = ReflectUtil.loadClass(classLoader,
bindingClassName);
return (Binding) bindingClass.newInstance();
} catch (Exception e) {
- parse.addProblem("couldn't instantiate activity binding
"+bindingClassName, e);
+ parse.addProblem("couldn't instantiate activity binding " +
bindingClassName, e);
}
}
return null;
Modified:
jbpm4/trunk/modules/bpmn/src/test/java/org/jbpm/bpmn/flownodes/ExclusiveGatewayTest.java
===================================================================
---
jbpm4/trunk/modules/bpmn/src/test/java/org/jbpm/bpmn/flownodes/ExclusiveGatewayTest.java 2009-07-30
20:26:44 UTC (rev 5400)
+++
jbpm4/trunk/modules/bpmn/src/test/java/org/jbpm/bpmn/flownodes/ExclusiveGatewayTest.java 2009-07-30
20:33:16 UTC (rev 5401)
@@ -56,7 +56,7 @@
}
}
- public void testNormalExecute() {
+ public void testNormalExecuteDecisionCondition() {
String deploymentId =
repositoryService.createDeployment().addResourceFromClasspath("org/jbpm/bpmn/flownodes/exclusiveGateway.bpmn.xml").deploy();
@@ -66,26 +66,48 @@
variables.put("test", "value");
ProcessInstance pi =
executionService.startProcessInstanceByKey("ExclusiveGateway", variables );
-
String pid = pi.getId();
-
TaskQuery taskQuery = taskService.createTaskQuery();
List<Task> allTasks = taskQuery.list();
- // since the uncontrolled sequence flow OUT of the activity behaves as a fork
- // we now have two tasks
assertEquals(1, allTasks.size());
assertEquals("doSomething", allTasks.get(0).getActivityName());
- //assertEquals("doSomethingElse", allTasks.get(1).getActivityName());
- // specifying a transition is unnecessary, BPMN has outgoing AND semantic!
- // TODO: fix
- // Currently not passing any 'outcome'
taskService.completeTask( allTasks.get(0).getId());
+
+ // process instance should be ended
+ pi = executionService.findProcessInstanceById(pid);
+ assertNull(pi);
+ }
+ finally {
+ repositoryService.deleteDeploymentCascade(deploymentId);
+ }
+ }
+
+ public void testNormalExecuteDefault() {
+
+ String deploymentId =
repositoryService.createDeployment().addResourceFromClasspath("org/jbpm/bpmn/flownodes/exclusiveGateway.bpmn.xml").deploy();
+
+ try {
+ Map variables = new HashMap();
+
+ variables.put("test", "other value");
+
+ ProcessInstance pi =
executionService.startProcessInstanceByKey("ExclusiveGateway", variables );
+ String pid = pi.getId();
+
+ TaskQuery taskQuery = taskService.createTaskQuery();
+ List<Task> allTasks = taskQuery.list();
+
+ assertEquals(1, allTasks.size());
+ assertEquals("doSomethingElse", allTasks.get(0).getActivityName());
+
+ taskService.completeTask( allTasks.get(0).getId());
+
+ // process instance should be ended
pi = executionService.findProcessInstanceById(pid);
- // process instance should be ended
assertNull(pi);
}
@@ -94,6 +116,7 @@
}
}
+
public void testNonBoundDefault() {
List<Problem> problems =
parse("org/jbpm/bpmn/flownodes/exclusiveGatewayNonBoundDefault.bpmn.xml");
Modified:
jbpm4/trunk/modules/bpmn/src/test/java/org/jbpm/bpmn/flownodes/UserTaskTest.java
===================================================================
---
jbpm4/trunk/modules/bpmn/src/test/java/org/jbpm/bpmn/flownodes/UserTaskTest.java 2009-07-30
20:26:44 UTC (rev 5400)
+++
jbpm4/trunk/modules/bpmn/src/test/java/org/jbpm/bpmn/flownodes/UserTaskTest.java 2009-07-30
20:33:16 UTC (rev 5401)
@@ -82,7 +82,9 @@
// process instance is ended
pi = executionService.findProcessInstanceById(pi.getId());
- assertEquals(true, pi.isEnded());
+ // One way or another I would also expect this to work... pi is gone from database
immediately when ended. Only in History DB
+ //assertEquals(true, pi.isEnded());
+ assertNull(pi);
}
finally {
repositoryService.deleteDeploymentCascade(deploymentId);
Modified:
jbpm4/trunk/modules/bpmn/src/test/resources/org/jbpm/bpmn/flownodes/exclusiveGateway.bpmn.xml
===================================================================
---
jbpm4/trunk/modules/bpmn/src/test/resources/org/jbpm/bpmn/flownodes/exclusiveGateway.bpmn.xml 2009-07-30
20:26:44 UTC (rev 5400)
+++
jbpm4/trunk/modules/bpmn/src/test/resources/org/jbpm/bpmn/flownodes/exclusiveGateway.bpmn.xml 2009-07-30
20:33:16 UTC (rev 5401)
@@ -13,7 +13,7 @@
targetRef="exclusiveGatewayDecision"
name="Start->exclusiveGateway" />
<bpmn:exclusiveGateway id="exclusiveGatewayDecision"
- name="Just a gateway" />
+ name="Just a gateway" default="flow3"/>
<!-- Sequence Flow -->
@@ -23,7 +23,6 @@
</bpmn:sequenceFlow>
<bpmn:sequenceFlow id="flow3"
sourceRef="exclusiveGatewayDecision"
targetRef="doSomethingElse">
- <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">${test ==
'other'}</bpmn:conditionExpression>
</bpmn:sequenceFlow>
<bpmn:userTask id="doSomething" name="Anything at all"