Search in sources :

Example 1 with CamundaTaskListener

use of org.camunda.bpm.model.cmmn.instance.camunda.CamundaTaskListener in project camunda-cmmn-model by camunda.

the class CamundaTaskListenerImpl method registerType.

public static void registerType(ModelBuilder modelBuilder) {
    ModelElementTypeBuilder typeBuilder = modelBuilder.defineType(CamundaTaskListener.class, CAMUNDA_ELEMENT_TASK_LISTENER).namespaceUri(CAMUNDA_NS).instanceProvider(new ModelTypeInstanceProvider<CamundaTaskListener>() {

        public CamundaTaskListener newInstance(ModelTypeInstanceContext instanceContext) {
            return new CamundaTaskListenerImpl(instanceContext);
        }
    });
    camundaEventAttribute = typeBuilder.stringAttribute(CAMUNDA_ATTRIBUTE_EVENT).namespace(CAMUNDA_NS).build();
    camundaClassAttribute = typeBuilder.stringAttribute(CAMUNDA_ATTRIBUTE_CLASS).namespace(CAMUNDA_NS).build();
    camundaExpressionAttribute = typeBuilder.stringAttribute(CAMUNDA_ATTRIBUTE_EXPRESSION).namespace(CAMUNDA_NS).build();
    camundaDelegateExpressionAttribute = typeBuilder.stringAttribute(CAMUNDA_ATTRIBUTE_DELEGATE_EXPRESSION).namespace(CAMUNDA_NS).build();
    SequenceBuilder sequenceBuilder = typeBuilder.sequence();
    camundaFieldCollection = sequenceBuilder.elementCollection(CamundaField.class).build();
    camundaScriptChild = sequenceBuilder.element(CamundaScript.class).build();
    typeBuilder.build();
}
Also used : CamundaTaskListener(org.camunda.bpm.model.cmmn.instance.camunda.CamundaTaskListener) SequenceBuilder(org.camunda.bpm.model.xml.type.child.SequenceBuilder) ModelElementTypeBuilder(org.camunda.bpm.model.xml.type.ModelElementTypeBuilder) ModelTypeInstanceContext(org.camunda.bpm.model.xml.impl.instance.ModelTypeInstanceContext)

Example 2 with CamundaTaskListener

use of org.camunda.bpm.model.cmmn.instance.camunda.CamundaTaskListener 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 3 with CamundaTaskListener

use of org.camunda.bpm.model.cmmn.instance.camunda.CamundaTaskListener 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 4 with CamundaTaskListener

use of org.camunda.bpm.model.cmmn.instance.camunda.CamundaTaskListener in project camunda-bpm-platform by camunda.

the class HumanTaskPlanItemHandlerTest method testDeleteTaskListenerByExpression.

@Test
public void testDeleteTaskListenerByExpression() {
    // given:
    ExtensionElements extensionElements = addExtensionElements(humanTask);
    CamundaTaskListener taskListener = createElement(extensionElements, null, CamundaTaskListener.class);
    String expression = "${myExpression}";
    String event = TaskListener.EVENTNAME_DELETE;
    taskListener.setCamundaEvent(event);
    taskListener.setCamundaExpression(expression);
    // 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 ExpressionTaskListener);
    ExpressionTaskListener expressionListener = (ExpressionTaskListener) listener;
    assertEquals(expression, expressionListener.getExpressionText());
}
Also used : ExtensionElements(org.camunda.bpm.model.cmmn.instance.ExtensionElements) TaskDefinition(org.camunda.bpm.engine.impl.task.TaskDefinition) CamundaTaskListener(org.camunda.bpm.model.cmmn.instance.camunda.CamundaTaskListener) 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) 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 CamundaTaskListener

use of org.camunda.bpm.model.cmmn.instance.camunda.CamundaTaskListener in project camunda-bpm-platform by camunda.

the class HumanTaskPlanItemHandlerTest method testAssignmentTaskListenerByClass.

@Test
public void testAssignmentTaskListenerByClass() {
    // given:
    ExtensionElements extensionElements = addExtensionElements(humanTask);
    CamundaTaskListener taskListener = createElement(extensionElements, null, CamundaTaskListener.class);
    String className = "org.camunda.bpm.test.tasklistener.ABC";
    String event = TaskListener.EVENTNAME_ASSIGNMENT;
    taskListener.setCamundaEvent(event);
    taskListener.setCamundaClass(className);
    // 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 ClassDelegateTaskListener);
    ClassDelegateTaskListener classDelegateListener = (ClassDelegateTaskListener) listener;
    assertEquals(className, classDelegateListener.getClassName());
    assertTrue(classDelegateListener.getFieldDeclarations().isEmpty());
}
Also used : ExtensionElements(org.camunda.bpm.model.cmmn.instance.ExtensionElements) 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) ClassDelegateTaskListener(org.camunda.bpm.engine.impl.task.listener.ClassDelegateTaskListener) Test(org.junit.Test)

Aggregations

CamundaTaskListener (org.camunda.bpm.model.cmmn.instance.camunda.CamundaTaskListener)15 TaskListener (org.camunda.bpm.engine.delegate.TaskListener)14 ClassDelegateTaskListener (org.camunda.bpm.engine.impl.task.listener.ClassDelegateTaskListener)14 DelegateExpressionTaskListener (org.camunda.bpm.engine.impl.task.listener.DelegateExpressionTaskListener)14 ExpressionTaskListener (org.camunda.bpm.engine.impl.task.listener.ExpressionTaskListener)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)2 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 ExecutableScript (org.camunda.bpm.engine.impl.scripting.ExecutableScript)1 HumanTask (org.camunda.bpm.model.cmmn.instance.HumanTask)1 CamundaField (org.camunda.bpm.model.cmmn.instance.camunda.CamundaField)1 CamundaScript (org.camunda.bpm.model.cmmn.instance.camunda.CamundaScript)1 ModelTypeInstanceContext (org.camunda.bpm.model.xml.impl.instance.ModelTypeInstanceContext)1 ModelElementTypeBuilder (org.camunda.bpm.model.xml.type.ModelElementTypeBuilder)1