Search in sources :

Example 1 with TaskListener

use of org.camunda.bpm.engine.delegate.TaskListener in project camunda-bpm-platform by camunda.

the class BpmnParse method parseTaskListeners.

protected void parseTaskListeners(Element userTaskElement, TaskDefinition taskDefinition) {
    Element extentionsElement = userTaskElement.element("extensionElements");
    if (extentionsElement != null) {
        List<Element> taskListenerElements = extentionsElement.elementsNS(CAMUNDA_BPMN_EXTENSIONS_NS, "taskListener");
        for (Element taskListenerElement : taskListenerElements) {
            String eventName = taskListenerElement.attribute("event");
            if (eventName != null) {
                if (TaskListener.EVENTNAME_CREATE.equals(eventName) || TaskListener.EVENTNAME_ASSIGNMENT.equals(eventName) || TaskListener.EVENTNAME_COMPLETE.equals(eventName) || TaskListener.EVENTNAME_DELETE.equals(eventName)) {
                    TaskListener taskListener = parseTaskListener(taskListenerElement);
                    taskDefinition.addTaskListener(eventName, taskListener);
                } else {
                    addError("Attribute 'event' must be one of {create|assignment|complete|delete}", userTaskElement);
                }
            } else {
                addError("Attribute 'event' is mandatory on taskListener", userTaskElement);
            }
        }
    }
}
Also used : Element(org.camunda.bpm.engine.impl.util.xml.Element) ScriptTaskListener(org.camunda.bpm.engine.impl.task.listener.ScriptTaskListener) ExpressionTaskListener(org.camunda.bpm.engine.impl.task.listener.ExpressionTaskListener) ClassDelegateTaskListener(org.camunda.bpm.engine.impl.task.listener.ClassDelegateTaskListener) TaskListener(org.camunda.bpm.engine.delegate.TaskListener) DelegateExpressionTaskListener(org.camunda.bpm.engine.impl.task.listener.DelegateExpressionTaskListener)

Example 2 with TaskListener

use of org.camunda.bpm.engine.delegate.TaskListener in project camunda-bpm-platform by camunda.

the class DelegateExpressionTaskListener method notify.

public void notify(DelegateTask delegateTask) {
    // Note: we can't cache the result of the expression, because the
    // execution can change: eg. delegateExpression='${mySpringBeanFactory.randomSpringBean()}'
    VariableScope variableScope = delegateTask.getExecution();
    if (variableScope == null) {
        variableScope = delegateTask.getCaseExecution();
    }
    Object delegate = expression.getValue(variableScope);
    applyFieldDeclaration(fieldDeclarations, delegate);
    if (delegate instanceof TaskListener) {
        try {
            Context.getProcessEngineConfiguration().getDelegateInterceptor().handleInvocation(new TaskListenerInvocation((TaskListener) delegate, delegateTask));
        } catch (Exception e) {
            throw new ProcessEngineException("Exception while invoking TaskListener: " + e.getMessage(), e);
        }
    } else {
        throw new ProcessEngineException("Delegate expression " + expression + " did not resolve to an implementation of " + TaskListener.class);
    }
}
Also used : TaskListenerInvocation(org.camunda.bpm.engine.impl.task.delegate.TaskListenerInvocation) TaskListener(org.camunda.bpm.engine.delegate.TaskListener) VariableScope(org.camunda.bpm.engine.delegate.VariableScope) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 3 with TaskListener

use of org.camunda.bpm.engine.delegate.TaskListener in project camunda-bpm-platform by camunda.

the class HumanTaskItemHandler method initializeTaskListener.

