gitgabrio commented on code in PR #2206:
URL:
https://github.com/apache/incubator-kie-kogito-apps/pull/2206#discussion_r2013608429
##########
jitexecutor/jitexecutor-dmn/src/main/java/org/kie/kogito/jitexecutor/dmn/responses/JITDMNResult.java:
##########
@@ -181,4 +185,12 @@ private static List<JITDMNMessage>
internalGetMessages(List<? extends DMNMessage
private static List<DMNDecisionResult> internalGetDecisionResults(List<?
extends DMNDecisionResult> decisionResults, Map<String, Map<String, Integer>>
decisionEvaluationHitIdsMap) {
return decisionResults.stream().map(dr -> JITDMNDecisionResult.of(dr,
decisionEvaluationHitIdsMap.getOrDefault(dr.getDecisionName(),
Collections.emptyMap()))).collect(Collectors.toList());
}
+
+ public List<List<String>> getInvalidElementPaths() {
Review Comment:
Hi @AthiraHari77
Could you please move those two public getter/setter up, together to the
others? Keep a class in good order make it easier to manage
##########
jitexecutor/jitexecutor-dmn/src/main/java/org/kie/kogito/jitexecutor/dmn/DMNEvaluator.java:
##########
@@ -95,6 +102,52 @@ static DMNEvaluator validateForErrors(DMNModel dmnModel,
DMNRuntime dmnRuntime)
}
}
+ static List<String> getPathToRoot(DMNModel dmnModel, String invalidId) {
+ List<String> path = new ArrayList<>();
+ DMNModelInstrumentedBase node = getNodeById(dmnModel, invalidId);
+
+ while (node != null && !(node instanceof Definitions)) {
+ if (node instanceof Decision) {
+ path.add(((Decision) node).getId());
+ } else if (node instanceof BusinessKnowledgeModel) {
+ path.add(((BusinessKnowledgeModel) node).getId());
+ } else if (node instanceof ChildExpression) {
+ path.add(((ChildExpression) node).getId());
+ } else {
+ path.add(node.getIdentifierString());
+ }
+ node = node.getParent();
+ }
+ Collections.reverse(path);
+ return path.isEmpty() ? Collections.singletonList(invalidId) : path;
+ }
+
+ static DMNModelInstrumentedBase getNodeById(DMNModel dmnModel, String id) {
+ return dmnModel.getDefinitions().getChildren().stream().map(child ->
getNodeById(child, id))
+ .filter(Objects::nonNull).findFirst().orElse(null);
+ }
+
+ static DMNModelInstrumentedBase getNodeById(DMNModelInstrumentedBase
dmnModelInstrumentedBase, String id) {
+ if (dmnModelInstrumentedBase.getIdentifierString().equals(id)) {
+ return dmnModelInstrumentedBase;
+ }
+ for (DMNModelInstrumentedBase child :
dmnModelInstrumentedBase.getChildren()) {
+ DMNModelInstrumentedBase result = getNodeById(child, id);
+ if (result != null) {
+ return result;
+ }
+ }
+ return null;
+ }
+
+ static List<List<String>> retrieveInvalidElementPaths(List<DMNMessage>
messages, DMNModel dmnModel) {
+ return messages.stream().filter(message ->
message.getLevel().equals(Message.Level.WARNING) ||
+ message.getLevel().equals(Message.Level.ERROR)).map(message ->
{
+ List<String> pathToRoot = getPathToRoot(dmnModel,
message.getSourceId());
Review Comment:
Please return directly that
`getPathToRoot(dmnModel, message.getSourceId());`
instead of creating a redundant variable
##########
jitexecutor/jitexecutor-dmn/src/main/java/org/kie/kogito/jitexecutor/dmn/DMNEvaluator.java:
##########
@@ -19,11 +19,13 @@
package org.kie.kogito.jitexecutor.dmn;
import java.io.StringReader;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
Review Comment:
This import seems unused: could you please remove it ?
##########
jitexecutor/jitexecutor-dmn/src/main/java/org/kie/kogito/jitexecutor/dmn/DMNEvaluator.java:
##########
@@ -95,6 +102,52 @@ static DMNEvaluator validateForErrors(DMNModel dmnModel,
DMNRuntime dmnRuntime)
}
}
+ static List<String> getPathToRoot(DMNModel dmnModel, String invalidId) {
+ List<String> path = new ArrayList<>();
+ DMNModelInstrumentedBase node = getNodeById(dmnModel, invalidId);
+
+ while (node != null && !(node instanceof Definitions)) {
Review Comment:
I think that loop could be replaced with
```java
while (node != null && !(node instanceof Definitions) ) {
if (node instanceof DMNElement dmnElement) {
path.add(dmnElement.getId());
} else {
path.add(node.getIdentifierString());
}
node = node.getParent();
}
```
This would
1. avoid direct reference to specific classes (that potentially could miss
others)
2. better represent the logic of the loop
Could you please give it a try (and remove imports of unused classes) ?
##########
jitexecutor/jitexecutor-dmn/src/main/java/org/kie/kogito/jitexecutor/dmn/JITDMNServiceImpl.java:
##########
@@ -119,14 +119,14 @@ public DMNResultWithExplanation
evaluateModelAndExplain(DMNEvaluator dmnEvaluato
Thread.currentThread().interrupt();
}
return new DMNResultWithExplanation(
- JITDMNResult.of(dmnEvaluator.getNamespace(),
dmnEvaluator.getName(), dmnResult, Collections.emptyMap()),
+ JITDMNResult.of(dmnEvaluator.getNamespace(),
dmnEvaluator.getName(), dmnResult, Collections.emptyMap(),
Collections.emptyList()),
Review Comment:
Please, replace with
`JITDMNResult.of(dmnEvaluator.getNamespace(), dmnEvaluator.getName(),
dmnResult, Collections.emptyMap(), dmnResult.getInvalidElementPaths()),`
##########
jitexecutor/jitexecutor-dmn/src/test/java/org/kie/kogito/jitexecutor/dmn/responses/JITDMNResultTest.java:
##########
@@ -78,7 +78,7 @@ void serializeDeserialize() throws JsonProcessingException {
dmnResult.setContext(createContext());
dmnResult.addDecisionResult(decisionResult);
- JITDMNResult jitdmnResult =
JITDMNResult.of("http://www.trisotech.com/definitions/_9d01a0c4-f529-4ad8-ad8e-ec5fb5d96ad4",
"Chapter 11 Example", dmnResult, Collections.emptyMap());
+ JITDMNResult jitdmnResult =
JITDMNResult.of("http://www.trisotech.com/definitions/_9d01a0c4-f529-4ad8-ad8e-ec5fb5d96ad4",
"Chapter 11 Example", dmnResult, Collections.emptyMap(),
Collections.emptyList());
Review Comment:
Could you also please modify the
`void deserialize() `
test, introducing the new invalidElementPaths ?
##########
jitexecutor/jitexecutor-dmn/src/main/java/org/kie/kogito/jitexecutor/dmn/JITDMNServiceImpl.java:
##########
@@ -119,14 +119,14 @@ public DMNResultWithExplanation
evaluateModelAndExplain(DMNEvaluator dmnEvaluato
Thread.currentThread().interrupt();
}
return new DMNResultWithExplanation(
- JITDMNResult.of(dmnEvaluator.getNamespace(),
dmnEvaluator.getName(), dmnResult, Collections.emptyMap()),
+ JITDMNResult.of(dmnEvaluator.getNamespace(),
dmnEvaluator.getName(), dmnResult, Collections.emptyMap(),
Collections.emptyList()),
new SalienciesResponse(EXPLAINABILITY_FAILED,
EXPLAINABILITY_FAILED_MESSAGE, null));
}
List<SaliencyResponse> saliencyModelResponse =
buildSalienciesResponse(dmnEvaluator.getDmnModel(), saliencyMap);
return new DMNResultWithExplanation(
- JITDMNResult.of(dmnEvaluator.getNamespace(),
dmnEvaluator.getName(), dmnResult, Collections.emptyMap()),
+ JITDMNResult.of(dmnEvaluator.getNamespace(),
dmnEvaluator.getName(), dmnResult, Collections.emptyMap(),
Collections.emptyList()),
Review Comment:
Please, replace with
`JITDMNResult.of(dmnEvaluator.getNamespace(), dmnEvaluator.getName(),
dmnResult, Collections.emptyMap(), dmnResult.getInvalidElementPaths()),`
##########
jitexecutor/jitexecutor-dmn/src/test/java/org/kie/kogito/jitexecutor/dmn/responses/JITDMNResultTest.java:
##########
@@ -78,7 +78,7 @@ void serializeDeserialize() throws JsonProcessingException {
dmnResult.setContext(createContext());
dmnResult.addDecisionResult(decisionResult);
- JITDMNResult jitdmnResult =
JITDMNResult.of("http://www.trisotech.com/definitions/_9d01a0c4-f529-4ad8-ad8e-ec5fb5d96ad4",
"Chapter 11 Example", dmnResult, Collections.emptyMap());
+ JITDMNResult jitdmnResult =
JITDMNResult.of("http://www.trisotech.com/definitions/_9d01a0c4-f529-4ad8-ad8e-ec5fb5d96ad4",
"Chapter 11 Example", dmnResult, Collections.emptyMap(),
Collections.emptyList());
Review Comment:
Please modify that invocation to also contain both
1. decisionEvaluationHitIdsMap
2. invalidElementPaths
The scope of this test is to double check serialization/deserialization
roundtrip
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]