diff --git a/src/main/java/org/kpmp/globus/GlobusService.java b/src/main/java/org/kpmp/globus/GlobusService.java index 18388840..61f3ff99 100644 --- a/src/main/java/org/kpmp/globus/GlobusService.java +++ b/src/main/java/org/kpmp/globus/GlobusService.java @@ -65,13 +65,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 e2cb0a35..5b344f88 100644 --- a/src/test/java/org/kpmp/packages/validation/PackageFilesValidationServiceTest.java +++ b/src/test/java/org/kpmp/packages/validation/PackageFilesValidationServiceTest.java @@ -102,6 +102,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 {