Search in sources :

Example 1 with FileSystemExecutionException

use of bio.terra.service.filedata.exception.FileSystemExecutionException in project jade-data-repo by DataBiosphere.

the class FireStoreDependencyDao method deleteSnapshotFileDependencies.

public void deleteSnapshotFileDependencies(Dataset dataset, String snapshotId) throws InterruptedException {
    DatasetDataProject dataProject = dataLocationService.getProjectOrThrow(dataset);
    FireStoreProject fireStoreProject = FireStoreProject.get(dataProject.getGoogleProjectId());
    String dependencyCollectionName = getDatasetDependencyId(dataset.getId().toString());
    CollectionReference depColl = fireStoreProject.getFirestore().collection(dependencyCollectionName);
    Query query = depColl.whereEqualTo("snapshotId", snapshotId);
    ApiFuture<QuerySnapshot> querySnapshot = query.get();
    try {
        List<QueryDocumentSnapshot> documents = querySnapshot.get().getDocuments();
        for (DocumentSnapshot docSnap : documents) {
            logger.info("deleting: " + docSnap.toString());
            docSnap.getReference().delete();
        }
    } catch (ExecutionException ex) {
        throw new FileSystemExecutionException("delete dependencies - execution exception", ex);
    }
}
Also used : QueryDocumentSnapshot(com.google.cloud.firestore.QueryDocumentSnapshot) DocumentSnapshot(com.google.cloud.firestore.DocumentSnapshot) Query(com.google.cloud.firestore.Query) QueryDocumentSnapshot(com.google.cloud.firestore.QueryDocumentSnapshot) FileSystemExecutionException(bio.terra.service.filedata.exception.FileSystemExecutionException) DatasetDataProject(bio.terra.service.dataset.DatasetDataProject) FileSystemExecutionException(bio.terra.service.filedata.exception.FileSystemExecutionException) ExecutionException(java.util.concurrent.ExecutionException) CollectionReference(com.google.cloud.firestore.CollectionReference) QuerySnapshot(com.google.cloud.firestore.QuerySnapshot)

Example 2 with FileSystemExecutionException

use of bio.terra.service.filedata.exception.FileSystemExecutionException in project jade-data-repo by DataBiosphere.

the class FireStoreDirectoryDao method updateDirectoryEntry.

// Non-transactional update of a directory entry
void updateDirectoryEntry(Firestore firestore, String collectionId, FireStoreDirectoryEntry entry) {
    try {
        DocumentReference newRef = getDocRef(firestore, collectionId, entry);
        ApiFuture<WriteResult> writeFuture = newRef.set(entry);
        writeFuture.get();
    } catch (InterruptedException ex) {
        Thread.currentThread().interrupt();
        throw new FileSystemExecutionException("updateDirectoryEntry - execution interrupted", ex);
    } catch (AbortedException | ExecutionException ex) {
        throw handleExecutionException("updateDirectoryEntry", ex);
    }
}
Also used : WriteResult(com.google.cloud.firestore.WriteResult) AbortedException(com.google.api.gax.rpc.AbortedException) FileSystemExecutionException(bio.terra.service.filedata.exception.FileSystemExecutionException) FileSystemExecutionException(bio.terra.service.filedata.exception.FileSystemExecutionException) ExecutionException(java.util.concurrent.ExecutionException) DocumentReference(com.google.cloud.firestore.DocumentReference)

Example 3 with FileSystemExecutionException

use of bio.terra.service.filedata.exception.FileSystemExecutionException in project jade-data-repo by DataBiosphere.

the class FireStoreFileDao method lookupByFileId.

private DocumentSnapshot lookupByFileId(Firestore firestore, String collectionId, String fileId, Transaction xn) {
    DocumentReference docRef = getFileDocRef(firestore, collectionId, fileId);
    ApiFuture<DocumentSnapshot> docSnapFuture = xn.get(docRef);
    try {
        return docSnapFuture.get();
    } catch (InterruptedException ex) {
        Thread.currentThread().interrupt();
        throw new FileSystemExecutionException("lookupByFileId - execution interrupted", ex);
    } catch (ExecutionException ex) {
        throw new FileSystemExecutionException("lookupByFileId - execution exception", ex);
    }
}
Also used : QueryDocumentSnapshot(com.google.cloud.firestore.QueryDocumentSnapshot) DocumentSnapshot(com.google.cloud.firestore.DocumentSnapshot) FileSystemExecutionException(bio.terra.service.filedata.exception.FileSystemExecutionException) FileSystemExecutionException(bio.terra.service.filedata.exception.FileSystemExecutionException) ExecutionException(java.util.concurrent.ExecutionException) DocumentReference(com.google.cloud.firestore.DocumentReference)

Example 4 with FileSystemExecutionException

