Search in sources :

Example 1 with BaseTaskListener

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

the class ListenerNotificationHelper method executeTaskListeners.

public void executeTaskListeners(UserTask userTask, TaskEntity taskEntity, String eventType) {
    for (ActivitiListener activitiListener : userTask.getTaskListeners()) {
        String event = activitiListener.getEvent();
        if (event.equals(eventType) || event.equals(TaskListener.EVENTNAME_ALL_EVENTS)) {
            BaseTaskListener taskListener = createTaskListener(activitiListener);
            if (activitiListener.getOnTransaction() != null) {
                planTransactionDependentTaskListener(taskEntity.getExecution(), (TransactionDependentTaskListener) taskListener, activitiListener);
            } else {
                taskEntity.setEventName(eventType);
                taskEntity.setCurrentActivitiListener(activitiListener);
                try {
                    Context.getProcessEngineConfiguration().getDelegateInterceptor().handleInvocation(new TaskListenerInvocation((TaskListener) taskListener, taskEntity));
                } catch (Exception e) {
                    throw new ActivitiException("Exception while invoking TaskListener: " + e.getMessage(), e);
                } finally {
                    taskEntity.setEventName(null);
                    taskEntity.setCurrentActivitiListener(null);
                }
            }
        }
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) TaskListenerInvocation(org.activiti.engine.impl.delegate.invocation.TaskListenerInvocation) BaseTaskListener(org.activiti.engine.delegate.BaseTaskListener) BaseTaskListener(org.activiti.engine.delegate.BaseTaskListener) TaskListener(org.activiti.engine.delegate.TaskListener) TransactionDependentTaskListener(org.activiti.engine.delegate.TransactionDependentTaskListener) ActivitiListener(org.activiti.bpmn.model.ActivitiListener) ActivitiException(org.activiti.engine.ActivitiException)

Example 2 with BaseTaskListener

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

the class ListenerNotificationHelper method createTaskListener.

protected BaseTaskListener createTaskListener(ActivitiListener activitiListener) {
    BaseTaskListener taskListener = null;
    ListenerFactory listenerFactory = Context.getProcessEngineConfiguration().getListenerFactory();
    if (ImplementationType.IMPLEMENTATION_TYPE_CLASS.equalsIgnoreCase(activitiListener.getImplementationType())) {
        taskListener = listenerFactory.createClassDelegateTaskListener(activitiListener);
    } else if (ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION.equalsIgnoreCase(activitiListener.getImplementationType())) {
        taskListener = listenerFactory.createExpressionTaskListener(activitiListener);
    } else if (ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION.equalsIgnoreCase(activitiListener.getImplementationType())) {
        if (activitiListener.getOnTransaction() != null) {
            taskListener = listenerFactory.createTransactionDependentDelegateExpressionTaskListener(activitiListener);
        } else {
            taskListener = listenerFactory.createDelegateExpressionTaskListener(activitiListener);
        }
    } else if (ImplementationType.IMPLEMENTATION_TYPE_INSTANCE.equalsIgnoreCase(activitiListener.getImplementationType())) {
        taskListener = (TaskListener) activitiListener.getInstance();
    }
    return taskListener;
}
Also used : BaseTaskListener(org.activiti.engine.delegate.BaseTaskListener) BaseTaskListener(org.activiti.engine.delegate.BaseTaskListener) TaskListener(org.activiti.engine.delegate.TaskListener) TransactionDependentTaskListener(org.activiti.engine.delegate.TransactionDependentTaskListener) ListenerFactory(org.activiti.engine.impl.bpmn.parser.factory.ListenerFactory)

Aggregations

BaseTaskListener (org.activiti.engine.delegate.BaseTaskListener)2 TaskListener (org.activiti.engine.delegate.TaskListener)2 TransactionDependentTaskListener (org.activiti.engine.delegate.TransactionDependentTaskListener)2 ActivitiListener (org.activiti.bpmn.model.ActivitiListener)1 ActivitiException (org.activiti.engine.ActivitiException)1 ListenerFactory (org.activiti.engine.impl.bpmn.parser.factory.ListenerFactory)1 TaskListenerInvocation (org.activiti.engine.impl.delegate.invocation.TaskListenerInvocation)1