5 Replies Latest reply on May 1, 2006 3:36 PM by neelixx

    Assign multi-users to auto-created tasks?

    neelixx

      I've built an action (node-enter) to create a certain amount of tasks based on the users selected. This is not known at design-time, but it is known at run-time.

      <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.Wfp15WithAssignment$CreateTasks' />" +
       " <assignment class='org.thepaxson5.jbpm.Wfp15WithAssignment$TestAssignmentHandler'/>" +
       " </event>" +
       " <task name='watch movie amadeus' />" +
       " <transition to='c' />" +
       " </task-node>" +
       " <state name='c' />" +
       "</process-definition>"
      


      I'm having a very difficult time with assigning the actors to a specific auto-created task, and then, removing their own task when completed.

      The test case is great when you only care about "the number" of tasks to add/remove. And normally, that would be fine for me, if I didn't want to include this in their "task-lists". However, I need each "actor" to be assigned to each auto-created task.

      Since I can only assign the users from my AssignmentHandler class, I lose the ability to send, as a parameter, the number of tasks I'm creating, and therefore, I don't know how to assign individuals to a created task.

      I first thought this would be easy, as I figured I would just include the setActorId() in my FOR loop creating the tasks. Little did I know, that I have to implement an interface to assign the tasks.

      Any ideas?
      ~~ Aaron

        • 1. Re: Assign multi-users to auto-created tasks?
          kukeltje

          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

            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

              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

                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

                  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).