use of org.camunda.bpm.engine.delegate.VariableListener in project camunda-bpm-platform by camunda.
the class CmmnExecution method invokeVariableListeners.
protected void invokeVariableListeners(boolean includeCustomerListeners) {
Queue<VariableEvent> variableEventsQueue = getVariableEventQueue();
while (!variableEventsQueue.isEmpty()) {
// do not remove the event yet, as otherwise new events will immediately be dispatched
VariableEvent nextEvent = variableEventsQueue.peek();
CmmnExecution sourceExecution = (CmmnExecution) nextEvent.getSourceScope();
DelegateCaseVariableInstanceImpl delegateVariable = DelegateCaseVariableInstanceImpl.fromVariableInstance(nextEvent.getVariableInstance());
delegateVariable.setEventName(nextEvent.getEventName());
delegateVariable.setSourceExecution(sourceExecution);
Map<String, List<VariableListener<?>>> listenersByActivity = sourceExecution.getActivity().getVariableListeners(delegateVariable.getEventName(), includeCustomerListeners);
CmmnExecution currentExecution = sourceExecution;
while (currentExecution != null) {
if (currentExecution.getActivityId() != null) {
List<VariableListener<?>> listeners = listenersByActivity.get(currentExecution.getActivityId());
if (listeners != null) {
delegateVariable.setScopeExecution(currentExecution);
for (VariableListener<?> listener : listeners) {
try {
CaseVariableListener caseVariableListener = (CaseVariableListener) listener;
CaseVariableListenerInvocation invocation = new CaseVariableListenerInvocation(caseVariableListener, delegateVariable, currentExecution);
Context.getProcessEngineConfiguration().getDelegateInterceptor().handleInvocation(invocation);
} catch (Exception e) {
throw LOG.invokeVariableListenerException(e);
}
}
}
}
currentExecution = currentExecution.getParent();
}
// finally remove the event from the queue
variableEventsQueue.remove();
}
}
use of org.camunda.bpm.engine.delegate.VariableListener 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.engine.delegate.VariableListener 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.engine.delegate.VariableListener 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