Search in sources :

Example 1 with NotImplementedException

use of bio.terra.common.exception.NotImplementedException in project jade-data-repo by DataBiosphere.

the class FireStoreDirectoryDao method addEntryToSnapshot.

// -- Snapshot filesystem methods --
/**
 * Given an file id from a dataset directory, create a similar entry in the snapshot directory.
 * The snapshot version of the entry differs because it has a the dataset name added to its path.
 */
public void addEntryToSnapshot(Firestore datasetFirestore, String datasetId, String datasetDirName, Firestore snapshotFirestore, String snapshotId, String fileId) {
    FireStoreDirectoryEntry datasetEntry = retrieveById(datasetFirestore, datasetId, fileId);
    if (!datasetEntry.getIsFileRef()) {
        throw new NotImplementedException("Directories are not yet supported as references");
    // TODO: Add directory support. Here is a sketch of a brute force implementation:
    // Given the directory, walk its entire subtree collecting the ids of all of the files.
    // Then loop through that id set calling this method on each id. It is simple, but wasteful
    // because as we walk the subtree, we can build the directory structure, so we can skip the
    // algorithm below that creates all of the parent directories. A better way would be to
    // insert the directory and its parents and then, as we walk the subtree, clone the directory
    // entries as we go. More efficient, but an entirely separate code path...
    }
    // Create the top directory structure (/_dr_/<datasetDirName>)
    storeTopDirectory(snapshotFirestore, snapshotId, datasetDirName);
    // Store the base entry under the datasetDir
    FireStoreDirectoryEntry snapEntry = datasetEntry.copyEntryUnderNewPath(datasetDirName);
    storeDirectoryEntry(snapshotFirestore, snapshotId, snapEntry);
    // Now we walk up the *dataset* directory path, retrieving existing directories.
    // For each directory, we make a new entry under the datasetDir path and store it.
    // That keeps the directory file ids consistent
    String lookupDirPath = makeLookupPath(datasetEntry.getPath());
    for (String testPath = lookupDirPath; !testPath.isEmpty(); testPath = fireStoreUtils.getDirectoryPath(testPath)) {
        DocumentSnapshot docSnap = lookupByPathNoXn(datasetFirestore, datasetId, testPath);
        FireStoreDirectoryEntry datasetDir = docSnap.toObject(FireStoreDirectoryEntry.class);
        FireStoreDirectoryEntry snapshotDir = datasetDir.copyEntryUnderNewPath(datasetDirName);
        storeDirectoryEntry(snapshotFirestore, snapshotId, snapshotDir);
    }
}
Also used : QueryDocumentSnapshot(com.google.cloud.firestore.QueryDocumentSnapshot) DocumentSnapshot(com.google.cloud.firestore.DocumentSnapshot) NotImplementedException(bio.terra.common.exception.NotImplementedException)

Aggregations

NotImplementedException (bio.terra.common.exception.NotImplementedException)1 DocumentSnapshot (com.google.cloud.firestore.DocumentSnapshot)1 QueryDocumentSnapshot (com.google.cloud.firestore.QueryDocumentSnapshot)1