Search in sources :

Example 1 with Expression

use of io.camunda.zeebe.el.Expression in project zeebe by camunda.

the class MultiInstanceActivityTransformer method transformLoopCharacteristics.

private ExecutableLoopCharacteristics transformLoopCharacteristics(final TransformContext context, final MultiInstanceLoopCharacteristics elementLoopCharacteristics) {
    final boolean isSequential = elementLoopCharacteristics.isSequential();
    final Optional<Expression> completionCondition = Optional.ofNullable(elementLoopCharacteristics.getCompletionCondition()).map(CompletionCondition::getTextContent).filter(e -> !e.isEmpty()).map(context.getExpressionLanguage()::parseExpression);
    final ZeebeLoopCharacteristics zeebeLoopCharacteristics = elementLoopCharacteristics.getSingleExtensionElement(ZeebeLoopCharacteristics.class);
    final Expression inputCollection = context.getExpressionLanguage().parseExpression(zeebeLoopCharacteristics.getInputCollection());
    final Optional<DirectBuffer> inputElement = Optional.ofNullable(zeebeLoopCharacteristics.getInputElement()).filter(e -> !e.isEmpty()).map(BufferUtil::wrapString);
    final Optional<DirectBuffer> outputCollection = Optional.ofNullable(zeebeLoopCharacteristics.getOutputCollection()).filter(e -> !e.isEmpty()).map(BufferUtil::wrapString);
    final Optional<Expression> outputElement = Optional.ofNullable(zeebeLoopCharacteristics.getOutputElement()).filter(e -> !e.isEmpty()).map(e -> context.getExpressionLanguage().parseExpression(e));
    return new ExecutableLoopCharacteristics(isSequential, completionCondition, inputCollection, inputElement, outputCollection, outputElement);
}
Also used : CompletionCondition(io.camunda.zeebe.model.bpmn.instance.CompletionCondition) LoopCharacteristics(io.camunda.zeebe.model.bpmn.instance.LoopCharacteristics) ExecutableMultiInstanceBody(io.camunda.zeebe.engine.processing.deployment.model.element.ExecutableMultiInstanceBody) ExecutableProcess(io.camunda.zeebe.engine.processing.deployment.model.element.ExecutableProcess) ExecutableLoopCharacteristics(io.camunda.zeebe.engine.processing.deployment.model.element.ExecutableLoopCharacteristics) ModelElementTransformer(io.camunda.zeebe.engine.processing.deployment.model.transformation.ModelElementTransformer) ExecutableFlowElementContainer(io.camunda.zeebe.engine.processing.deployment.model.element.ExecutableFlowElementContainer) MultiInstanceLoopCharacteristics(io.camunda.zeebe.model.bpmn.instance.MultiInstanceLoopCharacteristics) ZeebeLoopCharacteristics(io.camunda.zeebe.model.bpmn.instance.zeebe.ZeebeLoopCharacteristics) TransformContext(io.camunda.zeebe.engine.processing.deployment.model.transformation.TransformContext) BpmnElementType(io.camunda.zeebe.protocol.record.value.BpmnElementType) ExecutableActivity(io.camunda.zeebe.engine.processing.deployment.model.element.ExecutableActivity) Expression(io.camunda.zeebe.el.Expression) Optional(java.util.Optional) Activity(io.camunda.zeebe.model.bpmn.instance.Activity) Collections(java.util.Collections) BufferUtil(io.camunda.zeebe.util.buffer.BufferUtil) DirectBuffer(org.agrona.DirectBuffer) DirectBuffer(org.agrona.DirectBuffer) CompletionCondition(io.camunda.zeebe.model.bpmn.instance.CompletionCondition) BufferUtil(io.camunda.zeebe.util.buffer.BufferUtil) ZeebeLoopCharacteristics(io.camunda.zeebe.model.bpmn.instance.zeebe.ZeebeLoopCharacteristics) Expression(io.camunda.zeebe.el.Expression) ExecutableLoopCharacteristics(io.camunda.zeebe.engine.processing.deployment.model.element.ExecutableLoopCharacteristics)

Example 2 with Expression

use of io.camunda.zeebe.el.Expression in project zeebe by camunda.

the class BpmnVariableMappingBehavior method applyOutputMappings.

/**
 * Apply the output mappings for a BPMN element. Generally called on completing of the element.
 *
 * @param context The current bpmn element context
 * @param element The current bpmn element
 * @return either void if successful, otherwise a failure
 */
