06-19-2017 12:54 PM
I am trying to hook into process parsing to add task listeners to all tasks. I tried the following config:
<bean id="processEngineConfiguration"
class="org.activiti.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration">
...
<property name="postBpmnParseHandlers">
<list>
<bean class="xxx.yyy.DecorateTask" />
</list>
</property>
</bean>
Where the code for DecorateTask is:
public class DecorateTask extends AbstractBpmnParseHandler<UserTask> {
// private List<ActivitiListener> listeners = new ArrayList<>();
private String logfile = "logger.txt";
FileWriter log;
public DecorateTask() {
try {
log = new FileWriter(logfile, true);
log.write("Initialising Devorator\n");
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
protected Class getHandledType() {
return UserTask.class;
}
@Override
protected void executeParse(BpmnParse bpmnParse, UserTask element) {
try {
log.write(" >> " + element.getClass().getName() + "\n");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
However, the class is not even being instantiated, as I see no entries in the output file. Ideally, I want to intercept all tasks to emit events for internal logging purposes, but I tried to use BaseElement instead of UserTask, and that did not work either.
Any clues how to make it work will be greatly appreciated.
Thanks,
Mayank.
06-20-2017 02:13 PM
That was user error-I wasn't flushing the file. Adding log.flush() fixed that.
However, I still haven't solved the basic problem--I want to add a listener to all User and Script tasks, which should get called upon entry and exit to the task, so I can generate some events. Ideally, this should be done automatically on all processes when they are parsed, so the definition creator does not have to manually add the listeners to each task.
What is the best way to do that? I can add listeners in the designer, but how can I do it programmatically? The parsing hook does see to have a way to do that.
Thanks.
06-20-2017 02:17 AM
If your class is not even instantiated at all then it stands to reason that some Spring configuration may be overriding your configuration of the postBpmnParseHandlers
property, otherwise Spring would have to call the constructor of your class.
06-20-2017 02:13 PM
That was user error-I wasn't flushing the file. Adding log.flush() fixed that.
However, I still haven't solved the basic problem--I want to add a listener to all User and Script tasks, which should get called upon entry and exit to the task, so I can generate some events. Ideally, this should be done automatically on all processes when they are parsed, so the definition creator does not have to manually add the listeners to each task.
What is the best way to do that? I can add listeners in the designer, but how can I do it programmatically? The parsing hook does see to have a way to do that.
Thanks.
06-27-2017 05:09 PM
I found a possible solution in one of the threads, but it only partly works. 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?#processparsing
Any answers are greatly appreciated.
BTW, I am using Activiti 5.22 (CE).
Thanks.
06-29-2017 10:18 AM
Explore our Alfresco products with the links below. Use labels to filter content by product module.