Search in sources :

Example 1 with DecisionStructuredInputsResponse

use of org.kie.kogito.trusty.service.common.responses.decision.DecisionStructuredInputsResponse 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 DecisionStructuredInputsResponse

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

the class DecisionsApiV1IT method assertGetStructuredInputsCorrectFullResponse.

private void assertGetStructuredInputsCorrectFullResponse(ListStatus outcomesStatus) throws Exception {
    mockServiceWithDecision(ListStatus.FULL, outcomesStatus);
    DecisionStructuredInputsResponse response = get("/structuredInputs").as(DecisionStructuredInputsResponse.class);
    assertDecisionStructuredInputResponse(buildDecisionStructuredInputsResponse(ListStatus.FULL), response);
}
Also used : DecisionStructuredInputsResponse(org.kie.kogito.trusty.service.common.responses.decision.DecisionStructuredInputsResponse)

Example 3 with DecisionStructuredInputsResponse

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

the class DecisionsApiV1IT method assertGetStructuredInputsCorrectEmptyResponse.

private void assertGetStructuredInputsCorrectEmptyResponse(ListStatus outcomesStatus) throws Exception {
    mockServiceWithDecision(ListStatus.EMPTY, outcomesStatus);
    DecisionStructuredInputsResponse response = get("/structuredInputs").as(DecisionStructuredInputsResponse.class);
    assertDecisionStructuredInputResponse(buildDecisionStructuredInputsResponse(ListStatus.EMPTY), response);
}
Also used : DecisionStructuredInputsResponse(org.kie.kogito.trusty.service.common.responses.decision.DecisionStructuredInputsResponse)

Aggregations

DecisionStructuredInputsResponse (org.kie.kogito.trusty.service.common.responses.decision.DecisionStructuredInputsResponse)3 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 DecisionOutcomesResponse (org.kie.kogito.trusty.service.common.responses.decision.DecisionOutcomesResponse)1