Skip to content

Commit

Permalink
Merge pull request #304 from KPMP/develop
Browse files Browse the repository at this point in the history
Release v4.0 (take 2)
rlreamy authored Jun 5, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents 8450795 + a16c304 commit 5eb9ad0
Showing 2 changed files with 21 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -46,14 +46,12 @@ public PackageValidationResponse matchFiles(PackageFilesRequest request)
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);
@@ -63,8 +61,8 @@ public PackageValidationResponse matchFiles(PackageFilesRequest request)
// put top level files in our map

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

response.setFilesInGlobus(filePathsInGlobus);

@@ -84,15 +82,17 @@ public PackageValidationResponse matchFiles(PackageFilesRequest request)
return response;
}

protected List<String> getGlobusFilePaths(Map<String, List<String>> filesInGlobusDirectories) {
protected List<String> getGlobusFilePaths(Map<String, List<String>> filesInGlobusDirectories, String baseDirectory) {
List<String> filePaths = new ArrayList<>();
Set<String> directories = filesInGlobusDirectories.keySet();
for (String directory : directories) {
List<String> filesInDirectory = filesInGlobusDirectories.get(directory);
if (filesInDirectory.size() == 0) {
if (filesInDirectory.size() == 0 && directory != baseDirectory) {
directory = directory.replace(baseDirectory + "/", "");
filePaths.add(directory);
}
for (String file : filesInDirectory) {
directory = directory.replace(baseDirectory + "/", "");
String fileWithPath = directory + "/" + file;
if (directory == "") {
fileWithPath = file;
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package org.kpmp.packages.validation;

import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.io.IOException;
@@ -52,7 +49,7 @@ public void testGetGlobusFilePaths() {

List<String> expectedFilePaths = Arrays.asList("file1", "file2", "directory1/file3", "directory1/file4");

assertEquals(expectedFilePaths, service.getGlobusFilePaths(globusFilesInDirectories));
assertEquals(expectedFilePaths, service.getGlobusFilePaths(globusFilesInDirectories, ""));
}

@Test
@@ -63,7 +60,7 @@ public void testGetGlobusFilePaths_emptyDirectory() {

List<String> expectedFilePaths = Arrays.asList("file1", "file2", "directory1");

assertEquals(expectedFilePaths, service.getGlobusFilePaths(globusFilesInDirectories));
assertEquals(expectedFilePaths, service.getGlobusFilePaths(globusFilesInDirectories, ""));
}


@@ -225,7 +222,7 @@ public void testFilesNotInMetadata_ignoreMetadataFile() {
}

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

GlobusFileListing parent = new GlobusFileListing();
parent.setName("parent");
@@ -239,26 +236,33 @@ public void testMatchFile_perfectMatchIgnoresParentFolderWhenLone() throws JsonP
GlobusFileListing globusFile3 = new GlobusFileListing();
globusFile3.setName("file3");
globusFile3.setType("file");
List<GlobusFileListing> globusFileListing = Arrays.asList(globusFile1, globusFile2, globusFile3);
GlobusFileListing globusFolder1 = new GlobusFileListing();
globusFolder1.setName("folder1");
globusFolder1.setType("dir");
GlobusFileListing subFile1 = new GlobusFileListing();
subFile1.setName("subFile1");
subFile1.setType("file");
List<GlobusFileListing> globusFileListing = Arrays.asList(globusFile1, globusFile2, globusFile3, globusFolder1);
when(globus.getFilesAndDirectoriesAtEndpoint("package123")).thenReturn(Arrays.asList(parent));
when(globus.getFilesAndDirectoriesAtEndpoint("package123/parent")).thenReturn(globusFileListing);
when(globus.getFilesAndDirectoriesAtEndpoint("package123/parent/folder1")).thenReturn(Arrays.asList(subFile1));
PackageFilesRequest request = new PackageFilesRequest();
request.setFilenames("file1\nfile2,file3");
request.setFilenames("file1\nfile2\nfile3\nfolder1/subFile1");
request.setPackageId("package123");


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

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

GlobusFileListing globusFile1 = new GlobusFileListing();
globusFile1.setName("file1");
globusFile1.setType("file");
@@ -286,7 +290,6 @@ public void testMatchFile_perfectMatchOneLevel() throws JsonProcessingException,

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

GlobusFileListing globusFile1 = new GlobusFileListing();
globusFile1.setName("file1");
globusFile1.setType("file");
@@ -311,7 +314,6 @@ public void testMatchFile_misatchOneLevel() throws JsonProcessingException, IOEx

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

GlobusFileListing globusFile1 = new GlobusFileListing();
globusFile1.setName("file1");
globusFile1.setType("file");

0 comments on commit 5eb9ad0

Please sign in to comment.