Search in sources :

Example 1 with FirestoreAdminBlockingStub

use of com.google.firestore.admin.v1beta1.FirestoreAdminGrpc.FirestoreAdminBlockingStub in project grpc-gcp-java by GoogleCloudPlatform.

the class CreateIndex method createIndexCall.

public void createIndexCall() {
    System.out.println(":: Creating New Index ::");
    FirestoreAdminBlockingStub blockingStub = new GRPCFirebaseAdminClientFactory().createFirebaseAdminClient().getBlockingStub();
    String indexField = "initial";
    String indexMode = "initial";
    Scanner sc = new Scanner(System.in);
    ArrayList<IndexField> allIndexes = new ArrayList<>();
    while (!indexField.matches("DONE")) {
        System.out.print("Index Field Name: ");
        indexField = sc.next();
        if (!indexField.matches("DONE")) {
            System.out.print("Mode (*ASCENDING*/DESCENDING - DONE to finish): ");
            indexMode = sc.next();
            if ((!indexMode.matches("ASCENDING")) && (!indexMode.matches("DESCENDING"))) {
                System.out.println("Not Recognized, setting to default ASCENDING");
                indexMode = "ASCENDING";
            }
            IndexField iff = IndexField.newBuilder().setFieldPath(indexField).setMode((indexMode.matches("ASCENDING") ? IndexField.Mode.ASCENDING : IndexField.Mode.DESCENDING)).build();
            allIndexes.add(iff);
        }
    }
    Index newIndex = Index.newBuilder().setCollectionId("GrpcTestData").addAllFields(allIndexes).build();
    CreateIndexRequest createIndexRequest = CreateIndexRequest.newBuilder().setParent("projects/firestoretestclient/databases/(default)").setIndex(newIndex).build();
    try {
        blockingStub.createIndex(createIndexRequest);
    } catch (Exception e) {
        System.out.println("Error during call: " + e.getMessage() + e.getCause());
    }
    System.out.println("Successfully created new index!");
    Menu menu = new Menu();
    menu.draw();
}
Also used : Scanner(java.util.Scanner) FirestoreAdminBlockingStub(com.google.firestore.admin.v1beta1.FirestoreAdminGrpc.FirestoreAdminBlockingStub) ArrayList(java.util.ArrayList) Index(com.google.firestore.admin.v1beta1.Index) Menu(org.roguewave.grpc.util.gfx.Menu) GRPCFirebaseAdminClientFactory(org.roguewave.grpc.util.GRPCFirebaseAdminClientFactory) CreateIndexRequest(com.google.firestore.admin.v1beta1.CreateIndexRequest) IndexField(com.google.firestore.admin.v1beta1.IndexField)

Example 2 with FirestoreAdminBlockingStub

use of com.google.firestore.admin.v1beta1.FirestoreAdminGrpc.FirestoreAdminBlockingStub in project grpc-gcp-java by GoogleCloudPlatform.

the class DeleteIndex method deleteIndexCall.

public void deleteIndexCall() {
    System.out.println("\n :: Deleting an Index :: \n");
    FirestoreAdminBlockingStub blockingStub = new GRPCFirebaseAdminClientFactory().createFirebaseAdminClient().getBlockingStub();
    Scanner sc = new Scanner(System.in);
    System.out.print("Enter Index Name: ");
    String indexName = "projects/firestoretestclient/databases/(default)/indexes/" + sc.next();
    DeleteIndexRequest deleteIndexRequest = DeleteIndexRequest.newBuilder().setName(indexName).build();
    try {
        blockingStub.deleteIndex(deleteIndexRequest);
    } catch (Exception e) {
        System.out.println("Error during call: " + e.getMessage() + e.getCause());
        return;
    }
    System.out.println("Successfully deleted index " + indexName);
    Menu menu = new Menu();
    menu.draw();
}
Also used : Scanner(java.util.Scanner) FirestoreAdminBlockingStub(com.google.firestore.admin.v1beta1.FirestoreAdminGrpc.FirestoreAdminBlockingStub) DeleteIndexRequest(com.google.firestore.admin.v1beta1.DeleteIndexRequest) Menu(org.roguewave.grpc.util.gfx.Menu) GRPCFirebaseAdminClientFactory(org.roguewave.grpc.util.GRPCFirebaseAdminClientFactory)

Example 3 with FirestoreAdminBlockingStub

use of com.google.firestore.admin.v1beta1.FirestoreAdminGrpc.FirestoreAdminBlockingStub in project grpc-gcp-java by GoogleCloudPlatform.

the class GetIndex method getIndexCall.

