Skip to content

Commit

Permalink
consolidate duplicate code #6574
Browse files Browse the repository at this point in the history
  • Loading branch information
pdurbin committed May 6, 2020
1 parent 6ef84f8 commit 8d6a5c8
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions src/main/java/edu/harvard/iq/dataverse/ingest/IngestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,7 @@ public static String duplicateFilenameCheck(FileMetadata fileMetadata, Set<Strin
* @return true if there is a conflict, false otherwise.
*/
public static boolean conflictsWithExistingFilenames(String label, String directoryLabel, List<FileMetadata> fileMetadatas, DataFile dataFile) {
List<String> filePathsAndNames = new ArrayList<>();
for (FileMetadata fileMetadata : fileMetadatas) {
String path = "";
if (fileMetadata.getDirectoryLabel() != null) {
path = fileMetadata.getDirectoryLabel() + "/";
}
filePathsAndNames.add(path + fileMetadata.getLabel());
}
List<String> filePathsAndNames = getPathsAndFileNames(fileMetadatas);
if (label != null || directoryLabel != null) {
String path = "";
if (directoryLabel != null) {
Expand All @@ -150,16 +143,7 @@ public static boolean conflictsWithExistingFilenames(String label, String direct
* @return A Collection of Strings in the form of path/to/file.txt
*/
public static Collection<String> findDuplicateFilenames(DatasetVersion datasetVersion) {
List<String> allFileNamesWithPaths = new ArrayList<>();
for (FileMetadata fileMetadata : datasetVersion.getFileMetadatas()) {
String directoryLabel = fileMetadata.getDirectoryLabel();
String path = "";
if (directoryLabel != null) {
path = directoryLabel + "/";
}
String pathAndfileName = path + fileMetadata.getLabel();
allFileNamesWithPaths.add(pathAndfileName);
}
List<String> allFileNamesWithPaths = getPathsAndFileNames(datasetVersion.getFileMetadatas());
return findDuplicates(allFileNamesWithPaths);
}

Expand All @@ -175,6 +159,23 @@ private static <T> Set<T> findDuplicates(Collection<T> collection) {
return duplicates;
}

/**
* @return A List of Strings in the form of path/to/file.txt
*/
public static List<String> getPathsAndFileNames(List<FileMetadata> fileMetadatas) {
List<String> allFileNamesWithPaths = new ArrayList<>();
for (FileMetadata fileMetadata : fileMetadatas) {
String directoryLabel = fileMetadata.getDirectoryLabel();
String path = "";
if (directoryLabel != null) {
path = directoryLabel + "/";
}
String pathAndfileName = path + fileMetadata.getLabel();
allFileNamesWithPaths.add(pathAndfileName);
}
return allFileNamesWithPaths;
}

// This method is called on a single file, when we need to modify the name
// of an already ingested/persisted datafile. For ex., when we have converted
// a file to tabular data, and want to update the extension accordingly.
Expand Down

0 comments on commit 8d6a5c8

Please sign in to comment.