gonzalad
2013-02-20 11:15:50 UTC
gonzalad [https://community.jboss.org/people/gonzalad] created the discussion
"jBPM 5.4 : how to forward / reassign a task to a group ?"
To view the discussion, visit: https://community.jboss.org/message/798550#798550
--------------------------------------------------------------
As mentioned in https://community.jboss.org/thread/221465 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 !
--------------------------------------------------------------
Reply to this message by going to Community
[https://community.jboss.org/message/798550#798550]
Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
"jBPM 5.4 : how to forward / reassign a task to a group ?"
To view the discussion, visit: https://community.jboss.org/message/798550#798550
--------------------------------------------------------------
As mentioned in https://community.jboss.org/thread/221465 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 !
--------------------------------------------------------------
Reply to this message by going to Community
[https://community.jboss.org/message/798550#798550]
Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]