Hi all,
According to the current source code, it seems to me that a process instance is created through the method [font=Courier]org.activiti.engine.impl.cmd.StartProcessInstanceCmd.execute()[/font]:
<code>
…
1 // Start the process instance
2 ExecutionEntity processInstance = processDefinition.createProcessInstance(businessKey);
3
4 // now set the variables passed into the start command
5 if (variables != null) {
6 processInstance.setVariables(variables);
7 }
8
9 // now set processInstance name
10 if (processInstanceName != null) {
11 processInstance.setName(processInstanceName);
12 }
13
14 processInstance.start();
15
16 return processInstance;
</code>
The event ENTITY_CREATED is fired at line 1 by [font=Courier]processDefinition.createProcessInstance(businessKey)[/font], but variables are set into the process instance after the process instance creation.
After other investigations in source, the start of the process instance at line 14 performs the operation [font=Courier]org.activiti.engine.impl.pvm.runtime.AtomicOperation.PROCESS_START[/font] that is implemented by [font=Courier]org.activiti.engine.impl.pvm.runtime.AtomicOperationProcessStart[/font]. This implementation fires the event ENTITY_INITIALIZED.
Moreover, the events ENTITY_CREATED and ENTITY_INITIALIZED are not fired only for on a process instance creation. I receive them on an identify link add.
So, I must filter events in the event listener as following:
<code>
final ActivitiEntityWithVariablesEvent eventImpl = (ActivitiEntityWithVariablesEvent)event;
if (eventImpl.getEntity() instanceof ExecutionEntity) {
…
}
</code>
Is it correct ?
For performance reason and to avoid filtering, it seems to me that an event PROCESS_STARTED should be introduced and fired in the same location than the event ENTITY_INITIALIZED in [font=Courier]AtomicOperationProcessStart[/font]. What do you think ? If you are ok, I can contribute it.
Thanks for your help,
Regards,
Christophe DENEUX