Search in sources :

Example 1 with ClassDelegateCaseVariableListener

use of org.camunda.bpm.engine.impl.variable.listener.ClassDelegateCaseVariableListener in project camunda-bpm-platform by camunda.

the class CaseVariableListenerHandlerTest method testClassDelegateHandling.

@Test
public void testClassDelegateHandling() {
    ExtensionElements extensionElements = SpecUtil.createElement(modelInstance, caseTask, null, ExtensionElements.class);
    CamundaVariableListener variableListener = SpecUtil.createElement(modelInstance, extensionElements, null, CamundaVariableListener.class);
    CamundaField field = SpecUtil.createElement(modelInstance, variableListener, null, CamundaField.class);
    field.setCamundaName("fieldName");
    field.setCamundaStringValue("a string value");
    variableListener.setCamundaClass("a.class.Name");
    // when
    CmmnActivity activity = handler.handleElement(planItem, context);
    List<VariableListener<?>> listeners = activity.getVariableListenersLocal(CaseVariableListener.CREATE);
    Assert.assertEquals(1, listeners.size());
    ClassDelegateCaseVariableListener listener = (ClassDelegateCaseVariableListener) listeners.get(0);
    Assert.assertEquals("a.class.Name", listener.getClassName());
    Assert.assertEquals(1, listener.getFieldDeclarations().size());
    Assert.assertEquals("fieldName", listener.getFieldDeclarations().get(0).getName());
    Object fieldValue = listener.getFieldDeclarations().get(0).getValue();
    assertTrue(fieldValue instanceof Expression);
    Expression expressionValue = (Expression) fieldValue;
    assertEquals("a string value", expressionValue.getExpressionText());
    Assert.assertEquals(listener, activity.getVariableListenersLocal(CaseVariableListener.UPDATE).get(0));
    Assert.assertEquals(listener, activity.getVariableListenersLocal(CaseVariableListener.DELETE).get(0));
}
Also used : ExtensionElements(org.camunda.bpm.model.cmmn.instance.ExtensionElements) CamundaField(org.camunda.bpm.model.cmmn.instance.camunda.CamundaField) CamundaVariableListener(org.camunda.bpm.model.cmmn.instance.camunda.CamundaVariableListener) CaseVariableListener(org.camunda.bpm.engine.delegate.CaseVariableListener) ExpressionCaseVariableListener(org.camunda.bpm.engine.impl.variable.listener.ExpressionCaseVariableListener) DelegateExpressionCaseVariableListener(org.camunda.bpm.engine.impl.variable.listener.DelegateExpressionCaseVariableListener) CamundaVariableListener(org.camunda.bpm.model.cmmn.instance.camunda.CamundaVariableListener) VariableListener(org.camunda.bpm.engine.delegate.VariableListener) ClassDelegateCaseVariableListener(org.camunda.bpm.engine.impl.variable.listener.ClassDelegateCaseVariableListener) Expression(org.camunda.bpm.engine.delegate.Expression) CmmnActivity(org.camunda.bpm.engine.impl.cmmn.model.CmmnActivity) ClassDelegateCaseVariableListener(org.camunda.bpm.engine.impl.variable.listener.ClassDelegateCaseVariableListener) Test(org.junit.Test)

Example 2 with ClassDelegateCaseVariableListener

use of org.camunda.bpm.engine.impl.variable.listener.ClassDelegateCaseVariableListener in project camunda-bpm-platform by camunda.

the class ItemHandler method initializeVariableListener.

