Search in sources :

Example 1 with BufferUtil

use of io.camunda.zeebe.util.buffer.BufferUtil 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 BufferUtil

use of io.camunda.zeebe.util.buffer.BufferUtil in project zeebe by zeebe-io.

the class CatchEventAnalyzer method findCatchEvent.

public Either<Failure, CatchEventTuple> findCatchEvent(final DirectBuffer errorCode, ElementInstance instance, final Optional<DirectBuffer> jobErrorMessage) {
    // assuming that error events are used rarely
    // - just walk through the scope hierarchy and look for a matching catch event
    final ArrayList<DirectBuffer> availableCatchEvents = new ArrayList<>();
    while (instance != null && instance.isActive()) {
        final var instanceRecord = instance.getValue();
        final var process = getProcess(instanceRecord.getProcessDefinitionKey());
        final var found = findCatchEventInProcess(errorCode, process, instance);
        if (found.isRight()) {
            return Either.right(found.get());
        } else {
            availableCatchEvents.addAll(found.getLeft());
        }
        // find in parent process instance if exists
        final var parentElementInstanceKey = instanceRecord.getParentElementInstanceKey();
        instance = elementInstanceState.getInstance(parentElementInstanceKey);
    }
    final String incidentErrorMessage = String.format("Expected to throw an error event with the code '%s'%s, but it was not caught.%s", BufferUtil.bufferAsString(errorCode), jobErrorMessage.isPresent() && jobErrorMessage.get().capacity() > 0 ? String.format(" with message '%s'", BufferUtil.bufferAsString(jobErrorMessage.get())) : "", availableCatchEvents.isEmpty() ? " No error events are available in the scope." : String.format(" Available error events are [%s]", availableCatchEvents.stream().map(BufferUtil::bufferAsString).collect(Collectors.joining(", "))));
    // no matching catch event found
    return Either.left(new Failure(incidentErrorMessage, ErrorType.UNHANDLED_ERROR_EVENT));
}
Also used : DirectBuffer(org.agrona.DirectBuffer) BufferUtil(io.camunda.zeebe.util.buffer.BufferUtil) ArrayList(java.util.ArrayList) Failure(io.camunda.zeebe.engine.processing.common.Failure)

Example 3 with BufferUtil

use of io.camunda.zeebe.util.buffer.BufferUtil in project zeebe by camunda-cloud.

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 4 with BufferUtil

use of io.camunda.zeebe.util.buffer.BufferUtil in project zeebe by zeebe-io.

the class CatchEventBehavior method evaluateMessageName.

private Either<Failure, DirectBuffer> evaluateMessageName(final ExecutableCatchEvent event, final BpmnElementContext context) {
    if (!event.isMessage()) {
        return Either.right(null);
    }
    final var scopeKey = context.getElementInstanceKey();
    final ExecutableMessage message = event.getMessage();
    final Expression messageNameExpression = message.getMessageNameExpression();
    return expressionProcessor.evaluateStringExpression(messageNameExpression, scopeKey).map(BufferUtil::wrapString);
}
Also used : ExecutableMessage(io.camunda.zeebe.engine.processing.deployment.model.element.ExecutableMessage) BufferUtil(io.camunda.zeebe.util.buffer.BufferUtil) Expression(io.camunda.zeebe.el.Expression)

Example 5 with BufferUtil

use of io.camunda.zeebe.util.buffer.BufferUtil in project zeebe by zeebe-io.

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)

Aggregations

BufferUtil (io.camunda.zeebe.util.buffer.BufferUtil)9 Expression (io.camunda.zeebe.el.Expression)6 DirectBuffer (org.agrona.DirectBuffer)6 Failure (io.camunda.zeebe.engine.processing.common.Failure)3 ExecutableActivity (io.camunda.zeebe.engine.processing.deployment.model.element.ExecutableActivity)3 ExecutableFlowElementContainer (io.camunda.zeebe.engine.processing.deployment.model.element.ExecutableFlowElementContainer)3 ExecutableLoopCharacteristics (io.camunda.zeebe.engine.processing.deployment.model.element.ExecutableLoopCharacteristics)3 ExecutableMessage (io.camunda.zeebe.engine.processing.deployment.model.element.ExecutableMessage)3 ExecutableMultiInstanceBody (io.camunda.zeebe.engine.processing.deployment.model.element.ExecutableMultiInstanceBody)3 ExecutableProcess (io.camunda.zeebe.engine.processing.deployment.model.element.ExecutableProcess)3 ModelElementTransformer (io.camunda.zeebe.engine.processing.deployment.model.transformation.ModelElementTransformer)3 TransformContext (io.camunda.zeebe.engine.processing.deployment.model.transformation.TransformContext)3 Activity (io.camunda.zeebe.model.bpmn.instance.Activity)3 CompletionCondition (io.camunda.zeebe.model.bpmn.instance.CompletionCondition)3 LoopCharacteristics (io.camunda.zeebe.model.bpmn.instance.LoopCharacteristics)3 MultiInstanceLoopCharacteristics (io.camunda.zeebe.model.bpmn.instance.MultiInstanceLoopCharacteristics)3 ZeebeLoopCharacteristics (io.camunda.zeebe.model.bpmn.instance.zeebe.ZeebeLoopCharacteristics)3 BpmnElementType (io.camunda.zeebe.protocol.record.value.BpmnElementType)3 ArrayList (java.util.ArrayList)3 Collections (java.util.Collections)3