Search in sources :

Example 1 with FSDir

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;
}
Also used : FSDir(bio.terra.service.filedata.FSDir) FSItem(bio.terra.service.filedata.FSItem) ArrayList(java.util.ArrayList)

Aggregations

FSDir (bio.terra.service.filedata.FSDir)1 FSItem (bio.terra.service.filedata.FSItem)1 ArrayList (java.util.ArrayList)1