Search in sources :

Example 1 with MakeFieldsMap

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

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

Aggregations

FirestoreBlockingStub (com.google.firestore.v1beta1.FirestoreGrpc.FirestoreBlockingStub)2 Scanner (java.util.Scanner)2 GRPCFirebaseClientFactory (org.roguewave.grpc.util.GRPCFirebaseClientFactory)2 DrawDocument (org.roguewave.grpc.util.gfx.DrawDocument)2 MakeFieldsMap (org.roguewave.grpc.util.gfx.MakeFieldsMap)2 Menu (org.roguewave.grpc.util.gfx.Menu)2 CreateDocumentRequest (com.google.firestore.v1beta1.CreateDocumentRequest)1 Document (com.google.firestore.v1beta1.Document)1 Value (com.google.firestore.v1beta1.Value)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1