protected TaskListener initializeTaskListener(CmmnElement element, CmmnActivity activity, CmmnHandlerContext context, CamundaTaskListener listener) {
    Collection<CamundaField> fields = listener.getCamundaFields();
    List<FieldDeclaration> fieldDeclarations = initializeFieldDeclarations(element, activity, context, fields);
    ExpressionManager expressionManager = context.getExpressionManager();
    TaskListener taskListener = null;
    String className = listener.getCamundaClass();
    String expression = listener.getCamundaExpression();
    String delegateExpression = listener.getCamundaDelegateExpression();
    CamundaScript scriptElement = listener.getCamundaScript();
    if (className != null) {
        taskListener = new ClassDelegateTaskListener(className, fieldDeclarations);
    } else if (expression != null) {
        Expression expressionExp = expressionManager.createExpression(expression);
        taskListener = new ExpressionTaskListener(expressionExp);
    } else if (delegateExpression != null) {
        Expression delegateExp = expressionManager.createExpression(delegateExpression);
        taskListener = new DelegateExpressionTaskListener(delegateExp, fieldDeclarations);
    } else if (scriptElement != null) {
        ExecutableScript executableScript = initializeScript(element, activity, context, scriptElement);
        if (executableScript != null) {
            taskListener = new ScriptTaskListener(executableScript);
        }
    }
    return taskListener;
}
Also used : CamundaField(org.camunda.bpm.model.cmmn.instance.camunda.CamundaField) ExpressionManager(org.camunda.bpm.engine.impl.el.ExpressionManager) DelegateExpressionTaskListener(org.camunda.bpm.engine.impl.task.listener.DelegateExpressionTaskListener) FieldDeclaration(org.camunda.bpm.engine.impl.bpmn.parser.FieldDeclaration) Expression(org.camunda.bpm.engine.delegate.Expression) ExpressionTaskListener(org.camunda.bpm.engine.impl.task.listener.ExpressionTaskListener) DelegateExpressionTaskListener(org.camunda.bpm.engine.impl.task.listener.DelegateExpressionTaskListener) CamundaTaskListener(org.camunda.bpm.model.cmmn.instance.camunda.CamundaTaskListener) ExpressionTaskListener(org.camunda.bpm.engine.impl.task.listener.ExpressionTaskListener) ClassDelegateTaskListener(org.camunda.bpm.engine.impl.task.listener.ClassDelegateTaskListener) TaskListener(org.camunda.bpm.engine.delegate.TaskListener) DelegateExpressionTaskListener(org.camunda.bpm.engine.impl.task.listener.DelegateExpressionTaskListener) ScriptTaskListener(org.camunda.bpm.engine.impl.task.listener.ScriptTaskListener) ExecutableScript(org.camunda.bpm.engine.impl.scripting.ExecutableScript) ClassDelegateTaskListener(org.camunda.bpm.engine.impl.task.listener.ClassDelegateTaskListener) ScriptTaskListener(org.camunda.bpm.engine.impl.task.listener.ScriptTaskListener) CamundaScript(org.camunda.bpm.model.cmmn.instance.camunda.CamundaScript)

Example 4 with TaskListener

use of org.camunda.bpm.engine.delegate.TaskListener in project camunda-bpm-platform by camunda.

the class HumanTaskItemHandler method initializeTaskListeners.

protected void initializeTaskListeners(CmmnElement element, CmmnActivity activity, CmmnHandlerContext context, TaskDefinition taskDefinition) {
    HumanTask humanTask = getDefinition(element);
    List<CamundaTaskListener> listeners = queryExtensionElementsByClass(humanTask, CamundaTaskListener.class);
    for (CamundaTaskListener listener : listeners) {
        TaskListener taskListener = initializeTaskListener(element, activity, context, listener);
        String eventName = listener.getCamundaEvent();
        if (eventName != null) {
            taskDefinition.addTaskListener(eventName, taskListener);
        } else {
            taskDefinition.addTaskListener(TaskListener.EVENTNAME_CREATE, taskListener);
            taskDefinition.addTaskListener(TaskListener.EVENTNAME_ASSIGNMENT, taskListener);
            taskDefinition.addTaskListener(TaskListener.EVENTNAME_COMPLETE, taskListener);
            taskDefinition.addTaskListener(TaskListener.EVENTNAME_DELETE, taskListener);
        }
    }
}
Also used : CamundaTaskListener(org.camunda.bpm.model.cmmn.instance.camunda.CamundaTaskListener) CamundaTaskListener(org.camunda.bpm.model.cmmn.instance.camunda.CamundaTaskListener) ExpressionTaskListener(org.camunda.bpm.engine.impl.task.listener.ExpressionTaskListener) ClassDelegateTaskListener(org.camunda.bpm.engine.impl.task.listener.ClassDelegateTaskListener) TaskListener(org.camunda.bpm.engine.delegate.TaskListener) DelegateExpressionTaskListener(org.camunda.bpm.engine.impl.task.listener.DelegateExpressionTaskListener) ScriptTaskListener(org.camunda.bpm.engine.impl.task.listener.ScriptTaskListener) HumanTask(org.camunda.bpm.model.cmmn.instance.HumanTask)

