Skip to content

Commit

Permalink
Merge pull request #295 from KPMP/KPMP-5068_UnderstandDirectories
Browse files Browse the repository at this point in the history
KPMP-5068: Ignore lone top level directory
  • Loading branch information
zwright authored Feb 15, 2024
2 parents 3618eb4 + 2bd75c0 commit ef5f3aa
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,29 @@ public PackageValidationResponse matchFiles(PackageFilesRequest request)
}

if (response.getDirectoryExists()) {

List<String> globusFiles = getGlobusFileNames(objectsInGlobus);
List<String> globusDirectories = getGlobusDirectoryNames(objectsInGlobus);
List<String> filesFromMetadata = processIncomingFilenames(request);

String baseDirectory = "";
boolean ignoreBaseDirectory = false;
// if we only have a top level folder, ignore it and go down one to start validation
if (globusFiles.size() == 0 && globusDirectories.size() == 1) {
baseDirectory = globusDirectories.get(0);
objectsInGlobus = globus.getFilesAndDirectoriesAtEndpoint(request.getPackageId() + "/" +baseDirectory);
globusFiles = getGlobusFileNames(objectsInGlobus);
globusDirectories = getGlobusDirectoryNames(objectsInGlobus);
ignoreBaseDirectory = true;
}

response.setFilesFromMetadata(filesFromMetadata);
response.setPackageId(request.getPackageId());

Map<String, List<String>> filesInGlobusDirectories = new HashMap<>();
// put top level files in our map

filesInGlobusDirectories.put("", globusFiles);
String currentDirectory = "";
filesInGlobusDirectories = processGlobusDirectory(filesInGlobusDirectories, globusDirectories, request.getPackageId(), currentDirectory);
filesInGlobusDirectories = processGlobusDirectory(filesInGlobusDirectories, globusDirectories, request.getPackageId() + baseDirectory, baseDirectory);
List<String> filePathsInGlobus = getGlobusFilePaths(filesInGlobusDirectories);

response.setFilesInGlobus(filePathsInGlobus);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,38 @@ public void testFilesNotInMetadata_ignoreMetadataFile() {
assertEquals(Collections.emptyList(), service.filenamesNotInMetadata(globusListing, metadataFiles));
}

@Test
public void testMatchFile_perfectMatchIgnoresParentFolderWhenLone() throws JsonProcessingException, IOException {

GlobusFileListing parent = new GlobusFileListing();
parent.setName("parent");
parent.setType("dir");
GlobusFileListing globusFile1 = new GlobusFileListing();
globusFile1.setName("file1");
globusFile1.setType("file");
GlobusFileListing globusFile2 = new GlobusFileListing();
globusFile2.setName("file2");
globusFile2.setType("file");
GlobusFileListing globusFile3 = new GlobusFileListing();
globusFile3.setName("file3");
globusFile3.setType("file");
List<GlobusFileListing> globusFileListing = Arrays.asList(globusFile1, globusFile2, globusFile3);
when(globus.getFilesAndDirectoriesAtEndpoint("package123")).thenReturn(Arrays.asList(parent));
when(globus.getFilesAndDirectoriesAtEndpoint("package123/parent")).thenReturn(globusFileListing);
PackageFilesRequest request = new PackageFilesRequest();
request.setFilenames("file1\nfile2,file3");
request.setPackageId("package123");


PackageValidationResponse response = service.matchFiles(request);
assertEquals(true, response.getDirectoryExists());
assertEquals(Arrays.asList("file1", "file2", "file3"), response.getFilesFromMetadata());
assertEquals("package123", response.getPackageId());
assertEquals(Arrays.asList("file1", "file2", "file3"), response.getFilesInGlobus());
assertEquals(null, response.getMetadataFilesNotFoundInGlobus());
assertEquals(null, response.getGlobusFilesNotFoundInMetadata());
}

@Test
public void testMatchFile_perfectMatchOneLevel() throws JsonProcessingException, IOException {

Expand Down

0 comments on commit ef5f3aa

Please sign in to comment.