Author: rebody
Date: 2010-08-15 02:10:08 -0400 (Sun, 15 Aug 2010)
New Revision: 6594
Added:
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/TaskUnassignedCandidatesTest.java
Modified:
jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/bpmn/usertask/UserTaskTest.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/TaskQueryImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/TaskServiceImpl.java
Log:
JBPM-2773 allow query assigned candidates tasks
Modified:
jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/bpmn/usertask/UserTaskTest.java
===================================================================
---
jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/bpmn/usertask/UserTaskTest.java 2010-08-15
04:31:28 UTC (rev 6593)
+++
jbpm4/trunk/modules/examples/src/test/java/org/jbpm/examples/bpmn/usertask/UserTaskTest.java 2010-08-15
06:10:08 UTC (rev 6594)
@@ -35,35 +35,35 @@
* @author Joram Barrez
*/
public class UserTaskTest extends JbpmTestCase {
-
- private static String[] PROCESS_LOCATIONS =
+
+ private static String[] PROCESS_LOCATIONS =
{"org/jbpm/examples/bpmn/task/usertask/user_task_potential_owner_user.bpmn.xml",
"org/jbpm/examples/bpmn/task/usertask/user_task_potential_owner_group.bpmn.xml",
"org/jbpm/examples/bpmn/task/usertask/user_task_human_performer_user.bpmn.xml",
"org/jbpm/examples/bpmn/task/usertask/user_task_human_performer_variable.bpmn.xml"};
-
+
private static final String PETER = "peter";
private static final String MARY = "mary";
-
+
@Override
protected void setUp() throws Exception {
super.setUp();
-
+
for (String processLocation: PROCESS_LOCATIONS) {
NewDeployment deployment = repositoryService.createDeployment();
deployment.addResourceFromClasspath(processLocation);
- registerDeployment(deployment.deploy());
+ registerDeployment(deployment.deploy());
}
-
+
identityService.createGroup("management");
-
+
identityService.createUser(PETER, "Peter", "Pan");
identityService.createMembership(PETER, "management");
-
+
identityService.createUser(MARY, "Mary", "Littlelamb");
identityService.createMembership(MARY, "management");
}
-
+
@Override
protected void tearDown() throws Exception {
identityService.deleteGroup("management");
@@ -71,7 +71,7 @@
identityService.deleteUser(MARY);
super.tearDown();
}
-
+
public void testPotentialOwnerUser() {
ProcessInstance processInstance =
executionService.startProcessInstanceByKey("userTaskPotentialOwnerUser");
Task task = taskService.createTaskQuery().candidate(PETER).uniqueResult();
@@ -79,28 +79,28 @@
taskService.completeTask(task.getId());
assertProcessInstanceEnded(processInstance);
}
-
+
public void testPotentialOwnerGroup() {
ProcessInstance processInstance =
executionService.startProcessInstanceByKey("userTaskPotentialOwnerGroup");
-
+
// Peter and Mary are both part of management, so they both should see the task
List<Task> tasks = taskService.findGroupTasks(PETER);
assertEquals(1, tasks.size());
tasks = taskService.findGroupTasks(MARY);
assertEquals(1, tasks.size());
-
+
// Mary claims the task
Task task = tasks.get(0);
taskService.takeTask(task.getId(), MARY);
- assertNull(taskService.createTaskQuery().candidate(PETER).uniqueResult());
-
+
assertNull(taskService.createTaskQuery().candidate(PETER).unassigned().uniqueResult());
+
taskService.completeTask(task.getId());
assertProcessInstanceEnded(processInstance);
}
-
+
public void testHumanPerformerUser() {
ProcessInstance processInstance =
executionService.startProcessInstanceByKey("userTaskHumanPerformerUser");
- Task task = taskService.findPersonalTasks(MARY).get(0);
+ Task task = taskService.findPersonalTasks(MARY).get(0);
assertNotNull(task);
taskService.completeTask(task.getId());
assertProcessInstanceEnded(processInstance);
@@ -116,6 +116,6 @@
taskService.completeTask(task.getId());
assertProcessInstanceEnded(processInstance);
}
-
+
}
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/TaskQueryImpl.java
===================================================================
---
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/TaskQueryImpl.java 2010-08-15
04:31:28 UTC (rev 6593)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/TaskQueryImpl.java 2010-08-15
06:10:08 UTC (rev 6594)
@@ -73,7 +73,6 @@
public TaskQuery candidate(String userId) {
this.candidate = userId;
- unassigned();
return this;
}
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 2010-08-15
04:31:28 UTC (rev 6593)
+++
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/TaskServiceImpl.java 2010-08-15
06:10:08 UTC (rev 6594)
@@ -79,7 +79,7 @@
public void deleteTask(String taskId, String reason) {
commandService.execute(new DeleteTaskCmd(taskId, reason));
}
-
+
public void deleteTaskCascade(String taskId) {
commandService.execute(new DeleteTaskCmd(taskId, true));
}
@@ -87,7 +87,7 @@
public void completeTask(String taskId) {
commandService.execute(new CompleteTaskCmd(taskId));
}
-
+
public void completeTask(String taskId, Map<String, ?> variables) {
completeTask(taskId, null, variables);
}
@@ -95,7 +95,7 @@
public void completeTask(String taskId, String outcome) {
commandService.execute(new CompleteTaskCmd(taskId, outcome));
}
-
+
public void completeTask(String taskId, String outcome, Map<String, ?> variables)
{
SetTaskVariablesCmd setTaskVariablesCmd = new SetTaskVariablesCmd(taskId);
setTaskVariablesCmd.setVariables(variables);
@@ -129,14 +129,15 @@
public List<Task> findPersonalTasks(String userId) {
return createTaskQuery()
.assignee(userId)
- .orderDesc(TaskQuery.PROPERTY_PRIORITY)
+ .orderDesc(TaskQuery.PROPERTY_PRIORITY)
.list();
}
public List<Task> findGroupTasks(String userId) {
return createTaskQuery()
.candidate(userId)
- .orderDesc(TaskQuery.PROPERTY_PRIORITY)
+ .unassigned()
+ .orderDesc(TaskQuery.PROPERTY_PRIORITY)
.list();
}
Added:
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/TaskUnassignedCandidatesTest.java
===================================================================
---
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/TaskUnassignedCandidatesTest.java
(rev 0)
+++
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/task/TaskUnassignedCandidatesTest.java 2010-08-15
06:10:08 UTC (rev 6594)
@@ -0,0 +1,98 @@
+/*
+ * 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.List;
+
+import org.jbpm.api.ProcessInstance;
+import org.jbpm.api.task.Task;
+import org.jbpm.test.JbpmTestCase;
+
+/**
+ * @author Huisheng Xu
+ */
+public class TaskUnassignedCandidatesTest extends JbpmTestCase {
+
+ public static final String PROCESS_XML = "<process
name='TaskCandidates'>"
+ + " <start g='20,20,48,48'>"
+ + " <transition to='review' />"
+ + " </start>"
+ + " <task name='review'"
+ + " candidate-groups='sales-dept'"
+ + " g='96,16,127,52'>"
+ + " <transition to='wait' />"
+ + " </task>"
+ + " <state name='wait' g='255,16,88,52'/>"
+ + "</process>";
+
+ String deploymentId;
+ String dept;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ // create identities
+ dept = identityService.createGroup("sales-dept");
+
+ identityService.createUser("johndoe", "John",
"Doe");
+ identityService.createMembership("johndoe", dept,
"developer");
+
+ identityService.createUser("joesmoe", "Joe",
"Smoe");
+ identityService.createMembership("joesmoe", dept,
"developer");
+
+ // deploy process
+ deployJpdlXmlString(PROCESS_XML);
+ }
+
+ protected void tearDown() throws Exception {
+ // delete identities
+ identityService.deleteGroup(dept);
+ identityService.deleteUser("johndoe");
+ identityService.deleteUser("joesmoe");
+
+ super.tearDown();
+ }
+
+ public void testGroupCandidateAssignmentQueryAllCandidateTasks() {
+ executionService.startProcessInstanceByKey("TaskCandidates");
+
+ List<Task> taskList = taskService.findGroupTasks("johndoe");
+ Task task = taskList.get(0);
+ taskService.takeTask(task.getId(), "johndoe");
+
+ // should return assigned tasks as well, but doesn't
+ taskList = taskService.createTaskQuery().candidate("joesmoe").list();
+ assertContainsTask(taskList, "review");
+ }
+
+ public void testGroupCandidateAssignmentQueryUnassignedCandidateTasks() {
+ executionService.startProcessInstanceByKey("TaskCandidates");
+
+ List<Task> taskList = taskService.findGroupTasks("johndoe");
+ Task task = taskList.get(0);
+ taskService.takeTask(task.getId(), "johndoe");
+
+ // should return only unassigned candidate tasks (as before)
+ taskList =
taskService.createTaskQuery().candidate("joesmoe").unassigned().list();
+ assertEquals(0, taskList.size());
+ }
+}