Example 5 with TaskListener

use of org.camunda.bpm.engine.delegate.TaskListener in project camunda-bpm-platform by camunda.

the class TaskEntity method fireEvent.

public void fireEvent(String taskEventName) {
    List<TaskListener> taskEventListeners = getListenersForEvent(taskEventName);
    if (taskEventListeners != null) {
        for (TaskListener taskListener : taskEventListeners) {
            CoreExecution execution = getExecution();
            if (execution == null) {
                execution = getCaseExecution();
            }
            if (execution != null) {
                setEventName(taskEventName);
            }
            try {
                TaskListenerInvocation listenerInvocation = new TaskListenerInvocation(taskListener, this, execution);
                Context.getProcessEngineConfiguration().getDelegateInterceptor().handleInvocation(listenerInvocation);
            } catch (Exception e) {
                throw LOG.invokeTaskListenerException(e);
            }
        }
    }
}
Also used : CoreExecution(org.camunda.bpm.engine.impl.core.instance.CoreExecution) TaskListenerInvocation(org.camunda.bpm.engine.impl.task.delegate.TaskListenerInvocation) TaskListener(org.camunda.bpm.engine.delegate.TaskListener) NullValueException(org.camunda.bpm.engine.exception.NullValueException)

Aggregations

TaskListener (org.camunda.bpm.engine.delegate.TaskListener)21 ClassDelegateTaskListener (org.camunda.bpm.engine.impl.task.listener.ClassDelegateTaskListener)16 DelegateExpressionTaskListener (org.camunda.bpm.engine.impl.task.listener.DelegateExpressionTaskListener)16 ExpressionTaskListener (org.camunda.bpm.engine.impl.task.listener.ExpressionTaskListener)16 CamundaTaskListener (org.camunda.bpm.model.cmmn.instance.camunda.CamundaTaskListener)14 HumanTaskActivityBehavior (org.camunda.bpm.engine.impl.cmmn.behavior.HumanTaskActivityBehavior)12 CmmnActivity (org.camunda.bpm.engine.impl.cmmn.model.CmmnActivity)12 TaskDefinition (org.camunda.bpm.engine.impl.task.TaskDefinition)12 ExtensionElements (org.camunda.bpm.model.cmmn.instance.ExtensionElements)12 Test (org.junit.Test)12 ScriptTaskListener (org.camunda.bpm.engine.impl.task.listener.ScriptTaskListener)4 ExecutableScript (org.camunda.bpm.engine.impl.scripting.ExecutableScript)2 TaskListenerInvocation (org.camunda.bpm.engine.impl.task.delegate.TaskListenerInvocation)2 Element (org.camunda.bpm.engine.impl.util.xml.Element)2 Deployment (org.camunda.bpm.engine.test.Deployment)2 ArrayList (java.util.ArrayList)1 ProcessApplicationInterface (org.camunda.bpm.application.ProcessApplicationInterface)1 ProcessApplicationReference (org.camunda.bpm.application.ProcessApplicationReference)1 ProcessApplicationUnavailableException (org.camunda.bpm.application.ProcessApplicationUnavailableException)1 EmbeddedProcessApplication (org.camunda.bpm.application.impl.EmbeddedProcessApplication)1