Search in sources :

Example 1 with DelegateExpressionTaskListener

use of org.camunda.bpm.engine.impl.task.listener.DelegateExpressionTaskListener 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 2 with DelegateExpressionTaskListener

use of org.camunda.bpm.engine.impl.task.listener.DelegateExpressionTaskListener in project camunda-bpm-platform by camunda.

the class HumanTaskPlanItemHandlerTest method testCreateTaskListenerByDelegateExpression.

@Test
public void testCreateTaskListenerByDelegateExpression() {
    // given:
    ExtensionElements extensionElements = addExtensionElements(humanTask);
    CamundaTaskListener taskListener = createElement(extensionElements, null, CamundaTaskListener.class);
    String delegateExpression = "${myDelegateExpression}";
    String event = TaskListener.EVENTNAME_CREATE;
    taskListener.setCamundaEvent(event);
    taskListener.setCamundaDelegateExpression(delegateExpression);
    // when
    CmmnActivity activity = handler.handleElement(planItem, context);
    // then
    assertEquals(0, activity.getListeners().size());
    HumanTaskActivityBehavior behavior = (HumanTaskActivityBehavior) activity.getActivityBehavior();
    TaskDefinition taskDefinition = behavior.getTaskDefinition();
    assertNotNull(taskDefinition);
    assertEquals(1, taskDefinition.getTaskListeners().size());
    List<TaskListener> createListeners = taskDefinition.getTaskListeners(event);
    assertEquals(1, createListeners.size());
    TaskListener listener = createListeners.get(0);
    assertTrue(listener instanceof DelegateExpressionTaskListener);
    DelegateExpressionTaskListener delegateExpressionListener = (DelegateExpressionTaskListener) listener;
    assertEquals(delegateExpression, delegateExpressionListener.getExpressionText());
    assertTrue(delegateExpressionListener.getFieldDeclarations().isEmpty());
}
Also used : ExtensionElements(org.camunda.bpm.model.cmmn.instance.ExtensionElements) DelegateExpressionTaskListener(org.camunda.bpm.engine.impl.task.listener.DelegateExpressionTaskListener) TaskDefinition(org.camunda.bpm.engine.impl.task.TaskDefinition) 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) HumanTaskActivityBehavior(org.camunda.bpm.engine.impl.cmmn.behavior.HumanTaskActivityBehavior) CmmnActivity(org.camunda.bpm.engine.impl.cmmn.model.CmmnActivity) Test(org.junit.Test)

Example 3 with DelegateExpressionTaskListener

use of org.camunda.bpm.engine.impl.task.listener.DelegateExpressionTaskListener in project camunda-bpm-platform by camunda.

the class HumanTaskPlanItemHandlerTest method testDeleteTaskListenerByDelegateExpression.

@Test
public void testDeleteTaskListenerByDelegateExpression() {
    // given:
    ExtensionElements extensionElements = addExtensionElements(humanTask);
    CamundaTaskListener taskListener = createElement(extensionElements, null, CamundaTaskListener.class);
    String delegateExpression = "${myDelegateExpression}";
    String event = TaskListener.EVENTNAME_DELETE;
    taskListener.setCamundaEvent(event);
    taskListener.setCamundaDelegateExpression(delegateExpression);
    // when
    CmmnActivity activity = handler.handleElement(planItem, context);
    // then
    assertEquals(0, activity.getListeners().size());
    HumanTaskActivityBehavior behavior = (HumanTaskActivityBehavior) activity.getActivityBehavior();
    TaskDefinition taskDefinition = behavior.getTaskDefinition();
    assertNotNull(taskDefinition);
    assertEquals(1, taskDefinition.getTaskListeners().size());
    List<TaskListener> createListeners = taskDefinition.getTaskListeners(event);
    assertEquals(1, createListeners.size());
    TaskListener listener = createListeners.get(0);
    assertTrue(listener instanceof DelegateExpressionTaskListener);
    DelegateExpressionTaskListener delegateExpressionListener = (DelegateExpressionTaskListener) listener;
    assertEquals(delegateExpression, delegateExpressionListener.getExpressionText());
    assertTrue(delegateExpressionListener.getFieldDeclarations().isEmpty());
}
Also used : ExtensionElements(org.camunda.bpm.model.cmmn.instance.ExtensionElements) DelegateExpressionTaskListener(org.camunda.bpm.engine.impl.task.listener.DelegateExpressionTaskListener) TaskDefinition(org.camunda.bpm.engine.impl.task.TaskDefinition) 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) HumanTaskActivityBehavior(org.camunda.bpm.engine.impl.cmmn.behavior.HumanTaskActivityBehavior) CmmnActivity(org.camunda.bpm.engine.impl.cmmn.model.CmmnActivity) Test(org.junit.Test)

Example 4 with DelegateExpressionTaskListener

use of org.camunda.bpm.engine.impl.task.listener.DelegateExpressionTaskListener in project camunda-bpm-platform by camunda.

the class HumanTaskPlanItemHandlerTest method testAssignmentTaskListenerByDelegateExpression.