public Either<Failure, Void> applyOutputMappings(final BpmnElementContext context, final ExecutableFlowNode element) {
    final ProcessInstanceRecord record = context.getRecordValue();
    final long elementInstanceKey = context.getElementInstanceKey();
    final long processDefinitionKey = record.getProcessDefinitionKey();
    final long processInstanceKey = record.getProcessInstanceKey();
    final DirectBuffer bpmnProcessId = context.getBpmnProcessId();
    final long scopeKey = getVariableScopeKey(context);
    final Optional<Expression> outputMappingExpression = element.getOutputMappings();
    final EventTrigger eventTrigger = eventScopeInstanceState.peekEventTrigger(elementInstanceKey);
    boolean hasVariables = false;
    DirectBuffer variables = null;
    if (eventTrigger != null) {
        variables = eventTrigger.getVariables();
        hasVariables = variables.capacity() > 0;
    }
    if (outputMappingExpression.isPresent()) {
        // set as local variables
        if (hasVariables) {
            variableBehavior.mergeLocalDocument(elementInstanceKey, processDefinitionKey, processInstanceKey, bpmnProcessId, variables);
        }
        // apply the output mappings
        return expressionProcessor.evaluateVariableMappingExpression(outputMappingExpression.get(), elementInstanceKey).map(result -> {
            variableBehavior.mergeDocument(scopeKey, processDefinitionKey, processInstanceKey, bpmnProcessId, result);
            return null;
        });
    } else if (hasVariables) {
        // merge/propagate the event variables by default
        variableBehavior.mergeDocument(elementInstanceKey, processDefinitionKey, processInstanceKey, bpmnProcessId, variables);
    } else if (isConnectedToEventBasedGateway(element) || element.getElementType() == BpmnElementType.BOUNDARY_EVENT || element.getElementType() == BpmnElementType.START_EVENT) {
        // event variables are set local variables instead of temporary variables
        final var localVariables = variablesState.getVariablesLocalAsDocument(elementInstanceKey);
        variableBehavior.mergeDocument(scopeKey, processDefinitionKey, processInstanceKey, bpmnProcessId, localVariables);
    }
    return Either.right(null);
}
Also used : DirectBuffer(org.agrona.DirectBuffer) Expression(io.camunda.zeebe.el.Expression) ProcessInstanceRecord(io.camunda.zeebe.protocol.impl.record.value.processinstance.ProcessInstanceRecord) EventTrigger(io.camunda.zeebe.engine.state.instance.EventTrigger)

Example 3 with Expression

use of io.camunda.zeebe.el.Expression in project zeebe by camunda.

the class BpmnVariableMappingBehavior method applyInputMappings.

/**
 * Apply the input mappings for a BPMN element. Generally called on activating of the element.
 *
 * @param context The current bpmn element context
 * @param element The current bpmn element
 * @return either void if successful, otherwise a failure
 */
public Either<Failure, Void> applyInputMappings(final BpmnElementContext context, final ExecutableFlowNode element) {
    final long scopeKey = context.getElementInstanceKey();
    final long processDefinitionKey = context.getProcessDefinitionKey();
    final long processInstanceKey = context.getProcessInstanceKey();
    final DirectBuffer bpmnProcessId = context.getBpmnProcessId();
    final Optional<Expression> inputMappingExpression = element.getInputMappings();
    if (inputMappingExpression.isPresent()) {
        return expressionProcessor.evaluateVariableMappingExpression(inputMappingExpression.get(), scopeKey).map(result -> {
            variableBehavior.mergeLocalDocument(scopeKey, processDefinitionKey, processInstanceKey, bpmnProcessId, result);
            return null;
        });
    }
    return Either.right(null);
}
Also used : DirectBuffer(org.agrona.DirectBuffer) Expression(io.camunda.zeebe.el.Expression)

Example 4 with Expression

use of io.camunda.zeebe.el.Expression in project zeebe by zeebe-io.

the class MessageTransformer method transform.

