use of org.kie.kogito.decision.DecisionModel in project kogito-runtimes by kiegroup.
the class DecisionServiceImpl method evaluate.
@Override
public ExtendedDataContext evaluate(LocalId decisionId, DataContext inputContext) {
LocalDecisionId localDecisionId;
LocalDecisionServiceId decisionServiceId = null;
if (decisionId instanceof LocalDecisionId) {
localDecisionId = (LocalDecisionId) decisionId;
} else if (decisionId instanceof LocalDecisionServiceId) {
decisionServiceId = (LocalDecisionServiceId) decisionId;
localDecisionId = (LocalDecisionId) decisionServiceId.decisionId();
} else {
// LocalDecisionId.parse(decisionId);
throw new IllegalArgumentException("Not a valid decision id " + decisionId.toLocalId().asLocalUri());
}
DecisionModel decisionModel = decisionModels.getDecisionModel(localDecisionId.namespace(), localDecisionId.name());
ExtendedDataContext extendedDataContext = inputContext.as(ExtendedDataContext.class);
Map<String, Object> map = extendedDataContext.data().as(MapDataContext.class).toMap();
DMNContext ctx = DMNJSONUtils.ctx(decisionModel, map);
MetaDataContext inputMeta = extendedDataContext.meta();
MapDataContext mapInputMeta = MapDataContext.from(inputMeta);
DMNMetadata metadata = ctx.getMetadata();
for (Map.Entry<String, Object> kv : mapInputMeta.toMap().entrySet()) {
metadata.set(kv.getKey(), kv.getValue());
}
DMNResult dmnResult;
if (decisionServiceId == null) {
dmnResult = decisionModel.evaluateAll(ctx);
} else {
dmnResult = decisionModel.evaluateDecisionService(ctx, decisionServiceId.serviceId());
}
MapDataContext meta = MapDataContext.of(dmnResult.getContext().getMetadata().asMap());
MapDataContext data = MapDataContext.of(dmnResult.getContext().getAll());
return ExtendedDataContext.of(meta, data);
}
use of org.kie.kogito.decision.DecisionModel in project kogito-runtimes by kiegroup.
the class EventDrivenDecisionController method processRequest.
private EvaluationContext processRequest(EvaluationContext ctx) {
if (!ctx.isValidRequest()) {
ctx.setResponseError(DecisionResponseError.BAD_REQUEST);
return ctx;
}
Optional<DecisionModel> optDecisionModel = getDecisionModel(ctx.getRequestModelNamespace(), ctx.getRequestModelName());
if (!optDecisionModel.isPresent()) {
ctx.setResponseError(DecisionResponseError.MODEL_NOT_FOUND);
return ctx;
}
DecisionModel model = optDecisionModel.get();
DMNContext context = DMNJSONUtils.ctx(model, ctx.getRequestData());
DMNResult apiResult = ctx.isEvaluateDecisionServiceRequest() ? model.evaluateDecisionService(context, ctx.getRequestDecisionServiceToEvaluate()) : model.evaluateAll(context);
ctx.setResponseDmnResult(apiResult);
return ctx;
}
use of org.kie.kogito.decision.DecisionModel in project kogito-runtimes by kiegroup.
the class DecisionExplainabilityResourceExecutor method processRequest.
@Override
public PredictOutput processRequest(Application application, PredictInput predictInput) {
DecisionModel decisionModel = getDecisionModel(application.get(DecisionModels.class), predictInput.getModelIdentifier());
DMNContext dmnContext = decisionModel.newContext(convertDMNInput(predictInput));
dmnContext.getMetadata().set(SKIP_TRACING, true);
dmnContext.getMetadata().set(SKIP_MONITORING, true);
return convertDMNOutput(decisionModel.evaluateAll(dmnContext), predictInput);
}
Aggregations