@Test
public void testAssignmentTaskListenerByDelegateExpression() {
    // given:
    ExtensionElements extensionElements = addExtensionElements(humanTask);
    CamundaTaskListener taskListener = createElement(extensionElements, null, CamundaTaskListener.class);
    String delegateExpression = "${myDelegateExpression}";
    String event = TaskListener.EVENTNAME_ASSIGNMENT;
    taskListener.setCamundaEvent(event);
    taskListener.setCamundaDelegateExpression(delegateExpression);
    // when
    CmmnActivity activity = handler.handleElement(planItem, context);
    // then
    assertEquals(0, activity.getListeners().size());
    HumanTaskActivityBehavior behavior = (HumanTaskActivityBehavior) activity.getActivityBehavior();
    TaskDefinition taskDefinition = behavior.getTaskDefinition();
    assertNotNull(taskDefinition);
    assertEquals(1, taskDefinition.getTaskListeners().size());
    List<TaskListener> createListeners = taskDefinition.getTaskListeners(event);
    assertEquals(1, createListeners.size());
    TaskListener listener = createListeners.get(0);
    assertTrue(listener instanceof DelegateExpressionTaskListener);
    DelegateExpressionTaskListener delegateExpressionListener = (DelegateExpressionTaskListener) listener;
    assertEquals(delegateExpression, delegateExpressionListener.getExpressionText());
    assertTrue(delegateExpressionListener.getFieldDeclarations().isEmpty());
}
Also used : ExtensionElements(org.camunda.bpm.model.cmmn.instance.ExtensionElements) DelegateExpressionTaskListener(org.camunda.bpm.engine.impl.task.listener.DelegateExpressionTaskListener) TaskDefinition(org.camunda.bpm.engine.impl.task.TaskDefinition) 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) HumanTaskActivityBehavior(org.camunda.bpm.engine.impl.cmmn.behavior.HumanTaskActivityBehavior) CmmnActivity(org.camunda.bpm.engine.impl.cmmn.model.CmmnActivity) Test(org.junit.Test)

Example 5 with DelegateExpressionTaskListener

use of org.camunda.bpm.engine.impl.task.listener.DelegateExpressionTaskListener in project camunda-bpm-platform by camunda.

the class HumanTaskPlanItemHandlerTest method testCompleteTaskListenerByDelegateExpression.

@Test
public void testCompleteTaskListenerByDelegateExpression() {
    // given:
    ExtensionElements extensionElements = addExtensionElements(humanTask);
    CamundaTaskListener taskListener = createElement(extensionElements, null, CamundaTaskListener.class);
    String delegateExpression = "${myDelegateExpression}";
    String event = TaskListener.EVENTNAME_COMPLETE;
    taskListener.setCamundaEvent(event);
    taskListener.setCamundaDelegateExpression(delegateExpression);
    // when
    CmmnActivity activity = handler.handleElement(planItem, context);
    // then
    assertEquals(0, activity.getListeners().size());
    HumanTaskActivityBehavior behavior = (HumanTaskActivityBehavior) activity.getActivityBehavior();
    TaskDefinition taskDefinition = behavior.getTaskDefinition();
    assertNotNull(taskDefinition);
    assertEquals(1, taskDefinition.getTaskListeners().size());
    List<TaskListener> createListeners = taskDefinition.getTaskListeners(event);
    assertEquals(1, createListeners.size());
    TaskListener listener = createListeners.get(0);
    assertTrue(listener instanceof DelegateExpressionTaskListener);
    DelegateExpressionTaskListener delegateExpressionListener = (DelegateExpressionTaskListener) listener;
    assertEquals(delegateExpression, delegateExpressionListener.getExpressionText());
    assertTrue(delegateExpressionListener.getFieldDeclarations().isEmpty());
}
Also used : ExtensionElements(org.camunda.bpm.model.cmmn.instance.ExtensionElements) DelegateExpressionTaskListener(org.camunda.bpm.engine.impl.task.listener.DelegateExpressionTaskListener) TaskDefinition(org.camunda.bpm.engine.impl.task.TaskDefinition) 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) HumanTaskActivityBehavior(org.camunda.bpm.engine.impl.cmmn.behavior.HumanTaskActivityBehavior) CmmnActivity(org.camunda.bpm.engine.impl.cmmn.model.CmmnActivity) Test(org.junit.Test)

Aggregations

TaskListener (org.camunda.bpm.engine.delegate.TaskListener)6 ClassDelegateTaskListener (org.camunda.bpm.engine.impl.task.listener.ClassDelegateTaskListener)6 DelegateExpressionTaskListener (org.camunda.bpm.engine.impl.task.listener.DelegateExpressionTaskListener)6 ExpressionTaskListener (org.camunda.bpm.engine.impl.task.listener.ExpressionTaskListener)6 CamundaTaskListener (org.camunda.bpm.model.cmmn.instance.camunda.CamundaTaskListener)5 HumanTaskActivityBehavior (org.camunda.bpm.engine.impl.cmmn.behavior.HumanTaskActivityBehavior)4 CmmnActivity (org.camunda.bpm.engine.impl.cmmn.model.CmmnActivity)4 TaskDefinition (org.camunda.bpm.engine.impl.task.TaskDefinition)4 ExtensionElements (org.camunda.bpm.model.cmmn.instance.ExtensionElements)4 Test (org.junit.Test)4 ExecutableScript (org.camunda.bpm.engine.impl.scripting.ExecutableScript)2 ScriptTaskListener (org.camunda.bpm.engine.impl.task.listener.ScriptTaskListener)2 BpmnParseException (org.camunda.bpm.engine.BpmnParseException)1 Expression (org.camunda.bpm.engine.delegate.Expression)1 FieldDeclaration (org.camunda.bpm.engine.impl.bpmn.parser.FieldDeclaration)1 ExpressionManager (org.camunda.bpm.engine.impl.el.ExpressionManager)1 Element (org.camunda.bpm.engine.impl.util.xml.Element)1 CamundaField (org.camunda.bpm.model.cmmn.instance.camunda.CamundaField)1 CamundaScript (org.camunda.bpm.model.cmmn.instance.camunda.CamundaScript)1