Author: tom.baeyens(a)jboss.com
Date: 2009-05-19 05:28:01 -0400 (Tue, 19 May 2009)
New Revision: 4842
Added:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/GetOutcomes.java
Modified:
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/TaskService.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/TaskServiceImpl.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/taskactivity/TaskOutcomesTest.java
Log:
JBPM-2220 added TaskService.getOutcomes(long taskDbid)
Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/TaskService.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/TaskService.java 2009-05-19
09:08:49 UTC (rev 4841)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/TaskService.java 2009-05-19
09:28:01 UTC (rev 4842)
@@ -170,5 +170,5 @@
/** the set of possible valid outcomes for this task.
* An empty set means that any value is possible. */
- // Set<String> getOutcomes(long taskDbid);
+ Set<String> getOutcomes(long taskDbid);
}
Added: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/GetOutcomes.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/GetOutcomes.java
(rev 0)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/GetOutcomes.java 2009-05-19
09:28:01 UTC (rev 4842)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jbpm.pvm.internal.cmd;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.jbpm.api.JbpmException;
+import org.jbpm.api.cmd.Command;
+import org.jbpm.api.env.Environment;
+import org.jbpm.api.model.Transition;
+import org.jbpm.api.session.PvmDbSession;
+import org.jbpm.api.task.Task;
+import org.jbpm.pvm.internal.model.ActivityImpl;
+import org.jbpm.pvm.internal.model.ExecutionImpl;
+import org.jbpm.pvm.internal.task.TaskImpl;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class GetOutcomes implements Command<Set<String>> {
+
+ private static final long serialVersionUID = 1L;
+
+ protected long taskDbid;
+
+ public GetOutcomes(long taskDbid) {
+ this.taskDbid = taskDbid;
+ }
+
+ public Set<String> execute(Environment environment) {
+ PvmDbSession pvmDbSession = environment.get(PvmDbSession.class);
+ TaskImpl task = pvmDbSession.get(TaskImpl.class, taskDbid);
+ if (task==null) {
+ throw new JbpmException("task "+taskDbid+" doesn't
exist");
+ }
+
+ Set<String> outcomes = new HashSet<String>();
+ outcomes.add(Task.STATE_COMPLETED);
+
+ ExecutionImpl execution = (task!=null ? task.getExecution() : null);
+ ActivityImpl activity = (execution!=null ? execution.getActivity() : null);
+ List<Transition> outgoingTransitions = (activity!=null ?
activity.getOutgoingTransitions() : null);
+
+ if (outgoingTransitions!=null) {
+ for (Transition transition: outgoingTransitions) {
+ outcomes.add(transition.getName());
+ }
+ }
+
+ return outcomes;
+ }
+}
Property changes on:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/cmd/GetOutcomes.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/TaskServiceImpl.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/TaskServiceImpl.java 2009-05-19
09:08:49 UTC (rev 4841)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/TaskServiceImpl.java 2009-05-19
09:28:01 UTC (rev 4842)
@@ -167,4 +167,8 @@
cmd.setVariables(variables);
commandService.execute(cmd);
}
+
+ public Set<String> getOutcomes(long taskDbid) {
+ return commandService.execute(new GetOutcomes(taskDbid));
+ }
}
Modified:
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/taskactivity/TaskOutcomesTest.java
===================================================================
---
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/taskactivity/TaskOutcomesTest.java 2009-05-19
09:08:49 UTC (rev 4841)
+++
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/taskactivity/TaskOutcomesTest.java 2009-05-19
09:28:01 UTC (rev 4842)
@@ -21,7 +21,9 @@
*/
package org.jbpm.test.taskactivity;
-import org.jbpm.api.Execution;
+import java.util.HashSet;
+import java.util.Set;
+
import org.jbpm.api.ProcessInstance;
import org.jbpm.api.task.Task;
import org.jbpm.test.JbpmTestCase;
@@ -147,4 +149,126 @@
assertTrue(processInstance.isSuspended());
}
+
+ public void testGetOutcomesNoTransition() {
+ deployJpdlXmlString(
+ "<process name='UnmatchingOutcome'>" +
+ " <start>" +
+ " <transition to='review' />" +
+ " </start>" +
+ " <task name='review' " +
+ " assignee='johndoe'>" +
+ " </task>" +
+ " <state name='wait'/>" +
+ "</process>"
+ );
+
+ ProcessInstance processInstance =
executionService.startProcessInstanceByKey("UnmatchingOutcome");
+
+ Task task = taskService
+ .createTaskQuery()
+ .assignee("johndoe")
+ .uniqueResult();
+
+ Set<String> outcomes = taskService.getOutcomes(task.getDbid());
+
+ Set<String> expectedOutcomes = new HashSet<String>();
+ expectedOutcomes.add(Task.STATE_COMPLETED);
+
+ assertEquals(expectedOutcomes, outcomes);
+ }
+
+ public void testGetOutcomesSingleUnnamedTransition() {
+ deployJpdlXmlString(
+ "<process name='UnmatchingOutcome'>" +
+ " <start>" +
+ " <transition to='review' />" +
+ " </start>" +
+ " <task name='review' " +
+ " assignee='johndoe'>" +
+ " <transition to='wait' />" +
+ " </task>" +
+ " <state name='wait'/>" +
+ "</process>"
+ );
+
+ ProcessInstance processInstance =
executionService.startProcessInstanceByKey("UnmatchingOutcome");
+
+ Task task = taskService
+ .createTaskQuery()
+ .assignee("johndoe")
+ .uniqueResult();
+
+ Set<String> outcomes = taskService.getOutcomes(task.getDbid());
+
+ Set<String> expectedOutcomes = new HashSet<String>();
+ expectedOutcomes.add(Task.STATE_COMPLETED);
+ expectedOutcomes.add(null);
+
+ assertEquals(expectedOutcomes, outcomes);
+ }
+
+ public void testGetOutcomesSingleNamedTransition() {
+ deployJpdlXmlString(
+ "<process name='UnmatchingOutcome'>" +
+ " <start>" +
+ " <transition to='review' />" +
+ " </start>" +
+ " <task name='review' " +
+ " assignee='johndoe'>" +
+ " <transition name='toedeloe' to='wait' />" +
+ " </task>" +
+ " <state name='wait'/>" +
+ "</process>"
+ );
+
+ ProcessInstance processInstance =
executionService.startProcessInstanceByKey("UnmatchingOutcome");
+
+ Task task = taskService
+ .createTaskQuery()
+ .assignee("johndoe")
+ .uniqueResult();
+
+ Set<String> outcomes = taskService.getOutcomes(task.getDbid());
+
+ Set<String> expectedOutcomes = new HashSet<String>();
+ expectedOutcomes.add(Task.STATE_COMPLETED);
+ expectedOutcomes.add("toedeloe");
+
+ assertEquals(expectedOutcomes, outcomes);
+ }
+
+ public void testGetOutcomesMultipleTransitions() {
+ deployJpdlXmlString(
+ "<process name='UnmatchingOutcome'>" +
+ " <start>" +
+ " <transition to='review' />" +
+ " </start>" +
+ " <task name='review' " +
+ " assignee='johndoe'>" +
+ " <transition name='left' to='wait' />" +
+ " <transition name='right' to='wait' />" +
+ " <transition name='middle' to='wait' />" +
+ " </task>" +
+ " <state name='wait'/>" +
+ "</process>"
+ );
+
+ ProcessInstance processInstance =
executionService.startProcessInstanceByKey("UnmatchingOutcome");
+
+ Task task = taskService
+ .createTaskQuery()
+ .assignee("johndoe")
+ .uniqueResult();
+
+ Set<String> outcomes = taskService.getOutcomes(task.getDbid());
+
+ Set<String> expectedOutcomes = new HashSet<String>();
+ expectedOutcomes.add(Task.STATE_COMPLETED);
+ expectedOutcomes.add("left");
+ expectedOutcomes.add("right");
+ expectedOutcomes.add("middle");
+
+ assertEquals(expectedOutcomes, outcomes);
+ }
}