2 Replies Latest reply on Nov 19, 2007 7:53 PM by s b

    Assign viewers to a task

    Sander Nieuwenhuizen Newbie

      Hi there,

      I'm currently on a fork between either developing a workflow myself or using jBPM instead. The latter definitely sounds interesting, but I wonder if it's possible to link viewers to a task.

      A user is assigned a task. Say this user is a manager of a department and he wants to reassign this to one of his staff members (I think this is surely possible in jBPM?). Of course, the new assignee for the task is receiving a notification, just as the manager. But... is it possible to let the manager have a viewing role of this task? It might even be that certain people, like administrators, always need a notification and (r/w) access to a task from their task overview screen.

      Can this be achieved using jBPM?

        • 1. Re: Assign viewers to a task
          s b Newbie

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

          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.

          • 2. Re: Assign viewers to a task
            s b Newbie


            myJpbmContext.getTaskMgmtSession().findPooledTaskList(String actorId)

            should be
            myJpbmContext.getTaskMgmtSession().findPooledTaskInstances(String actorId)

            I think that's what I meant...

            There are still some hoops you have to jump through to get just the pooled task instances for all the process instances...