From ef21fd776ae3b7b97d68949bc20c1ab7e2dc42b4 Mon Sep 17 00:00:00 2001 From: Edoardo Vacchi Date: Thu, 7 Oct 2021 09:40:57 +0200 Subject: [PATCH 1/2] Incubation API should use MapDataContext.of(Map) --- .../main/java/org/acme/CustomRestPrediction.java | 15 +++++++++------ .../src/main/java/org/acme/CustomRestProcess.java | 3 ++- .../src/main/java/org/acme/CustomRestRules.java | 2 +- 3 files changed, 12 insertions(+), 8 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..c070978d21 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,17 +15,19 @@ */ package org.acme; +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; + import javax.inject.Inject; import javax.ws.rs.Consumes; import javax.ws.rs.POST; import javax.ws.rs.Path; 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.predictions.PredictionIds; -import org.kie.kogito.incubation.predictions.services.PredictionService; +import java.util.Map; @Path("/custom-rest-prediction") public class CustomRestPrediction { @@ -38,12 +40,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)); } From ef3737f3186b0fe3a3e1bda362d0d01a31e81db5 Mon Sep 17 00:00:00 2001 From: Edoardo Vacchi Date: Thu, 7 Oct 2021 09:44:10 +0200 Subject: [PATCH 2/2] formatting --- .../main/java/org/acme/CustomRestPrediction.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 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 c070978d21..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,11 +15,7 @@ */ package org.acme; -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; +import java.util.Map; import javax.inject.Inject; import javax.ws.rs.Consumes; @@ -27,7 +23,12 @@ import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; -import java.util.Map; + +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; @Path("/custom-rest-prediction") public class CustomRestPrediction {