Author: swiderski.maciej
Date: 2010-08-29 04:38:15 -0400 (Sun, 29 Aug 2010)
New Revision: 6633
Added:
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/forkjoin/ForkWithConditionTest.java
Modified:
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ForkBinding.java
Log:
JBPM-2920: enables possibility to use conditional transitions on fork activity
Modified:
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ForkBinding.java
===================================================================
---
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ForkBinding.java 2010-08-28
03:20:20 UTC (rev 6632)
+++
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/ForkBinding.java 2010-08-29
08:38:15 UTC (rev 6633)
@@ -21,13 +21,20 @@
*/
package org.jbpm.jpdl.internal.activity;
+import java.util.List;
+
import org.jbpm.jpdl.internal.xml.JpdlParser;
+import org.jbpm.pvm.internal.model.ActivityImpl;
+import org.jbpm.pvm.internal.model.ExpressionCondition;
+import org.jbpm.pvm.internal.model.TransitionImpl;
+import org.jbpm.pvm.internal.util.XmlUtil;
import org.jbpm.pvm.internal.xml.Parse;
import org.w3c.dom.Element;
/**
* @author Tom Baeyens
+ * @author Maciej Swiderski
*/
public class ForkBinding extends JpdlBinding {
@@ -35,7 +42,30 @@
super("fork");
}
+ @SuppressWarnings("unchecked")
public Object parseJpdl(Element element, Parse parse, JpdlParser parser) {
+
+ List<Element> transitionElements = XmlUtil.elements(element,
"transition");
+ ActivityImpl activity = parse.contextStackFind(ActivityImpl.class);
+ List<TransitionImpl> transitions = (List<TransitionImpl>)
activity.getOutgoingTransitions();
+
+ for (int i=0; i<transitionElements.size(); i++) {
+ TransitionImpl transition = transitions.get(i);
+ Element transitionElement = transitionElements.get(i);
+
+ Element conditionElement = XmlUtil.element(transitionElement,
"condition");
+ if (conditionElement!=null) {
+
+ if (conditionElement.hasAttribute("expr")) {
+ ExpressionCondition expressionCondition = new ExpressionCondition();
+
expressionCondition.setExpression(conditionElement.getAttribute("expr"));
+ expressionCondition.setLanguage(XmlUtil.attribute(conditionElement,
"lang"));
+ transition.setCondition(expressionCondition);
+
+ }
+ }
+ }
+
return new ForkActivity();
}
Added:
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/forkjoin/ForkWithConditionTest.java
===================================================================
---
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/forkjoin/ForkWithConditionTest.java
(rev 0)
+++
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/forkjoin/ForkWithConditionTest.java 2010-08-29
08:38:15 UTC (rev 6633)
@@ -0,0 +1,114 @@
+package org.jbpm.test.activity.forkjoin;
+
+import java.util.Collections;
+
+import org.jbpm.api.ProcessInstance;
+import org.jbpm.api.history.HistoryProcessInstance;
+import org.jbpm.api.task.Task;
+import org.jbpm.test.JbpmTestCase;
+
+
+public class ForkWithConditionTest extends JbpmTestCase {
+
+ private static final String PROCESS = ""
+ + "<process name='ForkCondition'
xmlns='http://jbpm.org/4.4/jpdl'>"
+ + " <start g='179,17,32,29' name='start1'>"
+ + " <transition g='-43,-18' name='to fork1'
to='fork1'/>"
+ + " </start>"
+ + " <fork g='185,95,49,50' name='fork1' >"
+ + " <transition name='left' to='task1'
g='-44,-18'>"
+ + " <condition expr='#{test > 1}' />"
+ + " </transition>"
+ + " <transition name='right' to='task2'
g='-44,-18'>"
+ + " <condition expr='#{test > 2}' />"
+ + " </transition>"
+ + " <transition name='right' to='task3'
g='-44,-18'>"
+ + " <condition expr='#{test > 3}' />"
+ + " </transition>"
+ + " </fork>"
+ + " <task name='task1' g='90,177,73,44'
assignee='mike'>"
+ + " <transition name='to join1' to='join1'
g='-43,-18'/>"
+ + " </task>"
+ + " <task name='task2' g='90,177,73,44'
assignee='alex'>"
+ + " <transition name='to join1' to='join1'
g='-43,-18'/>"
+ + " </task>"
+ + " <task name='task3' g='90,177,73,44'
assignee='peter'>"
+ + " <transition name='to join1' to='join1'
g='-43,-18'/>"
+ + " </task>"
+ + " <join name='join1' g='192,511,57,44'
multiplicity='2'>"
+ + " <transition name='to Big car' to='Big car'
g='-42,-18'/>"
+ + " </join>"
+ + " <state name='Big car' > "
+ + " <transition name='to end1' to='end1'
g='-43,-18'/>"
+ + " </state> "
+ + " <end g='193,606,38,33' name='end1'/>"
+ + "</process>";
+
+ public void testForkConditionNotAllTrue() {
+ deployJpdlXmlString(PROCESS);
+
+ ProcessInstance processInstance =
executionService.startProcessInstanceByKey("ForkCondition",
Collections.singletonMap("test", 3));
+
+ assertTrue(processInstance.getExecutions().size() == 2);
+
+ Task taskAlex =
taskService.createTaskQuery().assignee("alex").uniqueResult();
+ assertNotNull(taskAlex);
+ assertEquals("task2", taskAlex.getActivityName());
+
+ taskService.completeTask(taskAlex.getId());
+
+ Task taskMike =
taskService.createTaskQuery().assignee("mike").uniqueResult();
+ assertNotNull(taskMike);
+ assertEquals("task1", taskMike.getActivityName());
+
+ taskService.completeTask(taskMike.getId());
+
+ processInstance = executionService.findProcessInstanceById(processInstance.getId());
+
+
+ executionService.signalExecutionById(processInstance.getId());
+
+
+ HistoryProcessInstance history = historyService
+ .createHistoryProcessInstanceQuery()
+ .processInstanceId(processInstance.getId())
+ .uniqueResult();
+
+ assertNotNull(history);
+ assertEquals(ProcessInstance.STATE_ENDED, history.getState());
+ assertEquals("end1", history.getEndActivityName());
+ }
+
+ public void testForkConditionAllTrue() {
+ deployJpdlXmlString(PROCESS);
+
+ ProcessInstance processInstance =
executionService.startProcessInstanceByKey("ForkCondition",
Collections.singletonMap("test", 4));
+
+ assertTrue(processInstance.getExecutions().size() == 3);
+
+ Task taskAlex =
taskService.createTaskQuery().assignee("alex").uniqueResult();
+ assertNotNull(taskAlex);
+ assertEquals("task2", taskAlex.getActivityName());
+
+ taskService.completeTask(taskAlex.getId());
+
+ Task taskMike =
taskService.createTaskQuery().assignee("mike").uniqueResult();
+ assertNotNull(taskMike);
+ assertEquals("task1", taskMike.getActivityName());
+
+ taskService.completeTask(taskMike.getId());
+
+ processInstance = executionService.findProcessInstanceById(processInstance.getId());
+ executionService.signalExecutionById(processInstance.getId());
+
+ HistoryProcessInstance history = historyService
+ .createHistoryProcessInstanceQuery()
+ .processInstanceId(processInstance.getId())
+ .uniqueResult();
+
+ assertNotNull(history);
+ assertEquals(ProcessInstance.STATE_ENDED, history.getState());
+ assertEquals("end1", history.getEndActivityName());
+ }
+
+}