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);
}
}
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"));
}
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"));
}
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"));
}
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);
}
}
Aggregations