Search in sources :

Example 1 with DMNContextKS

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());
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) ServiceResponse(org.kie.server.api.model.ServiceResponse) DMNContext(org.kie.dmn.api.core.DMNContext) KieHelper(org.kie.internal.utils.KieHelper) KieSession(org.kie.api.runtime.KieSession) DMNResultKS(org.kie.server.api.model.dmn.DMNResultKS) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) DMNContextKS(org.kie.server.api.model.dmn.DMNContextKS) Test(org.junit.Test)

Example 2 with DMNContextKS

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);
}
Also used : DMNContextKS(org.kie.server.api.model.dmn.DMNContextKS) Test(org.junit.Test)

Example 3 with DMNContextKS

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());
}
Also used : DMNContextKS(org.kie.server.api.model.dmn.DMNContextKS) BeforeClass(org.junit.BeforeClass)

Example 4 with DMNContextKS

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);
    }
}
Also used : DMNEvaluationResult(org.kie.dmn.core.internal.utils.DMNEvaluationUtils.DMNEvaluationResult) ServiceResponse(org.kie.server.api.model.ServiceResponse) KieContainerInstanceImpl(org.kie.server.services.impl.KieContainerInstanceImpl) DMNResultKS(org.kie.server.api.model.dmn.DMNResultKS) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNContextKS(org.kie.server.api.model.dmn.DMNContextKS)

Example 5 with DMNContextKS

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);
}
Also used : DMNContextKS(org.kie.server.api.model.dmn.DMNContextKS) Test(org.junit.Test)

Aggregations

DMNContextKS (org.kie.server.api.model.dmn.DMNContextKS)10 Test (org.junit.Test)5 DMNContext (org.kie.dmn.api.core.DMNContext)2 DMNResult (org.kie.dmn.api.core.DMNResult)2 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)2 ServiceResponse (org.kie.server.api.model.ServiceResponse)2 DMNResultKS (org.kie.server.api.model.dmn.DMNResultKS)2 BeforeClass (org.junit.BeforeClass)1 KieSession (org.kie.api.runtime.KieSession)1 DMNModel (org.kie.dmn.api.core.DMNModel)1 DMNEvaluationResult (org.kie.dmn.core.internal.utils.DMNEvaluationUtils.DMNEvaluationResult)1 KieHelper (org.kie.internal.utils.KieHelper)1 DMNServicesClientImpl (org.kie.server.client.impl.DMNServicesClientImpl)1 KieContainerInstanceImpl (org.kie.server.services.impl.KieContainerInstanceImpl)1