gitgabrio commented on code in PR #6014:
URL: 
https://github.com/apache/incubator-kie-drools/pull/6014#discussion_r1670145902


##########
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/ImportDMNResolverUtil.java:
##########
@@ -29,55 +29,74 @@
 import org.kie.dmn.model.api.Import;
 import org.kie.dmn.model.api.NamespaceConsts;
 import org.kie.dmn.model.v1_1.TImport;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class ImportDMNResolverUtil {
 
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(ImportDMNResolverUtil.class);
+
     private ImportDMNResolverUtil() {
         // No constructor for util class.
     }
 
-    public static <T> Either<String, T> resolveImportDMN(Import _import, 
Collection<T> all, Function<T, QName> idExtractor) {
-        final String iNamespace = _import.getNamespace();
-        final String iName = _import.getName();
-        final String iModelName = 
_import.getAdditionalAttributes().get(TImport.MODELNAME_QNAME);
-        List<T> allInNS = all.stream()
-                             .filter(m -> 
idExtractor.apply(m).getNamespaceURI().equals(iNamespace))
+    public static <T> Either<String, T> resolveImportDMN(Import importElement, 
Collection<T> dmns, Function<T, QName> idExtractor) {
+        final String importNamespace = importElement.getNamespace();
+        final String importName = importElement.getName();
+        final String importLocationURI = importElement.getLocationURI(); // 
This is optional
+        final String importModelName = 
importElement.getAdditionalAttributes().get(TImport.MODELNAME_QNAME);
+
+        LOGGER.debug("Resolving DMN Import with namespace={} name={} 
locationURI={}, modelName={}",
+                importNamespace, importName, importLocationURI, 
importModelName);
+
+        List<T> matchingDmns = dmns.stream()
+                             .filter(m -> 
idExtractor.apply(m).getNamespaceURI().equals(importNamespace))
                              .collect(Collectors.toList());
-        if (allInNS.size() == 1) {
-            T located = allInNS.get(0);
+        if (matchingDmns.size() == 1) {
+            T located = matchingDmns.get(0);
             // Check if the located DMN Model in the NS, correspond for the 
import `drools:modelName`. 
-            if (iModelName == null || 
idExtractor.apply(located).getLocalPart().equals(iModelName)) {
+            if (importModelName == null || 
idExtractor.apply(located).getLocalPart().equals(importModelName)) {
+                LOGGER.debug("DMN Import with namespace={} and 
importModelName={} resolved!", importNamespace, importModelName);
                 return Either.ofRight(located);
             } else {
-                return Either.ofLeft(String.format("While importing DMN for 
namespace: %s, name: %s, modelName: %s, located within namespace only %s but 
does not match for the actual name",
-                                                   iNamespace, iName, 
iModelName,
+                LOGGER.error("Impossible to find the Imported DMN with {} 
namespace, {} name and {} modelName.",
+                        importNamespace, importName, importModelName);
+                return Either.ofLeft(String.format("While importing DMN for 
namespace: %s, name: %s, modelName: %s, located " +
+                                "within namespace only %s but does not match 
for the actual modelName",
+                                                   importNamespace, 
importName, importModelName,
                                                    
idExtractor.apply(located)));
             }
         } else {
-            List<T> usingNSandName = allInNS.stream()
-                                            .filter(m -> 
idExtractor.apply(m).getLocalPart().equals(iModelName))
-                                            .collect(Collectors.toList());
+            List<T> usingNSandName = matchingDmns.stream()
+                                            .filter(m -> 
idExtractor.apply(m).getLocalPart().equals(importModelName))
+                    .toList();
             if (usingNSandName.size() == 1) {
+                LOGGER.debug("DMN Import with namespace={} and 
importModelName={} resolved!", importNamespace, importModelName);
                 return Either.ofRight(usingNSandName.get(0));
-            } else if (usingNSandName.size() == 0) {
-                return Either.ofLeft(String.format("Could not locate required 
dependency while importing DMN for namespace: %s, name: %s, modelName: %s.",
-                                                   iNamespace, iName, 
iModelName));
+            } else if (usingNSandName.isEmpty()) {
+                LOGGER.error("Impossible to find the Imported DMN with {} 
namespace, {} name and {} modelName.",
+                        importNamespace, importName, importModelName);
+                return Either.ofLeft(String.format("Impossible to find the 
Imported DMN with %s namespace %s name and %s modelName.",
+                        importNamespace, importName, importModelName));
             } else {
-                return Either.ofLeft(String.format("While importing DMN for 
namespace: %s, name: %s, modelName: %s, could not locate required dependency 
within: %s.",
-                                                   iNamespace, iName, 
iModelName,
-                                                   
allInNS.stream().map(idExtractor).collect(Collectors.toList())));
+                LOGGER.error("Found {} number of collision resolving an 
Imported DMN with {} namespace {} name and {} modelName.",
+                        usingNSandName.size(), importNamespace, importName, 
importModelName);
+                return Either.ofLeft(String.format("Found a collision 
resolving an Imported DMN with %s namespace, %s " +

Review Comment:
   @yesamer 
   As in previous - I think it is better to have same message in logger and 
returned either



##########
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/ImportDMNResolverUtil.java:
##########
@@ -29,55 +29,74 @@
 import org.kie.dmn.model.api.Import;
 import org.kie.dmn.model.api.NamespaceConsts;
 import org.kie.dmn.model.v1_1.TImport;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class ImportDMNResolverUtil {
 
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(ImportDMNResolverUtil.class);
+
     private ImportDMNResolverUtil() {
         // No constructor for util class.
     }
 
-    public static <T> Either<String, T> resolveImportDMN(Import _import, 
Collection<T> all, Function<T, QName> idExtractor) {
-        final String iNamespace = _import.getNamespace();
-        final String iName = _import.getName();
-        final String iModelName = 
_import.getAdditionalAttributes().get(TImport.MODELNAME_QNAME);
-        List<T> allInNS = all.stream()
-                             .filter(m -> 
idExtractor.apply(m).getNamespaceURI().equals(iNamespace))
+    public static <T> Either<String, T> resolveImportDMN(Import importElement, 
Collection<T> dmns, Function<T, QName> idExtractor) {
+        final String importNamespace = importElement.getNamespace();
+        final String importName = importElement.getName();
+        final String importLocationURI = importElement.getLocationURI(); // 
This is optional
+        final String importModelName = 
importElement.getAdditionalAttributes().get(TImport.MODELNAME_QNAME);
+
+        LOGGER.debug("Resolving DMN Import with namespace={} name={} 
locationURI={}, modelName={}",
+                importNamespace, importName, importLocationURI, 
importModelName);
+
+        List<T> matchingDmns = dmns.stream()
+                             .filter(m -> 
idExtractor.apply(m).getNamespaceURI().equals(importNamespace))
                              .collect(Collectors.toList());
-        if (allInNS.size() == 1) {
-            T located = allInNS.get(0);
+        if (matchingDmns.size() == 1) {
+            T located = matchingDmns.get(0);
             // Check if the located DMN Model in the NS, correspond for the 
import `drools:modelName`. 
-            if (iModelName == null || 
idExtractor.apply(located).getLocalPart().equals(iModelName)) {
+            if (importModelName == null || 
idExtractor.apply(located).getLocalPart().equals(importModelName)) {
+                LOGGER.debug("DMN Import with namespace={} and 
importModelName={} resolved!", importNamespace, importModelName);
                 return Either.ofRight(located);
             } else {
-                return Either.ofLeft(String.format("While importing DMN for 
namespace: %s, name: %s, modelName: %s, located within namespace only %s but 
does not match for the actual name",
-                                                   iNamespace, iName, 
iModelName,
+                LOGGER.error("Impossible to find the Imported DMN with {} 
namespace, {} name and {} modelName.",
+                        importNamespace, importName, importModelName);
+                return Either.ofLeft(String.format("While importing DMN for 
namespace: %s, name: %s, modelName: %s, located " +

Review Comment:
   HI @yesamer - thx for the PR. IIUC, in this message there is not any 
indication of the "importing" model: if this is true, could you please add also 
some indication so that it is clear also which model tries to import ?
   Beside, I think it would be better to have exactly same message in both 
logger and as returned: wdyt ?
   



##########
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/ImportDMNResolverUtil.java:
##########
@@ -29,55 +29,74 @@
 import org.kie.dmn.model.api.Import;
 import org.kie.dmn.model.api.NamespaceConsts;
 import org.kie.dmn.model.v1_1.TImport;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class ImportDMNResolverUtil {
 
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(ImportDMNResolverUtil.class);
+
     private ImportDMNResolverUtil() {
         // No constructor for util class.
     }
 
-    public static <T> Either<String, T> resolveImportDMN(Import _import, 
Collection<T> all, Function<T, QName> idExtractor) {
-        final String iNamespace = _import.getNamespace();
-        final String iName = _import.getName();
-        final String iModelName = 
_import.getAdditionalAttributes().get(TImport.MODELNAME_QNAME);
-        List<T> allInNS = all.stream()
-                             .filter(m -> 
idExtractor.apply(m).getNamespaceURI().equals(iNamespace))
+    public static <T> Either<String, T> resolveImportDMN(Import importElement, 
Collection<T> dmns, Function<T, QName> idExtractor) {
+        final String importNamespace = importElement.getNamespace();
+        final String importName = importElement.getName();
+        final String importLocationURI = importElement.getLocationURI(); // 
This is optional
+        final String importModelName = 
importElement.getAdditionalAttributes().get(TImport.MODELNAME_QNAME);
+
+        LOGGER.debug("Resolving DMN Import with namespace={} name={} 
locationURI={}, modelName={}",
+                importNamespace, importName, importLocationURI, 
importModelName);
+
+        List<T> matchingDmns = dmns.stream()
+                             .filter(m -> 
idExtractor.apply(m).getNamespaceURI().equals(importNamespace))
                              .collect(Collectors.toList());
-        if (allInNS.size() == 1) {
-            T located = allInNS.get(0);
+        if (matchingDmns.size() == 1) {
+            T located = matchingDmns.get(0);
             // Check if the located DMN Model in the NS, correspond for the 
import `drools:modelName`. 
-            if (iModelName == null || 
idExtractor.apply(located).getLocalPart().equals(iModelName)) {
+            if (importModelName == null || 
idExtractor.apply(located).getLocalPart().equals(importModelName)) {
+                LOGGER.debug("DMN Import with namespace={} and 
importModelName={} resolved!", importNamespace, importModelName);
                 return Either.ofRight(located);
             } else {
-                return Either.ofLeft(String.format("While importing DMN for 
namespace: %s, name: %s, modelName: %s, located within namespace only %s but 
does not match for the actual name",
-                                                   iNamespace, iName, 
iModelName,
+                LOGGER.error("Impossible to find the Imported DMN with {} 
namespace, {} name and {} modelName.",
+                        importNamespace, importName, importModelName);
+                return Either.ofLeft(String.format("While importing DMN for 
namespace: %s, name: %s, modelName: %s, located " +
+                                "within namespace only %s but does not match 
for the actual modelName",
+                                                   importNamespace, 
importName, importModelName,
                                                    
idExtractor.apply(located)));
             }
         } else {
-            List<T> usingNSandName = allInNS.stream()
-                                            .filter(m -> 
idExtractor.apply(m).getLocalPart().equals(iModelName))
-                                            .collect(Collectors.toList());
+            List<T> usingNSandName = matchingDmns.stream()
+                                            .filter(m -> 
idExtractor.apply(m).getLocalPart().equals(importModelName))
+                    .toList();
             if (usingNSandName.size() == 1) {
+                LOGGER.debug("DMN Import with namespace={} and 
importModelName={} resolved!", importNamespace, importModelName);
                 return Either.ofRight(usingNSandName.get(0));
-            } else if (usingNSandName.size() == 0) {
-                return Either.ofLeft(String.format("Could not locate required 
dependency while importing DMN for namespace: %s, name: %s, modelName: %s.",
-                                                   iNamespace, iName, 
iModelName));
+            } else if (usingNSandName.isEmpty()) {
+                LOGGER.error("Impossible to find the Imported DMN with {} 
namespace, {} name and {} modelName.",
+                        importNamespace, importName, importModelName);
+                return Either.ofLeft(String.format("Impossible to find the 
Imported DMN with %s namespace %s name and %s modelName.",
+                        importNamespace, importName, importModelName));
             } else {
-                return Either.ofLeft(String.format("While importing DMN for 
namespace: %s, name: %s, modelName: %s, could not locate required dependency 
within: %s.",
-                                                   iNamespace, iName, 
iModelName,
-                                                   
allInNS.stream().map(idExtractor).collect(Collectors.toList())));
+                LOGGER.error("Found {} number of collision resolving an 
Imported DMN with {} namespace {} name and {} modelName.",
+                        usingNSandName.size(), importNamespace, importName, 
importModelName);
+                return Either.ofLeft(String.format("Found a collision 
resolving an Imported DMN with %s namespace, %s " +
+                                "name and modelName %s. There are %s DMN files 
with the same namespace in your project. Please " +
+                                "change the DMN namespaces and make them 
unique to fix this issue.",
+                        importNamespace, importName, importModelName, 
usingNSandName.size()));
             }
         }
     }
 
-    public static enum ImportType {

Review Comment:
   👍 😄 



##########
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/ImportDMNResolverUtil.java:
##########
@@ -29,55 +29,74 @@
 import org.kie.dmn.model.api.Import;
 import org.kie.dmn.model.api.NamespaceConsts;
 import org.kie.dmn.model.v1_1.TImport;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class ImportDMNResolverUtil {
 
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(ImportDMNResolverUtil.class);
+
     private ImportDMNResolverUtil() {
         // No constructor for util class.
     }
 
-    public static <T> Either<String, T> resolveImportDMN(Import _import, 
Collection<T> all, Function<T, QName> idExtractor) {
-        final String iNamespace = _import.getNamespace();
-        final String iName = _import.getName();
-        final String iModelName = 
_import.getAdditionalAttributes().get(TImport.MODELNAME_QNAME);
-        List<T> allInNS = all.stream()
-                             .filter(m -> 
idExtractor.apply(m).getNamespaceURI().equals(iNamespace))
+    public static <T> Either<String, T> resolveImportDMN(Import importElement, 
Collection<T> dmns, Function<T, QName> idExtractor) {
+        final String importNamespace = importElement.getNamespace();
+        final String importName = importElement.getName();
+        final String importLocationURI = importElement.getLocationURI(); // 
This is optional
+        final String importModelName = 
importElement.getAdditionalAttributes().get(TImport.MODELNAME_QNAME);
+
+        LOGGER.debug("Resolving DMN Import with namespace={} name={} 
locationURI={}, modelName={}",
+                importNamespace, importName, importLocationURI, 
importModelName);
+
+        List<T> matchingDmns = dmns.stream()
+                             .filter(m -> 
idExtractor.apply(m).getNamespaceURI().equals(importNamespace))
                              .collect(Collectors.toList());
-        if (allInNS.size() == 1) {
-            T located = allInNS.get(0);
+        if (matchingDmns.size() == 1) {
+            T located = matchingDmns.get(0);
             // Check if the located DMN Model in the NS, correspond for the 
import `drools:modelName`. 
-            if (iModelName == null || 
idExtractor.apply(located).getLocalPart().equals(iModelName)) {
+            if (importModelName == null || 
idExtractor.apply(located).getLocalPart().equals(importModelName)) {
+                LOGGER.debug("DMN Import with namespace={} and 
importModelName={} resolved!", importNamespace, importModelName);
                 return Either.ofRight(located);
             } else {
-                return Either.ofLeft(String.format("While importing DMN for 
namespace: %s, name: %s, modelName: %s, located within namespace only %s but 
does not match for the actual name",
-                                                   iNamespace, iName, 
iModelName,
+                LOGGER.error("Impossible to find the Imported DMN with {} 
namespace, {} name and {} modelName.",
+                        importNamespace, importName, importModelName);
+                return Either.ofLeft(String.format("While importing DMN for 
namespace: %s, name: %s, modelName: %s, located " +
+                                "within namespace only %s but does not match 
for the actual modelName",
+                                                   importNamespace, 
importName, importModelName,
                                                    
idExtractor.apply(located)));
             }
         } else {
-            List<T> usingNSandName = allInNS.stream()
-                                            .filter(m -> 
idExtractor.apply(m).getLocalPart().equals(iModelName))
-                                            .collect(Collectors.toList());
+            List<T> usingNSandName = matchingDmns.stream()
+                                            .filter(m -> 
idExtractor.apply(m).getLocalPart().equals(importModelName))
+                    .toList();
             if (usingNSandName.size() == 1) {
+                LOGGER.debug("DMN Import with namespace={} and 
importModelName={} resolved!", importNamespace, importModelName);
                 return Either.ofRight(usingNSandName.get(0));
-            } else if (usingNSandName.size() == 0) {
-                return Either.ofLeft(String.format("Could not locate required 
dependency while importing DMN for namespace: %s, name: %s, modelName: %s.",
-                                                   iNamespace, iName, 
iModelName));
+            } else if (usingNSandName.isEmpty()) {
+                LOGGER.error("Impossible to find the Imported DMN with {} 
namespace, {} name and {} modelName.",

Review Comment:
   @yesamer 
   As in previous - I think it is better to have same message in logger and 
returned either



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