Search in sources :

Example 1 with CreateIndexRequest

use of com.google.firestore.admin.v1beta1.CreateIndexRequest 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 CreateIndexRequest

use of com.google.firestore.admin.v1beta1.CreateIndexRequest in project java-firestore by googleapis.

the class FirestoreAdminClientTest method createIndexTest2.

@Test
public void createIndexTest2() throws Exception {
    Index expectedResponse = Index.newBuilder().setName(IndexName.of("[PROJECT]", "[DATABASE]", "[COLLECTION]", "[INDEX]").toString()).addAllFields(new ArrayList<Index.IndexField>()).build();
    Operation resultOperation = Operation.newBuilder().setName("createIndexTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
    mockFirestoreAdmin.addResponse(resultOperation);
    String parent = "parent-995424086";
    Index index = Index.newBuilder().build();
    Index actualResponse = client.createIndexAsync(parent, index).get();
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockFirestoreAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateIndexRequest actualRequest = ((CreateIndexRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertEquals(index, actualRequest.getIndex());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ArrayList(java.util.ArrayList) Index(com.google.firestore.admin.v1.Index) Operation(com.google.longrunning.Operation) CreateIndexRequest(com.google.firestore.admin.v1.CreateIndexRequest) Test(org.junit.Test)

Example 3 with CreateIndexRequest

use of com.google.firestore.admin.v1beta1.CreateIndexRequest in project java-datastore by googleapis.

the class DatastoreAdminClientTest method createIndexTest.

@Test
public void createIndexTest() throws Exception {
    Index expectedResponse = Index.newBuilder().setProjectId("projectId-894832108").setIndexId("indexId1943291277").setKind("kind3292052").addAllProperties(new ArrayList<Index.IndexedProperty>()).build();
    Operation resultOperation = Operation.newBuilder().setName("createIndexTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
    mockDatastoreAdmin.addResponse(resultOperation);
    CreateIndexRequest request = CreateIndexRequest.newBuilder().setProjectId("projectId-894832108").setIndex(Index.newBuilder().build()).build();
    Index actualResponse = client.createIndexAsync(request).get();
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockDatastoreAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateIndexRequest actualRequest = ((CreateIndexRequest) actualRequests.get(0));
    Assert.assertEquals(request.getProjectId(), actualRequest.getProjectId());
    Assert.assertEquals(request.getIndex(), actualRequest.getIndex());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ArrayList(java.util.ArrayList) Index(com.google.datastore.admin.v1.Index) Operation(com.google.longrunning.Operation) CreateIndexRequest(com.google.datastore.admin.v1.CreateIndexRequest) Test(org.junit.Test)

Example 4 with CreateIndexRequest

use of com.google.firestore.admin.v1beta1.CreateIndexRequest in project java-datastore by googleapis.

the class DatastoreAdminClientTest method createIndexExceptionTest.

@Test
public void createIndexExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockDatastoreAdmin.addException(exception);
    try {
        CreateIndexRequest request = CreateIndexRequest.newBuilder().setProjectId("projectId-894832108").setIndex(Index.newBuilder().build()).build();
        client.createIndexAsync(request).get();
        Assert.fail("No exception raised");
    } catch (ExecutionException e) {
        Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass());
        InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause());
        Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode());
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) CreateIndexRequest(com.google.datastore.admin.v1.CreateIndexRequest) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 5 with CreateIndexRequest

use of com.google.firestore.admin.v1beta1.CreateIndexRequest in project java-firestore by googleapis.

the class FirestoreAdminClientTest method createIndexTest.

@Test
public void createIndexTest() throws Exception {
    Index expectedResponse = Index.newBuilder().setName(IndexName.of("[PROJECT]", "[DATABASE]", "[COLLECTION]", "[INDEX]").toString()).addAllFields(new ArrayList<Index.IndexField>()).build();
    Operation resultOperation = Operation.newBuilder().setName("createIndexTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
    mockFirestoreAdmin.addResponse(resultOperation);
    CollectionGroupName parent = CollectionGroupName.of("[PROJECT]", "[DATABASE]", "[COLLECTION]");
    Index index = Index.newBuilder().build();
    Index actualResponse = client.createIndexAsync(parent, index).get();
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockFirestoreAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateIndexRequest actualRequest = ((CreateIndexRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertEquals(index, actualRequest.getIndex());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ArrayList(java.util.ArrayList) Index(com.google.firestore.admin.v1.Index) Operation(com.google.longrunning.Operation) CollectionGroupName(com.google.firestore.admin.v1.CollectionGroupName) CreateIndexRequest(com.google.firestore.admin.v1.CreateIndexRequest) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 Operation (com.google.longrunning.Operation)3 AbstractMessage (com.google.protobuf.AbstractMessage)3 CreateIndexRequest (com.google.datastore.admin.v1.CreateIndexRequest)2 CreateIndexRequest (com.google.firestore.admin.v1.CreateIndexRequest)2 Index (com.google.firestore.admin.v1.Index)2 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)1 Index (com.google.datastore.admin.v1.Index)1 CollectionGroupName (com.google.firestore.admin.v1.CollectionGroupName)1 CreateIndexRequest (com.google.firestore.admin.v1beta1.CreateIndexRequest)1 FirestoreAdminBlockingStub (com.google.firestore.admin.v1beta1.FirestoreAdminGrpc.FirestoreAdminBlockingStub)1 Index (com.google.firestore.admin.v1beta1.Index)1 IndexField (com.google.firestore.admin.v1beta1.IndexField)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1 Scanner (java.util.Scanner)1 ExecutionException (java.util.concurrent.ExecutionException)1 GRPCFirebaseAdminClientFactory (org.roguewave.grpc.util.GRPCFirebaseAdminClientFactory)1 Menu (org.roguewave.grpc.util.gfx.Menu)1