in trusty/trusty-service/trusty-service-common/src/main/java/org/kie/kogito/trusty/service/common/TrustyServiceImpl.java [216:266]
protected CounterfactualExplainabilityRequest makeCounterfactualRequest(String executionId,
List<NamedTypedValue> goals,
List<CounterfactualSearchDomain> searchDomains,
Long maxRunningTimeSeconds) {
Decision decision = getDecisionById(executionId);
//This is returned as null under Redis, so play safe
Collection<DecisionInput> decisionInputs = Objects.nonNull(decision.getInputs()) ? decision.getInputs() : Collections.emptyList();
if (!isStructureIdentical(decisionInputs, searchDomains)) {
String error = buildCounterfactualErrorMessage(String.format("The structure of the Search Domains do not match the structure of the original Inputs for decision with ID %s.", executionId),
"Decision inputs:-", decisionInputs,
"Search domains:-", searchDomains);
LOG.error(error);
throw new IllegalArgumentException(error);
}
//This is returned as null under Redis, so play safe
Collection<DecisionOutcome> decisionOutcomes = Objects.nonNull(decision.getOutcomes()) ? decision.getOutcomes() : Collections.emptyList();
if (!isStructureSubset(decisionOutcomes, goals)) {
String error =
buildCounterfactualErrorMessage(String.format("The structure of the Goals is not comparable to the structure of the original Outcomes for decision with ID %s.", executionId),
"Decision outcomes:-", decisionOutcomes,
"Goals:-", goals);
LOG.error(error);
throw new IllegalArgumentException(error);
}
List<NamedTypedValue> cfInputs = decision.getInputs() != null
? decision.getInputs().stream()
.map(input -> new NamedTypedValue(input.getName(), input.getValue()))
.collect(Collectors.toList())
: Collections.emptyList();
List<NamedTypedValue> cfGoals = goals != null
? goals
: Collections.emptyList();
List<CounterfactualSearchDomain> cfSearchDomains = searchDomains != null
? searchDomains
: Collections.emptyList();
return new CounterfactualExplainabilityRequest(
executionId,
decision.getServiceUrl(),
createDecisionModelIdentifier(decision),
UUID.randomUUID().toString(),
cfInputs,
cfGoals,
cfSearchDomains,
maxRunningTimeSeconds);
}