From 29507b2140b73347683c014d1c90a3c0da319f50 Mon Sep 17 00:00:00 2001 From: Becky Reamy Date: Thu, 7 Mar 2024 13:09:17 -0500 Subject: [PATCH 1/2] KPMP-5068: Allow spaces in folder --- .../java/org/kpmp/globus/GlobusService.java | 8 +++--- .../PackageFilesValidationServiceTest.java | 25 +++++++++++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/kpmp/globus/GlobusService.java b/src/main/java/org/kpmp/globus/GlobusService.java index ff49b0af..ca94bb21 100644 --- a/src/main/java/org/kpmp/globus/GlobusService.java +++ b/src/main/java/org/kpmp/globus/GlobusService.java @@ -66,13 +66,13 @@ protected String getFileManagerUrl(String fullDirName) { public List getFilesAndDirectoriesAtEndpoint(String packageId) throws JsonProcessingException, IOException { String topDirectory = env.getProperty("GLOBUS_DIR"); String fullDirName = topDirectory + "/" + packageId; - - GenericUrl url = new GenericUrl(API_URL + "/operation/endpoint/" + endpointID + "/ls?path=" + fullDirName); + fullDirName.replace(" ", "+"); + GenericUrl url = new GenericUrl(API_URL + "/operation/endpoint/" + endpointID + "/ls?path=" + fullDirName + "&type:dir"); + HttpRequest request = requestFactory.buildGetRequest(url); request.setParser(new JsonObjectParser(JSON_FACTORY)); - Type type = new TypeToken() { - }.getType(); + Type type = new TypeToken() {}.getType(); HttpResponse response = request.execute(); GlobusListingResponse globusListing = (GlobusListingResponse) response.parseAs(type); diff --git a/src/test/java/org/kpmp/packages/validation/PackageFilesValidationServiceTest.java b/src/test/java/org/kpmp/packages/validation/PackageFilesValidationServiceTest.java index 097ba7c4..6ae6c86c 100644 --- a/src/test/java/org/kpmp/packages/validation/PackageFilesValidationServiceTest.java +++ b/src/test/java/org/kpmp/packages/validation/PackageFilesValidationServiceTest.java @@ -93,6 +93,31 @@ public void testProcessGlobusDirectory() throws JsonProcessingException, IOExcep assertEquals(expectedResults, actualListing); } + @Test + public void testProcessGlobusDirectory_spacesInDirectoryNames() throws JsonProcessingException, IOException { + Map> actualListing = new HashMap>(); + GlobusFileListing globusFile1 = new GlobusFileListing(); + globusFile1.setName("file1"); + globusFile1.setType("file"); + GlobusFileListing globusFile2 = new GlobusFileListing(); + globusFile2.setName("file2"); + globusFile2.setType("file"); + when(globus.getFilesAndDirectoriesAtEndpoint("123/directory 1")).thenReturn(Arrays.asList(globusFile1, globusFile2)); + GlobusFileListing globusFile3 = new GlobusFileListing(); + globusFile3.setName("file3"); + globusFile3.setType("file"); + GlobusFileListing globusFile4 = new GlobusFileListing(); + globusFile4.setName("file4"); + globusFile4.setType("file"); + when(globus.getFilesAndDirectoriesAtEndpoint("123/directory2")).thenReturn(Arrays.asList(globusFile3, globusFile4)); + Map> expectedResults = new HashMap<>(); + expectedResults.put("directory 1", Arrays.asList("file1", "file2")); + expectedResults.put("directory2", Arrays.asList("file3", "file4")); + + actualListing = service.processGlobusDirectory(new HashMap>(), Arrays.asList("directory 1", "directory2"), "123", ""); + + assertEquals(expectedResults, actualListing); + } @Test public void testProcessGlobusDirectory_withSubdirectories() throws JsonProcessingException, IOException { From a1e66db8d79586d2d6e9366861865324597cd038 Mon Sep 17 00:00:00 2001 From: rlreamy <34109594+rlreamy@users.noreply.github.com> Date: Tue, 15 Oct 2024 14:17:02 -0400 Subject: [PATCH 2/2] Update PackageFilesValidationServiceTest.java --- .../packages/validation/PackageFilesValidationServiceTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/kpmp/packages/validation/PackageFilesValidationServiceTest.java b/src/test/java/org/kpmp/packages/validation/PackageFilesValidationServiceTest.java index 40913ba2..5b344f88 100644 --- a/src/test/java/org/kpmp/packages/validation/PackageFilesValidationServiceTest.java +++ b/src/test/java/org/kpmp/packages/validation/PackageFilesValidationServiceTest.java @@ -123,7 +123,7 @@ public void testProcessGlobusDirectory_spacesInDirectoryNames() throws JsonProce expectedResults.put("directory 1", Arrays.asList("file1", "file2")); expectedResults.put("directory2", Arrays.asList("file3", "file4")); - actualListing = service.processGlobusDirectory(new HashMap>(), Arrays.asList("directory 1", "directory2"), "123", ""); + actualListing = service.processGlobusDirectory(new HashMap>(), Arrays.asList("directory 1", "directory2"), "123", "", ""); assertEquals(expectedResults, actualListing); }