Author: tom.baeyens(a)jboss.com
Date: 2009-05-16 11:38:55 -0400 (Sat, 16 May 2009)
New Revision: 4829
Modified:
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/EndActivity.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activities/SuperStateBasicsTest.java
Log:
JBPM-2026 added super state exit capabilities
Modified:
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/EndActivity.java
===================================================================
---
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/EndActivity.java 2009-05-16
10:33:13 UTC (rev 4828)
+++
jbpm4/trunk/modules/jpdl/src/main/java/org/jbpm/jpdl/internal/activity/EndActivity.java 2009-05-16
15:38:55 UTC (rev 4829)
@@ -21,8 +21,12 @@
*/
package org.jbpm.jpdl.internal.activity;
+import java.util.List;
+
import org.jbpm.api.activity.ActivityExecution;
+import org.jbpm.api.model.Activity;
import org.jbpm.api.model.OpenExecution;
+import org.jbpm.api.model.Transition;
/**
@@ -36,18 +40,32 @@
protected String state = null;
public void execute(ActivityExecution execution) {
- OpenExecution executionToEnd = null;
- if (endProcessInstance) {
- executionToEnd = execution.getProcessInstance();
+ Activity activity = execution.getActivity();
+ List<Transition> outgoingTransitions = activity.getOutgoingTransitions();
+
+ Activity parentActivity = activity.getParentActivity();
+ if ( (parentActivity!=null)
+ && ("super-state".equals(parentActivity.getType()))
+ && (outgoingTransitions!=null)
+ && (outgoingTransitions.size()==1)
+ ) {
+ Transition outgoingTransition = outgoingTransitions.get(0);
+ execution.take(outgoingTransition);
+
} else {
- executionToEnd = execution;
+ OpenExecution executionToEnd = null;
+ if (endProcessInstance) {
+ executionToEnd = execution.getProcessInstance();
+ } else {
+ executionToEnd = execution;
+ }
+
+ if (state==null) {
+ execution.end(executionToEnd);
+ } else {
+ execution.end(executionToEnd, state);
+ }
}
-
- if (state==null) {
- execution.end(executionToEnd);
- } else {
- execution.end(executionToEnd, state);
- }
}
public void setEndProcessInstance(boolean endProcessInstance) {
Modified:
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activities/SuperStateBasicsTest.java
===================================================================
---
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activities/SuperStateBasicsTest.java 2009-05-16
10:33:13 UTC (rev 4828)
+++
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activities/SuperStateBasicsTest.java 2009-05-16
15:38:55 UTC (rev 4829)
@@ -60,7 +60,7 @@
assertTrue(processInstance.isEnded());
}
- public void testSuperStateStartActivityWithoutIncomingTransitions() {
+ public void testSuperStateWithoutStartActivity() {
deployJpdlXmlString(
"<process name='Super'>" +
" <start>" +
@@ -84,19 +84,29 @@
assertTrue(processInstance.isEnded());
}
- public void testSuperStateDirectEntry() {
+ public void testSuperStateMultipleEntryStartActivities() {
deployJpdlXmlString(
"<process name='Super'>" +
" <start>" +
- " <transition to='direct' />" +
+ " <transition to='choose' />" +
" </start>" +
+ " <decision name='choose' expr='#{theWayToGo}'>"
+
+ " <transition name='left' to='left' />" +
+ " <transition name='right' to='right' />" +
+ " </decision>" +
" <super-state name='super'>" +
- " <start name='direct'>" +
+ " <start name='left'>" +
" <transition to='a' />" +
" </start>" +
+ " <start name='right'>" +
+ " <transition to='b' />" +
+ " </start>" +
" <state name='a'>" +
" <transition to='done' />" +
" </state>" +
+ " <state name='b'>" +
+ " <transition to='done' />" +
+ " </state>" +
" <end name='done' />" +
" <transition to='end' />" +
" </super-state>" +
@@ -104,36 +114,35 @@
"</process>"
);
- ProcessInstance processInstance =
executionService.startProcessInstanceByKey("Super");
+ Map<String, Object> variables = new HashMap<String, Object>();
+ variables.put("theWayToGo", "left");
+ ProcessInstance processInstance =
executionService.startProcessInstanceByKey("Super", variables);
assertEquals("a", processInstance.getActivityName());
processInstance = executionService.signalExecutionById(processInstance.getId());
assertTrue(processInstance.isEnded());
+
+ variables.put("theWayToGo", "right");
+ processInstance = executionService.startProcessInstanceByKey("Super",
variables);
+ assertEquals("b", processInstance.getActivityName());
+
+ processInstance = executionService.signalExecutionById(processInstance.getId());
+ assertTrue(processInstance.isEnded());
}
- public void testSuperStateMultipleEntries() {
+ public void testSuperStateDirectEntryTransition() {
deployJpdlXmlString(
"<process name='Super'>" +
" <start>" +
- " <transition to='choose' />" +
+ " <transition to='direct' />" +
" </start>" +
- " <decision name='choose' expr='#{theWayToGo}'>"
+
- " <transition name='left' to='left' />" +
- " <transition name='right' to='right' />" +
- " </decision>" +
" <super-state name='super'>" +
- " <start name='left'>" +
+ " <start name='direct'>" +
" <transition to='a' />" +
" </start>" +
- " <start name='right'>" +
- " <transition to='b' />" +
- " </start>" +
" <state name='a'>" +
" <transition to='done' />" +
" </state>" +
- " <state name='b'>" +
- " <transition to='done' />" +
- " </state>" +
" <end name='done' />" +
" <transition to='end' />" +
" </super-state>" +
@@ -141,19 +150,100 @@
"</process>"
);
- Map<String, Object> variables = new HashMap<String, Object>();
- variables.put("theWayToGo", "left");
- ProcessInstance processInstance =
executionService.startProcessInstanceByKey("Super", variables);
+ ProcessInstance processInstance =
executionService.startProcessInstanceByKey("Super");
assertEquals("a", processInstance.getActivityName());
processInstance = executionService.signalExecutionById(processInstance.getId());
assertTrue(processInstance.isEnded());
+ }
- variables.put("theWayToGo", "right");
- processInstance = executionService.startProcessInstanceByKey("Super",
variables);
- assertEquals("b", processInstance.getActivityName());
+ public void testSuperStateWithoutEndActivity() {
+ deployJpdlXmlString(
+ "<process name='Super'>" +
+ " <start>" +
+ " <transition to='super' />" +
+ " </start>" +
+ " <super-state name='super'>" +
+ " <start>" +
+ " <transition to='a' />" +
+ " </start>" +
+ " <state name='a' />" +
+ " <transition to='end' />" +
+ " </super-state>" +
+ " <end name='end' />" +
+ "</process>"
+ );
+
+ ProcessInstance processInstance =
executionService.startProcessInstanceByKey("Super");
+ assertEquals("a", processInstance.getActivityName());
processInstance = executionService.signalExecutionById(processInstance.getId());
assertTrue(processInstance.isEnded());
}
+
+ public void testSuperStateMultipleExitEndActivities() {
+ deployJpdlXmlString(
+ "<process name='Super'>" +
+ " <start>" +
+ " <transition to='super' />" +
+ " </start>" +
+ " <super-state name='super'>" +
+ " <start>" +
+ " <transition to='a' />" +
+ " </start>" +
+ " <state name='a'>" +
+ " <transition name='a' to='exitA' />" +
+ " <transition name='b' to='exitB' />" +
+ " </state>" +
+ " <end name='exitA'>" +
+ " <transition to='endA' />" +
+ " </end>" +
+ " <end name='exitB'>" +
+ " <transition to='endB' />" +
+ " </end>" +
+ " </super-state>" +
+ " <end name='endA' />" +
+ " <end name='endB' />" +
+ "</process>"
+ );
+
+ ProcessInstance processInstance =
executionService.startProcessInstanceByKey("Super");
+ assertEquals("a", processInstance.getActivityName());
+
+ processInstance = executionService.signalExecutionById(processInstance.getId(),
"a");
+ assertTrue(processInstance.isEnded());
+ assertEquals("endA", processInstance.getActivityName());
+
+ processInstance = executionService.startProcessInstanceByKey("Super");
+ assertEquals("a", processInstance.getActivityName());
+
+ processInstance = executionService.signalExecutionById(processInstance.getId(),
"b");
+ assertTrue(processInstance.isEnded());
+ assertEquals("endB", processInstance.getActivityName());
+ }
+
+ public void testSuperStateDirectExitTransition() {
+ deployJpdlXmlString(
+ "<process name='Super'>" +
+ " <start>" +
+ " <transition to='super' />" +
+ " </start>" +
+ " <super-state name='super'>" +
+ " <start>" +
+ " <transition to='a' />" +
+ " </start>" +
+ " <state name='a'>" +
+ " <transition to='end' />" +
+ " </state>" +
+ " </super-state>" +
+ " <end name='end' />" +
+ "</process>"
+ );
+
+ ProcessInstance processInstance =
executionService.startProcessInstanceByKey("Super");
+ assertEquals("a", processInstance.getActivityName());
+
+ processInstance = executionService.signalExecutionById(processInstance.getId());
+ assertTrue(processInstance.isEnded());
+ }
}
Show replies by date