cancel
Showing results for 
Search instead for 
Did you mean: 

TaskListener cannot delete potential owners specified in XML

processengine
Champ in-the-making
Champ in-the-making
Version: Activiti 5.10 (with setup like in demo via ant demo.start)

In the XML I've defined a user task with a task listener on create event like this:
<userTask id="dynamicAssignmentTask" name="Dynamic Assignment Task" >
        <documentation>Some documentation here</documentation>
        <extensionElements>
          <activiti:taskListener event="create" class="org.activiti.tasklistener.DynamicAssignmentHandler" />
        </extensionElements>
        <potentialOwner>
          <resourceAssignmentExpression>
            <formalExpression>user(kermit), group(DynamicAssignmentGroup)</formalExpression>
          </resourceAssignmentExpression>
        </potentialOwner>
    </userTask>
I would like to reassign the task candidates within the task listener. For example:
@Override
   public void notify(DelegateTask delegateTask) {
      // This doesn't delete the candidate group specified in the XML.
      delegateTask.deleteCandidateGroup("DynamicAssignmentGroup");
      
      // This doesn't delete the user specified in the XML.
      delegateTask.deleteCandidateUser("kermit");

      
      // This is not specified in the XML and works perfectly.
      delegateTask.addCandidateUser("gonzo");
      delegateTask.deleteCandidateUser("gonzo");

   }
The problem is that the candidates which are specified within the XML cannot be deleted (removed from the candidate list) by using the API within a TaskListener. Adding/deleting candidates which aren't specified within the XML works perfectly.
Any ideas why this won't work? (Is it a bug?)

Thanks in advance
5 REPLIES 5

mitziuro
Champ in-the-making
Champ in-the-making
In the XML I've defined a user task with a task listener on create event like this:
Quote:
<userTask id="dynamicAssignmentTask" name="Dynamic Assignment Task" >
<documentation>Some documentation here</documentation>
<extensionElements>
<activiti:taskListener event="create" class="org.activiti.tasklistener.DynamicAssignmentHandler" />
</extensionElements>
<potentialOwner>
<resourceAssignmentExpression>
<formalExpression>user(kermit), group(DynamicAssignmentGroup)</formalExpression>
</resourceAssignmentExpression>
</potentialOwner>
</userTask>

I think the you're trying to delete the candidates before assignation.(Your taskListener it's executed before the <potentialOwner> sequence)

processengine
Champ in-the-making
Champ in-the-making
The user guide says: "When receiving the create event, we usually want to inspect all properties of the task including the assignee." So therefore the assignation should happend before.

I did the following demo to show that the candidates are already assigned when the listener is called:
  Set<IdentityLink> identityLinks = delegateTask.getCandidates();
  Iterator<IdentityLink> iterator = identityLinks.iterator();
 
  // Contains all candidate users (includes individual users and users from groups)
  List<String> candidateUsers = new LinkedList<String>();
 
  // Iterate over all candidate users for this task
  while (iterator.hasNext()) {
   IdentityLink identityLink = iterator.next();
  
   if (identityLink.getType().equals(IdentityLinkType.CANDIDATE)) {
    String userId = identityLink.getUserId();
    String groupId = identityLink.getGroupId();
   
    if (userId != null) {   // Single candidate user
     log.debug("userId (single user): " + userId);
     candidateUsers.add(userId);
    } else if (groupId != null) { // Group candidate users
     log.debug("groupId: " + groupId);
    
     List<User> users = ProcessEngines.getDefaultProcessEngine().getIdentityService().createUserQuery().memberOfGroup(groupId).list();
     for (User user : users) {
      candidateUsers.add(user.getId());
     }
    } else {
     log.warn("userId and groupId are null");
    }
   }
  
  }
 
  log.info("# candidate users = " + candidateUsers.size());
  assert candidateUsers.size() != 0;

Thank you for further suggestions!

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
I think this is a case of 'sometimes the documentation is (unfortunately) wrong'

michj_74
Champ in-the-making
Champ in-the-making
Hi,

what event type would be the right one for this case?

Thanks,
Mike

jbarrez
Star Contributor
Star Contributor
I don't get your question … even with reading the old posts above.
What 'event' or 'case' are you referring to?