Search in sources :

Example 91 with Document

use of com.google.firestore.v1beta1.Document 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 92 with Document

use of com.google.firestore.v1beta1.Document 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 93 with Document

use of com.google.firestore.v1beta1.Document 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 94 with Document

use of com.google.firestore.v1beta1.Document 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 95 with Document

use of com.google.firestore.v1beta1.Document in project MigrationMiner by hussien89aa.

the class CollectorClient method listOfJavaProjectLibrary.

// read Android Java pom.xml file
public String listOfJavaProjectLibrary(String projectVersionPath) {
    // String appProjectPath= projectVersionPath + "/pom.xml";
    if (projectVersionPath.length() == 0) {
        System.err.println("project doensot have pom.xml file");
        return "";
    }
    String versionLibraries = "";
    System.out.println("Search for  library at :" + projectVersionPath);
    try {
        File inputFile = new File(projectVersionPath);
        SAXBuilder saxBuilder = new SAXBuilder();
        Document document = saxBuilder.build(inputFile);
        Element root = document.getRootElement();
        // get public properties for library version
        HashMap<String, String> propertiesList = new HashMap<String, String>();
        try {
            Element properties = getchild(root, "properties");
            List<Element> propertiesListNode = properties.getChildren();
            for (int temp = 0; temp < propertiesListNode.size(); temp++) {
                Element property = propertiesListNode.get(temp);
                propertiesList.put("${" + property.getName() + "}", property.getValue());
            }
        } catch (Exception ex) {
        }
        /*
			 * DEBUG for (String element : propertiesList.keySet()) {
			 * System.out.println(element +":"+ propertiesList.get(element)); }
			 */
        // get library info
        Element dependencyManagement = getchild(root, "dependencyManagement");
        Element dependencies = null;
        if (dependencyManagement != null) {
            dependencies = getchild(dependencyManagement, "dependencies");
        } else {
            // dependencies may lives under root
            dependencies = getchild(root, "dependencies");
        }
        List<Element> dependencytList = dependencies.getChildren();
        for (int temp = 0; temp < dependencytList.size(); temp++) {
            Element dependency = dependencytList.get(temp);
            List<Element> librariesList = dependency.getChildren();
            String groupId = "";
            String artifactId = "";
            String version = "";
            for (int temp1 = 0; temp1 < librariesList.size(); temp1++) {
                Element libraryInfo = librariesList.get(temp1);
                if (libraryInfo.getName().equals("groupId"))
                    groupId = libraryInfo.getValue();
                if (libraryInfo.getName().equals("artifactId"))
                    artifactId = libraryInfo.getValue();
                if (libraryInfo.getName().equals("version")) {
                    version = libraryInfo.getValue();
                    if (version.startsWith("${")) {
                        version = propertiesList.get(version);
                    }
                }
            }
            String libraryLink = groupId + ":" + artifactId + ":" + version;
            if (versionLibraries.length() == 0) {
                versionLibraries = libraryLink;
            } else {
                if (versionLibraries.contains(libraryLink) == false) {
                    versionLibraries = versionLibraries + "," + libraryLink;
                }
            }
        }
    } catch (Exception e) {
        System.out.println(e.getMessage());
    }
    System.out.println("Found libraries-> " + versionLibraries);
    return versionLibraries;
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) HashMap(java.util.HashMap) Element(org.jdom2.Element) Document(org.jdom2.Document) ProjectBuildFile(com.project.settings.ProjectBuildFile) File(java.io.File) IOException(java.io.IOException)

Aggregations

Document (org.jdom2.Document)1034 Element (org.jdom2.Element)587 Test (org.junit.Test)340 SAXBuilder (org.jdom2.input.SAXBuilder)271 IOException (java.io.IOException)266 XMLOutputter (org.jdom2.output.XMLOutputter)182 JDOMException (org.jdom2.JDOMException)162 File (java.io.File)148 ArrayList (java.util.ArrayList)75 InputStream (java.io.InputStream)74 StringReader (java.io.StringReader)63 Path (java.nio.file.Path)59 HashMap (java.util.HashMap)58 DocumentHelper.getDocument (com.mulesoft.tools.migration.helper.DocumentHelper.getDocument)53 DocumentHelper.getElementsFromDocument (com.mulesoft.tools.migration.helper.DocumentHelper.getElementsFromDocument)53 MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)48 PID (edu.unc.lib.boxc.model.api.ids.PID)47 Attribute (org.jdom2.Attribute)44 List (java.util.List)42 Namespace (org.jdom2.Namespace)39