Search in sources :

Example 1 with DMNModelInfoList

use of org.kie.server.api.model.dmn.DMNModelInfoList in project droolsjbpm-integration by kiegroup.

the class ModelEvaluatorResource method getModels.

@ApiOperation(value = "Retrieves DMN model for given container", response = ServiceResponse.class, code = 200, notes = REF_KIESERVER_DMN_API_DOC)
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 404, message = "Models or container not found"), @ApiResponse(code = 200, response = String.class, message = "Successful response", examples = @Example(value = { @ExampleProperty(mediaType = MediaType.APPLICATION_JSON, value = EXAMPLE_KIESERVER_GET_RESPONSE_JSON), @ExampleProperty(mediaType = MediaType.APPLICATION_XML, value = EXAMPLE_KIESERVER_GET_RESPONSE_XML) })) })
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getModels(@javax.ws.rs.core.Context HttpHeaders headers, @ApiParam(value = "Container id that models should be loaded from", required = true, example = EXAMPLE_CONTAINER_ID) @PathParam(CONTAINER_ID) String containerId) {
    Variant v = getVariant(headers);
    Header conversationIdHeader = buildConversationIdHeader(containerId, modelEvaluatorService.getKieServerRegistry(), headers);
    try {
        ServiceResponse<DMNModelInfoList> result = modelEvaluatorService.getModels(containerId);
        if (result.getType() == ServiceResponse.ResponseType.SUCCESS) {
            return createCorrectVariant(marshallerHelper, containerId, result, headers, Response.Status.OK, conversationIdHeader);
        }
        return createCorrectVariant(marshallerHelper, containerId, result, headers, Response.Status.NOT_FOUND, conversationIdHeader);
    } catch (Exception e) {
        LOG.error("Unexpected error retrieving models. Message: '{}'", e.getMessage(), e);
        return internalServerError(MessageFormat.format("ERROR", e.getMessage()), v, conversationIdHeader);
    }
}
Also used : RestUtils.getVariant(org.kie.server.remote.rest.common.util.RestUtils.getVariant) RestUtils.createCorrectVariant(org.kie.server.remote.rest.common.util.RestUtils.createCorrectVariant) Variant(javax.ws.rs.core.Variant) DMNModelInfoList(org.kie.server.api.model.dmn.DMNModelInfoList) Header(org.kie.server.remote.rest.common.Header) RestUtils.buildConversationIdHeader(org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with DMNModelInfoList

use of org.kie.server.api.model.dmn.DMNModelInfoList in project droolsjbpm-integration by kiegroup.

the class DMNTwoDMNModelsIntegrationTest method test_getModelsWithAlias.

@Test
public void test_getModelsWithAlias() {
    ServiceResponse<DMNModelInfoList> getModels = dmnClient.getModels(CONTAINER_1_ALIAS);
    assertEquals(ResponseType.SUCCESS, getModels.getType());
    List<DMNModelInfo> models = getModels.getResult().getModels();
    assertThat(models, hasSize(2));
    DMNModelInfo fdModel = models.stream().filter(mi -> mi.getName().equals("function-definition")).findFirst().orElse(null);
    assertThat(fdModel, notNullValue());
    assertThat(fdModel.getNamespace(), is("https://www.drools.org/kie-dmn/function-definition"));
    assertThat(fdModel.getDecisions(), hasSize(1));
    assertThat(fdModel.getDecisions().iterator().next().getName(), is("Math"));
    DMNModelInfo idsModel = models.stream().filter(mi -> mi.getName().equals("input-data-string")).findFirst().orElse(null);
    assertThat(idsModel, notNullValue());
    assertThat(idsModel.getNamespace(), is("https://github.com/kiegroup/kie-dmn/input-data-string"));
    assertThat(idsModel.getDecisions(), hasSize(1));
    assertThat(idsModel.getDecisions().iterator().next().getName(), is("Greeting Message"));
}
Also used : DMNModelInfoList(org.kie.server.api.model.dmn.DMNModelInfoList) DMNModelInfo(org.kie.server.api.model.dmn.DMNModelInfo) Test(org.junit.Test)

Example 3 with DMNModelInfoList

use of org.kie.server.api.model.dmn.DMNModelInfoList in project droolsjbpm-integration by kiegroup.

the class DMNDecisionServiceIntegrationTest method test_getModels.

@Test
public void test_getModels() {
    ServiceResponse<DMNModelInfoList> getModels = dmnClient.getModels(CONTAINER_1_ID);
    KieServerAssert.assertSuccess(getModels);
    List<DMNModelInfo> models = getModels.getResult().getModels();
    assertThat(models, hasSize(3));
    DMNModelInfo fdModel = models.stream().filter(mi -> mi.getName().equals("Decision Services")).findFirst().orElse(null);
    assertThat(fdModel, notNullValue());
    assertThat(fdModel.getNamespace(), is("http://www.trisotech.com/definitions/_686f58d4-4ec3-4c65-8c06-0e4fd8983def"));
    assertThat(fdModel.getDecisionServices(), hasSize(2));
    DMNDecisionServiceInfo ds1 = fdModel.getDecisionServices().stream().filter(x -> x.getName().equals("A Only Knowing B and C")).findFirst().orElse(null);
    assertThat(ds1, notNullValue());
    assertThat(ds1.getId(), is("_70386614-9838-420b-a2ae-ff901ada63fb"));
    DMNDecisionServiceInfo ds2 = fdModel.getDecisionServices().stream().filter(x -> x.getName().equals("A only as output knowing D and E")).findFirst().orElse(null);
    assertThat(ds1, notNullValue());
    assertThat(ds2.getId(), is("_4620ef13-248a-419e-bc68-6b601b725a03"));
}
Also used : DMNModelInfoList(org.kie.server.api.model.dmn.DMNModelInfoList) DMNModelInfo(org.kie.server.api.model.dmn.DMNModelInfo) DMNDecisionServiceInfo(org.kie.server.api.model.dmn.DMNDecisionServiceInfo) Test(org.junit.Test)

Example 4 with DMNModelInfoList

use of org.kie.server.api.model.dmn.DMNModelInfoList in project droolsjbpm-integration by kiegroup.

the class DMNInputDataStringIntegrationTest method test_evaluateAll_withUpdate.

@Test
public void test_evaluateAll_withUpdate() {
    ServiceResponse<DMNModelInfoList> models = dmnClient.getModels(CONTAINER_ID);
    assertEquals(ResponseType.SUCCESS, models.getType());
    assertEquals(1, models.getResult().getModels().size());
    DMNContext dmnContext = dmnClient.newContext();
    dmnContext.set("Full Name", "John Doe");
    ServiceResponse<DMNResult> evaluateAll = dmnClient.evaluateAll(CONTAINER_ID, dmnContext);
    assertEquals(ResponseType.SUCCESS, evaluateAll.getType());
    DMNResult dmnResult = evaluateAll.getResult();
    assertThat(dmnResult.getDecisionResults().size(), is(1));
    assertThat(dmnResult.getDecisionResultByName("Greeting Message").getResult(), is("Hello John Doe"));
    DMNContext result = dmnResult.getContext();
    assertThat(result.get("Greeting Message"), is("Hello John Doe"));
    KieServerAssert.assertSuccess(client.updateReleaseId(CONTAINER_ID, kjar_v101));
    models = dmnClient.getModels(CONTAINER_ID);
    assertEquals(ResponseType.SUCCESS, models.getType());
    assertEquals(1, models.getResult().getModels().size());
    evaluateAll = dmnClient.evaluateAll(CONTAINER_ID, dmnContext);
    assertEquals(ResponseType.SUCCESS, evaluateAll.getType());
    dmnResult = evaluateAll.getResult();
    assertThat(dmnResult.getDecisionResults().size(), is(1));
    assertThat(dmnResult.getDecisionResultByName("Greeting Message").getResult(), is("Salve John Doe"));
}
Also used : DMNModelInfoList(org.kie.server.api.model.dmn.DMNModelInfoList) DMNResult(org.kie.dmn.api.core.DMNResult) DMNContext(org.kie.dmn.api.core.DMNContext) Test(org.junit.Test)

Example 5 with DMNModelInfoList

use of org.kie.server.api.model.dmn.DMNModelInfoList in project droolsjbpm-integration by kiegroup.

the class ModelEvaluatorServiceBase method getModels.

public ServiceResponse<DMNModelInfoList> getModels(String containerId) {
    try {
        KieContainerInstanceImpl kContainer = context.getContainer(containerId, ContainerLocatorProvider.get().getLocator());
        DMNRuntime kieRuntime = KieRuntimeFactory.of(kContainer.getKieContainer().getKieBase()).get(DMNRuntime.class);
        List<DMNModel> models = kieRuntime.getModels();
        List<DMNModelInfo> result = models.stream().map(ModelEvaluatorServiceBase::modelToInfo).collect(Collectors.toList());
        return new ServiceResponse<DMNModelInfoList>(ServiceResponse.ResponseType.SUCCESS, "OK models successfully retrieved from container '" + containerId + "'", new DMNModelInfoList(result));
    } catch (Exception e) {
        LOG.error("Error retrieving models from container '" + containerId + "'", e);
        return new ServiceResponse<DMNModelInfoList>(ServiceResponse.ResponseType.FAILURE, "Error retrieving models from container '" + containerId + "'" + e.getMessage(), null);
    }
}
Also used : DMNModelInfoList(org.kie.server.api.model.dmn.DMNModelInfoList) ServiceResponse(org.kie.server.api.model.ServiceResponse) KieContainerInstanceImpl(org.kie.server.services.impl.KieContainerInstanceImpl) DMNModelInfo(org.kie.server.api.model.dmn.DMNModelInfo) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel)

Aggregations

DMNModelInfoList (org.kie.server.api.model.dmn.DMNModelInfoList)9 Test (org.junit.Test)6 DMNModelInfo (org.kie.server.api.model.dmn.DMNModelInfo)6 ServiceResponse (org.kie.server.api.model.ServiceResponse)2 DMNInputDataInfo (org.kie.server.api.model.dmn.DMNInputDataInfo)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 HashMap (java.util.HashMap)1 GET (javax.ws.rs.GET)1 Produces (javax.ws.rs.Produces)1 Variant (javax.ws.rs.core.Variant)1 DMNContext (org.kie.dmn.api.core.DMNContext)1 DMNModel (org.kie.dmn.api.core.DMNModel)1 DMNResult (org.kie.dmn.api.core.DMNResult)1 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)1 CommandScript (org.kie.server.api.commands.CommandScript)1 DescriptorCommand (org.kie.server.api.commands.DescriptorCommand)1 KieServerCommand (org.kie.server.api.model.KieServerCommand)1 DMNDecisionInfo (org.kie.server.api.model.dmn.DMNDecisionInfo)1 DMNDecisionServiceInfo (org.kie.server.api.model.dmn.DMNDecisionServiceInfo)1