use of bio.terra.service.filedata.FSDir in project jade-data-repo by DataBiosphere.
the class FireStoreDao method makeFSDir.
private FSItem makeFSDir(Firestore firestore, String collectionId, int level, FireStoreDirectoryEntry fireStoreDirectoryEntry) {
if (fireStoreDirectoryEntry.getIsFileRef()) {
throw new IllegalStateException("Expected directory; got file!");
}
String fullPath = fireStoreUtils.getFullPath(fireStoreDirectoryEntry.getPath(), fireStoreDirectoryEntry.getName());
FSDir fsDir = new FSDir();
fsDir.fileId(UUID.fromString(fireStoreDirectoryEntry.getFileId())).collectionId(UUID.fromString(collectionId)).createdDate(Instant.parse(fireStoreDirectoryEntry.getFileCreatedDate())).path(fullPath).checksumCrc32c(fireStoreDirectoryEntry.getChecksumCrc32c()).checksumMd5(fireStoreDirectoryEntry.getChecksumMd5()).size(fireStoreDirectoryEntry.getSize()).description(StringUtils.EMPTY);
if (level != 0) {
List<FSItem> fsContents = new ArrayList<>();
List<FireStoreDirectoryEntry> dirContents = directoryDao.enumerateDirectory(firestore, collectionId, fullPath);
for (FireStoreDirectoryEntry fso : dirContents) {
if (fso.getIsFileRef()) {
// Files that are in the middle of being ingested can have a directory entry, but not yet have
// a file entry. We do not return files that do not yet have a file entry.
FSItem fsFile = makeFSFile(firestore, collectionId, fso);
if (fsFile != null) {
fsContents.add(fsFile);
}
} else {
fsContents.add(makeFSDir(firestore, collectionId, level - 1, fso));
}
}
fsDir.contents(fsContents);
}
return fsDir;
}