From 04e2bfb43fb37b192134ab3fa6835ea06698870c Mon Sep 17 00:00:00 2001 From: Edoardo Vacchi Date: Mon, 11 Oct 2021 13:51:45 +0200 Subject: [PATCH] KOGITO-6085 Public API: Examples should use MapDataContext.of(Map) (#920) --- .../src/main/java/org/acme/CustomRestPrediction.java | 10 +++++++--- .../src/main/java/org/acme/CustomRestProcess.java | 3 ++- .../src/main/java/org/acme/CustomRestRules.java | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/pmml-incubation-api-quarkus/src/main/java/org/acme/CustomRestPrediction.java b/pmml-incubation-api-quarkus/src/main/java/org/acme/CustomRestPrediction.java index c74ac5c712..a9c9f363fe 100644 --- a/pmml-incubation-api-quarkus/src/main/java/org/acme/CustomRestPrediction.java +++ b/pmml-incubation-api-quarkus/src/main/java/org/acme/CustomRestPrediction.java @@ -15,6 +15,8 @@ */ package org.acme; +import java.util.Map; + import javax.inject.Inject; import javax.ws.rs.Consumes; import javax.ws.rs.POST; @@ -22,8 +24,9 @@ import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; -import org.kie.kogito.incubation.application.*; -import org.kie.kogito.incubation.common.*; +import org.kie.kogito.incubation.application.AppRoot; +import org.kie.kogito.incubation.common.DataContext; +import org.kie.kogito.incubation.common.MapDataContext; import org.kie.kogito.incubation.predictions.PredictionIds; import org.kie.kogito.incubation.predictions.services.PredictionService; @@ -38,12 +41,13 @@ public class CustomRestPrediction { @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) - public DataContext linearRegression(MapDataContext ctx) { + public DataContext linearRegression(Map payload) { // path: /predictions/LinReg var id = appRoot .get(PredictionIds.class) .get("LinReg"); + MapDataContext ctx = MapDataContext.of(payload); return svc.evaluate(id, ctx); } diff --git a/process-incubation-api-quarkus/src/main/java/org/acme/CustomRestProcess.java b/process-incubation-api-quarkus/src/main/java/org/acme/CustomRestProcess.java index 7882875656..2d6846e20a 100644 --- a/process-incubation-api-quarkus/src/main/java/org/acme/CustomRestProcess.java +++ b/process-incubation-api-quarkus/src/main/java/org/acme/CustomRestProcess.java @@ -45,6 +45,7 @@ public DataContext customProcessScripts(Map payload) { // path: /processes/scripts var id = appRoot.get(ProcessIds.class).get("scripts"); - return svc.evaluate(id, MapDataContext.from(payload)); + MapDataContext ctx = MapDataContext.of(payload); + return svc.evaluate(id, ctx); } } \ No newline at end of file diff --git a/rules-incubation-api-quarkus/src/main/java/org/acme/CustomRestRules.java b/rules-incubation-api-quarkus/src/main/java/org/acme/CustomRestRules.java index 5bc2461f41..923a30f4f5 100644 --- a/rules-incubation-api-quarkus/src/main/java/org/acme/CustomRestRules.java +++ b/rules-incubation-api-quarkus/src/main/java/org/acme/CustomRestRules.java @@ -50,7 +50,7 @@ public Stream helloUnit(Map payload) { .get(Hello.class) .queries() .get("hello"); - DataContext ctx = MapDataContext.from(payload); + DataContext ctx = MapDataContext.of(payload); return svc.evaluate(queryId, ctx) // Stream .map(dc -> dc.as(MapDataContext.class).get("$s", String.class)); }