From dc9d5d0ed19d9c28b7b0a2e1ae578078a830184f Mon Sep 17 00:00:00 2001 From: dotasek Date: Wed, 11 Jan 2023 13:41:43 -0500 Subject: [PATCH 1/3] Set file transfers to binary type, ensure file contents match --- .../org/hl7/fhir/utilities/FTPClient.java | 20 +++++++++++-- .../org/hl7/fhir/utilities/FTPClientTest.java | 30 +++++++++++++------ 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/FTPClient.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/FTPClient.java index 3b91f3af2..912493d43 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/FTPClient.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/FTPClient.java @@ -1,5 +1,6 @@ package org.hl7.fhir.utilities; +import org.apache.commons.net.ftp.FTP; import org.apache.commons.net.ftp.FTPReply; @@ -52,15 +53,16 @@ public class FTPClient { else { clientImpl.connect(server); } + //clientImpl.setFileTransferMode(FTP.BINARY_FILE_TYPE); + clientImpl.login(user, password); - clientImpl.getSystemType(); int reply = clientImpl.getReplyCode(); if(!FTPReply.isPositiveCompletion(reply)) { clientImpl.disconnect(); - throw new IOException("FTP server refused connection."); + throw new IOException("FTP server refused connection. Reply code: " + reply); } } @@ -85,8 +87,20 @@ public class FTPClient { */ public void upload(String source, String path) throws IOException { String resolvedPath = resolveRemotePath(path); - FileInputStream localStream = new FileInputStream(new File(source)); + FileInputStream localStream = new FileInputStream(source); + clientImpl.setFileType(FTP.BINARY_FILE_TYPE); clientImpl.storeFile( resolvedPath, localStream); + localStream.close(); + + int reply = clientImpl.getReplyCode(); + + if(!FTPReply.isPositiveCompletion(reply)) { + throw new IOException("Error uploading file. Reply code: " + reply); + } + } + + public void disconnect() throws IOException { + clientImpl.disconnect(); } } diff --git a/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/FTPClientTest.java b/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/FTPClientTest.java index cac5f7a9a..7e2d97256 100644 --- a/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/FTPClientTest.java +++ b/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/FTPClientTest.java @@ -1,6 +1,7 @@ package org.hl7.fhir.utilities; +import org.apache.commons.io.IOUtils; import org.hl7.fhir.utilities.tests.ResourceLoaderTests; import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.AfterAll; @@ -11,12 +12,14 @@ import org.mockftpserver.fake.FakeFtpServer; import org.mockftpserver.fake.UserAccount; import org.mockftpserver.fake.filesystem.*; +import java.io.File; import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; @TestInstance(TestInstance.Lifecycle.PER_CLASS) public class FTPClientTest implements ResourceLoaderTests { @@ -30,6 +33,7 @@ public class FTPClientTest implements ResourceLoaderTests { public static final String DUMMY_FILE_TO_UPLOAD = "dummyFileToUpload"; public static final int FAKE_FTP_PORT = 8021; + public static final String DUMMY_FILE_CONTENT = "Dummy file content\nMore content\n"; FakeFtpServer fakeFtpServer; @@ -47,6 +51,8 @@ public class FTPClientTest implements ResourceLoaderTests { Path dummyFileToUploadPath; Path dummyUploadedFilePath; + String dummyFileContent; + @BeforeAll public void setup() throws IOException { setupDummyFileToUpload(); @@ -55,7 +61,14 @@ public class FTPClientTest implements ResourceLoaderTests { } private void setupDummyFileToUpload() throws IOException { + dummyFileContent = createDummyFileContent(); + dummyFileToUploadPath = Files.createTempFile("dummyFtpFileToUpload", "dummy"); + Files.write(dummyFileToUploadPath, DUMMY_FILE_CONTENT.getBytes(StandardCharsets.UTF_8)); + } + + private String createDummyFileContent() { + return DUMMY_FILE_CONTENT; } public void setupFakeFtpServer() throws IOException { @@ -74,6 +87,7 @@ public class FTPClientTest implements ResourceLoaderTests { fileSystem.add(new FileEntry(dummyFileToDeletePath.toFile().getAbsolutePath())); //fileSystem.add(new FileEntry("c:\\data\\run.exe")); fakeFtpServer.setFileSystem(fileSystem); + fakeFtpServer.start(); } @@ -102,17 +116,11 @@ public class FTPClientTest implements ResourceLoaderTests { FTPClient client = connectToFTPClient(); - String deleteFilePath = dummyFileToDeletePath.toFile().getAbsolutePath(); - assertTrue(fakeFtpServer.getFileSystem().exists(deleteFilePath)); client.delete( RELATIVE_PATH_2 + "/" + DUMMY_FILE_TO_DELETE); - assertFalse(fakeFtpServer.getFileSystem().exists(deleteFilePath)); - - - } @NotNull @@ -135,6 +143,10 @@ public class FTPClientTest implements ResourceLoaderTests { assertTrue(fakeFtpServer.getFileSystem().exists(uploadFilePath)); + FileEntry fileEntry= (FileEntry)fakeFtpServer.getFileSystem().getEntry(uploadFilePath); + InputStream inputStream = fileEntry.createInputStream(); + byte[] bytes = IOUtils.toByteArray(inputStream); + String actualContent = new String(bytes, StandardCharsets.UTF_8); + assertEquals(DUMMY_FILE_CONTENT,actualContent); } - } From ee9fc6e924cc6ce103e8b6ee1d597fc1e0e71320 Mon Sep 17 00:00:00 2001 From: dotasek Date: Wed, 11 Jan 2023 16:28:46 -0500 Subject: [PATCH 2/3] Add missing space to FHIRException message (matches r5 ResourceType now) (#1067) Co-authored-by: dotasek --- .../hl7/fhir/dstu2/model/ResourceType.java | 58 +++++++++---------- .../fhir/dstu2016may/model/ResourceType.java | 58 +++++++++---------- .../hl7/fhir/dstu3/model/ResourceType.java | 58 +++++++++---------- .../org/hl7/fhir/r4/model/ResourceType.java | 2 +- 4 files changed, 88 insertions(+), 88 deletions(-) diff --git a/org.hl7.fhir.dstu2/src/main/java/org/hl7/fhir/dstu2/model/ResourceType.java b/org.hl7.fhir.dstu2/src/main/java/org/hl7/fhir/dstu2/model/ResourceType.java index 010dc6a4b..47d382593 100644 --- a/org.hl7.fhir.dstu2/src/main/java/org/hl7/fhir/dstu2/model/ResourceType.java +++ b/org.hl7.fhir.dstu2/src/main/java/org/hl7/fhir/dstu2/model/ResourceType.java @@ -1,33 +1,33 @@ package org.hl7.fhir.dstu2.model; -/* - Copyright (c) 2011+, HL7, Inc. - All rights reserved. - - Redistribution and use in source and binary forms, with or without modification, - are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * Neither the name of HL7 nor the names of its contributors may be used to - endorse or promote products derived from this software without specific - prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. - - */ +/* + Copyright (c) 2011+, HL7, Inc. + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of HL7 nor the names of its contributors may be used to + endorse or promote products derived from this software without specific + prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + + */ @@ -517,7 +517,7 @@ public enum ResourceType { if ("VisionPrescription".equals(code)) return VisionPrescription; - throw new FHIRException("Unknown resource type"+code); + throw new FHIRException("Unknown resource type "+code); } } \ No newline at end of file diff --git a/org.hl7.fhir.dstu2016may/src/main/java/org/hl7/fhir/dstu2016may/model/ResourceType.java b/org.hl7.fhir.dstu2016may/src/main/java/org/hl7/fhir/dstu2016may/model/ResourceType.java index 4ac8374d3..437082130 100644 --- a/org.hl7.fhir.dstu2016may/src/main/java/org/hl7/fhir/dstu2016may/model/ResourceType.java +++ b/org.hl7.fhir.dstu2016may/src/main/java/org/hl7/fhir/dstu2016may/model/ResourceType.java @@ -1,33 +1,33 @@ package org.hl7.fhir.dstu2016may.model; -/* - Copyright (c) 2011+, HL7, Inc. - All rights reserved. - - Redistribution and use in source and binary forms, with or without modification, - are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * Neither the name of HL7 nor the names of its contributors may be used to - endorse or promote products derived from this software without specific - prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. - - */ +/* + Copyright (c) 2011+, HL7, Inc. + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of HL7 nor the names of its contributors may be used to + endorse or promote products derived from this software without specific + prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + + */ @@ -612,7 +612,7 @@ public enum ResourceType { if ("VisionPrescription".equals(code)) return VisionPrescription; - throw new FHIRException("Unknown resource type"+code); + throw new FHIRException("Unknown resource type "+code); } } \ No newline at end of file diff --git a/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/model/ResourceType.java b/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/model/ResourceType.java index 4ede27014..ca6f9c818 100644 --- a/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/model/ResourceType.java +++ b/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/model/ResourceType.java @@ -1,33 +1,33 @@ package org.hl7.fhir.dstu3.model; -/* - Copyright (c) 2011+, HL7, Inc. - All rights reserved. - - Redistribution and use in source and binary forms, with or without modification, - are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * Neither the name of HL7 nor the names of its contributors may be used to - endorse or promote products derived from this software without specific - prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. - - */ +/* + Copyright (c) 2011+, HL7, Inc. + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of HL7 nor the names of its contributors may be used to + endorse or promote products derived from this software without specific + prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + + */ @@ -632,7 +632,7 @@ public enum ResourceType { if ("VisionPrescription".equals(code)) return VisionPrescription; - throw new FHIRException("Unknown resource type"+code); + throw new FHIRException("Unknown resource type "+code); } } \ No newline at end of file diff --git a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/model/ResourceType.java b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/model/ResourceType.java index 5264bbcc6..00166e919 100644 --- a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/model/ResourceType.java +++ b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/model/ResourceType.java @@ -746,7 +746,7 @@ public enum ResourceType { if ("VisionPrescription".equals(code)) return VisionPrescription; - throw new FHIRException("Unknown resource type"+code); + throw new FHIRException("Unknown resource type "+code); } } \ No newline at end of file From 004ebfd0ac5758bb93d1e01ac58b047109bf46c2 Mon Sep 17 00:00:00 2001 From: dotasek Date: Fri, 13 Jan 2023 13:34:46 -0500 Subject: [PATCH 3/3] Update RELEASE_NOTES.md ***NO_CI*** --- RELEASE_NOTES.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 7b06c6ab5..6301a0bf9 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -4,4 +4,7 @@ ## Other code changes -* no changes \ No newline at end of file +* Better tracking and reporting of snapshot generation issues +* Inclusion of SAXON dependency for processing XSLT +* Error message spacing correction +* Basic FTPClient implementation