-
1. Re: Assign multi-users to auto-created tasks?
kukeltje Apr 30, 2006 7:08 PM (in response to neelixx)you don't have to use an assingnmenthandler class. You can do it (afaik) in the action class for creating the tasks.
Did you try that and it didn't work? Did you get any errors? -
2. Re: Assign multi-users to auto-created tasks?
neelixx Apr 30, 2006 9:50 PM (in response to neelixx)No, I haven't tried it yet. I'm just now building the test case on how to do this.
After reading your last statement, I went back to the Javadoc and did find a way to assign an actor to the TaskInstance. Thanks!!!TaskMgmtInstance tmi = executionContext.getTaskMgmtInstance(); for (int i = 1; i<userList.size(); i++) { TaskInstance taskInstance = tmi.createTaskInstance(task, executionContext.getToken()); taskInstance.setActorId(userList.get(i)); }
Now, however, I'm running into the problem of removing the task assigned to the actor. Too bad there isn't a .getUnfinishedTasks(actorId). I guess I'll just have to iterate through all the unfinished tasks, and look at each assigned actorId, and remove that specific task.
Thanks Ronald! -
3. Re: Assign multi-users to auto-created tasks?
neelixx Apr 30, 2006 11:30 PM (in response to neelixx)Completed!! Below is the testCase that I created (modified from the workflowpattern#14.)
This test case shows the creation of tasks (from Wfp#14) based on the number of users that need to be assigned the task. The task node IS NOT complete, until everyone completes their own assigned tasks.
Thanks Ronald, for your feedback.public class Wfp14WithAssignment extends TestCase { public static class CreateTasks implements ActionHandler { private static final long serialVersionUID = 1L; public void execute(ExecutionContext executionContext) throws Exception { TaskMgmtDefinition tmd = (TaskMgmtDefinition) executionContext.getDefinition(TaskMgmtDefinition.class); Task task = tmd.getTask("watch movie amadeus"); // This creates the tasks, and assigns an actor to it TaskMgmtInstance tmi = executionContext.getTaskMgmtInstance(); for (int i = 0; i<userListing.size(); i++) { TaskInstance taskInstance = tmi.createTaskInstance(task, executionContext.getToken()); taskInstance.setActorId((String)userListing.get(i)); } } } public static ProcessDefinition processDefinition = ProcessDefinition.parseXmlString( "<process-definition>" + " <start-state name='a'>" + " <transition to='b' />" + " </start-state>" + " <state name='b'>" + " <transition to='t' />" + " </state>" + " <task-node name='t' create-tasks='false'>" + " <event type='node-enter'>" + " <action class='org.thepaxson5.jbpm.Wfp14WithAssignment$CreateTasks' />" + " </event>" + " <task name='watch movie amadeus' />" + " <transition to='c' />" + " </task-node>" + " <state name='c' />" + "</process-definition>" ); public static Node t = processDefinition.getNode("t"); public static Node c = processDefinition.getNode("c"); public static List userListing = new ArrayList(); public void testAprioriRuntimeKnowledgeScenario4() { // 3 Users have been assigned to this task. // All 3 users MUST complete their assignments before // processing can continue userListing.add("user1"); userListing.add("user2"); userListing.add("user3"); ProcessInstance processInstance = new ProcessInstance(processDefinition); Token token = processInstance.getRootToken(); processInstance.signal(); processInstance.signal(); assertSame(t, token.getNode()); //End the task for user1 endOneTask(token,"user1"); //Are we still on the node 't' assertSame(t, token.getNode()); //End the task for user2 endOneTask(token, "user2"); //Are we still on the node 't' assertSame(t, token.getNode()); //End the task for user3 endOneTask(token, "user3"); //We should now be on node 'c' assertSame(c, token.getNode()); } public static void endOneTask(Token token, String actorId) { TaskMgmtInstance tmi = (TaskMgmtInstance)token.getProcessInstance().getInstance(TaskMgmtInstance.class); Iterator allTasks = tmi.getUnfinishedTasks(token).iterator(); while (allTasks.hasNext()){ TaskInstance taskInstance = (TaskInstance)allTasks.next(); if (taskInstance.getActorId() == actorId) { taskInstance.end(); } } } }
-
4. Re: Assign multi-users to auto-created tasks?
kukeltje May 1, 2006 6:49 AM (in response to neelixx)Do you want to retrieve the unfinished tasks for this actor for this taskinstance, or *all* of his unfinished tasks? If it is the latter, just use the getTaskList(actorid) on the JbpmContext
Ronald -
5. Re: Assign multi-users to auto-created tasks?
neelixx May 1, 2006 3:36 PM (in response to neelixx)Only for this task instance. I needed a way to end the task which was autocreated for the actor, in this task node only.
That is why I modified the endOneTask(token, actorId).