cancel
Showing results for 
Search instead for 
Did you mean: 

Adding TaskListener in custom BpmnParseHandler

jwojtczak
Champ in-the-making
Champ in-the-making
Hi,

I'm trying to add TaskListener to UserTask in custom BpmnParseHandler. I implemented BpmnParsehandler interface and added my TestBpmnParseHandler to the processEngineConfiguration bean.


   <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
      …
      <property name="preBpmnParseHandlers">
         <list>
            <bean class="com.testowy.test.TestBpmnParseHandler" />
         </list>
      </property>
      …
   </bean>


I tried to add TaskListener by adding ExstensionElement to BaseElement that is being processed, but it does not work, TaskListener is not being executed when the UserTask is completed.

   public class TestBpmnParseHandler implements BpmnParseHandler {
   //…
      @Override
      public void parse(BpmnParse bpmnParse, BaseElement element) {
         //…
         ExtensionElement ee = new ExtensionElement();
         ee.setNamespacePrefix("activiti");
         ee.setName("taskListener");
         ExtensionAttribute ea = new ExtensionAttribute();
         ea.setName("event");
         ea.setValue("complete");
         ee.addAttribute(ea);
         ExtensionAttribute ea2 = new ExtensionAttribute();
         ea2.setName("class");
         ea2.setValue("com.testowy.common.AOTaskListener");
         ee.addAttribute(ea2);
         element.addExtensionElement(ee);
         //…
      }
   //…
   }

Do You have any ideas what am I doing wrong?
4 REPLIES 4

jbarrez
Star Contributor
Star Contributor
No, that won't work, because at that point the parsing is already done. I agree, the name 'preparsehandler' does seem to indicate that.

Here's an example of how you need to do it: https://github.com/jbarrez/activiti-advanced-scripting/blob/master/src/test/java/org/activiti/Execut...

I tried adding a parse handler following the above example, but ((ProcessDefinitionEntity) bpmnParsegetCurrentScope().getProcessDefinition()).getTaskDefinitions() is an empty hash table. I tried both pre and postBpmnParseHandlers.

What am I doing wrong?

It seems that ((ProcessDefinitionEntity) bpmnParsegetCurrentScope().getProcessDefinition()).getTaskDefinitions() is non-empty only for User Tasks. For Service and Script Tasks, it is an empty collection.

What will be the best way to attach a listener to all task nodes in a process definition at parsing time?

frauke_heyl
Champ on-the-rise
Champ on-the-rise

Hello,

currently I am working on the transformation of the old BpmnParseListeners to the BpmnParseHandlers.

I was facing a similar problem, that is how can I add ExecutionListeners to certain tasks and processes? I found your example here in the forum and tried to do it like that, but the BpmnParse is empty and it's currrentXXX members are null.

    protected void executeParse(BpmnParse bpmnParse, Process element) {
        for (IConfigurableExecutionListener listener : m_executionListeners) {
            if (listener.supportsProcess()) {
                bpmnParse.getCurrentProcessDefinition().addExecutionListener(listener.supportedEvent(), listener);
            }
        }
    }

What did I do wrong?

I added the parse handler to the "preBpmnParseHandlers".

I use Activiti 5.22.0

Do you have some more detailed examples how to do the transformation from ParseListeners to ParseHandlers? Actually I am not sure how to use the parameters BpmnParse and Element correctly.