Search in sources :

Example 1 with GRPCFirebaseClientFactory

use of org.roguewave.grpc.util.GRPCFirebaseClientFactory 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 GRPCFirebaseClientFactory

use of org.roguewave.grpc.util.GRPCFirebaseClientFactory in project grpc-gcp-java by GoogleCloudPlatform.

the class BatchGetDocuments method batchGetDocumentsCall.

public void batchGetDocumentsCall() {
    List<String> docList = new ArrayList<String>();
    System.out.println("\n :: Batch Retrieve Documents :: \n");
    Scanner sc = new Scanner(System.in);
    String input = "initial";
    FirestoreGrpc.FirestoreStub firestoreStub = new GRPCFirebaseClientFactory().createFirebaseClient().getFirestoreStub();
    DrawDocument dd = new DrawDocument();
    while (!input.matches("DONE")) {
        System.out.print("Enter Document Id (Enter DONE when finished): ");
        input = sc.next();
        if (!input.matches("DONE")) {
            docList.add("projects/firestoretestclient/databases/(default)/documents/GrpcTestData/" + input);
        }
    }
    BatchGetDocumentsRequest batchGetDocsRequest = BatchGetDocumentsRequest.newBuilder().setDatabase("projects/firestoretestclient/databases/(default)").addAllDocuments(docList).build();
    final CountDownLatch finishLatch = new CountDownLatch(1);
    StreamObserver respStream = new StreamObserver() {

        @Override
        public void onNext(Object resp) {
            BatchGetDocumentsResponse response = (BatchGetDocumentsResponse) resp;
            Document doc = response.getFound();
            dd.draw(doc);
        }

        @Override
        public void onError(Throwable throwable) {
            System.out.println("Error During Call: " + throwable.getMessage());
            finishLatch.countDown();
        }

        @Override
        public void onCompleted() {
            Menu menu = new Menu();
            menu.draw();
            finishLatch.countDown();
        }
    };
    try {
        firestoreStub.batchGetDocuments(batchGetDocsRequest, respStream);
        finishLatch.await(1, TimeUnit.MINUTES);
    } catch (Exception e) {
        System.out.println("Error during call: " + e.getMessage() + e.getCause());
    }
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) Scanner(java.util.Scanner) GRPCFirebaseClientFactory(org.roguewave.grpc.util.GRPCFirebaseClientFactory) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) Document(com.google.firestore.v1beta1.Document) DrawDocument(org.roguewave.grpc.util.gfx.DrawDocument) BatchGetDocumentsRequest(com.google.firestore.v1beta1.BatchGetDocumentsRequest) BatchGetDocumentsResponse(com.google.firestore.v1beta1.BatchGetDocumentsResponse) Menu(org.roguewave.grpc.util.gfx.Menu) FirestoreGrpc(com.google.firestore.v1beta1.FirestoreGrpc) DrawDocument(org.roguewave.grpc.util.gfx.DrawDocument)

Example 3 with GRPCFirebaseClientFactory

use of org.roguewave.grpc.util.GRPCFirebaseClientFactory 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 4 with GRPCFirebaseClientFactory

use of org.roguewave.grpc.util.GRPCFirebaseClientFactory in project grpc-gcp-java by GoogleCloudPlatform.

the class DeleteDocument method deleteDocumentCall.

public void deleteDocumentCall() {
    Scanner sc = new Scanner(System.in);
    System.out.println("\n :: Deleting a Document ::\n");
    System.out.print("Enter Document Name: ");
    String docName = "projects/firestoretestclient/databases/(default)/documents/GrpcTestData/" + sc.next();
    FirestoreGrpc.FirestoreBlockingStub blockingStub = new GRPCFirebaseClientFactory().createFirebaseClient().getBlockingStub();
    DeleteDocumentRequest delReq = DeleteDocumentRequest.newBuilder().setName(docName).build();
    try {
        blockingStub.deleteDocument(delReq);
        System.out.println("Finished call...");
    } catch (Exception e) {
        System.out.println("Error executing blocking stub call: " + (e.getMessage() + "\n" + e.getCause().toString()));
    }
    Menu menu = new Menu();
    menu.draw();
}
Also used : Scanner(java.util.Scanner) GRPCFirebaseClientFactory(org.roguewave.grpc.util.GRPCFirebaseClientFactory) DeleteDocumentRequest(com.google.firestore.v1beta1.DeleteDocumentRequest) Menu(org.roguewave.grpc.util.gfx.Menu) FirestoreGrpc(com.google.firestore.v1beta1.FirestoreGrpc)

Example 5 with GRPCFirebaseClientFactory

use of org.roguewave.grpc.util.GRPCFirebaseClientFactory 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)

Aggregations

GRPCFirebaseClientFactory (org.roguewave.grpc.util.GRPCFirebaseClientFactory)12 Menu (org.roguewave.grpc.util.gfx.Menu)12 FirestoreBlockingStub (com.google.firestore.v1beta1.FirestoreGrpc.FirestoreBlockingStub)8 Scanner (java.util.Scanner)7 DrawDocument (org.roguewave.grpc.util.gfx.DrawDocument)6 Document (com.google.firestore.v1beta1.Document)4 FirestoreGrpc (com.google.firestore.v1beta1.FirestoreGrpc)4 StreamObserver (io.grpc.stub.StreamObserver)2 MakeFieldsMap (org.roguewave.grpc.util.gfx.MakeFieldsMap)2 com.google.firestore.v1beta1 (com.google.firestore.v1beta1)1 BatchGetDocumentsRequest (com.google.firestore.v1beta1.BatchGetDocumentsRequest)1 BatchGetDocumentsResponse (com.google.firestore.v1beta1.BatchGetDocumentsResponse)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 DeleteDocumentRequest (com.google.firestore.v1beta1.DeleteDocumentRequest)1 FirestoreStub (com.google.firestore.v1beta1.FirestoreGrpc.FirestoreStub)1 GetDocumentRequest (com.google.firestore.v1beta1.GetDocumentRequest)1 ListCollectionIdsRequest (com.google.firestore.v1beta1.ListCollectionIdsRequest)1