Tasks Assigned to Groups Not Found
williajd Jul 13, 2011 9:30 AMHi,
I'm using JBPM 5.1 Final and have spent a couple of hours learning how tasks are returned from the TaskService. I believe I have found a bug in the way tasks are returned when they are not assigned to a particular user.
I have 2 simple processes that I'm using to test my code. I'm making sure I can create a process and then return the first tasks from them.
The first one SimpleHumanTaskProcess has a single task with the owner id set to "testUser". When I create the process I can use the TaskClient.getTasksOwned method to return the created tasks as expected. When I look in the database the tasks are there and have owner and creator set to "testUser".
The second process is called SimpleGroupTaskProcess and has a single Human Task that has groupId = "testGroup". The process is created properly and I am able to examine the database and noticed that the task owner and creator are not set. The potential owner DOES include the "testGroup" so I would expect it to be found. Howevewr it is not retrieved when using the TaskClient.getTasksAssignedAsPotentialOwner passing in the user "testUser" and group "testGroup".
After some digging I think I have found the problem. The key is that the creator and owner is not set on the task. I found the underlying named query called "TasksAssignedAsPotentialOwnerWithGroups" in the orm.xml file. The query was not taking into account the null creator and owner so was only returning the tasks belonging to the "testUser" but not the group assignment.
Old | New |
---|---|
select new org.jbpm.task.query.TaskSummary( t.id, t.taskData.processInstanceId, name.text, subject.text, description.text, t.taskData.status, t.priority, t.taskData.skipable, t.taskData.actualOwner, t.taskData.createdBy, t.taskData.createdOn, t.taskData.activationTime, t.taskData.expirationTime) from Task t left join t.taskData.createdBy left join t.taskData.actualOwner left join t.subjects as subject left join t.descriptions as description left join t.names as name, OrganizationalEntity potentialOwners where ( potentialOwners.id = :userId or potentialOwners.id in (:groupIds) ) and potentialOwners in elements ( t.peopleAssignments.potentialOwners ) and ( name.language = :language or t.names.size = 0 ) and ( subject.language = :language or t.subjects.size = 0 ) and ( description.language = :language or t.descriptions.size = 0 ) and t.taskData.status in ('Created', 'Ready', 'Reserved', 'InProgress', 'Suspended') and t.taskData.expirationTime is nul | select new org.jbpm.task.query.TaskSummary( t.id, t.taskData.processInstanceId, name.text, subject.text, description.text, t.taskData.status, t.priority, t.taskData.skipable, owner, creator, t.taskData.createdOn, t.taskData.activationTime, t.taskData.expirationTime) from Task t left join t.taskData.createdBy as creator left join t.taskData.actualOwner as owner left join t.subjects as subject left join t.descriptions as description left join t.names as name, OrganizationalEntity potentialOwners where ( potentialOwners.id = :userId or potentialOwners.id in (:groupIds) ) and potentialOwners in elements ( t.peopleAssignments.potentialOwners ) and ( name.language = :language or t.names.size = 0 ) and ( subject.language = :language or t.subjects.size = 0 ) and ( description.language = :language or t.descriptions.size = 0 ) and t.taskData.status in ('Created', 'Ready', 'Reserved', 'InProgress', 'Suspended') and t.taskData.expirationTime is null |
This appears to work.
I do have a couple of questions though. Should tasks be created in the database without having at least a creator id? Is this expected behaviour for tasks assigned to groups?
I have attached my processes, just in case there is something I've done wrong that someone can help me with.
Thanks
James
-
SimpleGroupTaskProcess.bpmn.zip 997 bytes
-
SimpleHumanTaskProcess.bpmn.zip 930 bytes