yesamer commented on code in PR #6014:
URL:
https://github.com/apache/incubator-kie-drools/pull/6014#discussion_r1670241049
##########
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:
@gitgabrio
1. I can try, but bear in mind with the current setup we are not aware at
runtime if the importing model is a `DMNResource` or `DMNModel`, so I can
retrieve limited data from them (I guess the namespace only)
2. My choice was to have a more verbose message for the error, that should
be consumed by a human reader and a more concise message for the DEBUG. In some
cases, a message can fit well for both requirements, but I believe we shouldn't
necessarily force the message to be the same
--
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]