@Override
public void transform(final Message element, final TransformContext context) {
    final String id = element.getId();
    final ExpressionLanguage expressionLanguage = context.getExpressionLanguage();
    final ExecutableMessage executableElement = new ExecutableMessage(id);
    final ExtensionElements extensionElements = element.getExtensionElements();
    if (extensionElements != null) {
        final ZeebeSubscription subscription = extensionElements.getElementsQuery().filterByType(ZeebeSubscription.class).singleResult();
        final Expression correlationKeyExpression = expressionLanguage.parseExpression(subscription.getCorrelationKey());
        executableElement.setCorrelationKeyExpression(correlationKeyExpression);
    }
    if (element.getName() != null) {
        final Expression messageNameExpression = expressionLanguage.parseExpression(element.getName());
        executableElement.setMessageNameExpression(messageNameExpression);
        if (messageNameExpression.isStatic()) {
            final EvaluationResult messageNameResult = expressionLanguage.evaluateExpression(messageNameExpression, variable -> null);
            if (messageNameResult.getType() == ResultType.STRING) {
                final String messageName = messageNameResult.getString();
                executableElement.setMessageName(messageName);
            }
        }
        context.addMessage(executableElement);
    }
}
Also used : ExecutableMessage(io.camunda.zeebe.engine.processing.deployment.model.element.ExecutableMessage) ExtensionElements(io.camunda.zeebe.model.bpmn.instance.ExtensionElements) ZeebeSubscription(io.camunda.zeebe.model.bpmn.instance.zeebe.ZeebeSubscription) Expression(io.camunda.zeebe.el.Expression) ExpressionLanguage(io.camunda.zeebe.el.ExpressionLanguage) EvaluationResult(io.camunda.zeebe.el.EvaluationResult)

Example 5 with Expression

use of io.camunda.zeebe.el.Expression in project zeebe by zeebe-io.

the class SequenceFlowTransformer method parseCondition.

private void parseCondition(final SequenceFlow element, final ExecutableSequenceFlow sequenceFlow, final ExpressionLanguage expressionLanguage) {
    final ConditionExpression conditionExpression = element.getConditionExpression();
    if (conditionExpression != null) {
        final String condition = conditionExpression.getTextContent();
        final Expression parsedCondition = expressionLanguage.parseExpression(condition);
        sequenceFlow.setCondition(parsedCondition);
    }
}
Also used : ConditionExpression(io.camunda.zeebe.model.bpmn.instance.ConditionExpression) Expression(io.camunda.zeebe.el.Expression) ConditionExpression(io.camunda.zeebe.model.bpmn.instance.ConditionExpression)

Aggregations

Expression (io.camunda.zeebe.el.Expression)30 ExpressionLanguage (io.camunda.zeebe.el.ExpressionLanguage)9 ExecutableMessage (io.camunda.zeebe.engine.processing.deployment.model.element.ExecutableMessage)9 DirectBuffer (org.agrona.DirectBuffer)9 EvaluationResult (io.camunda.zeebe.el.EvaluationResult)6 Failure (io.camunda.zeebe.engine.processing.common.Failure)6 ExecutableProcess (io.camunda.zeebe.engine.processing.deployment.model.element.ExecutableProcess)6 ModelElementTransformer (io.camunda.zeebe.engine.processing.deployment.model.transformation.ModelElementTransformer)6 TransformContext (io.camunda.zeebe.engine.processing.deployment.model.transformation.TransformContext)6 Message (io.camunda.zeebe.model.bpmn.instance.Message)6 BufferUtil (io.camunda.zeebe.util.buffer.BufferUtil)6 ExecutableActivity (io.camunda.zeebe.engine.processing.deployment.model.element.ExecutableActivity)3 ExecutableCatchEventElement (io.camunda.zeebe.engine.processing.deployment.model.element.ExecutableCatchEventElement)3 ExecutableFlowElementContainer (io.camunda.zeebe.engine.processing.deployment.model.element.ExecutableFlowElementContainer)3 ExecutableLoopCharacteristics (io.camunda.zeebe.engine.processing.deployment.model.element.ExecutableLoopCharacteristics)3 ExecutableMultiInstanceBody (io.camunda.zeebe.engine.processing.deployment.model.element.ExecutableMultiInstanceBody)3 ExecutableSequenceFlow (io.camunda.zeebe.engine.processing.deployment.model.element.ExecutableSequenceFlow)3 JobWorkerProperties (io.camunda.zeebe.engine.processing.deployment.model.element.JobWorkerProperties)3 EventTrigger (io.camunda.zeebe.engine.state.instance.EventTrigger)3 Activity (io.camunda.zeebe.model.bpmn.instance.Activity)3