I need to add an event listener to every end event, so I'll have a way to notify users when a process instance has concluded.I've done some research and find out this post (http://forums.activiti.org/content/manipulating-bpmns-programmatically-prior-deployment) that describes exactly what I want to do.I have create a ProcessParseHandler like that:
public class ParseHandlerEndListener extends ProcessParseHandler {
@Override
protected void executeParse(BpmnParse bpmnParse, Process process) {
ActivitiListener endEventListener = new ActivitiListener();
endEventListener.setEvent(ExecutionListener.EVENTNAME_END);
endEventListener.setImplementation(MyListener.class.getName());
endEventListener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_CLASS);
process.setExecutionListeners(Arrays.asList(endEventListener));
}
}
And register it in my <b>activiti.cfg.xml</b>
<bean
id="processEngineConfiguration"
class="org.activiti.cdi.CdiJtaProcessEngineConfiguration">
…
<property name="postBpmnParseHandlers">
<list>
<bean class="com.mycompany.ParseHandlerEndListener" />
</list>
</property>
</bean>
The listener is declared like so:
@Named
public class MyListener implements ExecutionListener {
private static final long serialVersionUID = 1L;
@Override
public void notify(DelegateExecution execution) throws Exception {
// listener code
}
}
When I publish a new process, the <b>executeParse(BpmnParse bpmnParse, Process process) </b> is called as expected (I have debbuged and added some logs to check), and no exception is thrown. However, when I start and finish a process instance the <b>notify</b> method is not being called.If I add the listener directly into the process definition the <b>notify</b> is called and everything works perfectly.
<process
id="cushman-reembolso-fretado"
name="Reembolso fretado"
isExecutable="true">
<extensionElements>
<activiti:executionListener
class="br.com.glr.workflow.activiti.impl.NotificaProcessoConcluidoActiviti"
event="end" />
</extensionElements>
….
</process>