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();
}
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();
}
Aggregations