cancel
Showing results for 
Search instead for 
Did you mean: 

IdentityLink and execution listener

zze_one
Champ on-the-rise
Champ on-the-rise
Hi everyone.

I'm really looking forward for some help on how to set involved users and groups. Thanks in advance.

I'm adding an execution listener to a user task.


<userTask id="usertask1" name="First User Task">
      <extensionElements>
         <activiti:executionListener class="realfoundation.foundationservices.process.tasks.FoundationTaskListener" event="start">
            <activiti:field name="involvedGroups" expression="${organizers}" />
         </activiti:executionListener>
       </extensionElements>
    </userTask>


Thanks to this execution listener and to field injection, I'm able to catch the involved users I'd like to set on the task instance.

public class FoundationTaskListener implements ExecutionListener {

    private Expression involvedGroups;

    @Override
    public void notify(DelegateExecution paramDelegateExecution) throws Exception {

        if (involvedGroups != null) {
            for (String group : transformInvolvedActorsToList(involvedGroups.getValue(paramDelegateExecution).toString())) {
                paramDelegateExecution.setVariable("involvedPeps", involvedGroups.getValue(paramDelegateExecution).toString());
            }
        }
    }
}


How to add those involved users as IdentityLink ?
As the execution listener's event is set to start, the task instance is not yet instantiated.

Thanks again.
2 REPLIES 2

sathish1
Champ in-the-making
Champ in-the-making
Since you are having a user task, is there a reason you are not using the Task Listener to identify the users at that level.

More information on the <a href=http://activiti.org/userguide/#taskListeners">task listener </a>



<code>
<userTask id="myTask" name="My Task" >
  <extensionElements>
    <activiti:taskListener event="create" class="org.activiti.MyTaskCreateListener" />
  </extensionElements>
</userTask>
</code>

zze_one
Champ on-the-rise
Champ on-the-rise
Hey Sathish, thanks for replying.
The reason is the following :


My goal is to add involved users on task instances.
Let say my workflow is composed of two user tasks, usertask1 and usertask2.

By using a task listener
- I would provide the group of involved users in a process variable called involvedGroup when instantiating the process.
- I would write, in my listener's notify() method :
<code>
if (delegateTask.getVariables().containsKey("involvedGroup")) {
            delegateTask.addGroupIdentityLink(delegateTask.getVariable("involvedGroup").toString(), "involvedGroup");
           
        }
</code>

This would be a good solution if I wanted the same involved users associated with both task instances, from userTask1 and userTask2.


But 2 tasks instances of a same process instance may need different involved users.

By using an Execution Listener, I was hoping to provide those different values

<code>
<userTask id="usertask1" name="First User Task">
  <extensionElements>
       <activiti:executionListener class="realfoundation.foundationservices.process.tasks.FoundationTaskListener" event="start">
        <activiti:field name="involvedGroups" expression="${organizers}" />
       </activiti:executionListener>
     </extensionElements>
    </userTask>
</code>
<code>
<userTask id="usertask2" name="Second User Task">
  <extensionElements>
       <activiti:executionListener class="realfoundation.foundationservices.process.tasks.FoundationTaskListener" event="start">
        <activiti:field name="involvedGroups" expression="${organizers2}" />
       </activiti:executionListener>
     </extensionElements>
    </userTask>
</code>

I have a very hacky solution in mind (that would imply both, the execution listener and the task listener), but after reading advice from this post, i felt like that there was a better solution…