From 365eaefa0469a9311ef621a621b6c479dce4074d Mon Sep 17 00:00:00 2001 From: Evan Chicoine Date: Wed, 25 Oct 2023 16:27:08 -0400 Subject: [PATCH] Fixed pom entry for wiremock, abandoning multhreading on LibraryProcessor as it's too unstable at the server during ci checks, and added conditional path processing to tooling/src/test/java/org/opencds/cqf/tooling/operation/StripGeneratedContentOperationTest.java --- tooling/pom.xml | 3 +- .../cqf/tooling/library/LibraryProcessor.java | 43 +++---------------- .../StripGeneratedContentOperationTest.java | 23 +++++++--- 3 files changed, 26 insertions(+), 43 deletions(-) diff --git a/tooling/pom.xml b/tooling/pom.xml index 9029b88e7..c1ce0f87a 100644 --- a/tooling/pom.xml +++ b/tooling/pom.xml @@ -315,8 +315,9 @@ 4.1.0 test + - com.github.tomakehurst + org.wiremock wiremock 3.0.1 test diff --git a/tooling/src/main/java/org/opencds/cqf/tooling/library/LibraryProcessor.java b/tooling/src/main/java/org/opencds/cqf/tooling/library/LibraryProcessor.java index d39ed982a..0a850ee36 100644 --- a/tooling/src/main/java/org/opencds/cqf/tooling/library/LibraryProcessor.java +++ b/tooling/src/main/java/org/opencds/cqf/tooling/library/LibraryProcessor.java @@ -93,54 +93,25 @@ public List refreshIgLibraryContent(BaseProcessor parentContext, Encodin public Boolean bundleLibraryDependencies(String path, FhirContext fhirContext, Map resources, Encoding encoding, boolean versioned) { - return ThreadUtils.executeTasks(bundleLibraryDependenciesTasks(path, fhirContext, resources, encoding, versioned)); - } - - public List> bundleLibraryDependenciesTasks(String path, FhirContext fhirContext, Map resources, - Encoding encoding, boolean versioned) { - List> returnTasks = new ArrayList<>(); - String fileName = FilenameUtils.getName(path); boolean prefixed = fileName.toLowerCase().startsWith("library-"); + Boolean shouldPersist = true; try { Map dependencies = ResourceUtils.getDepLibraryResources(path, fhirContext, encoding, versioned, logger); // String currentResourceID = IOUtils.getTypeQualifiedResourceId(path, fhirContext); for (IBaseResource resource : dependencies.values()) { - returnTasks.add(() -> { - resources.putIfAbsent(resource.getIdElement().getIdPart(), resource); + resources.putIfAbsent(resource.getIdElement().getIdPart(), resource); - // NOTE: Assuming dependency library will be in directory of dependent. - String dependencyPath = IOUtils.getResourceFileName(IOUtils.getResourceDirectory(path), resource, encoding, fhirContext, versioned, prefixed); - returnTasks.addAll(bundleLibraryDependenciesTasks(dependencyPath, fhirContext, resources, encoding, versioned)); - return null; - }); + // NOTE: Assuming dependency library will be in directory of dependent. + String dependencyPath = IOUtils.getResourceFileName(IOUtils.getResourceDirectory(path), resource, encoding, fhirContext, versioned, prefixed); + bundleLibraryDependencies(dependencyPath, fhirContext, resources, encoding, versioned); } } catch (Exception e) { + shouldPersist = false; LogUtils.putException(path, e); } - return returnTasks; + return shouldPersist; } -//public Boolean bundleLibraryDependencies(String path, FhirContext fhirContext, Map resources, -// Encoding encoding, boolean versioned) { -// String fileName = FilenameUtils.getName(path); -// boolean prefixed = fileName.toLowerCase().startsWith("library-"); -// Boolean shouldPersist = true; -// try { -// Map dependencies = ResourceUtils.getDepLibraryResources(path, fhirContext, encoding, versioned, logger); -// // String currentResourceID = IOUtils.getTypeQualifiedResourceId(path, fhirContext); -// for (IBaseResource resource : dependencies.values()) { -// resources.putIfAbsent(resource.getIdElement().getIdPart(), resource); -// -// // NOTE: Assuming dependency library will be in directory of dependent. -// String dependencyPath = IOUtils.getResourceFileName(IOUtils.getResourceDirectory(path), resource, encoding, fhirContext, versioned, prefixed); -// bundleLibraryDependencies(dependencyPath, fhirContext, resources, encoding, versioned); -// } -// } catch (Exception e) { -// shouldPersist = false; -// LogUtils.putException(path, e); -// } -// return shouldPersist; -//} protected boolean versioned; diff --git a/tooling/src/test/java/org/opencds/cqf/tooling/operation/StripGeneratedContentOperationTest.java b/tooling/src/test/java/org/opencds/cqf/tooling/operation/StripGeneratedContentOperationTest.java index 3f68c7600..41a320824 100644 --- a/tooling/src/test/java/org/opencds/cqf/tooling/operation/StripGeneratedContentOperationTest.java +++ b/tooling/src/test/java/org/opencds/cqf/tooling/operation/StripGeneratedContentOperationTest.java @@ -16,7 +16,7 @@ import java.nio.file.Paths; public class StripGeneratedContentOperationTest { - + private static final String separator = System.getProperty("file.separator"); @Test public void test_strip_generated_content() throws URISyntaxException, FileNotFoundException { String dataInputPath = "strip-resources"; @@ -39,12 +39,23 @@ public void test_strip_generated_content() throws URISyntaxException, FileNotFou Operation stripGeneratedContentOperation = new StripGeneratedContentOperation(); stripGeneratedContentOperation.execute(args); - File classLocation = new File(getClass().getProtectionDomain().getCodeSource().getLocation().toURI()); - File parentDir = classLocation.getParentFile(); // Get the parent directory of the class location - File outputDir = new File(parentDir, "test-output/"); - File jsonFile = new File(outputDir, "strip-generated-contentLibraryBreastCancerScreeningFHIR.json"); + Library libraryAfterStrip = null; + if (separator.equalsIgnoreCase("/")) { + + Path path = Paths.get(getClass().getProtectionDomain().getCodeSource().getLocation().getPath() + + "/../test-output/strip-generated-content"); + libraryAfterStrip = (Library)FhirContext.forR4Cached().newJsonParser().parseResource( + new FileReader(path + "/LibraryBreastCancerScreeningFHIR.json")); + + }else{ + + File classLocation = new File(getClass().getProtectionDomain().getCodeSource().getLocation().toURI()); + File parentDir = classLocation.getParentFile(); // Get the parent directory of the class location + File outputDir = new File(parentDir, "test-output/"); + File jsonFile = new File(outputDir, "strip-generated-contentLibraryBreastCancerScreeningFHIR.json"); - Library libraryAfterStrip = (Library) FhirContext.forR4Cached().newJsonParser().parseResource(new FileReader(jsonFile)); + libraryAfterStrip = (Library) FhirContext.forR4Cached().newJsonParser().parseResource(new FileReader(jsonFile)); + } assertEquals(libraryAfterStrip.getContent().size(), 1);