Search in sources :

Example 1 with FirestoreBlockingStub

use of com.google.firestore.v1beta1.FirestoreGrpc.FirestoreBlockingStub in project grpc-gcp-java by GoogleCloudPlatform.

the class UpdateDocument method updateDocumentCall.

public void updateDocumentCall() {
    System.out.println("\n:: Updating a Document ::\n");
    FirestoreBlockingStub blockingStub = new GRPCFirebaseClientFactory().createFirebaseClient().getBlockingStub();
    Scanner sc = new Scanner(System.in);
    System.out.print("Enter Document Name: ");
    String docName = sc.next();
    GetDocumentRequest getDocumentRequest = GetDocumentRequest.newBuilder().setName("projects/firestoretestclient/databases/(default)/documents/GrpcTestData/" + docName).build();
    Document doc;
    try {
        doc = blockingStub.getDocument(getDocumentRequest);
    } catch (Exception e) {
        System.out.println("Error during call: " + e.getMessage() + e.getCause());
        return;
    }
    HashMap<String, Value> fieldsMap;
    MakeFieldsMap mfm = new MakeFieldsMap();
    fieldsMap = mfm.makeFieldsMap();
    doc = doc.toBuilder().putAllFields(fieldsMap).build();
    Iterator it = fieldsMap.entrySet().iterator();
    DocumentMask docMask = DocumentMask.newBuilder().build();
    while (it.hasNext()) {
        Map.Entry pair = (Map.Entry) it.next();
        docMask = docMask.toBuilder().addFieldPaths(pair.getKey().toString()).build();
    }
    UpdateDocumentRequest updateDocumentRequest = UpdateDocumentRequest.newBuilder().setDocument(doc).setMask(docMask).build();
    try {
        blockingStub.updateDocument(updateDocumentRequest);
    } catch (Exception e) {
        System.out.println("Error during call: " + e.getMessage() + e.getCause());
        return;
    }
    System.out.println("Success!");
    Menu menu = new Menu();
    menu.draw();
}
Also used : GRPCFirebaseClientFactory(org.roguewave.grpc.util.GRPCFirebaseClientFactory) Scanner(java.util.Scanner) FirestoreBlockingStub(com.google.firestore.v1beta1.FirestoreGrpc.FirestoreBlockingStub) MakeFieldsMap(org.roguewave.grpc.util.gfx.MakeFieldsMap) DrawDocument(org.roguewave.grpc.util.gfx.DrawDocument) Iterator(java.util.Iterator) Menu(org.roguewave.grpc.util.gfx.Menu) MakeFieldsMap(org.roguewave.grpc.util.gfx.MakeFieldsMap) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with FirestoreBlockingStub

use of com.google.firestore.v1beta1.FirestoreGrpc.FirestoreBlockingStub in project grpc-gcp-java by GoogleCloudPlatform.

the class Commit method commitCall.

public void commitCall() {
    System.out.println("\n:: Committing Transaction ::\n");
    if (Main.transactionId == null) {
        System.out.println("WARNING:  No current transaction open, run BeginTransaction first...");
        return;
    } else {
        System.out.println("Found Transaction ID '" + Main.transactionId.toString() + "'.  Committing....");
    }
    FirestoreBlockingStub blockingStub = new GRPCFirebaseClientFactory().createFirebaseClient().getBlockingStub();
    CommitRequest commitRequest = CommitRequest.newBuilder().setTransaction(Main.transactionId).setDatabase("projects/firestoretestclient/databases/(default)").build();
    try {
        blockingStub.commit(commitRequest);
    } catch (Exception e) {
        System.out.println("Error during call: " + e.getMessage() + e.getCause());
        return;
    }
    System.out.println("Success!");
    Menu menu = new Menu();
    menu.draw();
}
Also used : CommitRequest(com.google.firestore.v1beta1.CommitRequest) GRPCFirebaseClientFactory(org.roguewave.grpc.util.GRPCFirebaseClientFactory) FirestoreBlockingStub(com.google.firestore.v1beta1.FirestoreGrpc.FirestoreBlockingStub) Menu(org.roguewave.grpc.util.gfx.Menu)

Example 3 with FirestoreBlockingStub

use of com.google.firestore.v1beta1.FirestoreGrpc.FirestoreBlockingStub in project grpc-gcp-java by GoogleCloudPlatform.

the class RunQuery method runQueryCall.

public void runQueryCall() {
    System.out.println(":: Running a Query ::");
    FirestoreBlockingStub blockingStub = new GRPCFirebaseClientFactory().createFirebaseClient().getBlockingStub();
    DrawDocument dd = new DrawDocument();
    Scanner sc = new Scanner(System.in);
    System.out.print("Enter field to query: ");
    String queryField = sc.next();
    StructuredQuery.FieldReference fr = StructuredQuery.FieldReference.newBuilder().setFieldPath(queryField).build();
    StructuredQuery.Projection proj = StructuredQuery.Projection.newBuilder().addFields(fr).build();
    StructuredQuery sq = StructuredQuery.newBuilder().setSelect(proj).build();
    RunQueryRequest runQueryRequest = RunQueryRequest.newBuilder().setStructuredQuery(sq).setParent("projects/firestoretestclient/databases/(default)/documents").build();
    Iterator<RunQueryResponse> runQueryResponse;
    try {
        runQueryResponse = blockingStub.runQuery(runQueryRequest);
    } catch (Exception e) {
        System.out.println("Error during call: " + e.getMessage() + e.getCause());
        return;
    }
    System.out.println("Result set:\n");
    while (runQueryResponse.hasNext()) {
        RunQueryResponse response = runQueryResponse.next();
        Document doc = response.getDocument();
        dd.draw(doc);
    }
    System.out.println("Done!");
    Menu menu = new Menu();
    menu.draw();
}
Also used : GRPCFirebaseClientFactory(org.roguewave.grpc.util.GRPCFirebaseClientFactory) Scanner(java.util.Scanner) FirestoreBlockingStub(com.google.firestore.v1beta1.FirestoreGrpc.FirestoreBlockingStub) DrawDocument(org.roguewave.grpc.util.gfx.DrawDocument) Menu(org.roguewave.grpc.util.gfx.Menu) DrawDocument(org.roguewave.grpc.util.gfx.DrawDocument)

