From ceceb6c7d589840e66655b39b85bda87beb8787d Mon Sep 17 00:00:00 2001 From: dotasek Date: Mon, 17 Jul 2023 16:35:00 -0400 Subject: [PATCH 1/3] Bump shex dependency (#1351) --- org.hl7.fhir.r5/pom.xml | 4 +++- .../java/org/hl7/fhir/r5/test/ShexGeneratorTests.java | 8 ++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/org.hl7.fhir.r5/pom.xml b/org.hl7.fhir.r5/pom.xml index a01e85349..40e9cf3a0 100644 --- a/org.hl7.fhir.r5/pom.xml +++ b/org.hl7.fhir.r5/pom.xml @@ -58,10 +58,12 @@ es.weso shexs_2.12 - 0.2.31 + 0.2.32 true + + com.google.code.gson diff --git a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/ShexGeneratorTests.java b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/ShexGeneratorTests.java index 7d5c0774d..cbb4d2157 100644 --- a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/ShexGeneratorTests.java +++ b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/ShexGeneratorTests.java @@ -8,8 +8,8 @@ import java.util.ArrayList; import java.util.List; import es.weso.shex.Schema; -import es.weso.shex.validator.ShExsValidator; -import es.weso.shex.validator.ShExsValidatorBuilder; +import es.weso.shexsjena.ShExsJenaValidator; +import es.weso.shexsjena.ShExsJenaValidatorBuilder; import org.fhir.ucum.UcumException; import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.r5.conformance.profile.ProfileUtilities; @@ -353,7 +353,7 @@ public class ShexGeneratorTests { if (validateShEx) { try { - ShExsValidator validator = ShExsValidatorBuilder.fromStringSync(schema, "ShexC"); + ShExsJenaValidator validator =ShExsJenaValidatorBuilder.fromStringSync(schema, "ShexC"); Schema sch = validator.schema(); Assert.assertNotNull(sch); @@ -405,7 +405,7 @@ public class ShexGeneratorTests { if (!schema.isEmpty()) { if (validateShEx) { try { - ShExsValidator validator = ShExsValidatorBuilder.fromStringSync(schema, "ShexC"); + ShExsJenaValidator validator = ShExsJenaValidatorBuilder.fromStringSync(schema, "ShexC"); Schema sch = validator.schema(); Assert.assertNotNull(sch); From bdb415cf8ac61d293c0badc2b6e161697ad38b5a Mon Sep 17 00:00:00 2001 From: dotasek Date: Mon, 17 Jul 2023 16:35:28 -0400 Subject: [PATCH 2/3] Bump thymeleaf to 3.1.1.RELEASE (#1349) --- org.hl7.fhir.validation/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.hl7.fhir.validation/pom.xml b/org.hl7.fhir.validation/pom.xml index 843019a62..eef1dadab 100644 --- a/org.hl7.fhir.validation/pom.xml +++ b/org.hl7.fhir.validation/pom.xml @@ -211,7 +211,7 @@ org.thymeleaf thymeleaf - 3.0.9.RELEASE + 3.1.1.RELEASE com.google.guava From 89d0f6f867b38bf52d8e77671faa8fa711cc1c50 Mon Sep 17 00:00:00 2001 From: dotasek Date: Mon, 17 Jul 2023 18:20:53 -0400 Subject: [PATCH 3/3] Remove weso shex (#1352) * Bump shex dependency * Bump jackson to 2.15.2 * Bump thymeleaf to 3.1.1.RELEASE * Remove es.weso shexs_2.12 and ignored tests --- org.hl7.fhir.r5/pom.xml | 10 - .../hl7/fhir/r5/test/ShexGeneratorTests.java | 300 +----------------- pom.xml | 2 +- 3 files changed, 3 insertions(+), 309 deletions(-) diff --git a/org.hl7.fhir.r5/pom.xml b/org.hl7.fhir.r5/pom.xml index 40e9cf3a0..5955e370b 100644 --- a/org.hl7.fhir.r5/pom.xml +++ b/org.hl7.fhir.r5/pom.xml @@ -54,16 +54,6 @@ true - - - es.weso - shexs_2.12 - 0.2.32 - true - - - - com.google.code.gson diff --git a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/ShexGeneratorTests.java b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/ShexGeneratorTests.java index cbb4d2157..16f51bad3 100644 --- a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/ShexGeneratorTests.java +++ b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/ShexGeneratorTests.java @@ -4,28 +4,20 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.nio.file.FileSystems; import java.nio.file.Path; -import java.util.ArrayList; -import java.util.List; -import es.weso.shex.Schema; -import es.weso.shexsjena.ShExsJenaValidator; -import es.weso.shexsjena.ShExsJenaValidatorBuilder; import org.fhir.ucum.UcumException; import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.r5.conformance.profile.ProfileUtilities; import org.hl7.fhir.r5.conformance.ShExGenerator; import org.hl7.fhir.r5.conformance.ShExGenerator.HTMLLinkPolicy; -import org.hl7.fhir.r5.context.IWorkerContext; + import org.hl7.fhir.r5.model.StructureDefinition; import org.hl7.fhir.r5.test.utils.TestingUtilities; import org.hl7.fhir.utilities.TextFile; -import org.junit.Assert; -import org.junit.Ignore; + import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import static org.hl7.fhir.r5.test.ShexGeneratorTestUtils.printList; - public class ShexGeneratorTests { public ShExGenerator shexGenerator; @@ -132,293 +124,5 @@ public class ShexGeneratorTests { doTest("Element", ShexGeneratorTestUtils.RESOURCE_CATEGORY.STRUCTURE_DEFINITION); } - @Ignore - public void doTestAllSingleSDMode() throws FileNotFoundException, IOException, FHIRException, UcumException { - List sds = TestingUtilities.getSharedWorkerContext().fetchResourcesByType(StructureDefinition.class); - processSDList( - ShexGeneratorTestUtils.RESOURCE_CATEGORY.ALL, // Processing All kinds of Structure Definitions - sds, // List of Structure Definitions - false, //Process all extensions - // Process all types of constraints, do not skip - ShExGenerator.ConstraintTranslationPolicy.ALL, - // BatchMode - All Shex Schemas in one single file - false, - // process constraints or not - false - ); - } - - @Ignore - public void doTestAllBatchMode() throws FileNotFoundException, IOException, FHIRException, UcumException { - List sds = TestingUtilities.getSharedWorkerContext().fetchResourcesByType(StructureDefinition.class); - - processSDList( - ShexGeneratorTestUtils.RESOURCE_CATEGORY.ALL, // Processing All kinds of Structure Definitions - sds, // List of Structure Definitions - false, //Process all extensions - // Process all types of constraints, do not skip - ShExGenerator.ConstraintTranslationPolicy.ALL, - // BatchMode - All Shex Schemas in one single file - true, - // process constraints or not - true - ); - } - - @Ignore - public void doTestGenericExtensionsOnlyPolicy() throws FileNotFoundException, IOException, FHIRException, UcumException { - List sds = TestingUtilities.getSharedWorkerContext().fetchResourcesByType(StructureDefinition.class); - - processSDList( - ShexGeneratorTestUtils.RESOURCE_CATEGORY.ALL, // Processing All kinds of Structure Definitions - sds, // List of Structure Definitions - false, //Process all extensions - ShExGenerator.ConstraintTranslationPolicy.GENERIC_ONLY, - // Process generic constraints only, ignore constraints of type 'context of use' - false, - // process constraints or not - true - ); - - } - - @Ignore - public void doTestContextOfUseExtensionsOnlyPolicy() throws FileNotFoundException, IOException, FHIRException, UcumException { - List sds = TestingUtilities.getSharedWorkerContext().fetchResourcesByType(StructureDefinition.class); - - processSDList( - ShexGeneratorTestUtils.RESOURCE_CATEGORY.ALL, // Processing All kinds of Structure Definitions - sds, // List of Structure Definitions - false, //Process all extensions - ShExGenerator.ConstraintTranslationPolicy.CONTEXT_OF_USE_ONLY, - // Process constraints only where context of use found, skip otherwise - false, - // process constraints or not - true - ); - } - - @Ignore - public void doTestSelectedExtensions() throws FileNotFoundException, IOException, FHIRException, UcumException { - List sds = TestingUtilities.getSharedWorkerContext().fetchResourcesByType(StructureDefinition.class); - - processSDList( - ShexGeneratorTestUtils.RESOURCE_CATEGORY.ALL, // Processing All kinds of Structure Definitions - sds, // List of Structure Definitions - true, //Process only given/selected extensions, ignore other extensions - ShExGenerator.ConstraintTranslationPolicy.ALL, // Process all type of constraints - false, - // process constraints or not - true - ); - } - - @Ignore - public void testStructureDefinitionsOnly() throws FileNotFoundException, IOException, FHIRException, UcumException { - List sds = TestingUtilities.getSharedWorkerContext().fetchResourcesByType(StructureDefinition.class); - - processSDList( - ShexGeneratorTestUtils.RESOURCE_CATEGORY.STRUCTURE_DEFINITION, // Processing All kinds of Structure Definitions - sds, // List of Structure Definitions - false, //Process only given/selected extensions, ignore other extensions - ShExGenerator.ConstraintTranslationPolicy.ALL, // Process all type of constraints - false, - // process constraints or not - true - ); - } - - @Ignore - public void testExtensionsOnly() throws FileNotFoundException, IOException, FHIRException, UcumException { - List sds = TestingUtilities.getSharedWorkerContext().fetchResourcesByType(StructureDefinition.class); - - processSDList( - ShexGeneratorTestUtils.RESOURCE_CATEGORY.EXTENSION, // Processing All kinds of Structure Definitions - sds, // List of Structure Definitions - false, //Process only given/selected extensions, ignore other extensions - ShExGenerator.ConstraintTranslationPolicy.ALL, // Process all type of constraints - false, - // process constraints or not - true - ); - } - - @Ignore - public void testLogicalNamesOnly() throws FileNotFoundException, IOException, FHIRException, UcumException { - List sds = TestingUtilities.getSharedWorkerContext().fetchResourcesByType(StructureDefinition.class); - - processSDList( - ShexGeneratorTestUtils.RESOURCE_CATEGORY.LOGICAL_NAME, // Processing All kinds of Structure Definitions - sds, // List of Structure Definitions - false, //Process only given/selected extensions, ignore other extensions - ShExGenerator.ConstraintTranslationPolicy.ALL, // Process all type of constraints - false, - // process constraints or not - true - ); - } - - @Ignore - public void testProfilesOnly() throws FileNotFoundException, IOException, FHIRException, UcumException { - List sds = TestingUtilities.getSharedWorkerContext().fetchResourcesByType(StructureDefinition.class); - processSDList( - ShexGeneratorTestUtils.RESOURCE_CATEGORY.PROFILE, // Processing All kinds of Structure Definitions - sds, // List of Structure Definitions - false, //Process only given/selected extensions, ignore other extensions - ShExGenerator.ConstraintTranslationPolicy.ALL, // Process all type of constraints - false, - // process constraints or not - true - ); - } - - private void processSDList(ShexGeneratorTestUtils.RESOURCE_CATEGORY cat, - List sds, - boolean useSelectedExtensions, - ShExGenerator.ConstraintTranslationPolicy policy, - boolean batchMode, boolean processConstraints) { - if ((sds == null) || (sds.isEmpty())) { - throw new FHIRException("No StructuredDefinition found!"); - } - - ShexGeneratorTestUtils shexTestUtils = new ShexGeneratorTestUtils(); - List sdDefs = shexTestUtils.getSDs(sds, cat); - - printList(cat.toString(), sdDefs); - System.out.println("************************************************************************"); - System.out.println("Processing " + cat); - System.out.println("************************************************************************"); - - if (!batchMode) { - sdDefs.forEach((ShexGeneratorTestUtils.resDef resDef) -> { - String name = resDef.url; - if (resDef.url.indexOf("/") != -1) { - String els[] = resDef.url.split("/"); - name = els[els.length - 1]; - } - System.out.println("******************** " + resDef + " *********************"); - doTestSingleSD(name, resDef.kind, resDef.url, useSelectedExtensions, policy, true, true, false, processConstraints); - }); - } else { - doTestBatchSD(sds, useSelectedExtensions, policy, true, true, false, processConstraints); - } - - System.out.println("************************ END PROCESSING ******************************"); - - System.out.println("************************************************************************"); - List skipped = this.shexGenerator.getExcludedStructureDefinitionUrls(); - System.out.println("Total Items processed: " + sds.size()); - System.out.println("************************************************************************"); - } - - private void doTestSingleSD(String shortName, ShexGeneratorTestUtils.RESOURCE_CATEGORY cat, - String name, boolean useSelectedExtensions, - ShExGenerator.ConstraintTranslationPolicy policy, - boolean debugMode, boolean validateShEx, - boolean excludeMetaSDs, boolean processConstraints) { - IWorkerContext ctx = TestingUtilities.getSharedWorkerContext(); - StructureDefinition sd = ctx.fetchResource(StructureDefinition.class, ProfileUtilities.sdNs(name, null)); - if (sd == null) { - throw new FHIRException("StructuredDefinition for " + name + "(Kind:" + cat + ") was null"); - } - //Path outPath = FileSystems.getDefault().getPath(System.getProperty("java.io.tmpdir"), name.toLowerCase() + ".shex"); - Path outPath = FileSystems.getDefault().getPath(System.getProperty("user.home") + "/runtime_environments/ShExSchemas", shortName + ".shex"); - try { - this.shexGenerator = new ShExGenerator(ctx); - - this.shexGenerator.debugMode = debugMode; - this.shexGenerator.processConstraints = processConstraints; - this.shexGenerator.constraintPolicy = policy; - - if (excludeMetaSDs) { - // ShEx Generator skips resources which are at Meta level of FHIR Resource definitions - this.shexGenerator.setExcludedStructureDefinitionUrls( - ShexGeneratorTestUtils.getMetaStructureDefinitionsToSkip()); - } - - // when ShEx translates only selected resource extensions - if (useSelectedExtensions) { - List selExtns = new ArrayList(); - for (String eUrl : ShexGeneratorTestUtils.getSelectedExtensions()) { - StructureDefinition esd = ctx.fetchResource(StructureDefinition.class, ProfileUtilities.sdNs(eUrl, null)); - if (esd != null) - selExtns.add(esd); - } - this.shexGenerator.setSelectedExtension(selExtns); - } - - String schema = this.shexGenerator.generate(HTMLLinkPolicy.NONE, sd); - if (!schema.isEmpty()) { - - if (validateShEx) { - try { - ShExsJenaValidator validator =ShExsJenaValidatorBuilder.fromStringSync(schema, "ShexC"); - Schema sch = validator.schema(); - - Assert.assertNotNull(sch); - - System.out.println("VALIDATION PASSED for ShEx Schema " + sd.getName() + " (Kind:" + cat + ")"); - } catch (Exception e) { - System.out.println("VALIDATION FAILED for ShEx Schema " + sd.getName() + " (Kind:" + cat + ")"); - e.printStackTrace(); - } - } - TextFile.stringToFile(schema, outPath.toString()); - } - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - private void doTestBatchSD(List sds, boolean useSelectedExtensions, - ShExGenerator.ConstraintTranslationPolicy policy, boolean debugMode, - boolean validateShEx, boolean excludeMetaSDs, boolean processConstraints) { - IWorkerContext ctx = TestingUtilities.getSharedWorkerContext(); - //Path outPath = FileSystems.getDefault().getPath(System.getProperty("java.io.tmpdir"), name.toLowerCase() + ".shex"); - Path outPath = FileSystems.getDefault().getPath(System.getProperty("user.home") + "/runtime_environments/ShExSchemas", "ShEx.shex"); - try { - this.shexGenerator = new ShExGenerator(ctx); - - this.shexGenerator.debugMode = debugMode; - this.shexGenerator.processConstraints = processConstraints; - this.shexGenerator.constraintPolicy = policy; - - if (excludeMetaSDs) { - // ShEx Generator skips resources which are at Meta level of FHIR Resource definitions - this.shexGenerator.setExcludedStructureDefinitionUrls( - ShexGeneratorTestUtils.getMetaStructureDefinitionsToSkip()); - } - - // when ShEx translates only selected resource extensions - if (useSelectedExtensions) { - List selExtns = new ArrayList(); - for (String eUrl : ShexGeneratorTestUtils.getSelectedExtensions()) { - StructureDefinition esd = ctx.fetchResource(StructureDefinition.class, ProfileUtilities.sdNs(eUrl, null)); - if (esd != null) - selExtns.add(esd); - } - this.shexGenerator.setSelectedExtension(selExtns); - } - - String schema = this.shexGenerator.generate(HTMLLinkPolicy.NONE, sds); - if (!schema.isEmpty()) { - if (validateShEx) { - try { - ShExsJenaValidator validator = ShExsJenaValidatorBuilder.fromStringSync(schema, "ShexC"); - Schema sch = validator.schema(); - - Assert.assertNotNull(sch); - System.out.println("VALIDATION PASSED for ShEx Schema ALL SHEX STRUCTURES"); - } catch (Exception e) { - System.out.println("VALIDATION FAILED for ShEx Schema ALL SHEX STRUCTURES"); - e.printStackTrace(); - } - } - TextFile.stringToFile(schema, outPath.toString()); - } - } catch (IOException e) { - throw new RuntimeException(e); - } - } } \ No newline at end of file diff --git a/pom.xml b/pom.xml index cc9fb73a5..567a48484 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ 32.0.1-jre 6.4.1 1.3.15-SNAPSHOT - 2.14.0 + 2.15.2 5.9.2 1.8.2 3.0.0-M5