You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kie.apache.org by "ChinchuAjith (via GitHub)" <gi...@apache.org> on 2025/02/28 04:48:39 UTC
[PR] DMNCompilerImpl class code refactoring and Test cases [incubator-kie-drools]
ChinchuAjith opened a new pull request, #6267:
URL: https://github.com/apache/incubator-kie-drools/pull/6267
(no comment)
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] DMNCompilerImpl class code refactoring and Test cases [incubator-kie-drools]
Posted by "ChinchuAjith (via GitHub)" <gi...@apache.org>.
ChinchuAjith commented on code in PR #6267:
URL: https://github.com/apache/incubator-kie-drools/pull/6267#discussion_r1984500325
##########
kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/compiler/DMNCompilerImplTest.java:
##########
@@ -70,10 +84,168 @@ void getRootElement() {
InformationRequirement informationRequirement = new TInformationRequirement();
elementReference.setParent(informationRequirement);
- assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> DMNCompilerImpl.getRootElement(elementReference));
-
+ assertThatExceptionOfType(RuntimeException.class).isThrownBy(
+ () -> DMNCompilerImpl.getRootElement(elementReference)).withMessageContaining
+ ("Failed to get Definitions parent for org.kie.dmn.model.v1_5");
informationRequirement.setParent(parent);
retrieved = DMNCompilerImpl.getRootElement(elementReference);
assertThat(retrieved).isNotNull().isEqualTo(parent);
}
-}
\ No newline at end of file
+
+ @Test
+ void compile() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f27bb64b-6fc7-4e1f-9848-11ba35e0df44";
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel importedModel = dMNCompiler.compile( resource, dmnModels);
+ assertThat(importedModel).isNotNull();
+ assertThat(importedModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ assertThat(importedModel.getMessages()).isEmpty();
+ }
+
+ @Test
+ void compileWithUnknownTypeModelImports() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f27bb64b-6fc7-4e1f-9848-11ba35e0df44";
+ String modelName = "Imported Model";
+ String importType = String.valueOf(ImportDMNResolverUtil.ImportType.UNKNOWN);
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel model = dMNCompiler.compile( resource, dmnModels);
+ assertThat(model).isNotNull();
+ Definitions dmnDefn = model.getDefinitions();
+ addImport(dmnDefn, importType, nameSpace, modelName);
+ dmnModels.add(model);
+ model = dMNCompiler.compile(dmnDefn, resource, dmnModels);
+ assertThat(model).isNotNull();
+ assertThat(model.getName()).isNotNull().isEqualTo(modelName);
+ assertThat(model.getMessages()).isNotEmpty();
+ assertThat(model.getMessages().get(0).getText()).isEqualTo("DMN: Import type unknown: 'UNKNOWN'. (Invalid FEEL syntax on the referenced expression) ");
+
+ }
+
+ @Test
+ void compileWithImportingDmnModel() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel importedModel = dMNCompiler.compile( resource, dmnModels);
+ assertThat(importedModel).isNotNull();
+ dmnModels.add(importedModel);
+
+ //imported model - Importing_Named_Model.dmn
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f79aa7a4-f9a3-410a-ac95-bea496edabgc";
+ resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_Named_Model.dmn",
+ this.getClass());
+
+ DMNModel importingModel = dMNCompiler.compile(resource, dmnModels);
+ assertThat(importingModel).isNotNull();
+ assertThat(importingModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ assertThat(importingModel.getMessages()).isEmpty();
+ }
+
+ @Test
+ void compileImportingModelWithoutImportedModel() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String modelName = "Importing named Model";
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_Named_Model.dmn",
+ this.getClass());
+ DMNModel model = dMNCompiler.compile( resource, dmnModels);
+ assertThat(model).isNotNull();
+ assertThat(model.getName()).isNotNull().isEqualTo(modelName);
+
+ Definitions dmnDefn = model.getDefinitions();
+ dmnModels.add(model);
+ model = dMNCompiler.compile(dmnDefn, resource, dmnModels);
+ assertThat(model).isNotNull();
+ assertThat(model.getName()).isNotNull().isEqualTo(modelName);
+ assertThat(model.getMessages()).isNotEmpty();
Review Comment:
Done
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] DMNCompilerImpl class code refactoring and Test cases [incubator-kie-drools]
Posted by "ChinchuAjith (via GitHub)" <gi...@apache.org>.
ChinchuAjith commented on code in PR #6267:
URL: https://github.com/apache/incubator-kie-drools/pull/6267#discussion_r1984507779
##########
kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/compiler/DMNCompilerImplTest.java:
##########
@@ -70,10 +84,168 @@ void getRootElement() {
InformationRequirement informationRequirement = new TInformationRequirement();
elementReference.setParent(informationRequirement);
- assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> DMNCompilerImpl.getRootElement(elementReference));
-
+ assertThatExceptionOfType(RuntimeException.class).isThrownBy(
+ () -> DMNCompilerImpl.getRootElement(elementReference)).withMessageContaining
+ ("Failed to get Definitions parent for org.kie.dmn.model.v1_5");
informationRequirement.setParent(parent);
retrieved = DMNCompilerImpl.getRootElement(elementReference);
assertThat(retrieved).isNotNull().isEqualTo(parent);
}
-}
\ No newline at end of file
+
+ @Test
+ void compile() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f27bb64b-6fc7-4e1f-9848-11ba35e0df44";
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel importedModel = dMNCompiler.compile( resource, dmnModels);
+ assertThat(importedModel).isNotNull();
+ assertThat(importedModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ assertThat(importedModel.getMessages()).isEmpty();
+ }
+
+ @Test
+ void compileWithUnknownTypeModelImports() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f27bb64b-6fc7-4e1f-9848-11ba35e0df44";
+ String modelName = "Imported Model";
+ String importType = String.valueOf(ImportDMNResolverUtil.ImportType.UNKNOWN);
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel model = dMNCompiler.compile( resource, dmnModels);
+ assertThat(model).isNotNull();
+ Definitions dmnDefn = model.getDefinitions();
+ addImport(dmnDefn, importType, nameSpace, modelName);
+ dmnModels.add(model);
+ model = dMNCompiler.compile(dmnDefn, resource, dmnModels);
+ assertThat(model).isNotNull();
+ assertThat(model.getName()).isNotNull().isEqualTo(modelName);
+ assertThat(model.getMessages()).isNotEmpty();
+ assertThat(model.getMessages().get(0).getText()).isEqualTo("DMN: Import type unknown: 'UNKNOWN'. (Invalid FEEL syntax on the referenced expression) ");
+
+ }
+
+ @Test
+ void compileWithImportingDmnModel() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel importedModel = dMNCompiler.compile( resource, dmnModels);
+ assertThat(importedModel).isNotNull();
+ dmnModels.add(importedModel);
+
+ //imported model - Importing_Named_Model.dmn
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f79aa7a4-f9a3-410a-ac95-bea496edabgc";
+ resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_Named_Model.dmn",
+ this.getClass());
+
+ DMNModel importingModel = dMNCompiler.compile(resource, dmnModels);
+ assertThat(importingModel).isNotNull();
+ assertThat(importingModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ assertThat(importingModel.getMessages()).isEmpty();
+ }
+
+ @Test
+ void compileImportingModelWithoutImportedModel() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String modelName = "Importing named Model";
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_Named_Model.dmn",
+ this.getClass());
+ DMNModel model = dMNCompiler.compile( resource, dmnModels);
+ assertThat(model).isNotNull();
+ assertThat(model.getName()).isNotNull().isEqualTo(modelName);
+
+ Definitions dmnDefn = model.getDefinitions();
+ dmnModels.add(model);
+ model = dMNCompiler.compile(dmnDefn, resource, dmnModels);
+ assertThat(model).isNotNull();
+ assertThat(model.getName()).isNotNull().isEqualTo(modelName);
+ assertThat(model.getMessages()).isNotEmpty();
+ assertThat(model.getMessages().get(0).getMessageType()).isEqualTo(DMNMessageType.IMPORT_NOT_FOUND);
+
+ }
+
+ @Test
+ void resolveDMNImportType() {
+ List<DMNModel> toMerge = new ArrayList<>();
+ List<DMNModel> dmnModels = new ArrayList<>();
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel importedModel = dMNCompiler.compile( resource, dmnModels);
+ assertThat(importedModel).isNotNull();
+ dmnModels.add(importedModel);
+
+ //imported model - Importing_Named_Model.dmn
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f79aa7a4-f9a3-410a-ac95-bea496edabgc";
+ resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_Named_Model.dmn",
+ this.getClass());
+ DMNModel importingModel = dMNCompiler.compile(resource, dmnModels);
+ assertThat(importingModel).isNotNull();
+ assertThat(importingModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ assertThat(importingModel.getMessages()).isEmpty();
+
+ Import input = importingModel.getDefinitions().getImport().get(0);
+ DMNModelImpl model = new DMNModelImpl(importingModel.getDefinitions(), resource);
+ DMNCompilerImpl.resolveDMNImportType(input, dmnModels, model, toMerge);
+ assertThat(model.getMessages()).isEmpty();
+ assertThat(model.getImportAliasesForNS().entrySet().stream().findFirst().get().getValue().getLocalPart()).isNotNull().isEqualTo("Imported Model");
Review Comment:
Done. Added assertion on the get() invocation
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] DMNCompilerImpl class code refactoring and Test cases [incubator-kie-drools]
Posted by "ChinchuAjith (via GitHub)" <gi...@apache.org>.
ChinchuAjith commented on code in PR #6267:
URL: https://github.com/apache/incubator-kie-drools/pull/6267#discussion_r1984536255
##########
kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/compiler/DMNCompilerImplTest.java:
##########
@@ -70,10 +84,168 @@ void getRootElement() {
InformationRequirement informationRequirement = new TInformationRequirement();
elementReference.setParent(informationRequirement);
- assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> DMNCompilerImpl.getRootElement(elementReference));
-
+ assertThatExceptionOfType(RuntimeException.class).isThrownBy(
+ () -> DMNCompilerImpl.getRootElement(elementReference)).withMessageContaining
+ ("Failed to get Definitions parent for org.kie.dmn.model.v1_5");
informationRequirement.setParent(parent);
retrieved = DMNCompilerImpl.getRootElement(elementReference);
assertThat(retrieved).isNotNull().isEqualTo(parent);
}
-}
\ No newline at end of file
+
+ @Test
+ void compile() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f27bb64b-6fc7-4e1f-9848-11ba35e0df44";
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel importedModel = dMNCompiler.compile( resource, dmnModels);
+ assertThat(importedModel).isNotNull();
+ assertThat(importedModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ assertThat(importedModel.getMessages()).isEmpty();
+ }
+
+ @Test
+ void compileWithUnknownTypeModelImports() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f27bb64b-6fc7-4e1f-9848-11ba35e0df44";
+ String modelName = "Imported Model";
+ String importType = String.valueOf(ImportDMNResolverUtil.ImportType.UNKNOWN);
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel model = dMNCompiler.compile( resource, dmnModels);
+ assertThat(model).isNotNull();
+ Definitions dmnDefn = model.getDefinitions();
+ addImport(dmnDefn, importType, nameSpace, modelName);
+ dmnModels.add(model);
+ model = dMNCompiler.compile(dmnDefn, resource, dmnModels);
+ assertThat(model).isNotNull();
+ assertThat(model.getName()).isNotNull().isEqualTo(modelName);
+ assertThat(model.getMessages()).isNotEmpty();
Review Comment:
Done
##########
kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/compiler/DMNCompilerImplTest.java:
##########
@@ -70,10 +84,168 @@ void getRootElement() {
InformationRequirement informationRequirement = new TInformationRequirement();
elementReference.setParent(informationRequirement);
- assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> DMNCompilerImpl.getRootElement(elementReference));
-
+ assertThatExceptionOfType(RuntimeException.class).isThrownBy(
+ () -> DMNCompilerImpl.getRootElement(elementReference)).withMessageContaining
+ ("Failed to get Definitions parent for org.kie.dmn.model.v1_5");
informationRequirement.setParent(parent);
retrieved = DMNCompilerImpl.getRootElement(elementReference);
assertThat(retrieved).isNotNull().isEqualTo(parent);
}
-}
\ No newline at end of file
+
+ @Test
+ void compile() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f27bb64b-6fc7-4e1f-9848-11ba35e0df44";
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel importedModel = dMNCompiler.compile( resource, dmnModels);
+ assertThat(importedModel).isNotNull();
+ assertThat(importedModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ assertThat(importedModel.getMessages()).isEmpty();
+ }
+
+ @Test
+ void compileWithUnknownTypeModelImports() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f27bb64b-6fc7-4e1f-9848-11ba35e0df44";
+ String modelName = "Imported Model";
+ String importType = String.valueOf(ImportDMNResolverUtil.ImportType.UNKNOWN);
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel model = dMNCompiler.compile( resource, dmnModels);
+ assertThat(model).isNotNull();
+ Definitions dmnDefn = model.getDefinitions();
+ addImport(dmnDefn, importType, nameSpace, modelName);
+ dmnModels.add(model);
+ model = dMNCompiler.compile(dmnDefn, resource, dmnModels);
+ assertThat(model).isNotNull();
+ assertThat(model.getName()).isNotNull().isEqualTo(modelName);
+ assertThat(model.getMessages()).isNotEmpty();
+ assertThat(model.getMessages().get(0).getText()).isEqualTo("DMN: Import type unknown: 'UNKNOWN'. (Invalid FEEL syntax on the referenced expression) ");
+
+ }
+
+ @Test
+ void compileWithImportingDmnModel() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel importedModel = dMNCompiler.compile( resource, dmnModels);
+ assertThat(importedModel).isNotNull();
+ dmnModels.add(importedModel);
+
+ //imported model - Importing_Named_Model.dmn
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f79aa7a4-f9a3-410a-ac95-bea496edabgc";
+ resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_Named_Model.dmn",
+ this.getClass());
+
+ DMNModel importingModel = dMNCompiler.compile(resource, dmnModels);
+ assertThat(importingModel).isNotNull();
+ assertThat(importingModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ assertThat(importingModel.getMessages()).isEmpty();
+ }
+
+ @Test
+ void compileImportingModelWithoutImportedModel() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String modelName = "Importing named Model";
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_Named_Model.dmn",
+ this.getClass());
+ DMNModel model = dMNCompiler.compile( resource, dmnModels);
+ assertThat(model).isNotNull();
+ assertThat(model.getName()).isNotNull().isEqualTo(modelName);
+
+ Definitions dmnDefn = model.getDefinitions();
+ dmnModels.add(model);
+ model = dMNCompiler.compile(dmnDefn, resource, dmnModels);
+ assertThat(model).isNotNull();
+ assertThat(model.getName()).isNotNull().isEqualTo(modelName);
+ assertThat(model.getMessages()).isNotEmpty();
Review Comment:
Done
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] [incubator-kie-issues#1748] DMNCompilerImpl class code refactoring and Test cases [incubator-kie-drools]
Posted by "gitgabrio (via GitHub)" <gi...@apache.org>.
gitgabrio merged PR #6267:
URL: https://github.com/apache/incubator-kie-drools/pull/6267
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] DMNCompilerImpl class code refactoring and Test cases [incubator-kie-drools]
Posted by "ChinchuAjith (via GitHub)" <gi...@apache.org>.
ChinchuAjith commented on code in PR #6267:
URL: https://github.com/apache/incubator-kie-drools/pull/6267#discussion_r1984508794
##########
kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/compiler/DMNCompilerImplTest.java:
##########
@@ -70,10 +84,168 @@ void getRootElement() {
InformationRequirement informationRequirement = new TInformationRequirement();
elementReference.setParent(informationRequirement);
- assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> DMNCompilerImpl.getRootElement(elementReference));
-
+ assertThatExceptionOfType(RuntimeException.class).isThrownBy(
+ () -> DMNCompilerImpl.getRootElement(elementReference)).withMessageContaining
+ ("Failed to get Definitions parent for org.kie.dmn.model.v1_5");
informationRequirement.setParent(parent);
retrieved = DMNCompilerImpl.getRootElement(elementReference);
assertThat(retrieved).isNotNull().isEqualTo(parent);
}
-}
\ No newline at end of file
+
+ @Test
+ void compile() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f27bb64b-6fc7-4e1f-9848-11ba35e0df44";
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel importedModel = dMNCompiler.compile( resource, dmnModels);
+ assertThat(importedModel).isNotNull();
+ assertThat(importedModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ assertThat(importedModel.getMessages()).isEmpty();
+ }
+
+ @Test
+ void compileWithUnknownTypeModelImports() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f27bb64b-6fc7-4e1f-9848-11ba35e0df44";
+ String modelName = "Imported Model";
+ String importType = String.valueOf(ImportDMNResolverUtil.ImportType.UNKNOWN);
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel model = dMNCompiler.compile( resource, dmnModels);
+ assertThat(model).isNotNull();
+ Definitions dmnDefn = model.getDefinitions();
+ addImport(dmnDefn, importType, nameSpace, modelName);
+ dmnModels.add(model);
+ model = dMNCompiler.compile(dmnDefn, resource, dmnModels);
+ assertThat(model).isNotNull();
+ assertThat(model.getName()).isNotNull().isEqualTo(modelName);
+ assertThat(model.getMessages()).isNotEmpty();
+ assertThat(model.getMessages().get(0).getText()).isEqualTo("DMN: Import type unknown: 'UNKNOWN'. (Invalid FEEL syntax on the referenced expression) ");
+
+ }
+
+ @Test
+ void compileWithImportingDmnModel() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel importedModel = dMNCompiler.compile( resource, dmnModels);
+ assertThat(importedModel).isNotNull();
+ dmnModels.add(importedModel);
+
+ //imported model - Importing_Named_Model.dmn
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f79aa7a4-f9a3-410a-ac95-bea496edabgc";
+ resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_Named_Model.dmn",
+ this.getClass());
+
+ DMNModel importingModel = dMNCompiler.compile(resource, dmnModels);
+ assertThat(importingModel).isNotNull();
+ assertThat(importingModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ assertThat(importingModel.getMessages()).isEmpty();
+ }
+
+ @Test
+ void compileImportingModelWithoutImportedModel() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String modelName = "Importing named Model";
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_Named_Model.dmn",
+ this.getClass());
+ DMNModel model = dMNCompiler.compile( resource, dmnModels);
+ assertThat(model).isNotNull();
+ assertThat(model.getName()).isNotNull().isEqualTo(modelName);
+
+ Definitions dmnDefn = model.getDefinitions();
+ dmnModels.add(model);
+ model = dMNCompiler.compile(dmnDefn, resource, dmnModels);
+ assertThat(model).isNotNull();
+ assertThat(model.getName()).isNotNull().isEqualTo(modelName);
+ assertThat(model.getMessages()).isNotEmpty();
+ assertThat(model.getMessages().get(0).getMessageType()).isEqualTo(DMNMessageType.IMPORT_NOT_FOUND);
+
+ }
+
+ @Test
+ void resolveDMNImportType() {
+ List<DMNModel> toMerge = new ArrayList<>();
+ List<DMNModel> dmnModels = new ArrayList<>();
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel importedModel = dMNCompiler.compile( resource, dmnModels);
+ assertThat(importedModel).isNotNull();
+ dmnModels.add(importedModel);
+
+ //imported model - Importing_Named_Model.dmn
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f79aa7a4-f9a3-410a-ac95-bea496edabgc";
+ resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_Named_Model.dmn",
+ this.getClass());
+ DMNModel importingModel = dMNCompiler.compile(resource, dmnModels);
+ assertThat(importingModel).isNotNull();
+ assertThat(importingModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ assertThat(importingModel.getMessages()).isEmpty();
+
+ Import input = importingModel.getDefinitions().getImport().get(0);
+ DMNModelImpl model = new DMNModelImpl(importingModel.getDefinitions(), resource);
+ DMNCompilerImpl.resolveDMNImportType(input, dmnModels, model, toMerge);
+ assertThat(model.getMessages()).isEmpty();
+ assertThat(model.getImportAliasesForNS().entrySet().stream().findFirst().get().getValue().getLocalPart()).isNotNull().isEqualTo("Imported Model");
+
+ }
+
+ @Test
+ void checkLocatedDMNModel() {
+ List<DMNModel> toMerge = new ArrayList<>();
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f79aa7a4-f9a3-410a-ac95-bea496edabgc";
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_Named_Model.dmn",
+ this.getClass());
+ DMNModel importingModel = dMNCompiler.compile(resource, dmnModels);
+ assertThat(importingModel).isNotNull();
+ assertThat(importingModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+
+ Import input = importingModel.getDefinitions().getImport().get(0);
+ DMNModelImpl model = new DMNModelImpl(importingModel.getDefinitions(), resource);
+ DMNModel located = new DMNModelImpl(importingModel.getDefinitions(), resource);
+ DMNCompilerImpl.checkLocatedDMNModel(input, located, model, toMerge);
+ assertThat(importingModel).isNotNull();
+ assertThat(importingModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ assertThat(toMerge.isEmpty()).isTrue();
Review Comment:
Corrected
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] DMNCompilerImpl class code refactoring and Test cases [incubator-kie-drools]
Posted by "ChinchuAjith (via GitHub)" <gi...@apache.org>.
ChinchuAjith commented on code in PR #6267:
URL: https://github.com/apache/incubator-kie-drools/pull/6267#discussion_r1984510423
##########
kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/compiler/DMNCompilerImplTest.java:
##########
@@ -70,10 +84,168 @@ void getRootElement() {
InformationRequirement informationRequirement = new TInformationRequirement();
elementReference.setParent(informationRequirement);
- assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> DMNCompilerImpl.getRootElement(elementReference));
-
+ assertThatExceptionOfType(RuntimeException.class).isThrownBy(
+ () -> DMNCompilerImpl.getRootElement(elementReference)).withMessageContaining
+ ("Failed to get Definitions parent for org.kie.dmn.model.v1_5");
informationRequirement.setParent(parent);
retrieved = DMNCompilerImpl.getRootElement(elementReference);
assertThat(retrieved).isNotNull().isEqualTo(parent);
}
-}
\ No newline at end of file
+
+ @Test
+ void compile() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f27bb64b-6fc7-4e1f-9848-11ba35e0df44";
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel importedModel = dMNCompiler.compile( resource, dmnModels);
+ assertThat(importedModel).isNotNull();
+ assertThat(importedModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ assertThat(importedModel.getMessages()).isEmpty();
+ }
+
+ @Test
+ void compileWithUnknownTypeModelImports() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f27bb64b-6fc7-4e1f-9848-11ba35e0df44";
+ String modelName = "Imported Model";
+ String importType = String.valueOf(ImportDMNResolverUtil.ImportType.UNKNOWN);
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel model = dMNCompiler.compile( resource, dmnModels);
+ assertThat(model).isNotNull();
+ Definitions dmnDefn = model.getDefinitions();
+ addImport(dmnDefn, importType, nameSpace, modelName);
+ dmnModels.add(model);
+ model = dMNCompiler.compile(dmnDefn, resource, dmnModels);
+ assertThat(model).isNotNull();
+ assertThat(model.getName()).isNotNull().isEqualTo(modelName);
+ assertThat(model.getMessages()).isNotEmpty();
+ assertThat(model.getMessages().get(0).getText()).isEqualTo("DMN: Import type unknown: 'UNKNOWN'. (Invalid FEEL syntax on the referenced expression) ");
+
+ }
+
+ @Test
+ void compileWithImportingDmnModel() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel importedModel = dMNCompiler.compile( resource, dmnModels);
+ assertThat(importedModel).isNotNull();
+ dmnModels.add(importedModel);
+
+ //imported model - Importing_Named_Model.dmn
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f79aa7a4-f9a3-410a-ac95-bea496edabgc";
+ resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_Named_Model.dmn",
+ this.getClass());
+
+ DMNModel importingModel = dMNCompiler.compile(resource, dmnModels);
+ assertThat(importingModel).isNotNull();
+ assertThat(importingModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ assertThat(importingModel.getMessages()).isEmpty();
+ }
+
+ @Test
+ void compileImportingModelWithoutImportedModel() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String modelName = "Importing named Model";
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_Named_Model.dmn",
+ this.getClass());
+ DMNModel model = dMNCompiler.compile( resource, dmnModels);
+ assertThat(model).isNotNull();
+ assertThat(model.getName()).isNotNull().isEqualTo(modelName);
+
+ Definitions dmnDefn = model.getDefinitions();
+ dmnModels.add(model);
+ model = dMNCompiler.compile(dmnDefn, resource, dmnModels);
+ assertThat(model).isNotNull();
+ assertThat(model.getName()).isNotNull().isEqualTo(modelName);
+ assertThat(model.getMessages()).isNotEmpty();
+ assertThat(model.getMessages().get(0).getMessageType()).isEqualTo(DMNMessageType.IMPORT_NOT_FOUND);
+
+ }
+
+ @Test
+ void resolveDMNImportType() {
+ List<DMNModel> toMerge = new ArrayList<>();
+ List<DMNModel> dmnModels = new ArrayList<>();
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel importedModel = dMNCompiler.compile( resource, dmnModels);
+ assertThat(importedModel).isNotNull();
+ dmnModels.add(importedModel);
+
+ //imported model - Importing_Named_Model.dmn
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f79aa7a4-f9a3-410a-ac95-bea496edabgc";
+ resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_Named_Model.dmn",
+ this.getClass());
+ DMNModel importingModel = dMNCompiler.compile(resource, dmnModels);
+ assertThat(importingModel).isNotNull();
+ assertThat(importingModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ assertThat(importingModel.getMessages()).isEmpty();
+
+ Import input = importingModel.getDefinitions().getImport().get(0);
+ DMNModelImpl model = new DMNModelImpl(importingModel.getDefinitions(), resource);
+ DMNCompilerImpl.resolveDMNImportType(input, dmnModels, model, toMerge);
+ assertThat(model.getMessages()).isEmpty();
+ assertThat(model.getImportAliasesForNS().entrySet().stream().findFirst().get().getValue().getLocalPart()).isNotNull().isEqualTo("Imported Model");
+
+ }
+
+ @Test
+ void checkLocatedDMNModel() {
+ List<DMNModel> toMerge = new ArrayList<>();
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f79aa7a4-f9a3-410a-ac95-bea496edabgc";
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_Named_Model.dmn",
+ this.getClass());
+ DMNModel importingModel = dMNCompiler.compile(resource, dmnModels);
+ assertThat(importingModel).isNotNull();
+ assertThat(importingModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+
+ Import input = importingModel.getDefinitions().getImport().get(0);
+ DMNModelImpl model = new DMNModelImpl(importingModel.getDefinitions(), resource);
+ DMNModel located = new DMNModelImpl(importingModel.getDefinitions(), resource);
+ DMNCompilerImpl.checkLocatedDMNModel(input, located, model, toMerge);
+ assertThat(importingModel).isNotNull();
+ assertThat(importingModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ assertThat(toMerge.isEmpty()).isTrue();
+ }
+
+ @Test
+ void checkLocatedDMNModelWithAliasNull() {
+ String namespace="http://www.trisotech.com/dmn/definitions/_f79aa7a4-f9a3-410a-ac95-bea496edabgc";
+ List<DMNModel> toMerge = new ArrayList<>();
+ List<DMNModel> dmnModels = new ArrayList<>();
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_EmptyNamed_Model_Without_Href_Namespace.dmn",
+ this.getClass());
+ DMNModel emptyNamedModel = dMNCompiler.compile( resource, dmnModels);
+ assertThat(emptyNamedModel).isNotNull();
+ dmnModels.add(emptyNamedModel);
+
+ Import input = emptyNamedModel.getDefinitions().getImport().get(0);
+ DMNModelImpl model = new DMNModelImpl(emptyNamedModel.getDefinitions(), resource);
+ DMNModel located = new DMNModelImpl(emptyNamedModel.getDefinitions(), resource);
+ DMNCompilerImpl.checkLocatedDMNModel(input, located, model, toMerge);
+ assertThat(emptyNamedModel).isNotNull();
+ assertThat(toMerge.isEmpty()).isFalse();
Review Comment:
Done
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] DMNCompilerImpl class code refactoring and Test cases [incubator-kie-drools]
Posted by "gitgabrio (via GitHub)" <gi...@apache.org>.
gitgabrio commented on code in PR #6267:
URL: https://github.com/apache/incubator-kie-drools/pull/6267#discussion_r1986941690
##########
kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/compiler/DMNCompilerImplTest.java:
##########
@@ -70,10 +83,192 @@ void getRootElement() {
InformationRequirement informationRequirement = new TInformationRequirement();
elementReference.setParent(informationRequirement);
- assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> DMNCompilerImpl.getRootElement(elementReference));
-
+ assertThatExceptionOfType(RuntimeException.class).isThrownBy(
+ () -> DMNCompilerImpl.getRootElement(elementReference)).withMessageContaining
+ ("Failed to get Definitions parent for org.kie.dmn.model.v1_5");
informationRequirement.setParent(parent);
retrieved = DMNCompilerImpl.getRootElement(elementReference);
assertThat(retrieved).isNotNull().isEqualTo(parent);
}
-}
\ No newline at end of file
+
+ @Test
+ void compile() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f27bb64b-6fc7-4e1f-9848-11ba35e0df44";
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel importedModel = dMNCompiler.compile( resource, dmnModels);
+ assertThat(importedModel).isNotNull();
+ assertThat(importedModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ assertThat(importedModel.getMessages()).isEmpty();
+ }
+
+ @Test
+ void compileWithUnknownTypeModelImports() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f27bb64b-6fc7-4e1f-9848-11ba35e0df44";
+ String modelName = "Imported Model";
+ String importType = String.valueOf(ImportDMNResolverUtil.ImportType.UNKNOWN);
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel model = dMNCompiler.compile( resource, dmnModels);
+ assertThat(model).isNotNull();
+ Definitions dmnDefn = model.getDefinitions();
+ addImport(dmnDefn, importType, nameSpace, modelName);
+ dmnModels.add(model);
+ model = dMNCompiler.compile(dmnDefn, resource, dmnModels);
+ assertThat(model).isNotNull();
+ assertThat(model.getName()).isNotNull().isEqualTo(modelName);
+ assertThat(model.getMessages()).isNotEmpty();
Review Comment:
This could be removed (implemented by following one)
##########
kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/compiler/DMNCompilerImplTest.java:
##########
@@ -70,10 +83,192 @@ void getRootElement() {
InformationRequirement informationRequirement = new TInformationRequirement();
elementReference.setParent(informationRequirement);
- assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> DMNCompilerImpl.getRootElement(elementReference));
-
+ assertThatExceptionOfType(RuntimeException.class).isThrownBy(
+ () -> DMNCompilerImpl.getRootElement(elementReference)).withMessageContaining
+ ("Failed to get Definitions parent for org.kie.dmn.model.v1_5");
informationRequirement.setParent(parent);
retrieved = DMNCompilerImpl.getRootElement(elementReference);
assertThat(retrieved).isNotNull().isEqualTo(parent);
}
-}
\ No newline at end of file
+
+ @Test
+ void compile() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f27bb64b-6fc7-4e1f-9848-11ba35e0df44";
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel importedModel = dMNCompiler.compile( resource, dmnModels);
+ assertThat(importedModel).isNotNull();
+ assertThat(importedModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ assertThat(importedModel.getMessages()).isEmpty();
+ }
+
+ @Test
+ void compileWithUnknownTypeModelImports() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f27bb64b-6fc7-4e1f-9848-11ba35e0df44";
+ String modelName = "Imported Model";
+ String importType = String.valueOf(ImportDMNResolverUtil.ImportType.UNKNOWN);
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel model = dMNCompiler.compile( resource, dmnModels);
+ assertThat(model).isNotNull();
+ Definitions dmnDefn = model.getDefinitions();
+ addImport(dmnDefn, importType, nameSpace, modelName);
+ dmnModels.add(model);
+ model = dMNCompiler.compile(dmnDefn, resource, dmnModels);
+ assertThat(model).isNotNull();
+ assertThat(model.getName()).isNotNull().isEqualTo(modelName);
+ assertThat(model.getMessages()).isNotEmpty();
+ assertThat(model.getMessages().size()).isEqualTo(1);
+ assertThat(model.getMessages().get(0).getText()).isEqualTo("DMN: Import type unknown: 'UNKNOWN'. (Invalid FEEL syntax on the referenced expression) ");
+
+ }
+
+ @Test
+ void compileWithImportingDmnModel() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel importedModel = dMNCompiler.compile( resource, dmnModels);
+ assertThat(importedModel).isNotNull();
+ dmnModels.add(importedModel);
+
+ //imported model - Importing_Named_Model.dmn
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f79aa7a4-f9a3-410a-ac95-bea496edabgc";
+ resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_Named_Model.dmn",
+ this.getClass());
+
+ DMNModel importingModel = dMNCompiler.compile(resource, dmnModels);
+ assertThat(importingModel).isNotNull();
+ assertThat(importingModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ assertThat(importingModel.getMessages()).isEmpty();
+ }
+
+ @Test
+ void compileImportingModelWithoutImportedModel() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String modelName = "Importing named Model";
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_Named_Model.dmn",
+ this.getClass());
+ DMNModel model = dMNCompiler.compile( resource, dmnModels);
+ assertThat(model).isNotNull();
+ assertThat(model.getName()).isNotNull().isEqualTo(modelName);
+
+ Definitions dmnDefn = model.getDefinitions();
+ dmnModels.add(model);
+ model = dMNCompiler.compile(dmnDefn, resource, dmnModels);
+ assertThat(model).isNotNull();
+ assertThat(model.getName()).isNotNull().isEqualTo(modelName);
+ assertThat(model.getMessages()).isNotEmpty();
Review Comment:
This could be removed (implemented by following one)
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] [incubator-kie-issues#1748] DMNCompilerImpl class code refactoring and Test cases [incubator-kie-drools]
Posted by "ChinchuAjith (via GitHub)" <gi...@apache.org>.
ChinchuAjith commented on code in PR #6267:
URL: https://github.com/apache/incubator-kie-drools/pull/6267#discussion_r2007320787
##########
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:
Updated.
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] [incubator-kie-issues#1748] DMNCompilerImpl class code refactoring and Test cases [incubator-kie-drools]
Posted by "kie-ci3 (via GitHub)" <gi...@apache.org>.
kie-ci3 commented on PR #6267:
URL: https://github.com/apache/incubator-kie-drools/pull/6267#issuecomment-2737207257
**PR job** `#12` was: **UNSTABLE**
Possible explanation: This should be test failures
<details>
<summary><b>Reproducer</b></summary>
build-chain build full_downstream -f 'https://raw.githubusercontent.com/${AUTHOR:apache}/incubator-kie-kogito-pipelines/${BRANCH:main}/.ci/buildchain-config-pr-cdb.yaml' -o 'bc' -p apache/incubator-kie-drools -u https://github.com/apache/incubator-kie-drools/pull/6267 --skipParallelCheckout
NOTE: To install the build-chain tool, please refer to https://github.com/kiegroup/github-action-build-chain#local-execution
</details>
Please look here: https://ci-builds.apache.org/job/KIE/job/drools/job/main/job/pullrequest_jobs/job/drools-pr/job/PR-6267/12/display/redirect
**Test results:**
- PASSED: 23364
- FAILED: 1
Those are the test failures:
<details>
<summary><a href="https://ci-builds.apache.org/job/KIE/job/drools/job/main/job/pullrequest_jobs/job/drools-pr/job/PR-6267/12/testReport/org.kie.dmn.core.compiler/DMNCompilerImplTest/compileWithInvalidModel/">org.kie.dmn.core.compiler.DMNCompilerImplTest.compileWithInvalidModel</a></summary>
<br/>Expecting actual not to be null
</details>
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] DMNCompilerImpl class code refactoring and Test cases [incubator-kie-drools]
Posted by "ChinchuAjith (via GitHub)" <gi...@apache.org>.
ChinchuAjith commented on code in PR #6267:
URL: https://github.com/apache/incubator-kie-drools/pull/6267#discussion_r1987585302
##########
kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/compiler/DMNCompilerImplTest.java:
##########
@@ -70,10 +83,192 @@ void getRootElement() {
InformationRequirement informationRequirement = new TInformationRequirement();
elementReference.setParent(informationRequirement);
- assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> DMNCompilerImpl.getRootElement(elementReference));
-
+ assertThatExceptionOfType(RuntimeException.class).isThrownBy(
+ () -> DMNCompilerImpl.getRootElement(elementReference)).withMessageContaining
+ ("Failed to get Definitions parent for org.kie.dmn.model.v1_5");
informationRequirement.setParent(parent);
retrieved = DMNCompilerImpl.getRootElement(elementReference);
assertThat(retrieved).isNotNull().isEqualTo(parent);
}
-}
\ No newline at end of file
+
+ @Test
+ void compile() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f27bb64b-6fc7-4e1f-9848-11ba35e0df44";
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel importedModel = dMNCompiler.compile( resource, dmnModels);
+ assertThat(importedModel).isNotNull();
+ assertThat(importedModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ assertThat(importedModel.getMessages()).isEmpty();
+ }
+
+ @Test
+ void compileWithUnknownTypeModelImports() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f27bb64b-6fc7-4e1f-9848-11ba35e0df44";
+ String modelName = "Imported Model";
+ String importType = String.valueOf(ImportDMNResolverUtil.ImportType.UNKNOWN);
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel model = dMNCompiler.compile( resource, dmnModels);
+ assertThat(model).isNotNull();
+ Definitions dmnDefn = model.getDefinitions();
+ addImport(dmnDefn, importType, nameSpace, modelName);
+ dmnModels.add(model);
+ model = dMNCompiler.compile(dmnDefn, resource, dmnModels);
+ assertThat(model).isNotNull();
+ assertThat(model.getName()).isNotNull().isEqualTo(modelName);
+ assertThat(model.getMessages()).isNotEmpty();
+ assertThat(model.getMessages().size()).isEqualTo(1);
+ assertThat(model.getMessages().get(0).getText()).isEqualTo("DMN: Import type unknown: 'UNKNOWN'. (Invalid FEEL syntax on the referenced expression) ");
+
+ }
+
+ @Test
+ void compileWithImportingDmnModel() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel importedModel = dMNCompiler.compile( resource, dmnModels);
+ assertThat(importedModel).isNotNull();
+ dmnModels.add(importedModel);
+
+ //imported model - Importing_Named_Model.dmn
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f79aa7a4-f9a3-410a-ac95-bea496edabgc";
+ resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_Named_Model.dmn",
+ this.getClass());
+
+ DMNModel importingModel = dMNCompiler.compile(resource, dmnModels);
+ assertThat(importingModel).isNotNull();
+ assertThat(importingModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ assertThat(importingModel.getMessages()).isEmpty();
+ }
+
+ @Test
+ void compileImportingModelWithoutImportedModel() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String modelName = "Importing named Model";
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_Named_Model.dmn",
+ this.getClass());
+ DMNModel model = dMNCompiler.compile( resource, dmnModels);
+ assertThat(model).isNotNull();
+ assertThat(model.getName()).isNotNull().isEqualTo(modelName);
+
+ Definitions dmnDefn = model.getDefinitions();
+ dmnModels.add(model);
+ model = dMNCompiler.compile(dmnDefn, resource, dmnModels);
+ assertThat(model).isNotNull();
+ assertThat(model.getName()).isNotNull().isEqualTo(modelName);
+ assertThat(model.getMessages()).isNotEmpty();
Review Comment:
removed and committed the changes
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] DMNCompilerImpl class code refactoring and Test cases [incubator-kie-drools]
Posted by "gitgabrio (via GitHub)" <gi...@apache.org>.
gitgabrio commented on code in PR #6267:
URL: https://github.com/apache/incubator-kie-drools/pull/6267#discussion_r1993003307
##########
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/DMNCompilerImpl.java:
##########
@@ -209,60 +210,82 @@ public DMNModel compile(Definitions dmndefs, Collection<DMNModel> dmnModels, Res
}
DMNModelImpl model = new DMNModelImpl(dmndefs, resource);
model.setRuntimeTypeCheck(((DMNCompilerConfigurationImpl) dmnCompilerConfig).getOption(RuntimeTypeCheckOption.class).isRuntimeTypeCheck());
+ DMNCompilerContext ctx = configureDMNCompiler(model.getFeelDialect(), relativeResolver);
+ if (!dmndefs.getImport().isEmpty()) {
+ iterateImports(dmndefs, dmnModels, model, relativeResolver );
+ }
+ processItemDefinitions(ctx, model, dmndefs);
+ processDrgElements(ctx, model, dmndefs);
+ return model;
+ }
+
+ private DMNCompilerContext configureDMNCompiler(FEELDialect feeldialect, Function<String, Reader> relativeResolver) {
+
DMNCompilerConfigurationImpl cc = (DMNCompilerConfigurationImpl) dmnCompilerConfig;
List<FEELProfile> helperFEELProfiles = cc.getFeelProfiles();
- DMNFEELHelper feel = new DMNFEELHelper(cc.getRootClassLoader(), helperFEELProfiles, model.getFeelDialect());
+ DMNFEELHelper feel = new DMNFEELHelper(cc.getRootClassLoader(), helperFEELProfiles, feeldialect);
DMNCompilerContext ctx = new DMNCompilerContext(feel);
ctx.setRelativeResolver(relativeResolver);
+ return ctx;
+ }
+
+ private void iterateImports(Definitions dmndefs, Collection<DMNModel> dmnModels, DMNModelImpl model, Function<String, Reader> relativeResolver ) {
Review Comment:
Hi @ChinchuAjith - sorry: how this private method is tested ? What I meant was to test it completely, not its inner parts in isolation
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] DMNCompilerImpl class code refactoring and Test cases [incubator-kie-drools]
Posted by "bncriju (via GitHub)" <gi...@apache.org>.
bncriju commented on code in PR #6267:
URL: https://github.com/apache/incubator-kie-drools/pull/6267#discussion_r1991742886
##########
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/DMNImportsUtil.java:
##########
@@ -130,4 +141,84 @@ public static ImportType whichImportType(Import importElement) {
return ImportType.UNKNOWN;
}
}
+
+ static void resolveDMNImportType(Import i, Collection<DMNModel> dmnModels, DMNModelImpl model, List<DMNModel> toMerge) {
Review Comment:
please add javadoc
##########
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/DMNImportsUtil.java:
##########
@@ -130,4 +141,84 @@ public static ImportType whichImportType(Import importElement) {
return ImportType.UNKNOWN;
}
}
+
+ 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);
+
+ }
+
+ static void checkLocatedDMNModel(Import i, DMNModel located, DMNModelImpl model, List<DMNModel> toMerge) {
+ if (located != null) {
+ String iAlias = 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 (iAlias != null && !iAlias.isEmpty()) {
+ model.setImportAliasForNS(iAlias, located.getNamespace(), located.getName());
+ importFromModel(model, located, iAlias);
+ } else {
+ toMerge.add(located);
+ }
+ }
+ }
+
+ static void resolvePMMLImportType(DMNModelImpl model, Import i, Function<String, Reader> relativeResolver, DMNCompilerConfigurationImpl dmnCompilerConfig) {
Review Comment:
please add javadoc
##########
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/DMNCompilerImpl.java:
##########
@@ -317,6 +282,7 @@ protected static Resource resolveRelativeResource(ClassLoader classLoader, DMNMo
throw new UnsupportedOperationException("Unable to determine relative Resource for import named: " + i.getName());
}
+
Review Comment:
please add javadoc
##########
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/DMNImportsUtil.java:
##########
@@ -130,4 +141,84 @@ public static ImportType whichImportType(Import importElement) {
return ImportType.UNKNOWN;
}
}
+
+ 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);
+
+ }
+
+ static void checkLocatedDMNModel(Import i, DMNModel located, DMNModelImpl model, List<DMNModel> toMerge) {
+ if (located != null) {
+ String iAlias = 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 (iAlias != null && !iAlias.isEmpty()) {
+ model.setImportAliasForNS(iAlias, located.getNamespace(), located.getName());
+ importFromModel(model, located, iAlias);
+ } else {
+ toMerge.add(located);
+ }
+ }
+ }
+
+ 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 void resolvePMMLImportType(DMNModelImpl model, Import i, Resource relativeResource, DMNCompilerConfigurationImpl dmnCompilerConfig) {
Review Comment:
please add javadoc
##########
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/DMNImportsUtil.java:
##########
@@ -130,4 +141,84 @@ public static ImportType whichImportType(Import importElement) {
return ImportType.UNKNOWN;
}
}
+
+ 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);
+
+ }
+
+ static void checkLocatedDMNModel(Import i, DMNModel located, DMNModelImpl model, List<DMNModel> toMerge) {
+ if (located != null) {
+ String iAlias = 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 (iAlias != null && !iAlias.isEmpty()) {
+ model.setImportAliasForNS(iAlias, located.getNamespace(), located.getName());
+ importFromModel(model, located, iAlias);
+ } else {
+ toMerge.add(located);
+ }
+ }
+ }
+
+ 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 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);
+ }
+ }
+
+ static void logErrorMessage(DMNModelImpl model, String importType) {
+ MsgUtil.reportMessage(LOGGER,
+ DMNMessage.Severity.ERROR,
+ null,
+ model,
+ null,
+ null,
+ Msg.IMPORT_TYPE_UNKNOWN,
+ importType);
+ }
+
+ static void importFromModel(DMNModelImpl model, DMNModel m, String iAlias) {
Review Comment:
please add javadoc
##########
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/DMNImportsUtil.java:
##########
@@ -130,4 +141,84 @@ public static ImportType whichImportType(Import importElement) {
return ImportType.UNKNOWN;
}
}
+
+ 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);
+
+ }
+
+ static void checkLocatedDMNModel(Import i, DMNModel located, DMNModelImpl model, List<DMNModel> toMerge) {
Review Comment:
please add javadoc
##########
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/DMNImportsUtil.java:
##########
@@ -130,4 +141,84 @@ public static ImportType whichImportType(Import importElement) {
return ImportType.UNKNOWN;
}
}
+
+ 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);
+
+ }
+
+ static void checkLocatedDMNModel(Import i, DMNModel located, DMNModelImpl model, List<DMNModel> toMerge) {
+ if (located != null) {
+ String iAlias = 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 (iAlias != null && !iAlias.isEmpty()) {
+ model.setImportAliasForNS(iAlias, located.getNamespace(), located.getName());
+ importFromModel(model, located, iAlias);
+ } else {
+ toMerge.add(located);
+ }
+ }
+ }
+
+ 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 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);
+ }
+ }
+
+ static void logErrorMessage(DMNModelImpl model, String importType) {
Review Comment:
please add javadoc
##########
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/assembler/DMNAssemblerService.java:
##########
@@ -43,13 +43,9 @@
import org.kie.dmn.api.core.DMNModel;
import org.kie.dmn.api.marshalling.DMNMarshaller;
import org.kie.dmn.core.api.DMNFactory;
-import org.kie.dmn.core.compiler.DMNCompilerConfigurationImpl;
-import org.kie.dmn.core.compiler.DMNCompilerImpl;
-import org.kie.dmn.core.compiler.DMNDecisionLogicCompilerFactory;
-import org.kie.dmn.core.compiler.DMNProfile;
-import org.kie.dmn.core.compiler.ImportDMNResolverUtil;
-import org.kie.dmn.core.compiler.ImportDMNResolverUtil.ImportType;
-import org.kie.dmn.core.compiler.RuntimeTypeCheckOption;
+import org.kie.dmn.core.compiler.*;
Review Comment:
Instead of asterisk and importing everything, import what exactly is required
##########
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/DMNImportsUtil.java:
##########
@@ -130,4 +141,84 @@ public static ImportType whichImportType(Import importElement) {
return ImportType.UNKNOWN;
}
}
+
+ 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);
+
+ }
+
+ static void checkLocatedDMNModel(Import i, DMNModel located, DMNModelImpl model, List<DMNModel> toMerge) {
+ if (located != null) {
+ String iAlias = 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
Review Comment:
The comment regarding the incubator-kie-issues#852 is valuable but could be made clearer with a bit more context of the same
##########
kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/compiler/DMNImportsUtilTest.java:
##########
@@ -190,4 +197,96 @@ private Import makeImport(final String namespace, final String name, final Strin
return i;
}
+ @Test
+ void checkLocatedDMNModel() {
+ List<DMNModel> toMerge = new ArrayList<>();
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f79aa7a4-f9a3-410a-ac95-bea496edabgc";
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_Named_Model.dmn",
+ this.getClass());
+ DMNModel importingModel = dMNCompiler.compile(resource, dmnModels);
+ assertThat(importingModel).isNotNull();
+ assertThat(importingModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+
+ Import input = importingModel.getDefinitions().getImport().get(0);
+ DMNModelImpl model = new DMNModelImpl(importingModel.getDefinitions(), resource);
+ DMNModel located = new DMNModelImpl(importingModel.getDefinitions(), resource);
+ DMNImportsUtil.checkLocatedDMNModel(input, located, model, toMerge);
+ assertThat(importingModel).isNotNull();
+ assertThat(importingModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ assertThat(toMerge).isEmpty();
+ }
+
+ @Test
+ void resolveDMNImportType() {
+ List<DMNModel> toMerge = new ArrayList<>();
+ List<DMNModel> dmnModels = new ArrayList<>();
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel importedModel = dMNCompiler.compile( resource, dmnModels);
+ assertThat(importedModel).isNotNull();
+ dmnModels.add(importedModel);
+
+ //imported model - Importing_Named_Model.dmn
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f79aa7a4-f9a3-410a-ac95-bea496edabgc";
+ resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_Named_Model.dmn",
+ this.getClass());
+ DMNModel importingModel = dMNCompiler.compile(resource, dmnModels);
+ assertThat(importingModel).isNotNull();
+ assertThat(importingModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ assertThat(importingModel.getMessages()).isEmpty();
+
+ Import input = importingModel.getDefinitions().getImport().get(0);
+ DMNModelImpl model = new DMNModelImpl(importingModel.getDefinitions(), resource);
+ DMNImportsUtil.resolveDMNImportType(input, dmnModels, model, toMerge);
+ assertThat(model.getMessages()).isEmpty();
+ assertThat(model.getImportAliasesForNS().entrySet().stream().findFirst())
+ .isPresent().get().extracting(Map.Entry::getValue)
+ .extracting(QName::getLocalPart).isNotNull().isEqualTo("Imported Model");
+
+ }
+
+
+
+ @Test
+ void checkLocatedDMNModelWithAliasNull() {
+ String namespace="http://www.trisotech.com/dmn/definitions/_f79aa7a4-f9a3-410a-ac95-bea496edabgc";
+ List<DMNModel> toMerge = new ArrayList<>();
+ List<DMNModel> dmnModels = new ArrayList<>();
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_EmptyNamed_Model_Without_Href_Namespace.dmn",
+ this.getClass());
+ DMNModel emptyNamedModel = dMNCompiler.compile( resource, dmnModels);
+ assertThat(emptyNamedModel).isNotNull();
+ dmnModels.add(emptyNamedModel);
+
+ Import input = emptyNamedModel.getDefinitions().getImport().get(0);
+ DMNModelImpl model = new DMNModelImpl(emptyNamedModel.getDefinitions(), resource);
+ DMNModel located = new DMNModelImpl(emptyNamedModel.getDefinitions(), resource);
+ DMNImportsUtil.checkLocatedDMNModel(input, located, model, toMerge);
+ assertThat(emptyNamedModel).isNotNull();
+ assertThat(toMerge).isNotEmpty();
+ assertThat(toMerge.size()).isEqualTo(1);
+ assertThat(toMerge.get(0).getNamespace()).isNotNull().isEqualTo(namespace);
+ }
+
+ @Test
+ void resolvePMMLImportType() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ Resource dmnResource = new ClassPathResource( "../pmml/KiePMMLNewTree.dmn",
+ this.getClass());
+ DMNModel importingModel = dMNCompiler.compile( dmnResource, dmnModels);
+ assertThat(importingModel).isNotNull();
+
+
+ Import input = importingModel.getDefinitions().getImport().get(0);
+ DMNModelImpl model = new DMNModelImpl(importingModel.getDefinitions(), dmnResource);
+
+ Resource relativeResource = new ClassPathResource( "../pmml/test_tree_new.pmml",
+ this.getClass());
+ assertThat(model.getPmmlImportInfo()).isEmpty();
+ DMNCompilerConfigurationImpl dmnCompilerConfig = (DMNCompilerConfigurationImpl)((DMNCompilerImpl)dMNCompiler).getDmnCompilerConfig();
+ DMNImportsUtil.resolvePMMLImportType(model, input, relativeResource, dmnCompilerConfig);
+ assertThat(model.getPmmlImportInfo()).hasSize(1).containsOnlyKeys("test_tree");
+ }
+
Review Comment:
It might be beneficial to include edge cases, such as:
- An empty DMN file or one with invalid syntax.
- A case where the import model is valid but contains errors or discrepancies in the expected structure.
##########
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/DMNImportsUtil.java:
##########
@@ -130,4 +141,84 @@ public static ImportType whichImportType(Import importElement) {
return ImportType.UNKNOWN;
}
}
+
+ 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);
+
+ }
+
+ static void checkLocatedDMNModel(Import i, DMNModel located, DMNModelImpl model, List<DMNModel> toMerge) {
+ if (located != null) {
+ String iAlias = Optional.ofNullable(i.getName()).orElse(located.getName());
Review Comment:
iAlias could be renamed to importAlias to improve readability.
##########
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/DMNCompilerImpl.java:
##########
@@ -107,6 +98,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import static org.kie.dmn.core.compiler.DMNImportsUtil.*;
Review Comment:
Instead of asterisk and importing everything, import what exactly is required
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] DMNCompilerImpl class code refactoring and Test cases [incubator-kie-drools]
Posted by "ChinchuAjith (via GitHub)" <gi...@apache.org>.
ChinchuAjith commented on code in PR #6267:
URL: https://github.com/apache/incubator-kie-drools/pull/6267#discussion_r1992830989
##########
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/assembler/DMNAssemblerService.java:
##########
@@ -43,13 +43,9 @@
import org.kie.dmn.api.core.DMNModel;
import org.kie.dmn.api.marshalling.DMNMarshaller;
import org.kie.dmn.core.api.DMNFactory;
-import org.kie.dmn.core.compiler.DMNCompilerConfigurationImpl;
-import org.kie.dmn.core.compiler.DMNCompilerImpl;
-import org.kie.dmn.core.compiler.DMNDecisionLogicCompilerFactory;
-import org.kie.dmn.core.compiler.DMNProfile;
-import org.kie.dmn.core.compiler.ImportDMNResolverUtil;
-import org.kie.dmn.core.compiler.ImportDMNResolverUtil.ImportType;
-import org.kie.dmn.core.compiler.RuntimeTypeCheckOption;
+import org.kie.dmn.core.compiler.*;
Review Comment:
Done
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] DMNCompilerImpl class code refactoring and Test cases [incubator-kie-drools]
Posted by "yesamer (via GitHub)" <gi...@apache.org>.
yesamer commented on PR #6267:
URL: https://github.com/apache/incubator-kie-drools/pull/6267#issuecomment-2706224202
@ChinchuAjith Can you please describe the changes you applied in the first message? Thanks!
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] DMNCompilerImpl class code refactoring and Test cases [incubator-kie-drools]
Posted by "ChinchuAjith (via GitHub)" <gi...@apache.org>.
ChinchuAjith commented on code in PR #6267:
URL: https://github.com/apache/incubator-kie-drools/pull/6267#discussion_r1984499280
##########
kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/compiler/DMNCompilerImplTest.java:
##########
@@ -70,10 +84,168 @@ void getRootElement() {
InformationRequirement informationRequirement = new TInformationRequirement();
elementReference.setParent(informationRequirement);
- assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> DMNCompilerImpl.getRootElement(elementReference));
-
+ assertThatExceptionOfType(RuntimeException.class).isThrownBy(
+ () -> DMNCompilerImpl.getRootElement(elementReference)).withMessageContaining
+ ("Failed to get Definitions parent for org.kie.dmn.model.v1_5");
informationRequirement.setParent(parent);
retrieved = DMNCompilerImpl.getRootElement(elementReference);
assertThat(retrieved).isNotNull().isEqualTo(parent);
}
-}
\ No newline at end of file
+
+ @Test
+ void compile() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f27bb64b-6fc7-4e1f-9848-11ba35e0df44";
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel importedModel = dMNCompiler.compile( resource, dmnModels);
+ assertThat(importedModel).isNotNull();
+ assertThat(importedModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ assertThat(importedModel.getMessages()).isEmpty();
+ }
+
+ @Test
+ void compileWithUnknownTypeModelImports() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f27bb64b-6fc7-4e1f-9848-11ba35e0df44";
+ String modelName = "Imported Model";
+ String importType = String.valueOf(ImportDMNResolverUtil.ImportType.UNKNOWN);
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel model = dMNCompiler.compile( resource, dmnModels);
+ assertThat(model).isNotNull();
+ Definitions dmnDefn = model.getDefinitions();
+ addImport(dmnDefn, importType, nameSpace, modelName);
+ dmnModels.add(model);
+ model = dMNCompiler.compile(dmnDefn, resource, dmnModels);
+ assertThat(model).isNotNull();
+ assertThat(model.getName()).isNotNull().isEqualTo(modelName);
+ assertThat(model.getMessages()).isNotEmpty();
Review Comment:
Done
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] [incubator-kie-issues#1748] DMNCompilerImpl class code refactoring and Test cases [incubator-kie-drools]
Posted by "kie-ci3 (via GitHub)" <gi...@apache.org>.
kie-ci3 commented on PR #6267:
URL: https://github.com/apache/incubator-kie-drools/pull/6267#issuecomment-2736881774
**PR job** `#11` was: **UNSTABLE**
Possible explanation: This should be test failures
<details>
<summary><b>Reproducer</b></summary>
build-chain build full_downstream -f 'https://raw.githubusercontent.com/${AUTHOR:apache}/incubator-kie-kogito-pipelines/${BRANCH:main}/.ci/buildchain-config-pr-cdb.yaml' -o 'bc' -p apache/incubator-kie-drools -u https://github.com/apache/incubator-kie-drools/pull/6267 --skipParallelCheckout
NOTE: To install the build-chain tool, please refer to https://github.com/kiegroup/github-action-build-chain#local-execution
</details>
Please look here: https://ci-builds.apache.org/job/KIE/job/drools/job/main/job/pullrequest_jobs/job/drools-pr/job/PR-6267/11/display/redirect
**Test results:**
- PASSED: 23364
- FAILED: 1
Those are the test failures:
<details>
<summary><a href="https://ci-builds.apache.org/job/KIE/job/drools/job/main/job/pullrequest_jobs/job/drools-pr/job/PR-6267/11/testReport/org.kie.dmn.core.compiler/DMNCompilerImplTest/compileWithInvalidModel/">org.kie.dmn.core.compiler.DMNCompilerImplTest.compileWithInvalidModel</a></summary>
<br/>Expecting actual not to be null
</details>
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] [incubator-kie-issues#1748] DMNCompilerImpl class code refactoring and Test cases [incubator-kie-drools]
Posted by "gitgabrio (via GitHub)" <gi...@apache.org>.
gitgabrio commented on code in PR #6267:
URL: https://github.com/apache/incubator-kie-drools/pull/6267#discussion_r2003332637
##########
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/DMNCompilerImpl.java:
##########
@@ -209,60 +210,82 @@ public DMNModel compile(Definitions dmndefs, Collection<DMNModel> dmnModels, Res
}
DMNModelImpl model = new DMNModelImpl(dmndefs, resource);
model.setRuntimeTypeCheck(((DMNCompilerConfigurationImpl) dmnCompilerConfig).getOption(RuntimeTypeCheckOption.class).isRuntimeTypeCheck());
+ DMNCompilerContext ctx = configureDMNCompiler(model.getFeelDialect(), relativeResolver);
+ if (!dmndefs.getImport().isEmpty()) {
+ iterateImports(dmndefs, dmnModels, model, relativeResolver );
+ }
+ processItemDefinitions(ctx, model, dmndefs);
+ processDrgElements(ctx, model, dmndefs);
+ return model;
+ }
+
+ private DMNCompilerContext configureDMNCompiler(FEELDialect feeldialect, Function<String, Reader> relativeResolver) {
+
DMNCompilerConfigurationImpl cc = (DMNCompilerConfigurationImpl) dmnCompilerConfig;
List<FEELProfile> helperFEELProfiles = cc.getFeelProfiles();
- DMNFEELHelper feel = new DMNFEELHelper(cc.getRootClassLoader(), helperFEELProfiles, model.getFeelDialect());
+ DMNFEELHelper feel = new DMNFEELHelper(cc.getRootClassLoader(), helperFEELProfiles, feeldialect);
DMNCompilerContext ctx = new DMNCompilerContext(feel);
ctx.setRelativeResolver(relativeResolver);
+ return ctx;
+ }
+
+ private void iterateImports(Definitions dmndefs, Collection<DMNModel> dmnModels, DMNModelImpl model, Function<String, Reader> relativeResolver ) {
Review Comment:
Ok @ChinchuAjith, but it would be better to verify the method in isolation, and not just from hidden side-effect.
If, for whatever reason, something change in that inner method that breaks everything else in some strange corner-case, without a specific test we won't realize immediately: does this make sense ?
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] [incubator-kie-issues#1748] DMNCompilerImpl class code refactoring and Test cases [incubator-kie-drools]
Posted by "gitgabrio (via GitHub)" <gi...@apache.org>.
gitgabrio commented on code in PR #6267:
URL: https://github.com/apache/incubator-kie-drools/pull/6267#discussion_r2003332637
##########
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/DMNCompilerImpl.java:
##########
@@ -209,60 +210,82 @@ public DMNModel compile(Definitions dmndefs, Collection<DMNModel> dmnModels, Res
}
DMNModelImpl model = new DMNModelImpl(dmndefs, resource);
model.setRuntimeTypeCheck(((DMNCompilerConfigurationImpl) dmnCompilerConfig).getOption(RuntimeTypeCheckOption.class).isRuntimeTypeCheck());
+ DMNCompilerContext ctx = configureDMNCompiler(model.getFeelDialect(), relativeResolver);
+ if (!dmndefs.getImport().isEmpty()) {
+ iterateImports(dmndefs, dmnModels, model, relativeResolver );
+ }
+ processItemDefinitions(ctx, model, dmndefs);
+ processDrgElements(ctx, model, dmndefs);
+ return model;
+ }
+
+ private DMNCompilerContext configureDMNCompiler(FEELDialect feeldialect, Function<String, Reader> relativeResolver) {
+
DMNCompilerConfigurationImpl cc = (DMNCompilerConfigurationImpl) dmnCompilerConfig;
List<FEELProfile> helperFEELProfiles = cc.getFeelProfiles();
- DMNFEELHelper feel = new DMNFEELHelper(cc.getRootClassLoader(), helperFEELProfiles, model.getFeelDialect());
+ DMNFEELHelper feel = new DMNFEELHelper(cc.getRootClassLoader(), helperFEELProfiles, feeldialect);
DMNCompilerContext ctx = new DMNCompilerContext(feel);
ctx.setRelativeResolver(relativeResolver);
+ return ctx;
+ }
+
+ private void iterateImports(Definitions dmndefs, Collection<DMNModel> dmnModels, DMNModelImpl model, Function<String, Reader> relativeResolver ) {
Review Comment:
Ok, but we need to verify the method in isolation, and not just from hidden side-effect.
If, for whatever reason, something change in that inner method that breaks everything else in some strange corner-case, without a specific test we won't realize immediately: does this make sense ?
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] DMNCompilerImpl class code refactoring and Test cases [incubator-kie-drools]
Posted by "ChinchuAjith (via GitHub)" <gi...@apache.org>.
ChinchuAjith commented on PR #6267:
URL: https://github.com/apache/incubator-kie-drools/pull/6267#issuecomment-2709917913
> @ChinchuAjith Can you please describe the changes you applied in the first message? Thanks!
@yesamer added description for the PR
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] [incubator-kie-issues#1748] DMNCompilerImpl class code refactoring and Test cases [incubator-kie-drools]
Posted by "porcelli (via GitHub)" <gi...@apache.org>.
porcelli commented on PR #6267:
URL: https://github.com/apache/incubator-kie-drools/pull/6267#issuecomment-2747863250
@gitgabrio iirc, jenkins hasn't being used for PR checks for awhile
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] DMNCompilerImpl class code refactoring and Test cases [incubator-kie-drools]
Posted by "ChinchuAjith (via GitHub)" <gi...@apache.org>.
ChinchuAjith commented on code in PR #6267:
URL: https://github.com/apache/incubator-kie-drools/pull/6267#discussion_r1987584547
##########
kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/compiler/DMNCompilerImplTest.java:
##########
@@ -70,10 +83,192 @@ void getRootElement() {
InformationRequirement informationRequirement = new TInformationRequirement();
elementReference.setParent(informationRequirement);
- assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> DMNCompilerImpl.getRootElement(elementReference));
-
+ assertThatExceptionOfType(RuntimeException.class).isThrownBy(
+ () -> DMNCompilerImpl.getRootElement(elementReference)).withMessageContaining
+ ("Failed to get Definitions parent for org.kie.dmn.model.v1_5");
informationRequirement.setParent(parent);
retrieved = DMNCompilerImpl.getRootElement(elementReference);
assertThat(retrieved).isNotNull().isEqualTo(parent);
}
-}
\ No newline at end of file
+
+ @Test
+ void compile() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f27bb64b-6fc7-4e1f-9848-11ba35e0df44";
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel importedModel = dMNCompiler.compile( resource, dmnModels);
+ assertThat(importedModel).isNotNull();
+ assertThat(importedModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ assertThat(importedModel.getMessages()).isEmpty();
+ }
+
+ @Test
+ void compileWithUnknownTypeModelImports() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f27bb64b-6fc7-4e1f-9848-11ba35e0df44";
+ String modelName = "Imported Model";
+ String importType = String.valueOf(ImportDMNResolverUtil.ImportType.UNKNOWN);
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel model = dMNCompiler.compile( resource, dmnModels);
+ assertThat(model).isNotNull();
+ Definitions dmnDefn = model.getDefinitions();
+ addImport(dmnDefn, importType, nameSpace, modelName);
+ dmnModels.add(model);
+ model = dMNCompiler.compile(dmnDefn, resource, dmnModels);
+ assertThat(model).isNotNull();
+ assertThat(model.getName()).isNotNull().isEqualTo(modelName);
+ assertThat(model.getMessages()).isNotEmpty();
Review Comment:
Done
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] DMNCompilerImpl class code refactoring and Test cases [incubator-kie-drools]
Posted by "gitgabrio (via GitHub)" <gi...@apache.org>.
gitgabrio commented on code in PR #6267:
URL: https://github.com/apache/incubator-kie-drools/pull/6267#discussion_r1979223507
##########
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/DMNCompilerImpl.java:
##########
@@ -209,60 +210,82 @@ public DMNModel compile(Definitions dmndefs, Collection<DMNModel> dmnModels, Res
}
DMNModelImpl model = new DMNModelImpl(dmndefs, resource);
model.setRuntimeTypeCheck(((DMNCompilerConfigurationImpl) dmnCompilerConfig).getOption(RuntimeTypeCheckOption.class).isRuntimeTypeCheck());
+ DMNCompilerContext ctx = configureDMNCompiler(model.getFeelDialect(), relativeResolver);
+ if (!dmndefs.getImport().isEmpty()) {
+ iterateImports(dmndefs, dmnModels, model, relativeResolver );
+ }
+ processItemDefinitions(ctx, model, dmndefs);
+ processDrgElements(ctx, model, dmndefs);
+ return model;
+ }
+
+ private DMNCompilerContext configureDMNCompiler(FEELDialect feeldialect, Function<String, Reader> relativeResolver) {
+
DMNCompilerConfigurationImpl cc = (DMNCompilerConfigurationImpl) dmnCompilerConfig;
List<FEELProfile> helperFEELProfiles = cc.getFeelProfiles();
- DMNFEELHelper feel = new DMNFEELHelper(cc.getRootClassLoader(), helperFEELProfiles, model.getFeelDialect());
+ DMNFEELHelper feel = new DMNFEELHelper(cc.getRootClassLoader(), helperFEELProfiles, feeldialect);
DMNCompilerContext ctx = new DMNCompilerContext(feel);
ctx.setRelativeResolver(relativeResolver);
+ return ctx;
+ }
+
+ private void iterateImports(Definitions dmndefs, Collection<DMNModel> dmnModels, DMNModelImpl model, Function<String, Reader> relativeResolver ) {
Review Comment:
This method need to be tested, at least verify that elements are correctly iterated over
##########
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/DMNCompilerImpl.java:
##########
@@ -44,6 +44,7 @@
import javax.xml.namespace.QName;
+import org.codehaus.plexus.util.CollectionUtils;
Review Comment:
Pls remove this import
##########
kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/compiler/DMNCompilerImplTest.java:
##########
@@ -70,10 +84,168 @@ void getRootElement() {
InformationRequirement informationRequirement = new TInformationRequirement();
elementReference.setParent(informationRequirement);
- assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> DMNCompilerImpl.getRootElement(elementReference));
-
+ assertThatExceptionOfType(RuntimeException.class).isThrownBy(
+ () -> DMNCompilerImpl.getRootElement(elementReference)).withMessageContaining
+ ("Failed to get Definitions parent for org.kie.dmn.model.v1_5");
informationRequirement.setParent(parent);
retrieved = DMNCompilerImpl.getRootElement(elementReference);
assertThat(retrieved).isNotNull().isEqualTo(parent);
}
-}
\ No newline at end of file
+
+ @Test
+ void compile() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f27bb64b-6fc7-4e1f-9848-11ba35e0df44";
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel importedModel = dMNCompiler.compile( resource, dmnModels);
+ assertThat(importedModel).isNotNull();
+ assertThat(importedModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ assertThat(importedModel.getMessages()).isEmpty();
+ }
+
+ @Test
+ void compileWithUnknownTypeModelImports() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f27bb64b-6fc7-4e1f-9848-11ba35e0df44";
+ String modelName = "Imported Model";
+ String importType = String.valueOf(ImportDMNResolverUtil.ImportType.UNKNOWN);
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel model = dMNCompiler.compile( resource, dmnModels);
+ assertThat(model).isNotNull();
+ Definitions dmnDefn = model.getDefinitions();
+ addImport(dmnDefn, importType, nameSpace, modelName);
+ dmnModels.add(model);
+ model = dMNCompiler.compile(dmnDefn, resource, dmnModels);
+ assertThat(model).isNotNull();
+ assertThat(model.getName()).isNotNull().isEqualTo(modelName);
+ assertThat(model.getMessages()).isNotEmpty();
+ assertThat(model.getMessages().get(0).getText()).isEqualTo("DMN: Import type unknown: 'UNKNOWN'. (Invalid FEEL syntax on the referenced expression) ");
+
+ }
+
+ @Test
+ void compileWithImportingDmnModel() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel importedModel = dMNCompiler.compile( resource, dmnModels);
+ assertThat(importedModel).isNotNull();
+ dmnModels.add(importedModel);
+
+ //imported model - Importing_Named_Model.dmn
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f79aa7a4-f9a3-410a-ac95-bea496edabgc";
+ resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_Named_Model.dmn",
+ this.getClass());
+
+ DMNModel importingModel = dMNCompiler.compile(resource, dmnModels);
+ assertThat(importingModel).isNotNull();
+ assertThat(importingModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ assertThat(importingModel.getMessages()).isEmpty();
+ }
+
+ @Test
+ void compileImportingModelWithoutImportedModel() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String modelName = "Importing named Model";
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_Named_Model.dmn",
+ this.getClass());
+ DMNModel model = dMNCompiler.compile( resource, dmnModels);
+ assertThat(model).isNotNull();
+ assertThat(model.getName()).isNotNull().isEqualTo(modelName);
+
+ Definitions dmnDefn = model.getDefinitions();
+ dmnModels.add(model);
+ model = dMNCompiler.compile(dmnDefn, resource, dmnModels);
+ assertThat(model).isNotNull();
+ assertThat(model.getName()).isNotNull().isEqualTo(modelName);
+ assertThat(model.getMessages()).isNotEmpty();
+ assertThat(model.getMessages().get(0).getMessageType()).isEqualTo(DMNMessageType.IMPORT_NOT_FOUND);
+
+ }
+
+ @Test
+ void resolveDMNImportType() {
+ List<DMNModel> toMerge = new ArrayList<>();
+ List<DMNModel> dmnModels = new ArrayList<>();
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel importedModel = dMNCompiler.compile( resource, dmnModels);
+ assertThat(importedModel).isNotNull();
+ dmnModels.add(importedModel);
+
+ //imported model - Importing_Named_Model.dmn
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f79aa7a4-f9a3-410a-ac95-bea496edabgc";
+ resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_Named_Model.dmn",
+ this.getClass());
+ DMNModel importingModel = dMNCompiler.compile(resource, dmnModels);
+ assertThat(importingModel).isNotNull();
+ assertThat(importingModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ assertThat(importingModel.getMessages()).isEmpty();
+
+ Import input = importingModel.getDefinitions().getImport().get(0);
+ DMNModelImpl model = new DMNModelImpl(importingModel.getDefinitions(), resource);
+ DMNCompilerImpl.resolveDMNImportType(input, dmnModels, model, toMerge);
+ assertThat(model.getMessages()).isEmpty();
+ assertThat(model.getImportAliasesForNS().entrySet().stream().findFirst().get().getValue().getLocalPart()).isNotNull().isEqualTo("Imported Model");
+
+ }
+
+ @Test
+ void checkLocatedDMNModel() {
+ List<DMNModel> toMerge = new ArrayList<>();
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f79aa7a4-f9a3-410a-ac95-bea496edabgc";
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_Named_Model.dmn",
+ this.getClass());
+ DMNModel importingModel = dMNCompiler.compile(resource, dmnModels);
+ assertThat(importingModel).isNotNull();
+ assertThat(importingModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+
+ Import input = importingModel.getDefinitions().getImport().get(0);
+ DMNModelImpl model = new DMNModelImpl(importingModel.getDefinitions(), resource);
+ DMNModel located = new DMNModelImpl(importingModel.getDefinitions(), resource);
+ DMNCompilerImpl.checkLocatedDMNModel(input, located, model, toMerge);
+ assertThat(importingModel).isNotNull();
+ assertThat(importingModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ assertThat(toMerge.isEmpty()).isTrue();
Review Comment:
Pls replace with more idiomatic
` assertThat(toMerge).isEmpty();`
##########
kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/compiler/DMNCompilerImplTest.java:
##########
@@ -70,10 +84,168 @@ void getRootElement() {
InformationRequirement informationRequirement = new TInformationRequirement();
elementReference.setParent(informationRequirement);
- assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> DMNCompilerImpl.getRootElement(elementReference));
-
+ assertThatExceptionOfType(RuntimeException.class).isThrownBy(
+ () -> DMNCompilerImpl.getRootElement(elementReference)).withMessageContaining
+ ("Failed to get Definitions parent for org.kie.dmn.model.v1_5");
informationRequirement.setParent(parent);
retrieved = DMNCompilerImpl.getRootElement(elementReference);
assertThat(retrieved).isNotNull().isEqualTo(parent);
}
-}
\ No newline at end of file
+
+ @Test
+ void compile() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f27bb64b-6fc7-4e1f-9848-11ba35e0df44";
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel importedModel = dMNCompiler.compile( resource, dmnModels);
+ assertThat(importedModel).isNotNull();
+ assertThat(importedModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ assertThat(importedModel.getMessages()).isEmpty();
+ }
+
+ @Test
+ void compileWithUnknownTypeModelImports() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f27bb64b-6fc7-4e1f-9848-11ba35e0df44";
+ String modelName = "Imported Model";
+ String importType = String.valueOf(ImportDMNResolverUtil.ImportType.UNKNOWN);
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel model = dMNCompiler.compile( resource, dmnModels);
+ assertThat(model).isNotNull();
+ Definitions dmnDefn = model.getDefinitions();
+ addImport(dmnDefn, importType, nameSpace, modelName);
+ dmnModels.add(model);
+ model = dMNCompiler.compile(dmnDefn, resource, dmnModels);
+ assertThat(model).isNotNull();
+ assertThat(model.getName()).isNotNull().isEqualTo(modelName);
+ assertThat(model.getMessages()).isNotEmpty();
+ assertThat(model.getMessages().get(0).getText()).isEqualTo("DMN: Import type unknown: 'UNKNOWN'. (Invalid FEEL syntax on the referenced expression) ");
+
+ }
+
+ @Test
+ void compileWithImportingDmnModel() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel importedModel = dMNCompiler.compile( resource, dmnModels);
+ assertThat(importedModel).isNotNull();
+ dmnModels.add(importedModel);
+
+ //imported model - Importing_Named_Model.dmn
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f79aa7a4-f9a3-410a-ac95-bea496edabgc";
+ resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_Named_Model.dmn",
+ this.getClass());
+
+ DMNModel importingModel = dMNCompiler.compile(resource, dmnModels);
+ assertThat(importingModel).isNotNull();
+ assertThat(importingModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ assertThat(importingModel.getMessages()).isEmpty();
+ }
+
+ @Test
+ void compileImportingModelWithoutImportedModel() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String modelName = "Importing named Model";
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_Named_Model.dmn",
+ this.getClass());
+ DMNModel model = dMNCompiler.compile( resource, dmnModels);
+ assertThat(model).isNotNull();
+ assertThat(model.getName()).isNotNull().isEqualTo(modelName);
+
+ Definitions dmnDefn = model.getDefinitions();
+ dmnModels.add(model);
+ model = dMNCompiler.compile(dmnDefn, resource, dmnModels);
+ assertThat(model).isNotNull();
+ assertThat(model.getName()).isNotNull().isEqualTo(modelName);
+ assertThat(model.getMessages()).isNotEmpty();
+ assertThat(model.getMessages().get(0).getMessageType()).isEqualTo(DMNMessageType.IMPORT_NOT_FOUND);
+
+ }
+
+ @Test
+ void resolveDMNImportType() {
+ List<DMNModel> toMerge = new ArrayList<>();
+ List<DMNModel> dmnModels = new ArrayList<>();
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel importedModel = dMNCompiler.compile( resource, dmnModels);
+ assertThat(importedModel).isNotNull();
+ dmnModels.add(importedModel);
+
+ //imported model - Importing_Named_Model.dmn
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f79aa7a4-f9a3-410a-ac95-bea496edabgc";
+ resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_Named_Model.dmn",
+ this.getClass());
+ DMNModel importingModel = dMNCompiler.compile(resource, dmnModels);
+ assertThat(importingModel).isNotNull();
+ assertThat(importingModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ assertThat(importingModel.getMessages()).isEmpty();
+
+ Import input = importingModel.getDefinitions().getImport().get(0);
+ DMNModelImpl model = new DMNModelImpl(importingModel.getDefinitions(), resource);
+ DMNCompilerImpl.resolveDMNImportType(input, dmnModels, model, toMerge);
+ assertThat(model.getMessages()).isEmpty();
+ assertThat(model.getImportAliasesForNS().entrySet().stream().findFirst().get().getValue().getLocalPart()).isNotNull().isEqualTo("Imported Model");
+
+ }
+
+ @Test
+ void checkLocatedDMNModel() {
+ List<DMNModel> toMerge = new ArrayList<>();
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f79aa7a4-f9a3-410a-ac95-bea496edabgc";
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_Named_Model.dmn",
+ this.getClass());
+ DMNModel importingModel = dMNCompiler.compile(resource, dmnModels);
+ assertThat(importingModel).isNotNull();
+ assertThat(importingModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+
+ Import input = importingModel.getDefinitions().getImport().get(0);
+ DMNModelImpl model = new DMNModelImpl(importingModel.getDefinitions(), resource);
+ DMNModel located = new DMNModelImpl(importingModel.getDefinitions(), resource);
+ DMNCompilerImpl.checkLocatedDMNModel(input, located, model, toMerge);
+ assertThat(importingModel).isNotNull();
+ assertThat(importingModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ assertThat(toMerge.isEmpty()).isTrue();
+ }
+
+ @Test
+ void checkLocatedDMNModelWithAliasNull() {
+ String namespace="http://www.trisotech.com/dmn/definitions/_f79aa7a4-f9a3-410a-ac95-bea496edabgc";
+ List<DMNModel> toMerge = new ArrayList<>();
+ List<DMNModel> dmnModels = new ArrayList<>();
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_EmptyNamed_Model_Without_Href_Namespace.dmn",
+ this.getClass());
+ DMNModel emptyNamedModel = dMNCompiler.compile( resource, dmnModels);
+ assertThat(emptyNamedModel).isNotNull();
+ dmnModels.add(emptyNamedModel);
+
+ Import input = emptyNamedModel.getDefinitions().getImport().get(0);
+ DMNModelImpl model = new DMNModelImpl(emptyNamedModel.getDefinitions(), resource);
+ DMNModel located = new DMNModelImpl(emptyNamedModel.getDefinitions(), resource);
+ DMNCompilerImpl.checkLocatedDMNModel(input, located, model, toMerge);
+ assertThat(emptyNamedModel).isNotNull();
+ assertThat(toMerge.isEmpty()).isFalse();
+ assertThat(toMerge.get(0).getNamespace()).isNotNull().isEqualTo(namespace);
Review Comment:
As in previous comment, assert the size of `toMerge`
##########
kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/compiler/DMNCompilerImplTest.java:
##########
@@ -1,5 +1,5 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
+
Review Comment:
Pls remove this empty line
##########
kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/compiler/DMNCompilerImplTest.java:
##########
@@ -70,10 +84,168 @@ void getRootElement() {
InformationRequirement informationRequirement = new TInformationRequirement();
elementReference.setParent(informationRequirement);
- assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> DMNCompilerImpl.getRootElement(elementReference));
-
+ assertThatExceptionOfType(RuntimeException.class).isThrownBy(
+ () -> DMNCompilerImpl.getRootElement(elementReference)).withMessageContaining
+ ("Failed to get Definitions parent for org.kie.dmn.model.v1_5");
informationRequirement.setParent(parent);
retrieved = DMNCompilerImpl.getRootElement(elementReference);
assertThat(retrieved).isNotNull().isEqualTo(parent);
}
-}
\ No newline at end of file
+
+ @Test
+ void compile() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f27bb64b-6fc7-4e1f-9848-11ba35e0df44";
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel importedModel = dMNCompiler.compile( resource, dmnModels);
+ assertThat(importedModel).isNotNull();
+ assertThat(importedModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ assertThat(importedModel.getMessages()).isEmpty();
+ }
+
+ @Test
+ void compileWithUnknownTypeModelImports() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f27bb64b-6fc7-4e1f-9848-11ba35e0df44";
+ String modelName = "Imported Model";
+ String importType = String.valueOf(ImportDMNResolverUtil.ImportType.UNKNOWN);
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel model = dMNCompiler.compile( resource, dmnModels);
+ assertThat(model).isNotNull();
+ Definitions dmnDefn = model.getDefinitions();
+ addImport(dmnDefn, importType, nameSpace, modelName);
+ dmnModels.add(model);
+ model = dMNCompiler.compile(dmnDefn, resource, dmnModels);
+ assertThat(model).isNotNull();
+ assertThat(model.getName()).isNotNull().isEqualTo(modelName);
+ assertThat(model.getMessages()).isNotEmpty();
Review Comment:
THis test is error prone. It rely on the assumption that there is only one message, without checking it before. Please add assertion on `model.getMessages()` size.
Please notice assertions on the same object could be chained
##########
kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/compiler/DMNCompilerImplTest.java:
##########
@@ -70,10 +84,168 @@ void getRootElement() {
InformationRequirement informationRequirement = new TInformationRequirement();
elementReference.setParent(informationRequirement);
- assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> DMNCompilerImpl.getRootElement(elementReference));
-
+ assertThatExceptionOfType(RuntimeException.class).isThrownBy(
+ () -> DMNCompilerImpl.getRootElement(elementReference)).withMessageContaining
+ ("Failed to get Definitions parent for org.kie.dmn.model.v1_5");
informationRequirement.setParent(parent);
retrieved = DMNCompilerImpl.getRootElement(elementReference);
assertThat(retrieved).isNotNull().isEqualTo(parent);
}
-}
\ No newline at end of file
+
+ @Test
+ void compile() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f27bb64b-6fc7-4e1f-9848-11ba35e0df44";
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel importedModel = dMNCompiler.compile( resource, dmnModels);
+ assertThat(importedModel).isNotNull();
+ assertThat(importedModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ assertThat(importedModel.getMessages()).isEmpty();
+ }
+
+ @Test
+ void compileWithUnknownTypeModelImports() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f27bb64b-6fc7-4e1f-9848-11ba35e0df44";
+ String modelName = "Imported Model";
+ String importType = String.valueOf(ImportDMNResolverUtil.ImportType.UNKNOWN);
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel model = dMNCompiler.compile( resource, dmnModels);
+ assertThat(model).isNotNull();
+ Definitions dmnDefn = model.getDefinitions();
+ addImport(dmnDefn, importType, nameSpace, modelName);
+ dmnModels.add(model);
+ model = dMNCompiler.compile(dmnDefn, resource, dmnModels);
+ assertThat(model).isNotNull();
+ assertThat(model.getName()).isNotNull().isEqualTo(modelName);
+ assertThat(model.getMessages()).isNotEmpty();
+ assertThat(model.getMessages().get(0).getText()).isEqualTo("DMN: Import type unknown: 'UNKNOWN'. (Invalid FEEL syntax on the referenced expression) ");
+
+ }
+
+ @Test
+ void compileWithImportingDmnModel() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel importedModel = dMNCompiler.compile( resource, dmnModels);
+ assertThat(importedModel).isNotNull();
+ dmnModels.add(importedModel);
+
+ //imported model - Importing_Named_Model.dmn
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f79aa7a4-f9a3-410a-ac95-bea496edabgc";
+ resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_Named_Model.dmn",
+ this.getClass());
+
+ DMNModel importingModel = dMNCompiler.compile(resource, dmnModels);
+ assertThat(importingModel).isNotNull();
+ assertThat(importingModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ assertThat(importingModel.getMessages()).isEmpty();
+ }
+
+ @Test
+ void compileImportingModelWithoutImportedModel() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String modelName = "Importing named Model";
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_Named_Model.dmn",
+ this.getClass());
+ DMNModel model = dMNCompiler.compile( resource, dmnModels);
+ assertThat(model).isNotNull();
+ assertThat(model.getName()).isNotNull().isEqualTo(modelName);
+
+ Definitions dmnDefn = model.getDefinitions();
+ dmnModels.add(model);
+ model = dMNCompiler.compile(dmnDefn, resource, dmnModels);
+ assertThat(model).isNotNull();
+ assertThat(model.getName()).isNotNull().isEqualTo(modelName);
+ assertThat(model.getMessages()).isNotEmpty();
Review Comment:
Same as previous comment
##########
kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/compiler/DMNCompilerImplTest.java:
##########
@@ -70,10 +84,168 @@ void getRootElement() {
InformationRequirement informationRequirement = new TInformationRequirement();
elementReference.setParent(informationRequirement);
- assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> DMNCompilerImpl.getRootElement(elementReference));
-
+ assertThatExceptionOfType(RuntimeException.class).isThrownBy(
+ () -> DMNCompilerImpl.getRootElement(elementReference)).withMessageContaining
+ ("Failed to get Definitions parent for org.kie.dmn.model.v1_5");
informationRequirement.setParent(parent);
retrieved = DMNCompilerImpl.getRootElement(elementReference);
assertThat(retrieved).isNotNull().isEqualTo(parent);
}
-}
\ No newline at end of file
+
+ @Test
+ void compile() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f27bb64b-6fc7-4e1f-9848-11ba35e0df44";
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel importedModel = dMNCompiler.compile( resource, dmnModels);
+ assertThat(importedModel).isNotNull();
+ assertThat(importedModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ assertThat(importedModel.getMessages()).isEmpty();
+ }
+
+ @Test
+ void compileWithUnknownTypeModelImports() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f27bb64b-6fc7-4e1f-9848-11ba35e0df44";
+ String modelName = "Imported Model";
+ String importType = String.valueOf(ImportDMNResolverUtil.ImportType.UNKNOWN);
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel model = dMNCompiler.compile( resource, dmnModels);
+ assertThat(model).isNotNull();
+ Definitions dmnDefn = model.getDefinitions();
+ addImport(dmnDefn, importType, nameSpace, modelName);
+ dmnModels.add(model);
+ model = dMNCompiler.compile(dmnDefn, resource, dmnModels);
+ assertThat(model).isNotNull();
+ assertThat(model.getName()).isNotNull().isEqualTo(modelName);
+ assertThat(model.getMessages()).isNotEmpty();
+ assertThat(model.getMessages().get(0).getText()).isEqualTo("DMN: Import type unknown: 'UNKNOWN'. (Invalid FEEL syntax on the referenced expression) ");
+
+ }
+
+ @Test
+ void compileWithImportingDmnModel() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel importedModel = dMNCompiler.compile( resource, dmnModels);
+ assertThat(importedModel).isNotNull();
+ dmnModels.add(importedModel);
+
+ //imported model - Importing_Named_Model.dmn
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f79aa7a4-f9a3-410a-ac95-bea496edabgc";
+ resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_Named_Model.dmn",
+ this.getClass());
+
+ DMNModel importingModel = dMNCompiler.compile(resource, dmnModels);
+ assertThat(importingModel).isNotNull();
+ assertThat(importingModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ assertThat(importingModel.getMessages()).isEmpty();
+ }
+
+ @Test
+ void compileImportingModelWithoutImportedModel() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String modelName = "Importing named Model";
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_Named_Model.dmn",
+ this.getClass());
+ DMNModel model = dMNCompiler.compile( resource, dmnModels);
+ assertThat(model).isNotNull();
+ assertThat(model.getName()).isNotNull().isEqualTo(modelName);
+
+ Definitions dmnDefn = model.getDefinitions();
+ dmnModels.add(model);
+ model = dMNCompiler.compile(dmnDefn, resource, dmnModels);
+ assertThat(model).isNotNull();
+ assertThat(model.getName()).isNotNull().isEqualTo(modelName);
+ assertThat(model.getMessages()).isNotEmpty();
+ assertThat(model.getMessages().get(0).getMessageType()).isEqualTo(DMNMessageType.IMPORT_NOT_FOUND);
+
+ }
+
+ @Test
+ void resolveDMNImportType() {
+ List<DMNModel> toMerge = new ArrayList<>();
+ List<DMNModel> dmnModels = new ArrayList<>();
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel importedModel = dMNCompiler.compile( resource, dmnModels);
+ assertThat(importedModel).isNotNull();
+ dmnModels.add(importedModel);
+
+ //imported model - Importing_Named_Model.dmn
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f79aa7a4-f9a3-410a-ac95-bea496edabgc";
+ resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_Named_Model.dmn",
+ this.getClass());
+ DMNModel importingModel = dMNCompiler.compile(resource, dmnModels);
+ assertThat(importingModel).isNotNull();
+ assertThat(importingModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ assertThat(importingModel.getMessages()).isEmpty();
+
+ Import input = importingModel.getDefinitions().getImport().get(0);
+ DMNModelImpl model = new DMNModelImpl(importingModel.getDefinitions(), resource);
+ DMNCompilerImpl.resolveDMNImportType(input, dmnModels, model, toMerge);
+ assertThat(model.getMessages()).isEmpty();
+ assertThat(model.getImportAliasesForNS().entrySet().stream().findFirst().get().getValue().getLocalPart()).isNotNull().isEqualTo("Imported Model");
+
+ }
+
+ @Test
+ void checkLocatedDMNModel() {
+ List<DMNModel> toMerge = new ArrayList<>();
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f79aa7a4-f9a3-410a-ac95-bea496edabgc";
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_Named_Model.dmn",
+ this.getClass());
+ DMNModel importingModel = dMNCompiler.compile(resource, dmnModels);
+ assertThat(importingModel).isNotNull();
+ assertThat(importingModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+
+ Import input = importingModel.getDefinitions().getImport().get(0);
+ DMNModelImpl model = new DMNModelImpl(importingModel.getDefinitions(), resource);
+ DMNModel located = new DMNModelImpl(importingModel.getDefinitions(), resource);
+ DMNCompilerImpl.checkLocatedDMNModel(input, located, model, toMerge);
+ assertThat(importingModel).isNotNull();
+ assertThat(importingModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ assertThat(toMerge.isEmpty()).isTrue();
+ }
+
+ @Test
+ void checkLocatedDMNModelWithAliasNull() {
+ String namespace="http://www.trisotech.com/dmn/definitions/_f79aa7a4-f9a3-410a-ac95-bea496edabgc";
+ List<DMNModel> toMerge = new ArrayList<>();
+ List<DMNModel> dmnModels = new ArrayList<>();
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_EmptyNamed_Model_Without_Href_Namespace.dmn",
+ this.getClass());
+ DMNModel emptyNamedModel = dMNCompiler.compile( resource, dmnModels);
+ assertThat(emptyNamedModel).isNotNull();
+ dmnModels.add(emptyNamedModel);
+
+ Import input = emptyNamedModel.getDefinitions().getImport().get(0);
+ DMNModelImpl model = new DMNModelImpl(emptyNamedModel.getDefinitions(), resource);
+ DMNModel located = new DMNModelImpl(emptyNamedModel.getDefinitions(), resource);
+ DMNCompilerImpl.checkLocatedDMNModel(input, located, model, toMerge);
+ assertThat(emptyNamedModel).isNotNull();
+ assertThat(toMerge.isEmpty()).isFalse();
Review Comment:
Pls replace with more idiomatic
`assertThat(toMerge).isNotEmpty();`
##########
kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/compiler/DMNCompilerImplTest.java:
##########
@@ -70,10 +84,168 @@ void getRootElement() {
InformationRequirement informationRequirement = new TInformationRequirement();
elementReference.setParent(informationRequirement);
- assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> DMNCompilerImpl.getRootElement(elementReference));
-
+ assertThatExceptionOfType(RuntimeException.class).isThrownBy(
+ () -> DMNCompilerImpl.getRootElement(elementReference)).withMessageContaining
+ ("Failed to get Definitions parent for org.kie.dmn.model.v1_5");
informationRequirement.setParent(parent);
retrieved = DMNCompilerImpl.getRootElement(elementReference);
assertThat(retrieved).isNotNull().isEqualTo(parent);
}
-}
\ No newline at end of file
+
+ @Test
+ void compile() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f27bb64b-6fc7-4e1f-9848-11ba35e0df44";
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel importedModel = dMNCompiler.compile( resource, dmnModels);
+ assertThat(importedModel).isNotNull();
+ assertThat(importedModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ assertThat(importedModel.getMessages()).isEmpty();
+ }
+
+ @Test
+ void compileWithUnknownTypeModelImports() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f27bb64b-6fc7-4e1f-9848-11ba35e0df44";
+ String modelName = "Imported Model";
+ String importType = String.valueOf(ImportDMNResolverUtil.ImportType.UNKNOWN);
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel model = dMNCompiler.compile( resource, dmnModels);
+ assertThat(model).isNotNull();
+ Definitions dmnDefn = model.getDefinitions();
+ addImport(dmnDefn, importType, nameSpace, modelName);
+ dmnModels.add(model);
+ model = dMNCompiler.compile(dmnDefn, resource, dmnModels);
+ assertThat(model).isNotNull();
+ assertThat(model.getName()).isNotNull().isEqualTo(modelName);
+ assertThat(model.getMessages()).isNotEmpty();
+ assertThat(model.getMessages().get(0).getText()).isEqualTo("DMN: Import type unknown: 'UNKNOWN'. (Invalid FEEL syntax on the referenced expression) ");
+
+ }
+
+ @Test
+ void compileWithImportingDmnModel() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel importedModel = dMNCompiler.compile( resource, dmnModels);
+ assertThat(importedModel).isNotNull();
+ dmnModels.add(importedModel);
+
+ //imported model - Importing_Named_Model.dmn
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f79aa7a4-f9a3-410a-ac95-bea496edabgc";
+ resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_Named_Model.dmn",
+ this.getClass());
+
+ DMNModel importingModel = dMNCompiler.compile(resource, dmnModels);
+ assertThat(importingModel).isNotNull();
+ assertThat(importingModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ assertThat(importingModel.getMessages()).isEmpty();
+ }
+
+ @Test
+ void compileImportingModelWithoutImportedModel() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String modelName = "Importing named Model";
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_Named_Model.dmn",
+ this.getClass());
+ DMNModel model = dMNCompiler.compile( resource, dmnModels);
+ assertThat(model).isNotNull();
+ assertThat(model.getName()).isNotNull().isEqualTo(modelName);
+
+ Definitions dmnDefn = model.getDefinitions();
+ dmnModels.add(model);
+ model = dMNCompiler.compile(dmnDefn, resource, dmnModels);
+ assertThat(model).isNotNull();
+ assertThat(model.getName()).isNotNull().isEqualTo(modelName);
+ assertThat(model.getMessages()).isNotEmpty();
+ assertThat(model.getMessages().get(0).getMessageType()).isEqualTo(DMNMessageType.IMPORT_NOT_FOUND);
+
+ }
+
+ @Test
+ void resolveDMNImportType() {
+ List<DMNModel> toMerge = new ArrayList<>();
+ List<DMNModel> dmnModels = new ArrayList<>();
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel importedModel = dMNCompiler.compile( resource, dmnModels);
+ assertThat(importedModel).isNotNull();
+ dmnModels.add(importedModel);
+
+ //imported model - Importing_Named_Model.dmn
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f79aa7a4-f9a3-410a-ac95-bea496edabgc";
+ resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_Named_Model.dmn",
+ this.getClass());
+ DMNModel importingModel = dMNCompiler.compile(resource, dmnModels);
+ assertThat(importingModel).isNotNull();
+ assertThat(importingModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ assertThat(importingModel.getMessages()).isEmpty();
+
+ Import input = importingModel.getDefinitions().getImport().get(0);
+ DMNModelImpl model = new DMNModelImpl(importingModel.getDefinitions(), resource);
+ DMNCompilerImpl.resolveDMNImportType(input, dmnModels, model, toMerge);
+ assertThat(model.getMessages()).isEmpty();
+ assertThat(model.getImportAliasesForNS().entrySet().stream().findFirst().get().getValue().getLocalPart()).isNotNull().isEqualTo("Imported Model");
Review Comment:
Please add an assertion on the `get()` invocation, or throw an exception
##########
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/DMNCompilerImpl.java:
##########
@@ -209,60 +210,82 @@ public DMNModel compile(Definitions dmndefs, Collection<DMNModel> dmnModels, Res
}
DMNModelImpl model = new DMNModelImpl(dmndefs, resource);
model.setRuntimeTypeCheck(((DMNCompilerConfigurationImpl) dmnCompilerConfig).getOption(RuntimeTypeCheckOption.class).isRuntimeTypeCheck());
+ DMNCompilerContext ctx = configureDMNCompiler(model.getFeelDialect(), relativeResolver);
+ if (!dmndefs.getImport().isEmpty()) {
+ iterateImports(dmndefs, dmnModels, model, relativeResolver );
+ }
+ processItemDefinitions(ctx, model, dmndefs);
+ processDrgElements(ctx, model, dmndefs);
+ return model;
+ }
+
+ private DMNCompilerContext configureDMNCompiler(FEELDialect feeldialect, Function<String, Reader> relativeResolver) {
+
DMNCompilerConfigurationImpl cc = (DMNCompilerConfigurationImpl) dmnCompilerConfig;
List<FEELProfile> helperFEELProfiles = cc.getFeelProfiles();
- DMNFEELHelper feel = new DMNFEELHelper(cc.getRootClassLoader(), helperFEELProfiles, model.getFeelDialect());
+ DMNFEELHelper feel = new DMNFEELHelper(cc.getRootClassLoader(), helperFEELProfiles, feeldialect);
DMNCompilerContext ctx = new DMNCompilerContext(feel);
ctx.setRelativeResolver(relativeResolver);
+ return ctx;
+ }
+
+ private void iterateImports(Definitions dmndefs, Collection<DMNModel> dmnModels, DMNModelImpl model, Function<String, Reader> relativeResolver ) {
List<DMNModel> toMerge = new ArrayList<>();
- if (!dmndefs.getImport().isEmpty()) {
- for (Import i : dmndefs.getImport()) {
- if (ImportDMNResolverUtil.whichImportType(i) == ImportType.DMN) {
- Either<String, DMNModel> resolvedResult = ImportDMNResolverUtil.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());
- if (located != null) {
- String iAlias = 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 (iAlias != null && !iAlias.isEmpty()) {
- model.setImportAliasForNS(iAlias, located.getNamespace(), located.getName());
- importFromModel(model, located, iAlias);
- } else {
- toMerge.add(located);
- }
- }
- } else if (ImportDMNResolverUtil.whichImportType(i) == ImportType.PMML) {
- processPMMLImport(model, i, relativeResolver);
- model.setImportAliasForNS(i.getName(), i.getNamespace(), i.getName());
- } else {
- MsgUtil.reportMessage(logger,
- DMNMessage.Severity.ERROR,
- null,
- model,
- null,
- null,
- Msg.IMPORT_TYPE_UNKNOWN,
- i.getImportType());
- }
+ for (Import i : dmndefs.getImport()) {
+ if (ImportDMNResolverUtil.whichImportType(i) == ImportType.DMN) {
Review Comment:
This `if/else` could be replaced by switch
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] DMNCompilerImpl class code refactoring and Test cases [incubator-kie-drools]
Posted by "ChinchuAjith (via GitHub)" <gi...@apache.org>.
ChinchuAjith commented on code in PR #6267:
URL: https://github.com/apache/incubator-kie-drools/pull/6267#discussion_r1983149621
##########
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/DMNCompilerImpl.java:
##########
@@ -44,6 +44,7 @@
import javax.xml.namespace.QName;
+import org.codehaus.plexus.util.CollectionUtils;
Review Comment:
Done
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] DMNCompilerImpl class code refactoring and Test cases [incubator-kie-drools]
Posted by "ChinchuAjith (via GitHub)" <gi...@apache.org>.
ChinchuAjith commented on code in PR #6267:
URL: https://github.com/apache/incubator-kie-drools/pull/6267#discussion_r1984534164
##########
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/DMNCompilerImpl.java:
##########
@@ -209,60 +210,82 @@ public DMNModel compile(Definitions dmndefs, Collection<DMNModel> dmnModels, Res
}
DMNModelImpl model = new DMNModelImpl(dmndefs, resource);
model.setRuntimeTypeCheck(((DMNCompilerConfigurationImpl) dmnCompilerConfig).getOption(RuntimeTypeCheckOption.class).isRuntimeTypeCheck());
+ DMNCompilerContext ctx = configureDMNCompiler(model.getFeelDialect(), relativeResolver);
+ if (!dmndefs.getImport().isEmpty()) {
+ iterateImports(dmndefs, dmnModels, model, relativeResolver );
+ }
+ processItemDefinitions(ctx, model, dmndefs);
+ processDrgElements(ctx, model, dmndefs);
+ return model;
+ }
+
+ private DMNCompilerContext configureDMNCompiler(FEELDialect feeldialect, Function<String, Reader> relativeResolver) {
+
DMNCompilerConfigurationImpl cc = (DMNCompilerConfigurationImpl) dmnCompilerConfig;
List<FEELProfile> helperFEELProfiles = cc.getFeelProfiles();
- DMNFEELHelper feel = new DMNFEELHelper(cc.getRootClassLoader(), helperFEELProfiles, model.getFeelDialect());
+ DMNFEELHelper feel = new DMNFEELHelper(cc.getRootClassLoader(), helperFEELProfiles, feeldialect);
DMNCompilerContext ctx = new DMNCompilerContext(feel);
ctx.setRelativeResolver(relativeResolver);
+ return ctx;
+ }
+
+ private void iterateImports(Definitions dmndefs, Collection<DMNModel> dmnModels, DMNModelImpl model, Function<String, Reader> relativeResolver ) {
Review Comment:
The if/else inside this method have been replaced with switch case. Tested and is working fine now. Please review once and let me know if any further modification required here.
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] DMNCompilerImpl class code refactoring and Test cases [incubator-kie-drools]
Posted by "ChinchuAjith (via GitHub)" <gi...@apache.org>.
ChinchuAjith commented on code in PR #6267:
URL: https://github.com/apache/incubator-kie-drools/pull/6267#discussion_r1984511063
##########
kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/compiler/DMNCompilerImplTest.java:
##########
@@ -70,10 +84,168 @@ void getRootElement() {
InformationRequirement informationRequirement = new TInformationRequirement();
elementReference.setParent(informationRequirement);
- assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> DMNCompilerImpl.getRootElement(elementReference));
-
+ assertThatExceptionOfType(RuntimeException.class).isThrownBy(
+ () -> DMNCompilerImpl.getRootElement(elementReference)).withMessageContaining
+ ("Failed to get Definitions parent for org.kie.dmn.model.v1_5");
informationRequirement.setParent(parent);
retrieved = DMNCompilerImpl.getRootElement(elementReference);
assertThat(retrieved).isNotNull().isEqualTo(parent);
}
-}
\ No newline at end of file
+
+ @Test
+ void compile() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f27bb64b-6fc7-4e1f-9848-11ba35e0df44";
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel importedModel = dMNCompiler.compile( resource, dmnModels);
+ assertThat(importedModel).isNotNull();
+ assertThat(importedModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ assertThat(importedModel.getMessages()).isEmpty();
+ }
+
+ @Test
+ void compileWithUnknownTypeModelImports() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f27bb64b-6fc7-4e1f-9848-11ba35e0df44";
+ String modelName = "Imported Model";
+ String importType = String.valueOf(ImportDMNResolverUtil.ImportType.UNKNOWN);
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel model = dMNCompiler.compile( resource, dmnModels);
+ assertThat(model).isNotNull();
+ Definitions dmnDefn = model.getDefinitions();
+ addImport(dmnDefn, importType, nameSpace, modelName);
+ dmnModels.add(model);
+ model = dMNCompiler.compile(dmnDefn, resource, dmnModels);
+ assertThat(model).isNotNull();
+ assertThat(model.getName()).isNotNull().isEqualTo(modelName);
+ assertThat(model.getMessages()).isNotEmpty();
+ assertThat(model.getMessages().get(0).getText()).isEqualTo("DMN: Import type unknown: 'UNKNOWN'. (Invalid FEEL syntax on the referenced expression) ");
+
+ }
+
+ @Test
+ void compileWithImportingDmnModel() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel importedModel = dMNCompiler.compile( resource, dmnModels);
+ assertThat(importedModel).isNotNull();
+ dmnModels.add(importedModel);
+
+ //imported model - Importing_Named_Model.dmn
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f79aa7a4-f9a3-410a-ac95-bea496edabgc";
+ resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_Named_Model.dmn",
+ this.getClass());
+
+ DMNModel importingModel = dMNCompiler.compile(resource, dmnModels);
+ assertThat(importingModel).isNotNull();
+ assertThat(importingModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ assertThat(importingModel.getMessages()).isEmpty();
+ }
+
+ @Test
+ void compileImportingModelWithoutImportedModel() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String modelName = "Importing named Model";
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_Named_Model.dmn",
+ this.getClass());
+ DMNModel model = dMNCompiler.compile( resource, dmnModels);
+ assertThat(model).isNotNull();
+ assertThat(model.getName()).isNotNull().isEqualTo(modelName);
+
+ Definitions dmnDefn = model.getDefinitions();
+ dmnModels.add(model);
+ model = dMNCompiler.compile(dmnDefn, resource, dmnModels);
+ assertThat(model).isNotNull();
+ assertThat(model.getName()).isNotNull().isEqualTo(modelName);
+ assertThat(model.getMessages()).isNotEmpty();
+ assertThat(model.getMessages().get(0).getMessageType()).isEqualTo(DMNMessageType.IMPORT_NOT_FOUND);
+
+ }
+
+ @Test
+ void resolveDMNImportType() {
+ List<DMNModel> toMerge = new ArrayList<>();
+ List<DMNModel> dmnModels = new ArrayList<>();
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel importedModel = dMNCompiler.compile( resource, dmnModels);
+ assertThat(importedModel).isNotNull();
+ dmnModels.add(importedModel);
+
+ //imported model - Importing_Named_Model.dmn
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f79aa7a4-f9a3-410a-ac95-bea496edabgc";
+ resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_Named_Model.dmn",
+ this.getClass());
+ DMNModel importingModel = dMNCompiler.compile(resource, dmnModels);
+ assertThat(importingModel).isNotNull();
+ assertThat(importingModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ assertThat(importingModel.getMessages()).isEmpty();
+
+ Import input = importingModel.getDefinitions().getImport().get(0);
+ DMNModelImpl model = new DMNModelImpl(importingModel.getDefinitions(), resource);
+ DMNCompilerImpl.resolveDMNImportType(input, dmnModels, model, toMerge);
+ assertThat(model.getMessages()).isEmpty();
+ assertThat(model.getImportAliasesForNS().entrySet().stream().findFirst().get().getValue().getLocalPart()).isNotNull().isEqualTo("Imported Model");
+
+ }
+
+ @Test
+ void checkLocatedDMNModel() {
+ List<DMNModel> toMerge = new ArrayList<>();
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f79aa7a4-f9a3-410a-ac95-bea496edabgc";
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_Named_Model.dmn",
+ this.getClass());
+ DMNModel importingModel = dMNCompiler.compile(resource, dmnModels);
+ assertThat(importingModel).isNotNull();
+ assertThat(importingModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+
+ Import input = importingModel.getDefinitions().getImport().get(0);
+ DMNModelImpl model = new DMNModelImpl(importingModel.getDefinitions(), resource);
+ DMNModel located = new DMNModelImpl(importingModel.getDefinitions(), resource);
+ DMNCompilerImpl.checkLocatedDMNModel(input, located, model, toMerge);
+ assertThat(importingModel).isNotNull();
+ assertThat(importingModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ assertThat(toMerge.isEmpty()).isTrue();
+ }
+
+ @Test
+ void checkLocatedDMNModelWithAliasNull() {
+ String namespace="http://www.trisotech.com/dmn/definitions/_f79aa7a4-f9a3-410a-ac95-bea496edabgc";
+ List<DMNModel> toMerge = new ArrayList<>();
+ List<DMNModel> dmnModels = new ArrayList<>();
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_EmptyNamed_Model_Without_Href_Namespace.dmn",
+ this.getClass());
+ DMNModel emptyNamedModel = dMNCompiler.compile( resource, dmnModels);
+ assertThat(emptyNamedModel).isNotNull();
+ dmnModels.add(emptyNamedModel);
+
+ Import input = emptyNamedModel.getDefinitions().getImport().get(0);
+ DMNModelImpl model = new DMNModelImpl(emptyNamedModel.getDefinitions(), resource);
+ DMNModel located = new DMNModelImpl(emptyNamedModel.getDefinitions(), resource);
+ DMNCompilerImpl.checkLocatedDMNModel(input, located, model, toMerge);
+ assertThat(emptyNamedModel).isNotNull();
+ assertThat(toMerge.isEmpty()).isFalse();
+ assertThat(toMerge.get(0).getNamespace()).isNotNull().isEqualTo(namespace);
Review Comment:
Assertion added
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] [incubator-kie-issues#1748] DMNCompilerImpl class code refactoring and Test cases [incubator-kie-drools]
Posted by "ChinchuAjith (via GitHub)" <gi...@apache.org>.
ChinchuAjith commented on code in PR #6267:
URL: https://github.com/apache/incubator-kie-drools/pull/6267#discussion_r2007179594
##########
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:
done
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] [incubator-kie-issues#1748] DMNCompilerImpl class code refactoring and Test cases [incubator-kie-drools]
Posted by "ChinchuAjith (via GitHub)" <gi...@apache.org>.
ChinchuAjith commented on code in PR #6267:
URL: https://github.com/apache/incubator-kie-drools/pull/6267#discussion_r2007321188
##########
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:
Updated
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] DMNCompilerImpl class code refactoring and Test cases [incubator-kie-drools]
Posted by "ChinchuAjith (via GitHub)" <gi...@apache.org>.
ChinchuAjith commented on code in PR #6267:
URL: https://github.com/apache/incubator-kie-drools/pull/6267#discussion_r1984451459
##########
kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/compiler/DMNCompilerImplTest.java:
##########
@@ -1,5 +1,5 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
+
Review Comment:
Done
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] DMNCompilerImpl class code refactoring and Test cases [incubator-kie-drools]
Posted by "ChinchuAjith (via GitHub)" <gi...@apache.org>.
ChinchuAjith commented on code in PR #6267:
URL: https://github.com/apache/incubator-kie-drools/pull/6267#discussion_r1993019708
##########
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/DMNCompilerImpl.java:
##########
@@ -209,60 +210,82 @@ public DMNModel compile(Definitions dmndefs, Collection<DMNModel> dmnModels, Res
}
DMNModelImpl model = new DMNModelImpl(dmndefs, resource);
model.setRuntimeTypeCheck(((DMNCompilerConfigurationImpl) dmnCompilerConfig).getOption(RuntimeTypeCheckOption.class).isRuntimeTypeCheck());
+ DMNCompilerContext ctx = configureDMNCompiler(model.getFeelDialect(), relativeResolver);
+ if (!dmndefs.getImport().isEmpty()) {
+ iterateImports(dmndefs, dmnModels, model, relativeResolver );
+ }
+ processItemDefinitions(ctx, model, dmndefs);
+ processDrgElements(ctx, model, dmndefs);
+ return model;
+ }
+
+ private DMNCompilerContext configureDMNCompiler(FEELDialect feeldialect, Function<String, Reader> relativeResolver) {
+
DMNCompilerConfigurationImpl cc = (DMNCompilerConfigurationImpl) dmnCompilerConfig;
List<FEELProfile> helperFEELProfiles = cc.getFeelProfiles();
- DMNFEELHelper feel = new DMNFEELHelper(cc.getRootClassLoader(), helperFEELProfiles, model.getFeelDialect());
+ DMNFEELHelper feel = new DMNFEELHelper(cc.getRootClassLoader(), helperFEELProfiles, feeldialect);
DMNCompilerContext ctx = new DMNCompilerContext(feel);
ctx.setRelativeResolver(relativeResolver);
+ return ctx;
+ }
+
+ private void iterateImports(Definitions dmndefs, Collection<DMNModel> dmnModels, DMNModelImpl model, Function<String, Reader> relativeResolver ) {
Review Comment:
@gitgabrio what i meant is i have tested the compile method which will internally call this private method and is working fine.
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] [incubator-kie-issues#1748] DMNCompilerImpl class code refactoring and Test cases [incubator-kie-drools]
Posted by "gitgabrio (via GitHub)" <gi...@apache.org>.
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] [incubator-kie-issues#1748] DMNCompilerImpl class code refactoring and Test cases [incubator-kie-drools]
Posted by "ChinchuAjith (via GitHub)" <gi...@apache.org>.
ChinchuAjith commented on code in PR #6267:
URL: https://github.com/apache/incubator-kie-drools/pull/6267#discussion_r2007220086
##########
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:
Changed to this - "This method checks if a DMNModel is located and processes it by setting the import alias or merging it with the original model."
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] DMNCompilerImpl class code refactoring and Test cases [incubator-kie-drools]
Posted by "ChinchuAjith (via GitHub)" <gi...@apache.org>.
ChinchuAjith commented on code in PR #6267:
URL: https://github.com/apache/incubator-kie-drools/pull/6267#discussion_r1992838715
##########
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/DMNCompilerImpl.java:
##########
@@ -107,6 +98,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import static org.kie.dmn.core.compiler.DMNImportsUtil.*;
Review Comment:
Done
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] DMNCompilerImpl class code refactoring and Test cases [incubator-kie-drools]
Posted by "ChinchuAjith (via GitHub)" <gi...@apache.org>.
ChinchuAjith commented on code in PR #6267:
URL: https://github.com/apache/incubator-kie-drools/pull/6267#discussion_r1984536255
##########
kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/compiler/DMNCompilerImplTest.java:
##########
@@ -70,10 +84,168 @@ void getRootElement() {
InformationRequirement informationRequirement = new TInformationRequirement();
elementReference.setParent(informationRequirement);
- assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> DMNCompilerImpl.getRootElement(elementReference));
-
+ assertThatExceptionOfType(RuntimeException.class).isThrownBy(
+ () -> DMNCompilerImpl.getRootElement(elementReference)).withMessageContaining
+ ("Failed to get Definitions parent for org.kie.dmn.model.v1_5");
informationRequirement.setParent(parent);
retrieved = DMNCompilerImpl.getRootElement(elementReference);
assertThat(retrieved).isNotNull().isEqualTo(parent);
}
-}
\ No newline at end of file
+
+ @Test
+ void compile() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f27bb64b-6fc7-4e1f-9848-11ba35e0df44";
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel importedModel = dMNCompiler.compile( resource, dmnModels);
+ assertThat(importedModel).isNotNull();
+ assertThat(importedModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ assertThat(importedModel.getMessages()).isEmpty();
+ }
+
+ @Test
+ void compileWithUnknownTypeModelImports() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f27bb64b-6fc7-4e1f-9848-11ba35e0df44";
+ String modelName = "Imported Model";
+ String importType = String.valueOf(ImportDMNResolverUtil.ImportType.UNKNOWN);
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel model = dMNCompiler.compile( resource, dmnModels);
+ assertThat(model).isNotNull();
+ Definitions dmnDefn = model.getDefinitions();
+ addImport(dmnDefn, importType, nameSpace, modelName);
+ dmnModels.add(model);
+ model = dMNCompiler.compile(dmnDefn, resource, dmnModels);
+ assertThat(model).isNotNull();
+ assertThat(model.getName()).isNotNull().isEqualTo(modelName);
+ assertThat(model.getMessages()).isNotEmpty();
Review Comment:
Done
##########
kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/compiler/DMNCompilerImplTest.java:
##########
@@ -70,10 +84,168 @@ void getRootElement() {
InformationRequirement informationRequirement = new TInformationRequirement();
elementReference.setParent(informationRequirement);
- assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> DMNCompilerImpl.getRootElement(elementReference));
-
+ assertThatExceptionOfType(RuntimeException.class).isThrownBy(
+ () -> DMNCompilerImpl.getRootElement(elementReference)).withMessageContaining
+ ("Failed to get Definitions parent for org.kie.dmn.model.v1_5");
informationRequirement.setParent(parent);
retrieved = DMNCompilerImpl.getRootElement(elementReference);
assertThat(retrieved).isNotNull().isEqualTo(parent);
}
-}
\ No newline at end of file
+
+ @Test
+ void compile() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f27bb64b-6fc7-4e1f-9848-11ba35e0df44";
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel importedModel = dMNCompiler.compile( resource, dmnModels);
+ assertThat(importedModel).isNotNull();
+ assertThat(importedModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ assertThat(importedModel.getMessages()).isEmpty();
+ }
+
+ @Test
+ void compileWithUnknownTypeModelImports() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f27bb64b-6fc7-4e1f-9848-11ba35e0df44";
+ String modelName = "Imported Model";
+ String importType = String.valueOf(ImportDMNResolverUtil.ImportType.UNKNOWN);
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel model = dMNCompiler.compile( resource, dmnModels);
+ assertThat(model).isNotNull();
+ Definitions dmnDefn = model.getDefinitions();
+ addImport(dmnDefn, importType, nameSpace, modelName);
+ dmnModels.add(model);
+ model = dMNCompiler.compile(dmnDefn, resource, dmnModels);
+ assertThat(model).isNotNull();
+ assertThat(model.getName()).isNotNull().isEqualTo(modelName);
+ assertThat(model.getMessages()).isNotEmpty();
+ assertThat(model.getMessages().get(0).getText()).isEqualTo("DMN: Import type unknown: 'UNKNOWN'. (Invalid FEEL syntax on the referenced expression) ");
+
+ }
+
+ @Test
+ void compileWithImportingDmnModel() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Imported_Model_Unamed.dmn",
+ this.getClass());
+ DMNModel importedModel = dMNCompiler.compile( resource, dmnModels);
+ assertThat(importedModel).isNotNull();
+ dmnModels.add(importedModel);
+
+ //imported model - Importing_Named_Model.dmn
+ String nameSpace = "http://www.trisotech.com/dmn/definitions/_f79aa7a4-f9a3-410a-ac95-bea496edabgc";
+ resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_Named_Model.dmn",
+ this.getClass());
+
+ DMNModel importingModel = dMNCompiler.compile(resource, dmnModels);
+ assertThat(importingModel).isNotNull();
+ assertThat(importingModel.getNamespace()).isNotNull().isEqualTo(nameSpace);
+ assertThat(importingModel.getMessages()).isEmpty();
+ }
+
+ @Test
+ void compileImportingModelWithoutImportedModel() {
+ List<DMNModel> dmnModels = new ArrayList<>();
+ String modelName = "Importing named Model";
+ Resource resource = new ClassPathResource( "valid_models/DMNv1_5/Importing_Named_Model.dmn",
+ this.getClass());
+ DMNModel model = dMNCompiler.compile( resource, dmnModels);
+ assertThat(model).isNotNull();
+ assertThat(model.getName()).isNotNull().isEqualTo(modelName);
+
+ Definitions dmnDefn = model.getDefinitions();
+ dmnModels.add(model);
+ model = dMNCompiler.compile(dmnDefn, resource, dmnModels);
+ assertThat(model).isNotNull();
+ assertThat(model.getName()).isNotNull().isEqualTo(modelName);
+ assertThat(model.getMessages()).isNotEmpty();
Review Comment:
Done
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] DMNCompilerImpl class code refactoring and Test cases [incubator-kie-drools]
Posted by "ChinchuAjith (via GitHub)" <gi...@apache.org>.
ChinchuAjith commented on code in PR #6267:
URL: https://github.com/apache/incubator-kie-drools/pull/6267#discussion_r1984530204
##########
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/DMNCompilerImpl.java:
##########
@@ -209,60 +210,82 @@ public DMNModel compile(Definitions dmndefs, Collection<DMNModel> dmnModels, Res
}
DMNModelImpl model = new DMNModelImpl(dmndefs, resource);
model.setRuntimeTypeCheck(((DMNCompilerConfigurationImpl) dmnCompilerConfig).getOption(RuntimeTypeCheckOption.class).isRuntimeTypeCheck());
+ DMNCompilerContext ctx = configureDMNCompiler(model.getFeelDialect(), relativeResolver);
+ if (!dmndefs.getImport().isEmpty()) {
+ iterateImports(dmndefs, dmnModels, model, relativeResolver );
+ }
+ processItemDefinitions(ctx, model, dmndefs);
+ processDrgElements(ctx, model, dmndefs);
+ return model;
+ }
+
+ private DMNCompilerContext configureDMNCompiler(FEELDialect feeldialect, Function<String, Reader> relativeResolver) {
+
DMNCompilerConfigurationImpl cc = (DMNCompilerConfigurationImpl) dmnCompilerConfig;
List<FEELProfile> helperFEELProfiles = cc.getFeelProfiles();
- DMNFEELHelper feel = new DMNFEELHelper(cc.getRootClassLoader(), helperFEELProfiles, model.getFeelDialect());
+ DMNFEELHelper feel = new DMNFEELHelper(cc.getRootClassLoader(), helperFEELProfiles, feeldialect);
DMNCompilerContext ctx = new DMNCompilerContext(feel);
ctx.setRelativeResolver(relativeResolver);
+ return ctx;
+ }
+
+ private void iterateImports(Definitions dmndefs, Collection<DMNModel> dmnModels, DMNModelImpl model, Function<String, Reader> relativeResolver ) {
List<DMNModel> toMerge = new ArrayList<>();
- if (!dmndefs.getImport().isEmpty()) {
- for (Import i : dmndefs.getImport()) {
- if (ImportDMNResolverUtil.whichImportType(i) == ImportType.DMN) {
- Either<String, DMNModel> resolvedResult = ImportDMNResolverUtil.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());
- if (located != null) {
- String iAlias = 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 (iAlias != null && !iAlias.isEmpty()) {
- model.setImportAliasForNS(iAlias, located.getNamespace(), located.getName());
- importFromModel(model, located, iAlias);
- } else {
- toMerge.add(located);
- }
- }
- } else if (ImportDMNResolverUtil.whichImportType(i) == ImportType.PMML) {
- processPMMLImport(model, i, relativeResolver);
- model.setImportAliasForNS(i.getName(), i.getNamespace(), i.getName());
- } else {
- MsgUtil.reportMessage(logger,
- DMNMessage.Severity.ERROR,
- null,
- model,
- null,
- null,
- Msg.IMPORT_TYPE_UNKNOWN,
- i.getImportType());
- }
+ for (Import i : dmndefs.getImport()) {
+ if (ImportDMNResolverUtil.whichImportType(i) == ImportType.DMN) {
Review Comment:
Replaced with switch
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org