cancel
Showing results for 
Search instead for 
Did you mean: 

how to get candidate group info for the next task

gokhan
Champ in-the-making
Champ in-the-making
Hi everbody

I am new to Activiti, and in our project we need to assign some tasks to users at runtime.
So i need to fill a combobox with userIDs in a task form, and assign userID to the next task in next task's create listener event.
In order to fill the combobox with userIDs i need to get candidate group info for the next task so i can get the members of this group.

Is there any way to get the next task's candidate group information while in the current task.

Any help will be appreciated.
Thanks in advance.

gokhan
5 REPLIES 5

yz250
Champ in-the-making
Champ in-the-making
I' m looking for the same thing, I have to fill a combobox with all users of a group, then the initiator of the process can choose the user who will do the next task.

Thanks, Ivan.

trademak
Star Contributor
Star Contributor
Hi,

When you query the Activiti Engine for process definitions you get back an List<ProcessDefinition>
But this actually is a ProcessDefinitionEntity, and this class contains the parsed task information of that process.
Note however that this is no public API and this can change in feature releases.

Best regards,

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
But you still have to know what the next task will be… If there are gateways in between with constraints on the sequenceflows, it can be hard to determine.

nils1
Champ in-the-making
Champ in-the-making
Here is the API call you can use to get the candidate groups for a task:

List<IdentityLink> idLinks = taskService.getIdentityLinksForTask("YOUR TASK ID");

Cheers,
Nils

pprikryl
Champ in-the-making
Champ in-the-making
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>