Search in sources :

Example 1 with DrawDocument

use of org.roguewave.grpc.util.gfx.DrawDocument 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 2 with DrawDocument

use of org.roguewave.grpc.util.gfx.DrawDocument 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 3 with DrawDocument

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

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

the class CreateDocument method createDocumentCall.

public void createDocumentCall() {
    System.out.println("\n:: Creating New Document ::\n");
    FirestoreBlockingStub blockingStub = new GRPCFirebaseClientFactory().createFirebaseClient().getBlockingStub();
    Scanner sc = new Scanner(System.in);
    System.out.print("Enter Document Name: ");
    String docName = sc.next();
    HashMap<String, Value> fieldsMap;
    MakeFieldsMap mfm = new MakeFieldsMap();
    fieldsMap = mfm.makeFieldsMap();
    Document newDoc = Document.newBuilder().putAllFields(fieldsMap).build();
    CreateDocumentRequest createDocumentRequest = CreateDocumentRequest.newBuilder().setDocument(newDoc).setCollectionId("GrpcTestData").setParent("projects/firestoretestclient/databases/(default)/documents").setDocumentId(docName).build();
    Document finishedDoc;
    try {
        finishedDoc = blockingStub.createDocument(createDocumentRequest);
    } catch (Exception e) {
        System.out.println("Error during call: " + e.getMessage() + e.getCause());
        return;
    }
    DrawDocument dd = new DrawDocument();
    dd.draw(finishedDoc);
    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) CreateDocumentRequest(com.google.firestore.v1beta1.CreateDocumentRequest) MakeFieldsMap(org.roguewave.grpc.util.gfx.MakeFieldsMap) Value(com.google.firestore.v1beta1.Value) 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 DrawDocument

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

the class GetDocument method getDocumentCall.

public void getDocumentCall() {
    System.out.println("\n:: Getting a Document ::\n");
    FirestoreGrpc.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();
    try {
        Document doc = blockingStub.getDocument(getDocumentRequest);
        DrawDocument dd = new DrawDocument();
        dd.draw(doc);
    } catch (Exception e) {
        System.out.println("Error during call: " + e.getMessage() + e.getCause());
        return;
    }
    Menu menu = new Menu();
    menu.draw();
}
Also used : GRPCFirebaseClientFactory(org.roguewave.grpc.util.GRPCFirebaseClientFactory) Scanner(java.util.Scanner) Menu(org.roguewave.grpc.util.gfx.Menu) FirestoreGrpc(com.google.firestore.v1beta1.FirestoreGrpc) GetDocumentRequest(com.google.firestore.v1beta1.GetDocumentRequest) DrawDocument(org.roguewave.grpc.util.gfx.DrawDocument) Document(com.google.firestore.v1beta1.Document) DrawDocument(org.roguewave.grpc.util.gfx.DrawDocument)

Aggregations

GRPCFirebaseClientFactory (org.roguewave.grpc.util.GRPCFirebaseClientFactory)5 DrawDocument (org.roguewave.grpc.util.gfx.DrawDocument)5 Menu (org.roguewave.grpc.util.gfx.Menu)5 Document (com.google.firestore.v1beta1.Document)4 Scanner (java.util.Scanner)4 FirestoreBlockingStub (com.google.firestore.v1beta1.FirestoreGrpc.FirestoreBlockingStub)3 FirestoreGrpc (com.google.firestore.v1beta1.FirestoreGrpc)2 BatchGetDocumentsRequest (com.google.firestore.v1beta1.BatchGetDocumentsRequest)1 BatchGetDocumentsResponse (com.google.firestore.v1beta1.BatchGetDocumentsResponse)1 CreateDocumentRequest (com.google.firestore.v1beta1.CreateDocumentRequest)1 GetDocumentRequest (com.google.firestore.v1beta1.GetDocumentRequest)1 ListDocumentsRequest (com.google.firestore.v1beta1.ListDocumentsRequest)1 ListDocumentsResponse (com.google.firestore.v1beta1.ListDocumentsResponse)1 Value (com.google.firestore.v1beta1.Value)1 StreamObserver (io.grpc.stub.StreamObserver)1 ArrayList (java.util.ArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 MakeFieldsMap (org.roguewave.grpc.util.gfx.MakeFieldsMap)1