cancel
Showing results for 
Search instead for 
Did you mean: 

tasklistener event order

heymjo
Champ on-the-rise
Champ on-the-rise
Hi,

The doc states about tasklistener events that the assignment event is fired before the create event.

event (required): the type of task event on which the task listener will be invoked. Possible events are
  • create: occurs when the task has been created an all task properties are set.

  •    
  • assignment: occurs when the task is assigned to somebody. Note: when process execution arrives in a userTask, first an assignment event will be fired, before the create event is fired. This might seem an unnatural order, but the reason is pragmatic: when receiving the create event, we usually want to inspect all properties of the task including the assignee.

  •    
  • complete: occurs when the task is completed and just before the task is deleted from the runtime data.

after some testing and debugging it looks to me that the assignment event is never fired before the create event.

This is my task definition


    <userTask id="verifyReport" name="verify the report">
      <extensionElements>
        <activiti:taskListener event="create" delegateExpression="${fourEyesTaskListener}">
          <activiti:field name="fourEyesTask" stringValue="createReport"/>
        </activiti:taskListener>
      </extensionElements>
      <potentialOwner>
        <resourceAssignmentExpression>
          <formalExpression>ROLE_EDIT</formalExpression>
        </resourceAssignmentExpression>
      </potentialOwner>
    </userTask>

This, together with http://jira.codehaus.org/browse/ACT-847 is making it hard to implement a 4-eyes paradigm in activiti. Any ideas how to proceed here ?

Thanks
Jorg
6 REPLIES 6

heymjo
Champ on-the-rise
Champ on-the-rise
as often, only after posting to the forum i notice the issue :shock:

UserActivityBehaviour.handleAssignments sets the assignee but only if it is declared via the activiti:assignee shortcut


  protected void handleAssignments(TaskEntity task, ActivityExecution execution) {
    if (taskDefinition.getAssigneeExpression() != null) {
      task.setAssignee((String) taskDefinition.getAssigneeExpression().getValue(execution));
    }
    ….

so it looks like the doc needs adjusting and state that the assignment event is only fired before create in the case where an activiti:assignee element is declared on the user task.

Jorg

frederikherema1
Star Contributor
Star Contributor
In the task-definition, your listener is listening for the "create" event in the example. Or is that intended?

heymjo
Champ on-the-rise
Champ on-the-rise
well it doesn't matter really. If you put a breakpoint in TaskEntity.fireEvent you will observe that the order of events fired is always "create", "assignment", "complete" for below simple workflow


<process id="FourEyesExample">

    <startEvent id="begin"/>

    <sequenceFlow id="flow1" sourceRef="begin" targetRef="createReport"/>

    <userTask id="createReport" name="create the report">
      <potentialOwner>
        <resourceAssignmentExpression>
          <formalExpression>ROLE_CREATE</formalExpression>
        </resourceAssignmentExpression>
      </potentialOwner>
    </userTask>

    <sequenceFlow id="flow2" sourceRef="createReport" targetRef="end"/>

    <endEvent id="end"/>

  </process>

frederikherema1
Star Contributor
Star Contributor
Makes sense that the assignment event is not thrown when a "potentialOwner" is used (corresponds to a candidate, not a fixed assignee).

heymjo
Champ on-the-rise
Champ on-the-rise
mmmyeah ok understood, but the docs needs rewording then because it's not as clear cut as it says

… when process execution arrives in a userTask, first an assignment event will be fired, before the create event is fired.

so in order to implement foureyes paradigm i will need two listeners, <activiti:taskListener event="create,assignment"> does not work (yet?). That will get pretty verbose.

frederikherema1
Star Contributor
Star Contributor
The only way is to define 2 seperate listeners… One for create, and another one for assignment.