use of org.kie.server.api.model.dmn.DMNContextKS in project droolsjbpm-integration by kiegroup.
the class DecisionMarshallingTest method testMarshalling.
@Test
public void testMarshalling() {
KieSession kieSession = new KieHelper().addFromClassPath("/FunctionDefinition.dmn").build().newKieSession();
DMNRuntime dmnRuntime = kieSession.getKieRuntime(DMNRuntime.class);
DMNModel model = dmnRuntime.getModels().get(0);
DMNContext realCtx = dmnRuntime.newContext();
realCtx.set("a", 10);
realCtx.set("b", 5);
DMNContextKS dmnClientRequest = new DMNContextKS(realCtx.getAll());
DMNContextKS mu_dmnClientRequest = marshallUnmarshall(dmnClientRequest);
assertEquals(dmnClientRequest.getNamespace(), mu_dmnClientRequest.getNamespace());
assertEquals(dmnClientRequest.getModelName(), mu_dmnClientRequest.getModelName());
assertThat(dmnClientRequest.getDecisionNames(), is(mu_dmnClientRequest.getDecisionNames()));
assertEquals(dmnClientRequest.getDmnContext().size(), mu_dmnClientRequest.getDmnContext().size());
assertEquals(dmnClientRequest.getDmnContext().keySet(), mu_dmnClientRequest.getDmnContext().keySet());
DMNResult evaluateAll = dmnRuntime.evaluateAll(model, realCtx);
ServiceResponse<DMNResultKS> dmnClientResponse = new ServiceResponse<DMNResultKS>(ServiceResponse.ResponseType.SUCCESS, "Test case", new DMNResultKS(model.getNamespace(), model.getName(), dmnClientRequest.getDecisionNames(), evaluateAll));
ServiceResponse<DMNResultKS> mu_dmnClientResponse = marshallUnmarshall(dmnClientResponse);
assertEquals(dmnClientResponse.getResult().getNamespace(), mu_dmnClientResponse.getResult().getNamespace());
assertEquals(dmnClientResponse.getResult().getModelName(), mu_dmnClientResponse.getResult().getModelName());
assertThat(dmnClientResponse.getResult().getDecisionNames(), is(mu_dmnClientResponse.getResult().getDecisionNames()));
assertEquals(dmnClientResponse.getResult().getDmnContext().size(), mu_dmnClientResponse.getResult().getDmnContext().size());
assertEquals(dmnClientResponse.getResult().getDmnContext().keySet(), mu_dmnClientResponse.getResult().getDmnContext().keySet());
}
use of org.kie.server.api.model.dmn.DMNContextKS in project droolsjbpm-integration by kiegroup.
the class DMNContextKSMarshallingTest method testXStreamUnmarshalling.
@Test
public void testXStreamUnmarshalling() {
final DMNContextKS result = xStreamMarshaller.unmarshall(XSTREAM, DMNContextKS.class);
checkBean(result);
}
use of org.kie.server.api.model.dmn.DMNContextKS in project droolsjbpm-integration by kiegroup.
the class DMNContextKSMarshallingTest method setup.
@BeforeClass
public static void setup() {
BEAN = new DMNContextKS();
BEAN.setNamespace(NAMESPACE);
BEAN.setModelName(MODEL_NAME);
BEAN.setDecisionIds(Collections.singletonList(DECISION_ID));
BEAN.setDecisionNames(Collections.singletonList(DECISION_NAME));
BEAN.setDecisionServiceName(DECISION_SERVICE_NAME);
BEAN.setDmnContext(Collections.singletonMap(DMN_CONTEXT_KEY, DMN_CONTEXT_VALUE));
XSTREAM = "<dmn-evaluation-context>\n" + " <model-namespace>foo</model-namespace>\n" + " <model-name>bar</model-name>\n" + " <decision-name>qux</decision-name>\n" + " <decision-id>baz</decision-id>\n" + " <decision-service-name>ds</decision-service-name>\n" + " <dmn-context class=\"singleton-map\">\n" + " <entry>\n" + " <string>quux</string>\n" + " <string>corge</string>\n" + " </entry>\n" + " </dmn-context>\n" + "</dmn-evaluation-context>";
JAXB = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<dmn-evaluation-context>\n" + " <model-namespace>foo</model-namespace>\n" + " <model-name>bar</model-name>\n" + " <decision-name>qux</decision-name>\n" + " <decision-id>baz</decision-id>\n" + " <decision-service-name>ds</decision-service-name>\n" + " <dmn-context xsi:type=\"jaxbListWrapper\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" + " <type>MAP</type>\n" + " <element xsi:type=\"jaxbStringObjectPair\" key=\"quux\">\n" + " <value xsi:type=\"xs:string\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">corge</value>\n" + " </element>\n" + " </dmn-context>\n" + "</dmn-evaluation-context>\n";
JSON = String.format("{%n" + " \"model-namespace\" : \"foo\",%n" + " \"model-name\" : \"bar\",%n" + " \"decision-name\" : \"qux\",%n" + " \"decision-id\" : \"baz\",%n" + " \"decision-service-name\" : \"ds\",%n" + " \"dmn-context\" : {\"quux\" : \"corge\"}%n" + "}");
xStreamMarshaller = MarshallerFactory.getMarshaller(classes, MarshallingFormat.XSTREAM, DMNContextKS.class.getClassLoader());
jaxbMarshaller = MarshallerFactory.getMarshaller(classes, MarshallingFormat.JAXB, DMNContextKS.class.getClassLoader());
jsonMarshaller = MarshallerFactory.getMarshaller(MarshallingFormat.JSON, DMNContextKS.class.getClassLoader());
}
use of org.kie.server.api.model.dmn.DMNContextKS in project droolsjbpm-integration by kiegroup.
the class ModelEvaluatorServiceBase method evaluateDecisions.
public ServiceResponse<DMNResultKS> evaluateDecisions(String containerId, String contextPayload, String marshallingType) {
try {
KieContainerInstanceImpl kContainer = context.getContainer(containerId, ContainerLocatorProvider.get().getLocator());
DMNRuntime dmnRuntime = KieRuntimeFactory.of(kContainer.getKieContainer().getKieBase()).get(DMNRuntime.class);
wirePrometheus(kContainer, dmnRuntime);
LOG.debug("Will deserialize payload: {}", contextPayload);
DMNContextKS evalCtx = marshallerHelper.unmarshal(containerId, contextPayload, marshallingType, DMNContextKS.class);
DMNEvaluationResult evaluationResult = DMNEvaluationUtils.evaluate(dmnRuntime, evalCtx.getNamespace(), evalCtx.getModelName(), evalCtx.getDmnContext(), evalCtx.getDecisionNames(), evalCtx.getDecisionIds(), evalCtx.getDecisionServiceName());
DMNResultKS res = new DMNResultKS(evaluationResult.model.getNamespace(), evaluationResult.model.getName(), evalCtx.getDecisionNames(), evaluationResult.result);
return new ServiceResponse<DMNResultKS>(ServiceResponse.ResponseType.SUCCESS, "OK from container '" + containerId + "'", res);
} catch (Exception e) {
e.printStackTrace();
LOG.error("Error from container '" + containerId + "'", e);
return new ServiceResponse<DMNResultKS>(ServiceResponse.ResponseType.FAILURE, "Error from container '" + containerId + "'" + e.getMessage(), null);
}
}
use of org.kie.server.api.model.dmn.DMNContextKS in project droolsjbpm-integration by kiegroup.
the class DMNContextKSMarshallingTest method testJaxbUnmarshalling.
@Test
public void testJaxbUnmarshalling() {
final DMNContextKS result = jaxbMarshaller.unmarshall(JAXB, DMNContextKS.class);
checkBean(result);
}
Aggregations