use of bio.terra.service.filedata.exception.FileSystemExecutionException in project jade-data-repo by DataBiosphere.

the class FireStoreDependencyDao method getDatasetSnapshotFileIds.

public List<String> getDatasetSnapshotFileIds(Dataset dataset, String snapshotId) throws InterruptedException {
    DatasetDataProject dataProject = dataLocationService.getProjectOrThrow(dataset);
    FireStoreProject fireStoreProject = FireStoreProject.get(dataProject.getGoogleProjectId());
    String dependencyCollectionName = getDatasetDependencyId(dataset.getId().toString());
    CollectionReference depColl = fireStoreProject.getFirestore().collection(dependencyCollectionName);
    Query query = depColl.whereEqualTo("snapshotId", snapshotId);
    ApiFuture<QuerySnapshot> querySnapshot = query.get();
    List<String> fileIds = new ArrayList<>();
    try {
        List<QueryDocumentSnapshot> documents = querySnapshot.get().getDocuments();
        for (DocumentSnapshot docSnap : documents) {
            FireStoreDependency fireStoreDependency = docSnap.toObject(FireStoreDependency.class);
            fileIds.add(fireStoreDependency.getFileId());
        }
        return fileIds;
    } catch (ExecutionException ex) {
        throw new FileSystemExecutionException("get file ids - execution exception", ex);
    }
}
Also used : Query(com.google.cloud.firestore.Query) QueryDocumentSnapshot(com.google.cloud.firestore.QueryDocumentSnapshot) ArrayList(java.util.ArrayList) FileSystemExecutionException(bio.terra.service.filedata.exception.FileSystemExecutionException) DatasetDataProject(bio.terra.service.dataset.DatasetDataProject) CollectionReference(com.google.cloud.firestore.CollectionReference) QuerySnapshot(com.google.cloud.firestore.QuerySnapshot) QueryDocumentSnapshot(com.google.cloud.firestore.QueryDocumentSnapshot) DocumentSnapshot(com.google.cloud.firestore.DocumentSnapshot) FileSystemExecutionException(bio.terra.service.filedata.exception.FileSystemExecutionException) ExecutionException(java.util.concurrent.ExecutionException)

Example 5 with FileSystemExecutionException

use of bio.terra.service.filedata.exception.FileSystemExecutionException in project jade-data-repo by DataBiosphere.

the class FireStoreDirectoryDao method lookupByFilePath.

private DocumentSnapshot lookupByFilePath(Firestore firestore, String collectionId, String lookupPath, Transaction xn) {
    try {
        DocumentReference docRef = firestore.collection(collectionId).document(encodePathAsFirestoreDocumentName(lookupPath));
        ApiFuture<DocumentSnapshot> docSnapFuture = xn.get(docRef);
        return docSnapFuture.get();
    } catch (InterruptedException ex) {
        Thread.currentThread().interrupt();
        throw new FileSystemExecutionException("lookupByEntryPath - execution interrupted", ex);
    } catch (AbortedException | ExecutionException ex) {
        throw handleExecutionException("lookupByEntryPath", ex);
    }
}
Also used : QueryDocumentSnapshot(com.google.cloud.firestore.QueryDocumentSnapshot) DocumentSnapshot(com.google.cloud.firestore.DocumentSnapshot) AbortedException(com.google.api.gax.rpc.AbortedException) FileSystemExecutionException(bio.terra.service.filedata.exception.FileSystemExecutionException) FileSystemExecutionException(bio.terra.service.filedata.exception.FileSystemExecutionException) ExecutionException(java.util.concurrent.ExecutionException) DocumentReference(com.google.cloud.firestore.DocumentReference)

Aggregations

FileSystemExecutionException (bio.terra.service.filedata.exception.FileSystemExecutionException)10 ExecutionException (java.util.concurrent.ExecutionException)10 QueryDocumentSnapshot (com.google.cloud.firestore.QueryDocumentSnapshot)8 AbortedException (com.google.api.gax.rpc.AbortedException)6 DocumentSnapshot (com.google.cloud.firestore.DocumentSnapshot)6 DocumentReference (com.google.cloud.firestore.DocumentReference)5 CollectionReference (com.google.cloud.firestore.CollectionReference)4 QuerySnapshot (com.google.cloud.firestore.QuerySnapshot)4 Query (com.google.cloud.firestore.Query)3 DatasetDataProject (bio.terra.service.dataset.DatasetDataProject)2 FileSystemAbortTransactionException (bio.terra.service.filedata.exception.FileSystemAbortTransactionException)2 WriteResult (com.google.cloud.firestore.WriteResult)2 FirestoreException (com.google.cloud.firestore.FirestoreException)1 ArrayList (java.util.ArrayList)1