Search in sources :

Example 1 with DecisionOutcomesResponse

use of org.kie.kogito.trusty.service.common.responses.decision.DecisionOutcomesResponse in project kogito-apps by kiegroup.

the class AbstractTrustyExplainabilityEnd2EndIT method doCounterfactualRequests.

private Callable<Boolean> doCounterfactualRequests(final InfinispanTrustyServiceContainer trustyService, final String accessToken, final String executionId) {
    LOGGER.info(String.format("Reading Decision [%s]'s Inputs...", executionId));
    DecisionStructuredInputsResponse inputs = given().port(trustyService.getFirstMappedPort()).auth().oauth2(accessToken).when().get("/executions/decisions/" + executionId + "/structuredInputs").then().statusCode(200).extract().as(DecisionStructuredInputsResponse.class);
    LOGGER.info(String.format("Reading Decision [%s]'s Outputs...", executionId));
    DecisionOutcomesResponse outcomes = given().port(trustyService.getFirstMappedPort()).auth().oauth2(accessToken).when().get("/executions/decisions/" + executionId + "/outcomes").then().statusCode(200).extract().as(DecisionOutcomesResponse.class);
    // Debugging output (handy to keep).
    ObjectMapper mapper = new ObjectMapper();
    ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter();
    StringBuilder sb = new StringBuilder();
    sb.append("== INPUTS ==>\n");
    inputs.getInputs().forEach(i -> {
        try {
            sb.append(writer.writeValueAsString(i)).append("\n");
        } catch (JsonProcessingException jpe) {
        // Swallow
        }
    });
    sb.append("== OUTPUTS ==>\n");
    outcomes.getOutcomes().forEach(o -> {
        try {
            sb.append(writer.writeValueAsString(o.getOutcomeResult())).append("\n");
        } catch (JsonProcessingException jpe) {
        // Swallow
        }
    });
    LOGGER.debug(sb.toString());
    return () -> {
        LOGGER.info(String.format("Checking Decision [%s]'s Counterfactual request was successful...", executionId));
        // The Goals and Search Domain structures must match those of the original decision
        // See https://issues.redhat.com/browse/FAI-486
        CounterfactualRequestResponse counterfactualRequestResponse = given().port(trustyService.getFirstMappedPort()).auth().oauth2(accessToken).when().contentType(ContentType.JSON).body(new CounterfactualRequest(outcomes.getOutcomes().stream().map(AbstractTrustyExplainabilityEnd2EndIT::toCounterfactualGoal).collect(Collectors.toList()), inputs.getInputs().stream().map(AbstractTrustyExplainabilityEnd2EndIT::toCounterfactualSearchDomain).collect(Collectors.toList()))).post("/executions/decisions/" + executionId + "/explanations/counterfactuals").then().statusCode(200).extract().as(CounterfactualRequestResponse.class);
        return Objects.nonNull(counterfactualRequestResponse) && Objects.equals(executionId, counterfactualRequestResponse.getExecutionId()) && Objects.nonNull(counterfactualRequestResponse.getCounterfactualId());
    };
}
Also used : DecisionStructuredInputsResponse(org.kie.kogito.trusty.service.common.responses.decision.DecisionStructuredInputsResponse) DecisionOutcomesResponse(org.kie.kogito.trusty.service.common.responses.decision.DecisionOutcomesResponse) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) CounterfactualRequestResponse(org.kie.kogito.trusty.service.common.responses.CounterfactualRequestResponse) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) CounterfactualRequest(org.kie.kogito.trusty.service.common.requests.CounterfactualRequest)

Example 2 with DecisionOutcomesResponse

use of org.kie.kogito.trusty.service.common.responses.decision.DecisionOutcomesResponse in project kogito-apps by kiegroup.

the class DecisionsApiV1IT method assertGetOutcomesCorrectEmptyResponse.

private void assertGetOutcomesCorrectEmptyResponse(ListStatus inputsStatus) throws Exception {
    mockServiceWithDecision(inputsStatus, ListStatus.EMPTY);
    DecisionOutcomesResponse response = get("/outcomes").as(DecisionOutcomesResponse.class);
    assertDecisionOutcomesResponse(buildDecisionOutcomesResponse(ListStatus.EMPTY), response);
}
Also used : DecisionOutcomesResponse(org.kie.kogito.trusty.service.common.responses.decision.DecisionOutcomesResponse)

Example 3 with DecisionOutcomesResponse

use of org.kie.kogito.trusty.service.common.responses.decision.DecisionOutcomesResponse in project kogito-apps by kiegroup.

the class DecisionsApiV1IT method assertGetOutcomesCorrectFullResponse.

private void assertGetOutcomesCorrectFullResponse(ListStatus inputsStatus) throws Exception {
    mockServiceWithDecision(inputsStatus, ListStatus.FULL);
    DecisionOutcomesResponse response = get("/outcomes").as(DecisionOutcomesResponse.class);
    assertDecisionOutcomesResponse(buildDecisionOutcomesResponse(ListStatus.FULL), response);
}
Also used : DecisionOutcomesResponse(org.kie.kogito.trusty.service.common.responses.decision.DecisionOutcomesResponse)

Example 4 with DecisionOutcomesResponse

use of org.kie.kogito.trusty.service.common.responses.decision.DecisionOutcomesResponse in project kogito-apps by kiegroup.

the class DecisionsApiV1IT method assertGetOutcomesCorrectNullResponse.

private void assertGetOutcomesCorrectNullResponse(ListStatus inputsStatus) throws Exception {
    mockServiceWithDecision(inputsStatus, ListStatus.NULL);
    DecisionOutcomesResponse response = get("/outcomes").as(DecisionOutcomesResponse.class);
    assertDecisionOutcomesResponse(buildDecisionOutcomesResponse(ListStatus.NULL), response);
}
Also used : DecisionOutcomesResponse(org.kie.kogito.trusty.service.common.responses.decision.DecisionOutcomesResponse)

Aggregations

DecisionOutcomesResponse (org.kie.kogito.trusty.service.common.responses.decision.DecisionOutcomesResponse)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)1 CounterfactualRequest (org.kie.kogito.trusty.service.common.requests.CounterfactualRequest)1 CounterfactualRequestResponse (org.kie.kogito.trusty.service.common.responses.CounterfactualRequestResponse)1 DecisionStructuredInputsResponse (org.kie.kogito.trusty.service.common.responses.decision.DecisionStructuredInputsResponse)1