08-24-2012 08:47 AM
<userTask id="dynamicAssignmentTask" name="Dynamic Assignment Task" >I would like to reassign the task candidates within the task listener. For example:
<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>
@OverrideThe 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.
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");
}
08-27-2012 08:00 AM
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>
08-27-2012 08:44 AM
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;
08-27-2012 05:15 PM
07-11-2013 05:11 AM
07-12-2013 03:22 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.