Search in sources :

Example 16 with DocumentSnapshot

use of com.google.cloud.firestore.DocumentSnapshot 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 17 with DocumentSnapshot

use of com.google.cloud.firestore.DocumentSnapshot in project spring-cloud-gcp by GoogleCloudPlatform.

the class FirestoreSampleApp method readDocumentToMap.

private void readDocumentToMap() throws ExecutionException, InterruptedException {
    DocumentReference docRef = this.firestore.document("users/ada");
    ApiFuture<DocumentSnapshot> documentSnapshotApiFuture = docRef.get();
    DocumentSnapshot document = documentSnapshotApiFuture.get();
    System.out.println("read: " + document.getData());
}
Also used : DocumentSnapshot(com.google.cloud.firestore.DocumentSnapshot) DocumentReference(com.google.cloud.firestore.DocumentReference)

Example 18 with DocumentSnapshot

use of com.google.cloud.firestore.DocumentSnapshot in project spring-cloud-gcp by GoogleCloudPlatform.

the class FirestoreDefaultClassMapper method documentToEntity.

public <T> T documentToEntity(Document document, Class<T> clazz) {
    DocumentSnapshot documentSnapshot = INTERNAL.snapshotFromProto(Timestamp.now(), document);
    T entity = documentSnapshot.toObject(clazz);
    return setUpdateTime(entity, documentSnapshot.getUpdateTime());
}
Also used : DocumentSnapshot(com.google.cloud.firestore.DocumentSnapshot)

Example 19 with DocumentSnapshot

use of com.google.cloud.firestore.DocumentSnapshot in project Protego by nickdlc.

the class ProtegoHomeController method getUser.

@GetMapping("/user")
public ProtegoUser getUser(@RequestParam("user") String uid) {
    // Get user with id uid
    try {
        // Temporarily create a new doctor and return that
        FirebaseAttributes.firestore.collection("users").document(uid).get();
        // Asynchronously retrieve multiple documents
        ApiFuture<DocumentSnapshot> future = FirebaseAttributes.firestore.collection("users").document(uid).get();
        // future.get() blocks on response
        DocumentSnapshot document = future.get();
        return document.toObject(ProtegoUser.class);
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (ExecutionException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : DocumentSnapshot(com.google.cloud.firestore.DocumentSnapshot) ExecutionException(java.util.concurrent.ExecutionException)

Example 20 with DocumentSnapshot

use of com.google.cloud.firestore.DocumentSnapshot in project Protego by nickdlc.

the class ProtegoHomeController method getDoctor.

@GetMapping("/doctor")
public Doctor getDoctor(@RequestParam("doctor") String duid) {
    // Get doctor with id duid
    try {
        // Temporarily create a new doctor and return that
        FirebaseAttributes.firestore.collection("users").document(duid).get();
        // Asynchronously retrieve multiple documents
        ApiFuture<DocumentSnapshot> future = FirebaseAttributes.firestore.collection("users").document(duid).get();
        // future.get() blocks on response
        DocumentSnapshot document = future.get();
        return document.toObject(Doctor.class);
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (ExecutionException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : DocumentSnapshot(com.google.cloud.firestore.DocumentSnapshot) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

DocumentSnapshot (com.google.cloud.firestore.DocumentSnapshot)102 QueryDocumentSnapshot (com.google.cloud.firestore.QueryDocumentSnapshot)73 Test (org.junit.Test)52 DocumentReference (com.google.cloud.firestore.DocumentReference)48 QuerySnapshot (com.google.cloud.firestore.QuerySnapshot)23 ExecutionException (java.util.concurrent.ExecutionException)13 CollectionReference (com.google.cloud.firestore.CollectionReference)12 Query (com.google.cloud.firestore.Query)12 BaseIntegrationTest (com.example.firestore.BaseIntegrationTest)10 SingleField (com.google.cloud.firestore.LocalFirestoreHelper.SingleField)9 WriteResult (com.google.cloud.firestore.WriteResult)9 ArrayList (java.util.ArrayList)7 FileSystemExecutionException (bio.terra.service.filedata.exception.FileSystemExecutionException)6 HashMap (java.util.HashMap)6 BulkWriter (com.google.cloud.firestore.BulkWriter)5 City (com.example.firestore.snippets.model.City)4 Timestamp (com.google.cloud.Timestamp)4 FirestoreBundleTest.verifyNamedQuery (com.google.cloud.firestore.FirestoreBundleTest.verifyNamedQuery)4 AllSupportedTypes (com.google.cloud.firestore.LocalFirestoreHelper.AllSupportedTypes)4 WriteBatch (com.google.cloud.firestore.WriteBatch)4