Copilot commented on code in PR #6463:
URL: 
https://github.com/apache/incubator-kie-drools/pull/6463#discussion_r2374998812


##########
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/impl/DMNEventUtils.java:
##########
@@ -66,18 +69,24 @@ public static Map<String, Object> 
extractDSParameters(BeforeEvaluateDecisionServ
 
     public static Map<String, Object> 
extractDSOutputDecisionsValues(AfterEvaluateDecisionServiceEvent event) {
         Map<String, Object> results = new LinkedHashMap<>();
+        String namespace = event.getDecisionService().getModelNamespace();
         List<String> decisionIDs = 
event.getDecisionService().getDecisionService().getOutputDecision().stream().map(er
 -> DMNCompilerImpl.getId(er)).collect(Collectors.toList());
         for (String id : decisionIDs) {
-            DecisionNode decisionNode = ((DMNResultImpl) 
event.getResult()).getModel().getDecisionById(id);
-            if (decisionNode != null) {
-                String decisionName = decisionNode.getName();
-                Object decisionResult = 
event.getResult().getContext().get(decisionName);
-                results.put(decisionName, decisionResult);
-            }
+            DecisionNode decisionNode = retrieveDecisionNode(((DMNResultImpl) 
event.getResult()).getModel(), id, namespace);
+            String decisionName = decisionNode.getName();
+            Object decisionResult = 
event.getResult().getContext().get(decisionName);
+            results.put(decisionName, decisionResult);
         }
         return results;
     }
 
+    static DecisionNode retrieveDecisionNode(DMNModel model, String id, String 
namespace) {
+        return Optional.ofNullable(model.getDecisionById(id))
+                .or(() -> Optional.ofNullable(model.getDecisionById(namespace 
+ "#" + id)))
+                .orElseThrow(() -> new NoSuchElementException(
+                        String.format("Decision node with ID '" + id + "' was 
not found in the model.")));

Review Comment:
   The string concatenation within String.format is inefficient and 
inconsistent. Use String.format placeholders instead: `String.format(\"Decision 
node with ID '%s' was not found in the model.\", id)`
   ```suggestion
                           String.format("Decision node with ID '%s' was not 
found in the model.", id)));
   ```



##########
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/impl/DMNEventUtils.java:
##########
@@ -66,18 +69,24 @@ public static Map<String, Object> 
extractDSParameters(BeforeEvaluateDecisionServ
 
     public static Map<String, Object> 
extractDSOutputDecisionsValues(AfterEvaluateDecisionServiceEvent event) {
         Map<String, Object> results = new LinkedHashMap<>();
+        String namespace = event.getDecisionService().getModelNamespace();
         List<String> decisionIDs = 
event.getDecisionService().getDecisionService().getOutputDecision().stream().map(er
 -> DMNCompilerImpl.getId(er)).collect(Collectors.toList());
         for (String id : decisionIDs) {
-            DecisionNode decisionNode = ((DMNResultImpl) 
event.getResult()).getModel().getDecisionById(id);
-            if (decisionNode != null) {
-                String decisionName = decisionNode.getName();
-                Object decisionResult = 
event.getResult().getContext().get(decisionName);
-                results.put(decisionName, decisionResult);
-            }
+            DecisionNode decisionNode = retrieveDecisionNode(((DMNResultImpl) 
event.getResult()).getModel(), id, namespace);
+            String decisionName = decisionNode.getName();
+            Object decisionResult = 
event.getResult().getContext().get(decisionName);
+            results.put(decisionName, decisionResult);
         }

Review Comment:
   Consider extracting the model retrieval outside the loop to avoid repeated 
casting and method calls: `DMNModel model = ((DMNResultImpl) 
event.getResult()).getModel();`



-- 
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]

Reply via email to