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