From c9ec2eb659c957427b826d18daa03cc24e2afbbb Mon Sep 17 00:00:00 2001 From: Yeser Amer Date: Wed, 17 Jul 2024 10:50:12 +0200 Subject: [PATCH] [incubator-kie-issues#1150] Improve Import Resolver error messages to be more user friendly - Part II (#6025) --- .../core/compiler/ImportDMNResolverUtil.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/ImportDMNResolverUtil.java b/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/ImportDMNResolverUtil.java index be11db65f25..91b86b40ac4 100644 --- a/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/ImportDMNResolverUtil.java +++ b/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/ImportDMNResolverUtil.java @@ -21,7 +21,6 @@ import java.util.Collection; import java.util.List; import java.util.function.Function; -import java.util.stream.Collectors; import javax.xml.namespace.QName; @@ -51,27 +50,27 @@ public static Either resolveImportDMN(Import importElement, Colle LOGGER.debug("Resolving an Import in DMN Model with name={} and namespace={}. " + "Importing a DMN model with namespace={} name={} locationURI={}, modelName={}", - importerDMNNamespace, importerDMNName, importNamespace, importName, importLocationURI, importModelName); + importerDMNName, importerDMNNamespace, importNamespace, importName, importLocationURI, importModelName); List matchingDMNList = dmns.stream() .filter(m -> idExtractor.apply(m).getNamespaceURI().equals(importNamespace)) - .collect(Collectors.toList()); + .toList(); if (matchingDMNList.size() == 1) { T located = matchingDMNList.get(0); // Check if the located DMN Model in the NS, correspond for the import `drools:modelName`. if (importModelName == null || idExtractor.apply(located).getLocalPart().equals(importModelName)) { LOGGER.debug("DMN Model with name={} and namespace={} successfully imported a DMN " + "with namespace={} name={} locationURI={}, modelName={}", - importerDMNNamespace, importerDMNName, importNamespace, importName, importLocationURI, importModelName); + importerDMNName, importerDMNNamespace, importNamespace, importName, importLocationURI, importModelName); return Either.ofRight(located); } else { LOGGER.error("DMN Model with name={} and namespace={} can't import a DMN with namespace={}, name={}, modelName={}, " + "located within namespace only {} but does not match for the actual modelName", - importerDMNNamespace, importerDMNName, importNamespace, importName, importModelName, idExtractor.apply(located)); + importerDMNName, importerDMNNamespace, importNamespace, importName, importModelName, idExtractor.apply(located)); return Either.ofLeft(String.format( "DMN Model with name=%s and namespace=%s can't import a DMN with namespace=%s, name=%s, modelName=%s, " + "located within namespace only %s but does not match for the actual modelName", - importerDMNNamespace, importerDMNName, importNamespace, importName, importModelName, idExtractor.apply(located))); + importerDMNName, importerDMNNamespace, importNamespace, importName, importModelName, idExtractor.apply(located))); } } else { List usingNSandName = matchingDMNList.stream() @@ -80,22 +79,22 @@ public static Either resolveImportDMN(Import importElement, Colle if (usingNSandName.size() == 1) { LOGGER.debug("DMN Model with name={} and namespace={} successfully imported a DMN " + "with namespace={} name={} locationURI={}, modelName={}", - importerDMNNamespace, importerDMNName, importNamespace, importName, importLocationURI, importModelName); + importerDMNName, importerDMNNamespace, importNamespace, importName, importLocationURI, importModelName); return Either.ofRight(usingNSandName.get(0)); } else if (usingNSandName.isEmpty()) { LOGGER.error("DMN Model with name={} and namespace={} failed to import a DMN with namespace={} name={} locationURI={}, modelName={}.", - importerDMNNamespace, importerDMNName, importNamespace, importName, importLocationURI, importModelName); + importerDMNName, importerDMNNamespace, importNamespace, importName, importLocationURI, importModelName); return Either.ofLeft(String.format( "DMN Model with name=%s and namespace=%s failed to import a DMN with namespace=%s name=%s locationURI=%s, modelName=%s. ", - importerDMNNamespace, importerDMNName, importNamespace, importName, importLocationURI, importModelName)); + importerDMNName, importerDMNNamespace, importNamespace, importName, importLocationURI, importModelName)); } else { LOGGER.error("DMN Model with name={} and namespace={} detected a collision ({} elements) trying to import a DMN with namespace={} name={} locationURI={}, modelName={}", - importerDMNNamespace, importerDMNName, usingNSandName.size(), importNamespace, importName, importLocationURI, importModelName); + importerDMNName, importerDMNNamespace, usingNSandName.size(), importNamespace, importName, importLocationURI, importModelName); return Either.ofLeft(String.format( "DMN Model with name=%s and namespace=%s detected a collision trying to import a 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.", - importerDMNNamespace, importerDMNName, importNamespace, importName, importModelName, usingNSandName.size())); + importerDMNName, importerDMNNamespace, importNamespace, importName, importModelName, usingNSandName.size())); } } }