use of org.camunda.bpm.model.cmmn.instance.camunda.CamundaVariableListener in project camunda-cmmn-model by camunda.
the class CamundaVariableListenerImpl method registerType.
public static void registerType(ModelBuilder modelBuilder) {
ModelElementTypeBuilder typeBuilder = modelBuilder.defineType(CamundaVariableListener.class, CAMUNDA_ELEMENT_VARIABLE_LISTENER).namespaceUri(CAMUNDA_NS).instanceProvider(new ModelTypeInstanceProvider<CamundaVariableListener>() {
public CamundaVariableListener newInstance(ModelTypeInstanceContext instanceContext) {
return new CamundaVariableListenerImpl(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();
}
use of org.camunda.bpm.model.cmmn.instance.camunda.CamundaVariableListener in project camunda-bpm-platform by camunda.
the class ItemHandler method initializeVariableListeners.
protected void initializeVariableListeners(CmmnElement element, CmmnActivity activity, CmmnHandlerContext context) {
PlanItemDefinition definition = getDefinition(element);
List<CamundaVariableListener> listeners = queryExtensionElementsByClass(definition, CamundaVariableListener.class);
for (CamundaVariableListener listener : listeners) {
CaseVariableListener variableListener = initializeVariableListener(element, activity, context, listener);
String eventName = listener.getCamundaEvent();
if (eventName != null) {
activity.addVariableListener(eventName, variableListener);
} else {
for (String event : DEFAULT_VARIABLE_EVENTS) {
activity.addVariableListener(event, variableListener);
}
}
}
}
use of org.camunda.bpm.model.cmmn.instance.camunda.CamundaVariableListener in project camunda-bpm-platform by camunda.
the class CaseVariableListenerHandlerTest method testDelegateExpressionDelegateHandling.
@Test
public void testDelegateExpressionDelegateHandling() {
ExtensionElements extensionElements = SpecUtil.createElement(modelInstance, caseTask, null, ExtensionElements.class);
CamundaVariableListener variableListener = SpecUtil.createElement(modelInstance, extensionElements, null, CamundaVariableListener.class);
variableListener.setCamundaDelegateExpression("${expression}");
variableListener.setCamundaEvent(CaseVariableListener.CREATE);
// when
CmmnActivity activity = handler.handleElement(planItem, context);
List<VariableListener<?>> listeners = activity.getVariableListenersLocal(CaseVariableListener.CREATE);
Assert.assertEquals(1, listeners.size());
DelegateExpressionCaseVariableListener listener = (DelegateExpressionCaseVariableListener) listeners.get(0);
Assert.assertEquals("${expression}", listener.getExpressionText());
Assert.assertEquals(0, activity.getVariableListenersLocal(CaseVariableListener.UPDATE).size());
Assert.assertEquals(0, activity.getVariableListenersLocal(CaseVariableListener.DELETE).size());
}
use of org.camunda.bpm.model.cmmn.instance.camunda.CamundaVariableListener 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));
}
use of org.camunda.bpm.model.cmmn.instance.camunda.CamundaVariableListener in project camunda-bpm-platform by camunda.
the class CaseVariableListenerHandlerTest method testExpressionDelegateHandling.
@Test
public void testExpressionDelegateHandling() {
ExtensionElements extensionElements = SpecUtil.createElement(modelInstance, caseTask, null, ExtensionElements.class);
CamundaVariableListener variableListener = SpecUtil.createElement(modelInstance, extensionElements, null, CamundaVariableListener.class);
variableListener.setCamundaExpression("${expression}");
variableListener.setCamundaEvent(CaseVariableListener.CREATE);
// when
CmmnActivity activity = handler.handleElement(planItem, context);
List<VariableListener<?>> listeners = activity.getVariableListenersLocal(CaseVariableListener.CREATE);
Assert.assertEquals(1, listeners.size());
ExpressionCaseVariableListener listener = (ExpressionCaseVariableListener) listeners.get(0);
Assert.assertEquals("${expression}", listener.getExpressionText());
Assert.assertEquals(0, activity.getVariableListenersLocal(CaseVariableListener.UPDATE).size());
Assert.assertEquals(0, activity.getVariableListenersLocal(CaseVariableListener.DELETE).size());
}
Aggregations