gitgabrio commented on code in PR #6267:
URL:
https://github.com/apache/incubator-kie-drools/pull/6267#discussion_r2007149285
##########
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/DMNImportsUtil.java:
##########
@@ -130,4 +141,123 @@ public static ImportType whichImportType(Import
importElement) {
return ImportType.UNKNOWN;
}
}
+
+ /**
+ * Method to resolve the dmn models based on the import type
+ * @param i : object of the Import interface which represents an imported
resource in a DMN model
+ * @param dmnModels : List of decision models
+ * @param model : represents a DMN model, which includes all the necessary
components like decision tables and other elements defined in the DMN standard.
+ * @param toMerge : This is a list that will hold DMN models that are to
be merged later
+ */
+ static void resolveDMNImportType(Import i, Collection<DMNModel> dmnModels,
DMNModelImpl model, List<DMNModel> toMerge) {
+ Either<String, DMNModel> resolvedResult =
DMNImportsUtil.resolveImportDMN(i, dmnModels, (DMNModel m) -> new
QName(m.getNamespace(), m.getName()));
+ DMNModel located = resolvedResult.cata(msg -> {
+ MsgUtil.reportMessage(LOGGER,
+ DMNMessage.Severity.ERROR,
+ i,
+ model,
+ null,
+ null,
+ Msg.IMPORT_NOT_FOUND_FOR_NODE,
+ msg,
+ i);
+ return null;
+ }, Function.identity());
+ checkLocatedDMNModel(i, located, model, toMerge);
+
+ }
+
+ /**
+ * Method to import the dmn model to the default namespace
Review Comment:
This is not 100% true:
- if `Import` has the name of imported model, then the imported model is
mapped by its namespace (line 184),
- in `Import` odes not has the name of imported model (_unnamed import_),
then the imported model is add to the default namespace
##########
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/DMNImportsUtil.java:
##########
@@ -130,4 +141,123 @@ public static ImportType whichImportType(Import
importElement) {
return ImportType.UNKNOWN;
}
}
+
+ /**
+ * Method to resolve the dmn models based on the import type
+ * @param i : object of the Import interface which represents an imported
resource in a DMN model
+ * @param dmnModels : List of decision models
+ * @param model : represents a DMN model, which includes all the necessary
components like decision tables and other elements defined in the DMN standard.
+ * @param toMerge : This is a list that will hold DMN models that are to
be merged later
+ */
+ static void resolveDMNImportType(Import i, Collection<DMNModel> dmnModels,
DMNModelImpl model, List<DMNModel> toMerge) {
+ Either<String, DMNModel> resolvedResult =
DMNImportsUtil.resolveImportDMN(i, dmnModels, (DMNModel m) -> new
QName(m.getNamespace(), m.getName()));
+ DMNModel located = resolvedResult.cata(msg -> {
+ MsgUtil.reportMessage(LOGGER,
+ DMNMessage.Severity.ERROR,
+ i,
+ model,
+ null,
+ null,
+ Msg.IMPORT_NOT_FOUND_FOR_NODE,
+ msg,
+ i);
+ return null;
+ }, Function.identity());
+ checkLocatedDMNModel(i, located, model, toMerge);
+
+ }
+
+ /**
+ * Method to import the dmn model to the default namespace
+ * @param i : represents an import object, and it has a name
(i.getName()). If the name is available, it will be used as the import alias.
+ * @param located : it is a DMN model that has been locate
+ * @param model : it is the target DMN model where the import or merge is
being applied
+ * @param toMerge : This is a list that will hold DMN models that are to
be merged later, instead of being directly imported.
+ */
+ static void checkLocatedDMNModel(Import i, DMNModel located, DMNModelImpl
model, List<DMNModel> toMerge) {
+ if (located != null) {
+ String importAlias =
Optional.ofNullable(i.getName()).orElse(located.getName());
+ // incubator-kie-issues#852: The idea is to not treat the
anonymous models as import, but to "merge" them
+ // with original one,
+ // because otherwise we would have to deal with clashing name
aliases, or similar issues
+ if (importAlias != null && !importAlias.isEmpty()) {
+ model.setImportAliasForNS(importAlias, located.getNamespace(),
located.getName());
+ importFromModel(model, located, importAlias);
+ } else {
+ toMerge.add(located);
+ }
+ }
+ }
+
+ /**
+ * Reolve model with import type as PMML
+ * @param model : represents a DMN model, which includes all the necessary
components like decision tables and other elements defined in the DMN standard.
+ * @param i : object of the Import interface which represents an imported
resource in a DMN model
+ * @param relativeResolver : is a functional interface used to resolve
relative paths to resources
+ * @param dmnCompilerConfig : object of the DMNCompilerConfigurationImpl
which is used to configure how the DMN models should be processed and compiled
by the DMN engine.
+ */
+ static void resolvePMMLImportType(DMNModelImpl model, Import i,
Function<String, Reader> relativeResolver, DMNCompilerConfigurationImpl
dmnCompilerConfig) {
+ ClassLoader rootClassLoader = dmnCompilerConfig.getRootClassLoader();
+ Resource relativeResource = resolveRelativeResource(rootClassLoader,
model, i, i, relativeResolver);
+ resolvePMMLImportType(model, i, relativeResource, dmnCompilerConfig);
+ }
+
+ /**
+ * Static methods to resolve the pmml models
+ * @param model : represents a DMN model, which includes all the necessary
components like decision tables and other elements defined in the DMN standard.
+ * @param i : object of the Import interface which represents an imported
resource in a DMN model
+ * @param relativeResource : is a functional interface used to resolve
relative paths to resources
+ * @param dmnCompilerConfig : object of the DMNCompilerConfigurationImpl
which is used to configure how the DMN models should be processed and compiled
by the DMN engine.
+ */
+ static void resolvePMMLImportType(DMNModelImpl model, Import i, Resource
relativeResource, DMNCompilerConfigurationImpl dmnCompilerConfig) {
+ try (InputStream pmmlIS = relativeResource.getInputStream()) {
+ DMNImportPMMLInfo.from(pmmlIS, dmnCompilerConfig, model,
i).consume(new DMNCompilerImpl.PMMLImportErrConsumer(model, i),
+ model::addPMMLImportInfo);
+ } catch (IOException e) {
+ new DMNCompilerImpl.PMMLImportErrConsumer(model, i).accept(e);
+ }
+ }
+
+ /**
+ * Logs the error messages which comes while processing a dmn with an
unknown import type
+ * @param model : represents a DMN model, which includes all the necessary
components like decision tables and other elements defined in the DMN standard.
+ * @param importType : Type of import used within a Drools rule file
+ */
+ static void logErrorMessage(DMNModelImpl model, String importType) {
+ MsgUtil.reportMessage(LOGGER,
+ DMNMessage.Severity.ERROR,
+ null,
+ model,
+ null,
+ null,
+ Msg.IMPORT_TYPE_UNKNOWN,
+ importType);
+ }
+
+ /**
+ * Method to handle imports from the model
Review Comment:
Please describe what the method does
##########
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/DMNImportsUtil.java:
##########
@@ -130,4 +141,123 @@ public static ImportType whichImportType(Import
importElement) {
return ImportType.UNKNOWN;
}
}
+
+ /**
+ * Method to resolve the dmn models based on the import type
+ * @param i : object of the Import interface which represents an imported
resource in a DMN model
+ * @param dmnModels : List of decision models
+ * @param model : represents a DMN model, which includes all the necessary
components like decision tables and other elements defined in the DMN standard.
+ * @param toMerge : This is a list that will hold DMN models that are to
be merged later
+ */
+ static void resolveDMNImportType(Import i, Collection<DMNModel> dmnModels,
DMNModelImpl model, List<DMNModel> toMerge) {
+ Either<String, DMNModel> resolvedResult =
DMNImportsUtil.resolveImportDMN(i, dmnModels, (DMNModel m) -> new
QName(m.getNamespace(), m.getName()));
+ DMNModel located = resolvedResult.cata(msg -> {
+ MsgUtil.reportMessage(LOGGER,
+ DMNMessage.Severity.ERROR,
+ i,
+ model,
+ null,
+ null,
+ Msg.IMPORT_NOT_FOUND_FOR_NODE,
+ msg,
+ i);
+ return null;
+ }, Function.identity());
+ checkLocatedDMNModel(i, located, model, toMerge);
+
+ }
+
+ /**
+ * Method to import the dmn model to the default namespace
+ * @param i : represents an import object, and it has a name
(i.getName()). If the name is available, it will be used as the import alias.
+ * @param located : it is a DMN model that has been locate
+ * @param model : it is the target DMN model where the import or merge is
being applied
+ * @param toMerge : This is a list that will hold DMN models that are to
be merged later, instead of being directly imported.
+ */
+ static void checkLocatedDMNModel(Import i, DMNModel located, DMNModelImpl
model, List<DMNModel> toMerge) {
+ if (located != null) {
+ String importAlias =
Optional.ofNullable(i.getName()).orElse(located.getName());
+ // incubator-kie-issues#852: The idea is to not treat the
anonymous models as import, but to "merge" them
+ // with original one,
+ // because otherwise we would have to deal with clashing name
aliases, or similar issues
+ if (importAlias != null && !importAlias.isEmpty()) {
+ model.setImportAliasForNS(importAlias, located.getNamespace(),
located.getName());
+ importFromModel(model, located, importAlias);
+ } else {
+ toMerge.add(located);
+ }
+ }
+ }
+
+ /**
+ * Reolve model with import type as PMML
+ * @param model : represents a DMN model, which includes all the necessary
components like decision tables and other elements defined in the DMN standard.
+ * @param i : object of the Import interface which represents an imported
resource in a DMN model
+ * @param relativeResolver : is a functional interface used to resolve
relative paths to resources
+ * @param dmnCompilerConfig : object of the DMNCompilerConfigurationImpl
which is used to configure how the DMN models should be processed and compiled
by the DMN engine.
+ */
+ static void resolvePMMLImportType(DMNModelImpl model, Import i,
Function<String, Reader> relativeResolver, DMNCompilerConfigurationImpl
dmnCompilerConfig) {
+ ClassLoader rootClassLoader = dmnCompilerConfig.getRootClassLoader();
+ Resource relativeResource = resolveRelativeResource(rootClassLoader,
model, i, i, relativeResolver);
+ resolvePMMLImportType(model, i, relativeResource, dmnCompilerConfig);
+ }
+
+ /**
+ * Static methods to resolve the pmml models
Review Comment:
Please describe what the method does
##########
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/DMNCompilerImpl.java:
##########
@@ -203,77 +198,70 @@ public DMNModel compile(Definitions dmndefs, Resource
resource, Collection<DMNMo
return null;
}
+ /**
+ * Method to compile the dmn model
+ * @param dmndefs : defines the structure of the rules, models, and
associated metadata
Review Comment:
please replace "rules" with "decisions"
--
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]