3 Replies Latest reply on Jan 18, 2008 9:07 AM by Frank

    How to retrieve the Task list of a user ?

    Frank Newbie

      Hi all !
      I have developed a web application which should be a front-end for a Jbpm process.
      In the main Servlet I should list all Task pending for a user.
      Unfortunately the task list is empty, where do I am wrong ??

      This is the simple process:

      <process-definition
       xmlns="urn:jbpm.org:jpdl-3.2"
       name="simple">
       <swimlane name="user">
       </swimlane>
       <start-state name="start">
       <transition name="" to="state1"></transition>
       </start-state>
       <state name="state1">
       <transition name="" to="task1"></transition>
       </state>
       <task-node name="task1">
       <task name="task1" swimlane="user"></task>
       <transition name="" to="end1"></transition>
       </task-node>
      
       <end-state name="end1"></end-state>
      
      </process-definition>


      Inside the servlet I signal the process until it reaches the Task1.
      Then I expect to find one pending task for user "user". But the list is empty.

      JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
      
      JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
      
      ProcessDefinition processDefinition = ProcessDefinition.parseXmlResource("processDefinition.xml");
      
      jbpmContext.deployProcessDefinition(processDefinition);
      
      ProcessInstance instance = new ProcessInstance(processDefinition);
      
      
      // Move the process instance from its start state to the state1.
      instance.signal();
      
      System.out.println("You are in state: "+instance.getRootToken().getNode().getName());
      
      // Move to Task1
      instance.signal();
      
      Vector vec = new Vector();
      vec.add("user");
      
      List list = jbpmContext.getGroupTaskList(vec);
      
      if (list != null) {
       for (int ii=0;ii<list.size();ii++){
       System.out.println(list.get(ii));
       }
      }


      Unfortunaly the List is empty.
      What is missing ? Have I assigned uncorrectly the task to "user" ??
      or Should I istantiate the Actor class and inject the "user" as userId ?

      I'm using JBoss 4.0.2 and JBPM 3.2
      Thanks
      Francesco

        • 1. Re: How to retrieve the Task list of a user ?
          Ronald van Kuijk Master

          actor class is not needed. Please make a unit test that demonstrates the problem....

          • 2. Re: How to retrieve the Task list of a user ?
            David Roberts Apprentice

            In your process definition, you have:

            <swimlane name="user">
            </swimlane>
            


            You've defined a swimlane called "user", but you haven't assigned any users to that swimlane.

            Also, to get a list of tasks that can potentially be assigned to a user, I use a method like this:
            /**
             * Gets all task instances that a user with the given actor id could claim.
             * @return List of jbpm task instances.
             */
             public static List getUnClaimedTaskInstancesForActorId (JbpmContext jbpmContext, String actorId) {
             Session session = jbpmContext.getSession();
            
             //create list of possible id's (this includes groups) that
             //belong to the current user.
             List actorsList = new ArrayList();
             actorsList.add(actorId);
             IdentitySession identitySession = new IdentitySession(session);
             org.jbpm.identity.User jbpmUser = identitySession.getUserByName(actorId);
             Iterator i = jbpmUser.getMemberships().iterator();
             while(i.hasNext()){
             Membership m = (Membership) i.next();
             actorsList.add(m.getGroup().getName());
             }
             List pooledTaskInstances = jbpmContext.getTaskMgmtSession().findPooledTaskInstances(actorsList);
             List jbpmTaskInstanceList = session.createQuery("from org.jbpm.taskmgmt.exe.TaskInstance ti where ti.start is null and ti.end is null and actorId = '"+actorId+"'").list();
             //add pooledTaskInstances to taskList
             jbpmTaskInstanceList.addAll(pooledTaskInstances);
            
             //TODO sort jbpmTaskInstanceList by task instance id
            
             return jbpmTaskInstanceList;
             }


            Hope this helps a bit. Good luck!

            • 3. Re: How to retrieve the Task list of a user ?
              Frank Newbie

              Thanks for your kind replies.
              At the moment I have solved the problem using an assignment handler which fires when the Task node is entered.
              Thanks for your hints.