Skip to content

Commit

Permalink
Merge pull request #148 from sbesson/saveFileset_originalfile_orderin…
Browse files Browse the repository at this point in the history
…g_bug

Fix ordering of OriginalFile objects registered in saveFileset()
  • Loading branch information
jburel authored May 7, 2024
2 parents 1c87482 + e4c3f57 commit 7feed13
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/main/java/ome/services/blitz/repo/RepositoryDaoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -779,15 +779,15 @@ public Void doWork(Session session, ServiceFactory sf) {
* Internal file registration which must happen within a single tx. All
* files in the same directory are loaded in one block.
*
* @param repoUuid
* @param checked
* @param repoUuid UUID of the repository where original files should be registered
* @param checked a list of checked server paths to register as OriginalFile
* @param parents a list of parent server paths. Must be of the same length and in the same order as checked
* @param checksumAlgorithm
* @param mimetype
* @param parent
* @param sf non-null
* @param sql non-null
* @param session
* @return
* @return a list of OriginalFile of the same length and in the same order as the checked input
*/
private List<ome.model.core.OriginalFile> _internalRegister(final String repoUuid,
final List<CheckedPath> checked, final List<CheckedPath> parents,
Expand Down Expand Up @@ -842,7 +842,23 @@ private List<ome.model.core.OriginalFile> _internalRegister(final String repoUui
}
sw.stop("omero.repo.internal_register.load");
}
return toReturn;

// At this stage, the order of toReturn will be determined by
// order in which the levels ListMultimap was processed
// We are sorting this list to match the order of checked
StopWatch sw = new Slf4JStopWatch();
final List<ome.model.core.OriginalFile> toReturnSorted = new ArrayList<ome.model.core.OriginalFile>();
for (CheckedPath path : checked) {
// Newly created OriginalFile objects with createOriginalFile()
// will have their names prefixed with fileRepoSecretKey
ome.model.core.OriginalFile of = toReturn.stream().filter(
f -> (f.getName().equals(path.getName()) ||
f.getName().equals(fileRepoSecretKey + path.getName())) &&
f.getPath().equals(path.getRelativePath())).findFirst().get();
toReturnSorted.add(of);
}
sw.stop("omero.repo.internal_register.sort");
return toReturnSorted;
}

public FsFile getFile(final long id, final Ice.Current current,
Expand Down

0 comments on commit 7feed13

Please sign in to comment.