protected CaseVariableListener initializeVariableListener(CmmnElement element, CmmnActivity activity, CmmnHandlerContext context, CamundaVariableListener listener) {
    Collection<CamundaField> fields = listener.getCamundaFields();
    List<FieldDeclaration> fieldDeclarations = initializeFieldDeclarations(element, activity, context, fields);
    ExpressionManager expressionManager = context.getExpressionManager();
    String className = listener.getCamundaClass();
    String expression = listener.getCamundaExpression();
    String delegateExpression = listener.getCamundaDelegateExpression();
    CamundaScript scriptElement = listener.getCamundaScript();
    CaseVariableListener variableListener = null;
    if (className != null) {
        variableListener = new ClassDelegateCaseVariableListener(className, fieldDeclarations);
    } else if (expression != null) {
        Expression expressionExp = expressionManager.createExpression(expression);
        variableListener = new ExpressionCaseVariableListener(expressionExp);
    } else if (delegateExpression != null) {
        Expression delegateExp = expressionManager.createExpression(delegateExpression);
        variableListener = new DelegateExpressionCaseVariableListener(delegateExp, fieldDeclarations);
    } else if (scriptElement != null) {
        ExecutableScript executableScript = initializeScript(element, activity, context, scriptElement);
        if (executableScript != null) {
            variableListener = new ScriptCaseVariableListener(executableScript);
        }
    }
    return variableListener;
}
Also used : CamundaField(org.camunda.bpm.model.cmmn.instance.camunda.CamundaField) ExpressionManager(org.camunda.bpm.engine.impl.el.ExpressionManager) ScriptCaseVariableListener(org.camunda.bpm.engine.impl.variable.listener.ScriptCaseVariableListener) DelegateExpressionCaseVariableListener(org.camunda.bpm.engine.impl.variable.listener.DelegateExpressionCaseVariableListener) CamundaString(org.camunda.bpm.model.cmmn.instance.camunda.CamundaString) ExpressionCaseVariableListener(org.camunda.bpm.engine.impl.variable.listener.ExpressionCaseVariableListener) DelegateExpressionCaseVariableListener(org.camunda.bpm.engine.impl.variable.listener.DelegateExpressionCaseVariableListener) CaseVariableListener(org.camunda.bpm.engine.delegate.CaseVariableListener) ScriptCaseVariableListener(org.camunda.bpm.engine.impl.variable.listener.ScriptCaseVariableListener) ClassDelegateCaseVariableListener(org.camunda.bpm.engine.impl.variable.listener.ClassDelegateCaseVariableListener) FieldDeclaration(org.camunda.bpm.engine.impl.bpmn.parser.FieldDeclaration) CamundaExpression(org.camunda.bpm.model.cmmn.instance.camunda.CamundaExpression) Expression(org.camunda.bpm.engine.delegate.Expression) ConditionExpression(org.camunda.bpm.model.cmmn.instance.ConditionExpression) ExecutableScript(org.camunda.bpm.engine.impl.scripting.ExecutableScript) ClassDelegateCaseVariableListener(org.camunda.bpm.engine.impl.variable.listener.ClassDelegateCaseVariableListener) ExpressionCaseVariableListener(org.camunda.bpm.engine.impl.variable.listener.ExpressionCaseVariableListener) DelegateExpressionCaseVariableListener(org.camunda.bpm.engine.impl.variable.listener.DelegateExpressionCaseVariableListener) CamundaScript(org.camunda.bpm.model.cmmn.instance.camunda.CamundaScript)

Aggregations

CaseVariableListener (org.camunda.bpm.engine.delegate.CaseVariableListener)2 Expression (org.camunda.bpm.engine.delegate.Expression)2 ClassDelegateCaseVariableListener (org.camunda.bpm.engine.impl.variable.listener.ClassDelegateCaseVariableListener)2 DelegateExpressionCaseVariableListener (org.camunda.bpm.engine.impl.variable.listener.DelegateExpressionCaseVariableListener)2 ExpressionCaseVariableListener (org.camunda.bpm.engine.impl.variable.listener.ExpressionCaseVariableListener)2 CamundaField (org.camunda.bpm.model.cmmn.instance.camunda.CamundaField)2 VariableListener (org.camunda.bpm.engine.delegate.VariableListener)1 FieldDeclaration (org.camunda.bpm.engine.impl.bpmn.parser.FieldDeclaration)1 CmmnActivity (org.camunda.bpm.engine.impl.cmmn.model.CmmnActivity)1 ExpressionManager (org.camunda.bpm.engine.impl.el.ExpressionManager)1 ExecutableScript (org.camunda.bpm.engine.impl.scripting.ExecutableScript)1 ScriptCaseVariableListener (org.camunda.bpm.engine.impl.variable.listener.ScriptCaseVariableListener)1 ConditionExpression (org.camunda.bpm.model.cmmn.instance.ConditionExpression)1 ExtensionElements (org.camunda.bpm.model.cmmn.instance.ExtensionElements)1 CamundaExpression (org.camunda.bpm.model.cmmn.instance.camunda.CamundaExpression)1 CamundaScript (org.camunda.bpm.model.cmmn.instance.camunda.CamundaScript)1 CamundaString (org.camunda.bpm.model.cmmn.instance.camunda.CamundaString)1 CamundaVariableListener (org.camunda.bpm.model.cmmn.instance.camunda.CamundaVariableListener)1 Test (org.junit.Test)1