Example 4 with FirestoreBlockingStub

use of com.google.firestore.v1beta1.FirestoreGrpc.FirestoreBlockingStub in project grpc-gcp-java by GoogleCloudPlatform.

the class ListDocuments method listDocumentsCall.

public void listDocumentsCall() {
    System.out.println("\n:: Listing all Documents ::\n");
    FirestoreBlockingStub blockingStub = new GRPCFirebaseClientFactory().createFirebaseClient().getBlockingStub();
    ListDocumentsRequest ldr = ListDocumentsRequest.newBuilder().setParent("projects/firestoretestclient/databases/(default)/documents").setCollectionId("GrpcTestData").build();
    try {
        ListDocumentsResponse listDocumentsResponse = blockingStub.listDocuments(ldr);
        List<Document> allDocs = listDocumentsResponse.getDocumentsList();
        DrawDocument dd = new DrawDocument();
        for (Document doc : allDocs) {
            dd.draw(doc);
        }
        Menu menu = new Menu();
        menu.draw();
        System.out.println("Finished call...");
    } catch (Exception e) {
        System.out.println("Error executing streaming stub call: " + (e.getMessage() + "\n" + e.getCause().toString()));
    }
}
Also used : ListDocumentsRequest(com.google.firestore.v1beta1.ListDocumentsRequest) GRPCFirebaseClientFactory(org.roguewave.grpc.util.GRPCFirebaseClientFactory) FirestoreBlockingStub(com.google.firestore.v1beta1.FirestoreGrpc.FirestoreBlockingStub) ListDocumentsResponse(com.google.firestore.v1beta1.ListDocumentsResponse) Menu(org.roguewave.grpc.util.gfx.Menu) DrawDocument(org.roguewave.grpc.util.gfx.DrawDocument) Document(com.google.firestore.v1beta1.Document) DrawDocument(org.roguewave.grpc.util.gfx.DrawDocument)

Example 5 with FirestoreBlockingStub

use of com.google.firestore.v1beta1.FirestoreGrpc.FirestoreBlockingStub in project grpc-gcp-java by GoogleCloudPlatform.

the class BeginTransaction method beginTransactionCall.

public void beginTransactionCall() {
    FirestoreBlockingStub blockingStub = new GRPCFirebaseClientFactory().createFirebaseClient().getBlockingStub();
    TransactionOptions tOpts = TransactionOptions.newBuilder().build();
    BeginTransactionRequest beginTransactionRequest = BeginTransactionRequest.newBuilder().setDatabase("projects/firestoretestclient/databases/(default)").setOptions(tOpts).build();
    BeginTransactionResponse response;
    try {
        response = blockingStub.beginTransaction(beginTransactionRequest);
    } catch (Exception e) {
        System.out.println("Error during call: " + e.getMessage() + e.getCause());
        return;
    }
    System.out.println("Began Transaction: " + response.getTransaction().toString());
    Main.transactionId = response.getTransaction();
    Menu menu = new Menu();
    menu.draw();
}
Also used : GRPCFirebaseClientFactory(org.roguewave.grpc.util.GRPCFirebaseClientFactory) FirestoreBlockingStub(com.google.firestore.v1beta1.FirestoreGrpc.FirestoreBlockingStub) TransactionOptions(com.google.firestore.v1beta1.TransactionOptions) BeginTransactionRequest(com.google.firestore.v1beta1.BeginTransactionRequest) Menu(org.roguewave.grpc.util.gfx.Menu) BeginTransactionResponse(com.google.firestore.v1beta1.BeginTransactionResponse)

Aggregations

FirestoreBlockingStub (com.google.firestore.v1beta1.FirestoreGrpc.FirestoreBlockingStub)8 GRPCFirebaseClientFactory (org.roguewave.grpc.util.GRPCFirebaseClientFactory)8 Menu (org.roguewave.grpc.util.gfx.Menu)8 Scanner (java.util.Scanner)4 DrawDocument (org.roguewave.grpc.util.gfx.DrawDocument)4 Document (com.google.firestore.v1beta1.Document)2 MakeFieldsMap (org.roguewave.grpc.util.gfx.MakeFieldsMap)2 com.google.firestore.v1beta1 (com.google.firestore.v1beta1)1 BeginTransactionRequest (com.google.firestore.v1beta1.BeginTransactionRequest)1 BeginTransactionResponse (com.google.firestore.v1beta1.BeginTransactionResponse)1 CommitRequest (com.google.firestore.v1beta1.CommitRequest)1 CreateDocumentRequest (com.google.firestore.v1beta1.CreateDocumentRequest)1 FirestoreStub (com.google.firestore.v1beta1.FirestoreGrpc.FirestoreStub)1 ListDocumentsRequest (com.google.firestore.v1beta1.ListDocumentsRequest)1 ListDocumentsResponse (com.google.firestore.v1beta1.ListDocumentsResponse)1 RollbackRequest (com.google.firestore.v1beta1.RollbackRequest)1 TransactionOptions (com.google.firestore.v1beta1.TransactionOptions)1 Value (com.google.firestore.v1beta1.Value)1 ByteString (com.google.protobuf.ByteString)1 StreamObserver (io.grpc.stub.StreamObserver)1