Skip to content

Commit

Permalink
KOGITO-6085 Public API: Examples should use MapDataContext.of(Map) (#920
Browse files Browse the repository at this point in the history
)
  • Loading branch information
evacchi authored Oct 11, 2021
1 parent 44ae695 commit 04e2bfb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@
*/
package org.acme;

import java.util.Map;

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.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;

Expand All @@ -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<String, Object> payload) {
// path: /predictions/LinReg
var id = appRoot
.get(PredictionIds.class)
.get("LinReg");

MapDataContext ctx = MapDataContext.of(payload);
return svc.evaluate(id, ctx);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public DataContext customProcessScripts(Map<String, Object> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public Stream<String> helloUnit(Map<String, Object> payload) {
.get(Hello.class)
.queries()
.get("hello");
DataContext ctx = MapDataContext.from(payload);
DataContext ctx = MapDataContext.of(payload);
return svc.evaluate(queryId, ctx) // Stream<DataContext>
.map(dc -> dc.as(MapDataContext.class).get("$s", String.class));
}
Expand Down

0 comments on commit 04e2bfb

Please sign in to comment.