0 Replies Latest reply on Feb 20, 2013 6:15 AM by gonzalad

    jBPM 5.4 : how to forward / reassign a task to a group ?

    gonzalad

      As mentioned in https://community.jboss.org/thread/221465, I need to reassign a task to a group.

       

      This isn't normally possible via taskService.forward as per the spec WS-Huma,Task 1.0 chapter 4.7.3 Delegating or Forwarding a Human Task :

       

      Forwarding is possible if the task has a set of individually assigned potential owners, not if its potential owners are assigned using one or many groups.

       

      Is there a good way to do it with jBPM ?

       

      For the moment, here's my working code, but it's kind of ugly :

       

       

      public void reassign(TaskSummary taskSummary, String username,
          String targetGroupname) {
      
        Task task = taskService.getTask(taskSummary.getId());
      
        // check if username is in potentialOwners
        boolean userInPotentialOwners = false;
        for (OrganizationalEntity entity : task.getPeopleAssignments()
            .getPotentialOwners()) {
          if (entity.getId().equals(username)) {
            userInPotentialOwners = true;
            break;
          }
        }
      
        if (!userInPotentialOwners) {
          org.jbpm.task.User actualOwner = task.getTaskData()
              .getActualOwner();
      
          // we claim the task just to set actualOwner to current user
          if (taskSummary.getStatus() == Status.Ready
              && (actualOwner == null || !actualOwner.getId().equals(
                  username))) {
            taskService.claim(task.getId(), username);
            actualOwner = task.getTaskData().getActualOwner();
          }
      
          // if actualOwner is current user, we add it to potentialOwnersn,
          // just to call forward - see
          // https://community.jboss.org/thread/221465?tstart=0
          task.getPeopleAssignments().getPotentialOwners().add(actualOwner);
        }
      
        taskService.forward(taskSummary.getId(), username, targetGroupname);
      
        // forward reassigns the task.
        // if the task was already assigned to other groups / users, those groups / users are not removed from potentialOwners
        // we must do it explicitly
        PeopleAssignments peopleAssignments = task.getPeopleAssignments();
        List<OrganizationalEntity> clonedList = peopleAssignments
            .getPotentialOwners();
        for (OrganizationalEntity entity : clonedList) {
          if (!entity.getId().equals(targetGroupname)
              && !entity.getId().equals("Administrator")) {
            peopleAssignments.getPotentialOwners().remove(entity);
          }
        }
      }
      

       

      Thanks !