Search in sources :

Example 1 with CaseVariableListener

use of org.camunda.bpm.engine.delegate.CaseVariableListener 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);
            }
        }
    }
}
Also used : PlanItemDefinition(org.camunda.bpm.model.cmmn.instance.PlanItemDefinition) CamundaVariableListener(org.camunda.bpm.model.cmmn.instance.camunda.CamundaVariableListener) 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) CamundaString(org.camunda.bpm.model.cmmn.instance.camunda.CamundaString)

Example 2 with CaseVariableListener

use of org.camunda.bpm.engine.delegate.CaseVariableListener 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 3 with CaseVariableListener

use of org.camunda.bpm.engine.delegate.CaseVariableListener in project camunda-bpm-platform by camunda.

the class DelegateExpressionCaseVariableListener method notify.

public void notify(DelegateCaseVariableInstance variableInstance) throws Exception {
    Object delegate = expression.getValue(variableInstance.getSourceExecution());
    applyFieldDeclaration(fieldDeclarations, delegate);
    if (delegate instanceof CaseVariableListener) {
        CaseVariableListener listenerInstance = (CaseVariableListener) delegate;
        Context.getProcessEngineConfiguration().getDelegateInterceptor().handleInvocation(new CaseVariableListenerInvocation(listenerInstance, variableInstance));
    } else {
        throw new ProcessEngineException("Delegate expression " + expression + " did not resolve to an implementation of " + CaseVariableListener.class);
    }
}
Also used : CaseVariableListener(org.camunda.bpm.engine.delegate.CaseVariableListener) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 4 with CaseVariableListener

use of org.camunda.bpm.engine.delegate.CaseVariableListener in project camunda-bpm-platform by camunda.

the class ClassDelegateCaseVariableListener method notify.

public void notify(DelegateCaseVariableInstance variableInstance) throws Exception {
    CaseVariableListener variableListenerInstance = getVariableListenerInstance();
    Context.getProcessEngineConfiguration().getDelegateInterceptor().handleInvocation(new CaseVariableListenerInvocation(variableListenerInstance, variableInstance));
}
Also used : CaseVariableListener(org.camunda.bpm.engine.delegate.CaseVariableListener)

Example 5 with CaseVariableListener

use of org.camunda.bpm.engine.delegate.CaseVariableListener 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)5 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 ScriptCaseVariableListener (org.camunda.bpm.engine.impl.variable.listener.ScriptCaseVariableListener)2 CamundaString (org.camunda.bpm.model.cmmn.instance.camunda.CamundaString)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)1 Expression (org.camunda.bpm.engine.delegate.Expression)1 VariableListener (org.camunda.bpm.engine.delegate.VariableListener)1 FieldDeclaration (org.camunda.bpm.engine.impl.bpmn.parser.FieldDeclaration)1 VariableEvent (org.camunda.bpm.engine.impl.core.variable.event.VariableEvent)1 ExpressionManager (org.camunda.bpm.engine.impl.el.ExpressionManager)1 PvmException (org.camunda.bpm.engine.impl.pvm.PvmException)1 ExecutableScript (org.camunda.bpm.engine.impl.scripting.ExecutableScript)1 CaseVariableListenerInvocation (org.camunda.bpm.engine.impl.variable.listener.CaseVariableListenerInvocation)1 DelegateCaseVariableInstanceImpl (org.camunda.bpm.engine.impl.variable.listener.DelegateCaseVariableInstanceImpl)1 ConditionExpression (org.camunda.bpm.model.cmmn.instance.ConditionExpression)1