use of io.camunda.zeebe.protocol.record.intent.DecisionEvaluationIntent in project zeebe by zeebe-io.
the class BpmnDecisionBehavior method writeDecisionEvaluationEvent.
private void writeDecisionEvaluationEvent(final PersistedDecision decision, final DecisionEvaluationResult decisionResult, final BpmnElementContext context) {
final var decisionEvaluationEvent = new DecisionEvaluationRecord().setDecisionKey(decision.getDecisionKey()).setDecisionId(decision.getDecisionId()).setDecisionName(decision.getDecisionName()).setDecisionVersion(decision.getVersion()).setDecisionRequirementsKey(decision.getDecisionRequirementsKey()).setDecisionRequirementsId(decision.getDecisionRequirementsId()).setProcessDefinitionKey(context.getProcessDefinitionKey()).setBpmnProcessId(context.getBpmnProcessId()).setProcessInstanceKey(context.getProcessInstanceKey()).setElementInstanceKey(context.getElementInstanceKey()).setElementId(context.getElementId());
final var decisionKeysByDecisionId = decisionState.findDecisionsByDecisionRequirementsKey(decision.getDecisionRequirementsKey()).stream().collect(Collectors.toMap(persistedDecision -> bufferAsString(persistedDecision.getDecisionId()), PersistedDecision::getDecisionKey));
decisionResult.getEvaluatedDecisions().forEach(evaluatedDecision -> addDecisionToEvaluationEvent(evaluatedDecision, decisionKeysByDecisionId.getOrDefault(evaluatedDecision.decisionId(), UNKNOWN_DECISION_KEY), decisionEvaluationEvent));
final DecisionEvaluationIntent decisionEvaluationIntent;
if (decisionResult.isFailure()) {
decisionEvaluationIntent = DecisionEvaluationIntent.FAILED;
decisionEvaluationEvent.setEvaluationFailureMessage(decisionResult.getFailureMessage()).setFailedDecisionId(decisionResult.getFailedDecisionId());
} else {
decisionEvaluationIntent = DecisionEvaluationIntent.EVALUATED;
decisionEvaluationEvent.setDecisionOutput(decisionResult.getOutput());
}
final var newDecisionEvaluationKey = keyGenerator.nextKey();
stateWriter.appendFollowUpEvent(newDecisionEvaluationKey, decisionEvaluationIntent, decisionEvaluationEvent);
}
Aggregations