I used above method, but it was slowly. I tried to load all tasks and it tooks minute. So I Implemented this helper class. It is not perfect, but it fits for me:
<code>
private static class IdentityCache {
private final Map<String, ProcessDefinitionEntity> processDefinitions = Maps.newHashMap();
private final RepositoryService repositoryService;
public IdentityCache(RepositoryService repositoryService) {
this.repositoryService = repositoryService;
}
public List<String> getCandidateUsers(org.activiti.engine.task.Task task) {
List<String> ret = Lists.newLinkedList();
ProcessDefinitionEntity processDefinition = getProcessDefinition(task.getProcessDefinitionId());
Set<Expression> candidateUserIdExpressions = processDefinition.getTaskDefinitions().get(task.getTaskDefinitionKey()).getCandidateUserIdExpressions();
for (Expression expression : candidateUserIdExpressions) {
ret.add(expression.getExpressionText());
}
return ret;
}
private ProcessDefinitionEntity getProcessDefinition(String processDefinitionId) {
ProcessDefinitionEntity processDefinition = processDefinitions.get(processDefinitionId);
if (processDefinition == null) {
ProcessDefinitionEntity loadedProcessDefinition = (ProcessDefinitionEntity) repositoryService.getProcessDefinition(processDefinitionId);
processDefinitions.put(processDefinitionId, loadedProcessDefinition);
processDefinition = loadedProcessDefinition;
}
return processDefinition;
}
public List<String> getCandidateGroups(org.activiti.engine.task.Task task) {
List<String> ret = Lists.newLinkedList();
ProcessDefinitionEntity processDefinition = getProcessDefinition(task.getProcessDefinitionId());
Set<Expression> candidateUserIdExpressions = processDefinition.getTaskDefinitions().get(task.getTaskDefinitionKey()).getCandidateGroupIdExpressions();
for (Expression expression : candidateUserIdExpressions) {
ret.add(expression.getExpressionText());
}
return ret;
}
}
</code>