cancel
Showing results for 
Search instead for 
Did you mean: 

Add EndEvent listener programmatically not working

felipe1
Champ in-the-making
Champ in-the-making
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>
1 ACCEPTED ANSWER

maxr24
Champ in-the-making
Champ in-the-making
This may be a pretty late reply, but for anyone else looking at this thread (like I was for a while):

You want to add that to the PREBpmnParseHandlers not POSTBpmnParseHandlers. The documentation for this is pretty non-existent, but if you set it as a POST handler the execution listeners will be set after the process definition entity is created, making it useless.

View answer in original post

5 REPLIES 5

trademak
Star Contributor
Star Contributor
Which version of Activiti are you using?
The code looks ok on first hand. Is this problem still present in the latest Activiti version?

Best regards,

felipe1
Champ in-the-making
Champ in-the-making
I'm using 5.15 I'll check if there is a newer version and try to reproduce the behaviour on it. Thanks Tijs 🙂

jfigueiredo
Champ in-the-making
Champ in-the-making
I'm using 5.16.4 and i'm having the same behaviour. Do you still have this problem?

Thanks.

jbarrez
Star Contributor
Star Contributor
Would be good if you can create a simple unit test that demonstrates this, so we can quickly fix this.

maxr24
Champ in-the-making
Champ in-the-making
This may be a pretty late reply, but for anyone else looking at this thread (like I was for a while):

You want to add that to the PREBpmnParseHandlers not POSTBpmnParseHandlers. The documentation for this is pretty non-existent, but if you set it as a POST handler the execution listeners will be set after the process definition entity is created, making it useless.