Search in sources :

Example 1 with TransactionDependentExecutionListener

use of org.activiti.engine.delegate.TransactionDependentExecutionListener in project Activiti by Activiti.

the class ListenerNotificationHelper method executeExecutionListeners.

public void executeExecutionListeners(HasExecutionListeners elementWithExecutionListeners, DelegateExecution execution, String eventType) {
    List<ActivitiListener> listeners = elementWithExecutionListeners.getExecutionListeners();
    if (listeners != null && listeners.size() > 0) {
        ListenerFactory listenerFactory = Context.getProcessEngineConfiguration().getListenerFactory();
        for (ActivitiListener activitiListener : listeners) {
            if (eventType.equals(activitiListener.getEvent())) {
                BaseExecutionListener executionListener = null;
                if (ImplementationType.IMPLEMENTATION_TYPE_CLASS.equalsIgnoreCase(activitiListener.getImplementationType())) {
                    executionListener = listenerFactory.createClassDelegateExecutionListener(activitiListener);
                } else if (ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION.equalsIgnoreCase(activitiListener.getImplementationType())) {
                    executionListener = listenerFactory.createExpressionExecutionListener(activitiListener);
                } else if (ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION.equalsIgnoreCase(activitiListener.getImplementationType())) {
                    if (activitiListener.getOnTransaction() != null) {
                        executionListener = listenerFactory.createTransactionDependentDelegateExpressionExecutionListener(activitiListener);
                    } else {
                        executionListener = listenerFactory.createDelegateExpressionExecutionListener(activitiListener);
                    }
                } else if (ImplementationType.IMPLEMENTATION_TYPE_INSTANCE.equalsIgnoreCase(activitiListener.getImplementationType())) {
                    executionListener = (ExecutionListener) activitiListener.getInstance();
                }
                if (executionListener != null) {
                    if (activitiListener.getOnTransaction() != null) {
                        planTransactionDependentExecutionListener(listenerFactory, execution, (TransactionDependentExecutionListener) executionListener, activitiListener);
                    } else {
                        // eventName is used to differentiate the event when reusing an execution listener for various events
                        execution.setEventName(eventType);
                        execution.setCurrentActivitiListener(activitiListener);
                        ((ExecutionListener) executionListener).notify(execution);
                        execution.setEventName(null);
                        execution.setCurrentActivitiListener(null);
                    }
                }
            }
        }
    }
}
Also used : BaseExecutionListener(org.activiti.engine.delegate.BaseExecutionListener) ActivitiListener(org.activiti.bpmn.model.ActivitiListener) ListenerFactory(org.activiti.engine.impl.bpmn.parser.factory.ListenerFactory) BaseExecutionListener(org.activiti.engine.delegate.BaseExecutionListener) ExecutionListener(org.activiti.engine.delegate.ExecutionListener) TransactionDependentExecutionListener(org.activiti.engine.delegate.TransactionDependentExecutionListener)

Example 2 with TransactionDependentExecutionListener

use of org.activiti.engine.delegate.TransactionDependentExecutionListener in project Activiti by Activiti.

the class DelegateExpressionTransactionDependentExecutionListener method notify.

@Override
public void notify(String processInstanceId, String executionId, FlowElement flowElement, Map<String, Object> executionVariables, Map<String, Object> customPropertiesMap) {
    NoExecutionVariableScope scope = new NoExecutionVariableScope();
    Object delegate = expression.getValue(scope);
    if (delegate instanceof TransactionDependentExecutionListener) {
        ((TransactionDependentExecutionListener) delegate).notify(processInstanceId, executionId, flowElement, executionVariables, customPropertiesMap);
    } else {
        throw new ActivitiIllegalArgumentException("Delegate expression " + expression + " did not resolve to an implementation of " + TransactionDependentExecutionListener.class);
    }
}
Also used : ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) NoExecutionVariableScope(org.activiti.engine.impl.el.NoExecutionVariableScope) TransactionDependentExecutionListener(org.activiti.engine.delegate.TransactionDependentExecutionListener)

Aggregations

TransactionDependentExecutionListener (org.activiti.engine.delegate.TransactionDependentExecutionListener)2 ActivitiListener (org.activiti.bpmn.model.ActivitiListener)1 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)1 BaseExecutionListener (org.activiti.engine.delegate.BaseExecutionListener)1 ExecutionListener (org.activiti.engine.delegate.ExecutionListener)1 ListenerFactory (org.activiti.engine.impl.bpmn.parser.factory.ListenerFactory)1 NoExecutionVariableScope (org.activiti.engine.impl.el.NoExecutionVariableScope)1