[jbpm-commits] JBoss JBPM SVN: r5032 - in jbpm4/trunk/modules: pvm/src/main/java/org/jbpm/pvm/internal/task and 1 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Fri Jun 12 09:18:58 EDT 2009
Author: tom.baeyens at jboss.com
Date: 2009-06-12 09:18:58 -0400 (Fri, 12 Jun 2009)
New Revision: 5032
Added:
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/TaskQueryProcessTest.java
Modified:
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/TaskQuery.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/task/TaskQueryImpl.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/TaskQueryTest.java
Log:
JBPM-2305 adding task query capabilities
Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/TaskQuery.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/TaskQuery.java 2009-06-12 09:52:01 UTC (rev 5031)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/TaskQuery.java 2009-06-12 13:18:58 UTC (rev 5032)
@@ -51,8 +51,21 @@
* to the task or the user could be a member of a group that is
* associated as a candidate group to the task. */
TaskQuery candidate(String userId);
+
+ /** only query for tasks that are associated to the given process instance */
+ TaskQuery processInstanceId(String processInstanceId);
+ /** only query for tasks that are associated to the given process definition */
+ TaskQuery processDefinitionId(String processDefinitionId);
+
+ /** only query for tasks that are associated to the given activity name. This
+ * can be used in combination with the {@link #processDefinitionId(String)} */
+ TaskQuery activityName(String activityName);
+
+ /** only query for suspended tasks */
TaskQuery suspended();
+
+ /** exclude suspended tasks */
TaskQuery notSuspended();
TaskQuery page(int firstResult, int maxResults);
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/task/TaskQueryImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/task/TaskQueryImpl.java 2009-06-12 09:52:01 UTC (rev 5031)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/task/TaskQueryImpl.java 2009-06-12 13:18:58 UTC (rev 5032)
@@ -50,6 +50,9 @@
protected String assignee = null;
protected String candidate = null;
protected Boolean suspended = null;
+ protected String processInstanceId = null;
+ protected String processDefinitionId = null;
+ protected String activityName = null;
/* groupIds transports the groupIds from the hql to the applyParameters */
protected List<String> groupIds;
@@ -68,6 +71,21 @@
return this;
}
+ public TaskQuery processInstanceId(String processInstanceId) {
+ this.processInstanceId = processInstanceId;
+ return this;
+ }
+
+ public TaskQuery processDefinitionId(String processDefinitionId) {
+ this.processDefinitionId = processDefinitionId;
+ return this;
+ }
+
+ public TaskQuery activityName(String activityName) {
+ this.activityName = activityName;
+ return this;
+ }
+
public TaskQuery unassigned() {
this.assignee = null;
this.unassigned = true;
@@ -154,9 +172,19 @@
appendWhereClause("task.state != '"+ExecutionImpl.STATE_SUSPENDED+"' ", hql);
}
}
+
+ if (processInstanceId!=null) {
+ appendWhereClause("task.processInstance.id = '"+processInstanceId+"' ", hql);
+ }
- appendWhereClause("task.state != '"+Task.STATE_SUSPENDED+"' ", hql);
+ if (activityName!=null) {
+ appendWhereClause("task.execution.activityName = '"+activityName+"' ", hql);
+ }
+ if (processDefinitionId!=null) {
+ appendWhereClause("task.processInstance.processDefinitionId = '"+processDefinitionId+"' ", hql);
+ }
+
if (assignee!=null) {
appendWhereClause("task.assignee = :assignee ", hql);
} else if (unassigned) {
Added: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/TaskQueryProcessTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/TaskQueryProcessTest.java (rev 0)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/TaskQueryProcessTest.java 2009-06-12 13:18:58 UTC (rev 5032)
@@ -0,0 +1,246 @@
+/*
+ * 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.test.task;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.jbpm.api.ProcessInstance;
+import org.jbpm.api.task.Task;
+import org.jbpm.test.JbpmTestCase;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class TaskQueryProcessTest extends JbpmTestCase {
+
+
+ public void testTaskQueryProcessInstanceId() {
+ deployJpdlXmlString(
+ "<process name='VacationTrip'>" +
+ " <start>" +
+ " <transition to='f' />" +
+ " </start>" +
+ " <fork name='f'>" +
+ " <transition to='select destination' />" +
+ " <transition to='work hard for the money' />" +
+ " </fork>" +
+ " <task name='select destination' " +
+ " assignee='johndoe'>" +
+ " <transition to='wait' />" +
+ " </task>" +
+ " <task name='work hard for the money' " +
+ " assignee='johndoe'>" +
+ " <transition to='wait' />" +
+ " </task>" +
+ " <state name='wait'/>" +
+ "</process>"
+ );
+
+ Map<String, Object> variables = new HashMap<String, Object>();
+ variables.put("destination", "Bruges");
+ executionService.startProcessInstanceByKey("VacationTrip", variables);
+
+ variables = new HashMap<String, Object>();
+ variables.put("destination", "Paris");
+ ProcessInstance parisProcessInstance = executionService.startProcessInstanceByKey("VacationTrip", variables);
+
+ variables = new HashMap<String, Object>();
+ variables.put("destination", "Malaga");
+ executionService.startProcessInstanceByKey("VacationTrip", variables);
+
+
+ deployJpdlXmlString(
+ "<process name='BusinessTrip'>" +
+ " <start>" +
+ " <transition to='try to get someone else to do it' />" +
+ " </start>" +
+ " <task name='try to get someone else to do it' " +
+ " assignee='johndoe'>" +
+ " <transition to='wait' />" +
+ " </task>" +
+ " <state name='wait'/>" +
+ "</process>"
+ );
+
+ executionService.startProcessInstanceByKey("BusinessTrip");
+ executionService.startProcessInstanceByKey("BusinessTrip");
+
+
+ List<Task> parisTasks = taskService
+ .createTaskQuery()
+ .processInstanceId(parisProcessInstance.getId())
+ .list();
+
+ assertEquals("expected 2 elements, but was "+parisTasks.toString(), 2, parisTasks.size());
+
+ Set<String> expectedTaskNames = new HashSet<String>();
+ expectedTaskNames.add("select destination");
+ expectedTaskNames.add("work hard for the money");
+
+ Set<String> taskNames = new HashSet<String>();
+ for (Task task: parisTasks) {
+ taskNames.add(task.getName());
+ assertEquals("Paris", taskService.getVariable(task.getDbid(), "destination"));
+ }
+
+ assertEquals(expectedTaskNames, taskNames);
+ }
+
+ public void testTaskQueryProcessDefinitionId() {
+ deployJpdlXmlString(
+ "<process name='VacationTrip'>" +
+ " <start>" +
+ " <transition to='select destination' />" +
+ " </start>" +
+ " <task name='select destination' " +
+ " assignee='johndoe'>" +
+ " <transition to='work hard for the money' />" +
+ " </task>" +
+ " <task name='work hard for the money' " +
+ " assignee='johndoe'>" +
+ " <transition to='wait' />" +
+ " </task>" +
+ " <state name='wait'/>" +
+ "</process>"
+ );
+
+ // we bring one process instance in task book travel
+ executionService.startProcessInstanceByKey("VacationTrip").getId();
+ taskService.completeTask(taskService.findPersonalTasks("johndoe").get(0).getDbid());
+
+ // and twto process instances in task select destination
+ executionService.startProcessInstanceByKey("VacationTrip");
+ executionService.startProcessInstanceByKey("VacationTrip");
+
+
+ deployJpdlXmlString(
+ "<process name='BusinessTrip'>" +
+ " <start>" +
+ " <transition to='find customer' />" +
+ " </start>" +
+ " <task name='find customer' " +
+ " assignee='johndoe'>" +
+ " <transition to='wait' />" +
+ " </task>" +
+ " <state name='wait'/>" +
+ "</process>"
+ );
+
+ executionService.startProcessInstanceByKey("BusinessTrip");
+ executionService.startProcessInstanceByKey("BusinessTrip");
+
+ List<Task> tasks = taskService
+ .createTaskQuery()
+ .processDefinitionId("VacationTrip-1")
+ .list();
+
+ assertEquals("expected 3 elements, but was "+tasks.toString(), 3, tasks.size());
+
+ int selectDestinationTasks = 0;
+ int workHardForTheMoneyTasks = 0;
+
+ for (Task task: tasks) {
+ if (task.getName().equals("select destination")) {
+ selectDestinationTasks++;
+ }
+ if (task.getName().equals("work hard for the money")) {
+ workHardForTheMoneyTasks++;
+ }
+ }
+
+ assertEquals(2, selectDestinationTasks);
+ assertEquals(1, workHardForTheMoneyTasks);
+ }
+
+ public void testTaskQueryActivityName() {
+ deployJpdlXmlString(
+ "<process name='VacationTrip'>" +
+ " <start>" +
+ " <transition to='select destination' />" +
+ " </start>" +
+ " <task name='select destination' " +
+ " assignee='johndoe'>" +
+ " <transition to='work hard for the money' />" +
+ " </task>" +
+ " <task name='work hard for the money' " +
+ " assignee='johndoe'>" +
+ " <transition to='wait' />" +
+ " </task>" +
+ " <state name='wait'/>" +
+ "</process>"
+ );
+
+ // we bring one process instance in task book travel
+ executionService.startProcessInstanceByKey("VacationTrip").getId();
+ taskService.completeTask(taskService.findPersonalTasks("johndoe").get(0).getDbid());
+
+ // and twto process instances in task select destination
+ executionService.startProcessInstanceByKey("VacationTrip");
+ executionService.startProcessInstanceByKey("VacationTrip");
+
+
+ deployJpdlXmlString(
+ "<process name='BusinessTrip'>" +
+ " <start>" +
+ " <transition to='find customer' />" +
+ " </start>" +
+ " <task name='find customer' " +
+ " assignee='johndoe'>" +
+ " <transition to='wait' />" +
+ " </task>" +
+ " <state name='wait'/>" +
+ "</process>"
+ );
+
+ executionService.startProcessInstanceByKey("BusinessTrip");
+ executionService.startProcessInstanceByKey("BusinessTrip");
+
+ List<Task> tasks = taskService
+ .createTaskQuery()
+ .processDefinitionId("VacationTrip-1")
+ .activityName("select destination")
+ .list();
+
+ assertEquals("expected 2 elements, but was "+tasks.toString(), 2, tasks.size());
+
+ int selectDestinationTasks = 0;
+ int workHardForTheMoneyTasks = 0;
+
+ for (Task task: tasks) {
+ if (task.getName().equals("select destination")) {
+ selectDestinationTasks++;
+ }
+ if (task.getName().equals("work hard for the money")) {
+ workHardForTheMoneyTasks++;
+ }
+ }
+
+ assertEquals(2, selectDestinationTasks);
+ assertEquals(0, workHardForTheMoneyTasks);
+ }
+
+}
Property changes on: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/TaskQueryProcessTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/TaskQueryTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/TaskQueryTest.java 2009-06-12 09:52:01 UTC (rev 5031)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/TaskQueryTest.java 2009-06-12 13:18:58 UTC (rev 5032)
@@ -117,5 +117,4 @@
taskService.deleteTask(dyperTaskDbid);
taskService.deleteTask(laudryTaskDbid);
}
-
}
More information about the jbpm-commits
mailing list