[jboss-user] [JBoss jBPM] - Re: Assign viewers to a task
simonbaker
do-not-reply at jboss.com
Mon Nov 19 15:10:41 EST 2007
We are implementing something similar, and our "super manager" generally has the power to reassign the task or perform the task directly.
I'm not an expert on jBPM, but this is my understanding. The code snippets are not tested, so I apologize for any errors and typos :
Assigning an actor to a task does not mean that actor has to "perform" the task. It just means that when you retrieve the tasks for that actor, only the tasks that that actor has been assigned to will be in the list. Thats about all it means to assign an actor to a task.
Assuming you are familiar with getting a JbpmContext object at the start of any code involving Jbpm objects, e.g.
| JbpmContext myJbpmContext = JbpmConfiguration.getInstance().createJbpmContext(),
|
one way to get the task list for an actor is with the method:
| List myTaskList = myJpbmContext.getTaskList(String actorId)
|
(note: List contains a list of TaskInstance objects -- the method should be called "getTaskInstanceList()...)
Performing the task is just a matter of calling one of the "end" methods of a TaskInstances object, e.g.:
| TaskInstance myTaskInstance = (TaskInstance) myTaskList.get(0);
| TaskInstance.end(..)
|
So if you can retrieve a handle to a taskinstance by any means, you can "perform" the task regardless of who you are.
Now, the "super manager" wants to see everyone's tasks, not just for his own. If you have deployed only one workflow (ProcessDefinition) one way to do that, is get all TaskInstances for all ProcessInstances of that ProcessDefinition:
| ProcessDefinition myprocdef = JbpmContext.getGraphSession().findLatestProcessDefinition(String name);
|
| List allProcessInstances = JbpmContext.getGraphSession().findProcessInstances(myprocdef.getId());
|
| ArrayList allTaskInstances = new ArrayList();
|
| for (int i = 0; i < allProcessInstances.size(); i++)
| {
| ProcessInstance myProcessInstance = (ProcessInstance) allProcessInstances.get(i);
|
| List myTaskInstances = myJbpmContext.getTaskMgmtSession().findTaskInstancesByProcessInstance(myProcessInstance.getId());
|
| allTaskInstances.addAll(allTaskInstances.size(), myTaskInstances);
| }
|
|
The "allTaskInstances" list is the basis for what we display to our "super manager". We create a simple web page listing the tasks (name, the process they belong to, who is assigned if anyone) and a hidden field with the task instance id, so we can do something to a task such as assign someone else to it, etc. The super manager can select a task and post the web page with a command button such as "Perform Task", and our code fetches the task by id and calls the "end()" method, for example.
"Pooled tasks" are just tasks that have no actor assigned but do have a "pooled list" of actors assigned. Assignment is done using, e.g.:
| TaskInstance.setPooledActors(String[] actorIds)
|
Getting all "pooled tasks" is done by:
| List myTaskList = myJpbmContext.getTaskMgmtSession().findPooledTaskList(String actorId)
|
More general, is:
| List myTaskList = myJpbmContext.getGroupTaskList(List actorIds)
|
which I believe returns all tasks that have at least one actor in actorIds in its "pooled actor list" created by "TaskInstance.setPooledActors(..)".
The main point is that assigning actors does not mean much other than associating an actor with a task and does not restrict actions you can perform on tasks in your code.
Also note: the list of task instances returned on the above lists only includes tasks that are "blocking", i.e. waiting for a signal to proceed via a transition to the next node (I think). So completed tasks or tasks later in the process will not appear in the lists. More expert users can advise you better on many of these issues and I hope they do.
BTW, finding the methods to get these objects is not intuitive in my opinion and requires poking around a lot and looking at any examples you can find.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4106152#4106152
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4106152
More information about the jboss-user
mailing list