use of io.camunda.zeebe.engine.processing.bpmn.BpmnElementContext in project zeebe by zeebe-io.
the class BpmnDecisionBehavior method evaluateDecision.
/**
* Evaluate a decision during the processing of a bpmn element.
*
* @param element the called decision of the current bpmn element
* @param context process instance-related data of the element that is executed
* @return either an evaluated decision's result or a failure
*/
public Either<Failure, DecisionEvaluationResult> evaluateDecision(final ExecutableCalledDecision element, final BpmnElementContext context) {
final var scopeKey = context.getElementInstanceKey();
final var decisionIdOrFailure = evalDecisionIdExpression(element, scopeKey);
if (decisionIdOrFailure.isLeft()) {
return Either.left(decisionIdOrFailure.getLeft());
}
final var decisionId = decisionIdOrFailure.get();
// todo(#8571): avoid parsing drg every time
final var decisionOrFailure = findDecisionById(decisionId);
final var resultOrFailure = decisionOrFailure.flatMap(this::findDrgByDecision).mapLeft(failure -> new Failure("Expected to evaluate decision '%s', but %s".formatted(decisionId, failure.getMessage()))).flatMap(drg -> parseDrg(drg.getResource())).mapLeft(f -> new Failure(f.getMessage(), ErrorType.CALLED_DECISION_ERROR, scopeKey)).flatMap(drg -> {
final var evaluationResult = evaluateDecisionInDrg(drg, decisionId, scopeKey);
final var decision = decisionOrFailure.get();
writeDecisionEvaluationEvent(decision, evaluationResult, context);
if (evaluationResult.isFailure()) {
metrics.increaseFailedEvaluatedDmnElements(evaluationResult.getEvaluatedDecisions().size());
return Either.left(new Failure(evaluationResult.getFailureMessage(), ErrorType.DECISION_EVALUATION_ERROR, scopeKey));
} else {
metrics.increaseSuccessfullyEvaluatedDmnElements(evaluationResult.getEvaluatedDecisions().size());
return Either.right(evaluationResult);
}
});
resultOrFailure.ifRight(result -> {
// The output mapping behavior determines what to do with the decision result. Since the
// output mapping may fail and raise an incident, we need to write the variable to a
// record. This is because we want to evaluate the decision on element activation, while
// the output mapping happens on element completion. We don't want to re-evaluate the
// decision for output mapping related incidents.
triggerProcessEventWithResultVariable(context, element.getResultVariable(), result);
});
return resultOrFailure;
}
use of io.camunda.zeebe.engine.processing.bpmn.BpmnElementContext in project zeebe by camunda.
the class BpmnStateTransitionBehavior method takeSequenceFlow.
public void takeSequenceFlow(final BpmnElementContext context, final ExecutableSequenceFlow sequenceFlow) {
verifyTransition(context, ProcessInstanceIntent.SEQUENCE_FLOW_TAKEN);
final var target = sequenceFlow.getTarget();
followUpInstanceRecord.wrap(context.getRecordValue());
followUpInstanceRecord.setElementId(sequenceFlow.getId()).setBpmnElementType(sequenceFlow.getElementType());
// take the sequence flow
final var sequenceFlowKey = keyGenerator.nextKey();
stateWriter.appendFollowUpEvent(sequenceFlowKey, ProcessInstanceIntent.SEQUENCE_FLOW_TAKEN, followUpInstanceRecord);
final BpmnElementContext sequenceFlowTaken = context.copy(sequenceFlowKey, followUpInstanceRecord, ProcessInstanceIntent.SEQUENCE_FLOW_TAKEN);
if (canActivateTargetElement(context, target)) {
activateElementInstanceInFlowScope(sequenceFlowTaken, target);
}
}
use of io.camunda.zeebe.engine.processing.bpmn.BpmnElementContext in project zeebe by camunda.
the class SubProcessProcessor method onActivate.
@Override
public void onActivate(final ExecutableFlowElementContainer element, final BpmnElementContext activating) {
variableMappingBehavior.applyInputMappings(activating, element).flatMap(ok -> eventSubscriptionBehavior.subscribeToEvents(element, activating)).ifRightOrLeft(ok -> {
final var activated = stateTransitionBehavior.transitionToActivated(activating);
final ExecutableStartEvent startEvent = element.getNoneStartEvent();
if (startEvent == null) {
throw new BpmnProcessingException(activated, NO_NONE_START_EVENT_ERROR_MSG);
}
stateTransitionBehavior.activateChildInstance(activated, startEvent);
}, failure -> incidentBehavior.createIncident(failure, activating));
}
use of io.camunda.zeebe.engine.processing.bpmn.BpmnElementContext in project zeebe by zeebe-io.
the class StartEventProcessor method onComplete.
@Override
public void onComplete(final ExecutableStartEvent element, final BpmnElementContext context) {
final var flowScope = (ExecutableCatchEventSupplier) element.getFlowScope();
final BpmnElementContextImpl flowScopeInstanceContext = buildContextForFlowScopeInstance(context);
variableMappingBehavior.applyOutputMappings(context, element).flatMap(ok -> eventSubscriptionBehavior.subscribeToEvents(flowScope, flowScopeInstanceContext)).flatMap(ok -> stateTransitionBehavior.transitionToCompleted(element, context)).ifRightOrLeft(completed -> stateTransitionBehavior.takeOutgoingSequenceFlows(element, completed), failure -> incidentBehavior.createIncident(failure, context));
}
use of io.camunda.zeebe.engine.processing.bpmn.BpmnElementContext in project zeebe by zeebe-io.
the class BpmnStateTransitionBehavior method getParentProcessScope.
private ExecutableCallActivity getParentProcessScope(final BpmnElementContext callActivityContext, final BpmnElementContext childContext) {
final var processDefinitionKey = callActivityContext.getProcessDefinitionKey();
final var elementId = callActivityContext.getElementId();
return stateBehavior.getProcess(processDefinitionKey).map(DeployedProcess::getProcess).map(process -> process.getElementById(elementId, BpmnElementType.CALL_ACTIVITY, ExecutableCallActivity.class)).orElseThrow(() -> new BpmnProcessingException(childContext, String.format(NO_PROCESS_FOUND_MESSAGE, processDefinitionKey)));
}
Aggregations