public void getIndexCall() {
    System.out.println("\n :: Getting an Index :: \n");
    FirestoreAdminBlockingStub blockingStub = new GRPCFirebaseAdminClientFactory().createFirebaseAdminClient().getBlockingStub();
    Scanner sc = new Scanner(System.in);
    System.out.print("Enter Index Name: ");
    String indexName = "projects/firestoretestclient/databases/(default)/indexes/" + sc.next();
    GetIndexRequest getIndexRequest = GetIndexRequest.newBuilder().setName(indexName).build();
    Index index;
    try {
        index = blockingStub.getIndex(getIndexRequest);
    } catch (Exception e) {
        System.out.println("Error during call: " + e.getMessage() + e.getCause());
        return;
    }
    DrawIndex di = new DrawIndex();
    di.drawIndex(index);
    Menu menu = new Menu();
    menu.draw();
}
Also used : Scanner(java.util.Scanner) FirestoreAdminBlockingStub(com.google.firestore.admin.v1beta1.FirestoreAdminGrpc.FirestoreAdminBlockingStub) DrawIndex(org.roguewave.grpc.util.gfx.DrawIndex) GetIndexRequest(com.google.firestore.admin.v1beta1.GetIndexRequest) Index(com.google.firestore.admin.v1beta1.Index) DrawIndex(org.roguewave.grpc.util.gfx.DrawIndex) Menu(org.roguewave.grpc.util.gfx.Menu) GRPCFirebaseAdminClientFactory(org.roguewave.grpc.util.GRPCFirebaseAdminClientFactory)

Example 4 with FirestoreAdminBlockingStub

use of com.google.firestore.admin.v1beta1.FirestoreAdminGrpc.FirestoreAdminBlockingStub in project grpc-gcp-java by GoogleCloudPlatform.

the class ListIndexes method listIndexesCall.

public void listIndexesCall() {
    System.out.println(":: Listing All Indexes ::");
    FirestoreAdminBlockingStub blockingStub = new GRPCFirebaseAdminClientFactory().createFirebaseAdminClient().getBlockingStub();
    ListIndexesRequest listIndexesRequest = ListIndexesRequest.newBuilder().setParent("projects/firestoretestclient/databases/(default)").build();
    ListIndexesResponse response;
    try {
        response = blockingStub.listIndexes(listIndexesRequest);
    } catch (Exception e) {
        System.out.println("Error during call: " + e.getMessage() + e.getCause());
        return;
    }
    List<Index> indexList = response.getIndexesList();
    DrawIndex di = new DrawIndex();
    for (Index index : indexList) {
        di.drawIndex(index);
    }
    Menu menu = new Menu();
    menu.draw();
}
Also used : ListIndexesResponse(com.google.firestore.admin.v1beta1.ListIndexesResponse) FirestoreAdminBlockingStub(com.google.firestore.admin.v1beta1.FirestoreAdminGrpc.FirestoreAdminBlockingStub) DrawIndex(org.roguewave.grpc.util.gfx.DrawIndex) Index(com.google.firestore.admin.v1beta1.Index) DrawIndex(org.roguewave.grpc.util.gfx.DrawIndex) Menu(org.roguewave.grpc.util.gfx.Menu) GRPCFirebaseAdminClientFactory(org.roguewave.grpc.util.GRPCFirebaseAdminClientFactory) ListIndexesRequest(com.google.firestore.admin.v1beta1.ListIndexesRequest)

Aggregations

FirestoreAdminBlockingStub (com.google.firestore.admin.v1beta1.FirestoreAdminGrpc.FirestoreAdminBlockingStub)4 GRPCFirebaseAdminClientFactory (org.roguewave.grpc.util.GRPCFirebaseAdminClientFactory)4 Menu (org.roguewave.grpc.util.gfx.Menu)4 Index (com.google.firestore.admin.v1beta1.Index)3 Scanner (java.util.Scanner)3 DrawIndex (org.roguewave.grpc.util.gfx.DrawIndex)2 CreateIndexRequest (com.google.firestore.admin.v1beta1.CreateIndexRequest)1 DeleteIndexRequest (com.google.firestore.admin.v1beta1.DeleteIndexRequest)1 GetIndexRequest (com.google.firestore.admin.v1beta1.GetIndexRequest)1 IndexField (com.google.firestore.admin.v1beta1.IndexField)1 ListIndexesRequest (com.google.firestore.admin.v1beta1.ListIndexesRequest)1 ListIndexesResponse (com.google.firestore.admin.v1beta1.ListIndexesResponse)1 ArrayList (java.util.ArrayList)1