Skip to content

Commit

Permalink
[incubator-kie-issues#1150] Improve Import Resolver error messages to…
Browse files Browse the repository at this point in the history
… be more user friendly - Part II (apache#6025)
  • Loading branch information
yesamer authored and rgdoliveira committed Jul 17, 2024
1 parent 99cfd16 commit c9ec2eb
Showing 1 changed file with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -51,27 +50,27 @@ public static <T> Either<String, T> 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<T> 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<T> usingNSandName = matchingDMNList.stream()
Expand All @@ -80,22 +79,22 @@ public static <T> Either<String, T> 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()));
}
}
}
Expand Down

0 comments on commit c9ec2eb

Please sign in to comment.