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


##########
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/DecisionServiceCompiler.java:
##########
@@ -120,98 +123,98 @@ private static String inputQualifiedNamePrefix(DMNNode 
input, DMNModelImpl model
                                       ((DMNBaseNode)input).getSource());
                 return null;
             }
-            return importAlias.get();
         }
+     }
+
+    private static String getInputNamePrefix(DMNNode input, DMNModelImpl 
model) {
+        Optional<String> importAlias = 
model.getImportAliasFor(input.getModelNamespace(), input.getModelName());
+        if (importAlias.isEmpty()) {
+            throw new IllegalStateException("Missing import alias for model " 
+ input.getModelName() +
+                    "with namespace " + input.getModelNamespace());
+        }
+        return importAlias.get();
     }
 
     @Override
     public void compileEvaluator(DMNNode node, DMNCompilerImpl compiler, 
DMNCompilerContext ctx, DMNModelImpl model) {
         DecisionServiceNodeImpl ni = (DecisionServiceNodeImpl) node;
-
         List<DSFormalParameter> parameters = new ArrayList<>();
-        
+        processInputData(ni, model, parameters);
+        processInputDecisions(ni, model, parameters);
+        validateEncapsulatedDecision(ni, model);
+        List<DecisionNode> outputDecisions = getOutputDecisions(ni, model);
+
+        boolean coerceSingleton = ((DMNCompilerConfigurationImpl) 
compiler.getDmnCompilerConfig()).getOption(CoerceDecisionServiceSingletonOutputOption.class).isCoerceSingleton();
+        DMNDecisionServiceFunctionDefinitionEvaluator exprEvaluator = new 
DMNDecisionServiceFunctionDefinitionEvaluator(ni, parameters, coerceSingleton);
+        ni.setEvaluator(exprEvaluator);
+
+        if (ni.getType() != null) {
+            checkFnConsistency(model, ni, ni.getType(), outputDecisions);
+        }
+    }
+
+    private void processInputData(DecisionServiceNodeImpl ni, DMNModelImpl 
model, List<DSFormalParameter> parameters) {
         for (DMNElementReference er : ni.getDecisionService().getInputData()) {
             String id = DMNCompilerImpl.getId(er);
             InputDataNode input = model.getInputById(id);
-            String inputNamePrefix = inputQualifiedNamePrefix(input, model);
             if (input != null) {
+                String inputNamePrefix = inputQualifiedNamePrefix(input, 
model);
                 ni.addInputParameter(inputNamePrefix != null ? inputNamePrefix 
+ "." + input.getName() : input.getName(), input);
                 parameters.add(new DSFormalParameter(inputNamePrefix, 
input.getName(), input.getType()));
             } else {
-                MsgUtil.reportMessage(LOG,
-                                      DMNMessage.Severity.ERROR,
-                                      ni.getDecisionService(),
-                                      model,
-                                      null,
-                                      null,
-                                      Msg.REFERENCE_NOT_FOUND_FOR_DS,
-                                      id,
-                                      node.getName());
+                reportReferenceError(ni, model, id);
             }
         }
+    }
+
+    private void processInputDecisions(DecisionServiceNodeImpl ni, 
DMNModelImpl model, List<DSFormalParameter> parameters) {
         for (DMNElementReference er : 
ni.getDecisionService().getInputDecision()) {
             String id = DMNCompilerImpl.getId(er);
             DecisionNode input = model.getDecisionById(id);
-            String inputNamePrefix = inputQualifiedNamePrefix(input, model);
             if (input != null) {
+                String inputNamePrefix = inputQualifiedNamePrefix(input, 
model);
                 ni.addInputParameter(inputNamePrefix != null ? inputNamePrefix 
+ "." + input.getName() : input.getName(), input);
                 parameters.add(new DSFormalParameter(inputNamePrefix, 
input.getName(), input.getResultType()));
             } else {
-                MsgUtil.reportMessage(LOG,
-                                      DMNMessage.Severity.ERROR,
-                                      ni.getDecisionService(),
-                                      model,
-                                      null,
-                                      null,
-                                      Msg.REFERENCE_NOT_FOUND_FOR_DS,
-                                      id,
-                                      node.getName());
+                reportReferenceError(ni, model, id);
             }
         }
+    }
+
+    private void validateEncapsulatedDecision(DecisionServiceNodeImpl ni, 
DMNModelImpl model) {
         for (DMNElementReference er : 
ni.getDecisionService().getEncapsulatedDecision()) {
             String id = DMNCompilerImpl.getId(er);
             DecisionNode input = model.getDecisionById(id);
-            if (input != null) {
-                // nothing to do.
-            } else {
-                MsgUtil.reportMessage(LOG,
-                                      DMNMessage.Severity.ERROR,
-                                      ni.getDecisionService(),
-                                      model,
-                                      null,
-                                      null,
-                                      Msg.REFERENCE_NOT_FOUND_FOR_DS,
-                                      id,
-                                      node.getName());
+            if (model.getDecisionById(id) == null) {

Review Comment:
   This condition duplicates the null check that was already performed by 
assigning 'input' variable. Consider reusing the 'input' variable instead of 
calling 'model.getDecisionById(id)' again.
   ```suggestion
               if (input == null) {
   ```



##########
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/DecisionServiceCompiler.java:
##########
@@ -103,12 +105,13 @@ public boolean accept(DMNNode node) {
      * The qualified name of an element named E that is defined in the same 
decision model as S is simply E.
      * Otherwise, the qualified name is I.E, where I is the name of the import 
element that refers to the model where E is defined.
      */
-    private static String inputQualifiedNamePrefix(DMNNode input, DMNModelImpl 
model) {
-        if (input.getModelNamespace().equals(model.getNamespace())) {
+     static String inputQualifiedNamePrefix(DMNNode input, DMNModelImpl model) 
{
+        if (input.getModelNamespace().equals(model.getNamespace()) || 
isInUnnamedImport(input, model)) {
             return null;
         } else {
-            Optional<String> importAlias = 
model.getImportAliasFor(input.getModelNamespace(), input.getModelName());
-            if (importAlias.isEmpty()) {
+            try {
+                return getInputNamePrefix(input, model);
+            } catch(IllegalStateException e) {

Review Comment:
   Missing space after 'catch' keyword. Should be 'catch (IllegalStateException 
e)'.
   ```suggestion
               } catch (IllegalStateException e) {
   ```



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