From 96003a44ccd4c9adaa1b2c8d5020248b7a1848b6 Mon Sep 17 00:00:00 2001 From: James Agnew Date: Fri, 13 Dec 2019 13:40:26 -0500 Subject: [PATCH] Correct issue with CLI --- .../fhir/cli/UploadTerminologyCommand.java | 2 +- .../cli/UploadTerminologyCommandTest.java | 32 +++++++++++++++++++ src/changes/changes.xml | 4 +++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/hapi-fhir-cli/hapi-fhir-cli-api/src/main/java/ca/uhn/fhir/cli/UploadTerminologyCommand.java b/hapi-fhir-cli/hapi-fhir-cli-api/src/main/java/ca/uhn/fhir/cli/UploadTerminologyCommand.java index 328ae4be441..2cfddadbbdc 100644 --- a/hapi-fhir-cli/hapi-fhir-cli-api/src/main/java/ca/uhn/fhir/cli/UploadTerminologyCommand.java +++ b/hapi-fhir-cli/hapi-fhir-cli-api/src/main/java/ca/uhn/fhir/cli/UploadTerminologyCommand.java @@ -134,7 +134,7 @@ public class UploadTerminologyCommand extends BaseCommand { for (String nextDataFile : theDatafile) { try (FileInputStream fileInputStream = new FileInputStream(nextDataFile)) { - if (nextDataFile.endsWith(".csv")) { + if (nextDataFile.endsWith(".csv") || nextDataFile.endsWith(".properties")) { ourLog.info("Compressing and adding file: {}", nextDataFile); ZipEntry nextEntry = new ZipEntry(stripPath(nextDataFile)); diff --git a/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/UploadTerminologyCommandTest.java b/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/UploadTerminologyCommandTest.java index 0797b94631b..0cf9e2b5069 100644 --- a/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/UploadTerminologyCommandTest.java +++ b/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/UploadTerminologyCommandTest.java @@ -64,6 +64,8 @@ public class UploadTerminologyCommandTest extends BaseTest { private File myTextFile = new File(myTextFileName); private File myArchiveFile; private String myArchiveFileName; + private String myPropertiesFileName = "target/hello.properties"; + private File myPropertiesFile = new File(myTextFileName); @Test public void testDeltaAdd() throws IOException { @@ -238,6 +240,8 @@ public class UploadTerminologyCommandTest extends BaseTest { @Test public void testSnapshot() throws IOException { + + writeConceptAndHierarchyFiles(); when(myTermLoaderSvc.loadCustom(any(), anyList(), any())).thenReturn(new UploadStatistics(100, new IdType("CodeSystem/101"))); @@ -260,6 +264,33 @@ public class UploadTerminologyCommandTest extends BaseTest { assertThat(IOUtils.toByteArray(listOfDescriptors.get(0).getInputStream()).length, greaterThan(100)); } + @Test + public void testPropertiesFile() throws IOException { + try (FileWriter w = new FileWriter(myPropertiesFileName, false)) { + w.append("a=b\n"); + } + + when(myTermLoaderSvc.loadCustom(any(), anyList(), any())).thenReturn(new UploadStatistics(100, new IdType("CodeSystem/101"))); + + App.main(new String[]{ + UploadTerminologyCommand.UPLOAD_TERMINOLOGY, + "-v", "r4", + "-m", "SNAPSHOT", + "-t", "http://localhost:" + myPort, + "-u", "http://foo", + "-d", myPropertiesFileName, + }); + + verify(myTermLoaderSvc, times(1)).loadCustom(any(), myDescriptorListCaptor.capture(), any()); + + List listOfDescriptors = myDescriptorListCaptor.getValue(); + assertEquals(1, listOfDescriptors.size()); + assertThat(listOfDescriptors.get(0).getFilename(), matchesPattern(".*\\.zip$")); + assertThat(IOUtils.toByteArray(listOfDescriptors.get(0).getInputStream()).length, greaterThan(100)); + + + } + /** * When transferring large files, we use a local file to store the binary instead of * using HTTP to transfer a giant base 64 encoded attachment. Hopefully we can @@ -342,6 +373,7 @@ public class UploadTerminologyCommandTest extends BaseTest { FileUtils.deleteQuietly(myArchiveFile); FileUtils.deleteQuietly(myCodeSystemFile); FileUtils.deleteQuietly(myTextFile); + FileUtils.deleteQuietly(myPropertiesFile); UploadTerminologyCommand.setTransferSizeLimitForUnitTest(-1); } diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 5a4382bdcbf..03c7942e03b 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -73,6 +73,10 @@ A missing mandatory was added to the SNOMED CT CodeSystem that is uploaded when SCT is uploaded to the JPA server. Thanks to Anders Havn for the pull request! + + An issue with the HAPI FHIR CLI was corrected that prevented the upload of LOINC due to an error + regarding the properties file. +