AnsweredAssumed Answered

Custom Execution Listener triggered by VARIABLE_UPDATED event

Question asked by rhafner on Mar 25, 2015
Latest reply on Mar 26, 2015 by rhafner
Our proprietary workflow engine supports firing a hierarchy of listeners (that are modeled) when a DataObject is updated.

Process
  DataObject-1
  Listener-1
  Listener-2
  Subprocess
    DataObject-2
    Listener-3

For example, when DataObject-2 is updated Listener-3 will run followed by Listener-2. When DataObject-1 is updated Listener-1 will run.

I'm attempting to use an execution listener with a custom type that is triggered by the VARIABLE_UPDATED event in Activiti to support this behavior. Thus far I have been able to get the DataObject-1/Listener-1 case to work but I am having difficulty getting similar behavior to work for the other case involving a subprocess.

The ActivitiEvent that is sent to the VARIABLE_UPDATED listener in the subprocess case contains an execution id that is related to the the subprocesses execution. This execution has an Activity (ACT_ID) that refers to the UserTask that is defined on the subprocess and not the id of the subprocess as defined in the BPMN template. In order to retrieve the execution listeners for the subprocess from the ProcessDefinition I need the id of the subprocess from the template.

Questions:
* Is there a way to access the id of the subprocess as defined in the template from within the listener?
* Are there alternative ways to implement this behavior that we should be investigating?

Here is a code snippet of the VariableUpdated Listener for reference:

public void onEvent(ActivitiEvent activitiEvent)
{
   Execution execution =runtimeService.createExecutionQuery().executionId(activitiEvent.getExecutionId()).singleResult();
   while (null != execution)
   {
     ExecutionEntity executionEntity = (ExecutionEntity)execution;
     if (null != executionEntity.getVariableLocal(Constants.PROCESS_PATH))
     {
       ScopeImpl scope;
       if (executionEntity.getId().equals(executionEntity.getProcessInstanceId()))
       {
         scope = executionEntity.getProcessDefinition();
       }
       else
       {
         // UserTask in subprocess. Need the subprocess.
         scope = executionEntity.getActivity();
       }

       List<ExecutionListener> listeners = scope.getExecutionListeners(message);
        for (ExecutionListener listener : listeners)
        {
           listener.notify(executionEntity);
        }    
        execution = executionEntity.getParent();
   }
}

Outcomes