AnsweredAssumed Answered

Customized handling of UserTasks

Question asked by jolivier on Dec 20, 2013
Latest reply on Dec 23, 2013 by trademak

I start using Activiti and would like to use my own front-end for user tasks. So I want my custom code to be called each time a user task is created. My options are:
- Poll for taskService.createTaskQuery().taskCandidateGroup(group.list(); for all groups and all users I know, this seem to be very expensive.
- Add a TaskListener to my user tasks in my xml processes definitions. This looks great, but I need to do that for all user tasks and all processes that my code will start, so I guess this could be automated.
- I try to automate this by modifying on the fly all created Process like this:

BpmnModel model = new BpmnModel();
      Process process;
      try {
         XMLInputFactory xif = XMLInputFactory.newInstance();
         XMLStreamReader xtr = null;
         InputStreamReader in = new InputStreamReader(getClass().getClassLoader().getResourceAsStream("myprocess.bpmn20.xml"), "UTF-8");
         xtr = xif.createXMLStreamReader(in);
         process = new ProcessParser().parse(xtr, model);
                        // I can modify here my process and add the TaskListeners
                        for (UserTask userTask : process.findFlowElementsOfType(UserTask.class)) {
                                // Add the listener, but how?
      } catch (Exception e) {
         throw new RuntimeException("Could create process from xml.", e);

      String deploymentId = repositoryService
            .addBpmnModel("dynamic-model.bpmn", model).name("Dynamic process deployment.")
The two issue with this way is that
- I don't see how to add the listeners programmaticaly to the UserTask.
- It looks like I circumvent a lot of logic this way (validation of the xml for instance), so I would prefer a way with less impact.

What is the preferred way to do this?

Thanks in advance