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
This commit is contained in:
dotasek 2023-07-17 18:20:53 -04:00 committed by GitHub
parent bdb415cf8a
commit 89d0f6f867
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 3 additions and 309 deletions

View File

@ -54,16 +54,6 @@
<optional>true</optional>
</dependency>
<!-- ShEx -->
<dependency>
<groupId>es.weso</groupId>
<artifactId>shexs_2.12</artifactId>
<version>0.2.32</version>
<optional>true</optional>
</dependency>
<!-- JSON Parsers -->
<dependency>
<groupId>com.google.code.gson</groupId>

View File

@ -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<StructureDefinition> 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<StructureDefinition> 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<StructureDefinition> 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<StructureDefinition> 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<StructureDefinition> 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<StructureDefinition> 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<StructureDefinition> 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<StructureDefinition> 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<StructureDefinition> 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<StructureDefinition> 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<ShexGeneratorTestUtils.resDef> 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<String> 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<StructureDefinition> selExtns = new ArrayList<StructureDefinition>();
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<StructureDefinition> 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<StructureDefinition> selExtns = new ArrayList<StructureDefinition>();
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);
}
}
}

View File

@ -21,7 +21,7 @@
<guava_version>32.0.1-jre</guava_version>
<hapi_fhir_version>6.4.1</hapi_fhir_version>
<validator_test_case_version>1.3.15-SNAPSHOT</validator_test_case_version>
<jackson_version>2.14.0</jackson_version>
<jackson_version>2.15.2</jackson_version>
<junit_jupiter_version>5.9.2</junit_jupiter_version>
<junit_platform_launcher_version>1.8.2</junit_platform_launcher_version>
<maven_surefire_version>3.0.0-M5</maven_surefire_version>