Search in sources :

Example 1 with VariableListener

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();
    }
}
Also used : DelegateCaseVariableInstanceImpl(org.camunda.bpm.engine.impl.variable.listener.DelegateCaseVariableInstanceImpl) CaseVariableListener(org.camunda.bpm.engine.delegate.CaseVariableListener) VariableListener(org.camunda.bpm.engine.delegate.VariableListener) CaseVariableListener(org.camunda.bpm.engine.delegate.CaseVariableListener) PvmException(org.camunda.bpm.engine.impl.pvm.PvmException) VariableEvent(org.camunda.bpm.engine.impl.core.variable.event.VariableEvent) CaseVariableListenerInvocation(org.camunda.bpm.engine.impl.variable.listener.CaseVariableListenerInvocation) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList)

Example 2 with VariableListener

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());
}
Also used : ExtensionElements(org.camunda.bpm.model.cmmn.instance.ExtensionElements) 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) DelegateExpressionCaseVariableListener(org.camunda.bpm.engine.impl.variable.listener.DelegateExpressionCaseVariableListener) CmmnActivity(org.camunda.bpm.engine.impl.cmmn.model.CmmnActivity) Test(org.junit.Test)

Example 3 with VariableListener

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));
}
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 4 with VariableListener

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());
}
Also used : ExtensionElements(org.camunda.bpm.model.cmmn.instance.ExtensionElements) 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) CmmnActivity(org.camunda.bpm.engine.impl.cmmn.model.CmmnActivity) ExpressionCaseVariableListener(org.camunda.bpm.engine.impl.variable.listener.ExpressionCaseVariableListener) DelegateExpressionCaseVariableListener(org.camunda.bpm.engine.impl.variable.listener.DelegateExpressionCaseVariableListener) Test(org.junit.Test)

Aggregations

CaseVariableListener (org.camunda.bpm.engine.delegate.CaseVariableListener)4 VariableListener (org.camunda.bpm.engine.delegate.VariableListener)4 CmmnActivity (org.camunda.bpm.engine.impl.cmmn.model.CmmnActivity)3 ClassDelegateCaseVariableListener (org.camunda.bpm.engine.impl.variable.listener.ClassDelegateCaseVariableListener)3 DelegateExpressionCaseVariableListener (org.camunda.bpm.engine.impl.variable.listener.DelegateExpressionCaseVariableListener)3 ExpressionCaseVariableListener (org.camunda.bpm.engine.impl.variable.listener.ExpressionCaseVariableListener)3 ExtensionElements (org.camunda.bpm.model.cmmn.instance.ExtensionElements)3 CamundaVariableListener (org.camunda.bpm.model.cmmn.instance.camunda.CamundaVariableListener)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Expression (org.camunda.bpm.engine.delegate.Expression)1 VariableEvent (org.camunda.bpm.engine.impl.core.variable.event.VariableEvent)1 PvmException (org.camunda.bpm.engine.impl.pvm.PvmException)1 CaseVariableListenerInvocation (org.camunda.bpm.engine.impl.variable.listener.CaseVariableListenerInvocation)1 DelegateCaseVariableInstanceImpl (org.camunda.bpm.engine.impl.variable.listener.DelegateCaseVariableInstanceImpl)1 CamundaField (org.camunda.bpm.model.cmmn.instance.camunda.CamundaField)1