diff --git a/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/FirestoreAdminClient.java b/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/FirestoreAdminClient.java
index f88b656545..baefebd67a 100644
--- a/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/FirestoreAdminClient.java
+++ b/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/FirestoreAdminClient.java
@@ -20,6 +20,7 @@
import com.google.api.core.ApiFutures;
import com.google.api.core.BetaApi;
import com.google.api.gax.core.BackgroundResource;
+import com.google.api.gax.httpjson.longrunning.OperationsClient;
import com.google.api.gax.longrunning.OperationFuture;
import com.google.api.gax.paging.AbstractFixedSizeCollection;
import com.google.api.gax.paging.AbstractPage;
@@ -60,7 +61,6 @@
import com.google.firestore.admin.v1.UpdateDatabaseRequest;
import com.google.firestore.admin.v1.UpdateFieldRequest;
import com.google.longrunning.Operation;
-import com.google.longrunning.OperationsClient;
import com.google.protobuf.Empty;
import com.google.protobuf.FieldMask;
import java.io.IOException;
@@ -157,13 +157,28 @@
* FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create(firestoreAdminSettings);
* }
*
+ * To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over
+ * the wire:
+ *
+ *
{@code
+ * // This snippet has been automatically generated for illustrative purposes only.
+ * // It may require modifications to work in your environment.
+ * FirestoreAdminSettings firestoreAdminSettings =
+ * FirestoreAdminSettings.newBuilder()
+ * .setTransportChannelProvider(
+ * FirestoreAdminSettings.defaultHttpJsonTransportProviderBuilder().build())
+ * .build();
+ * FirestoreAdminClient firestoreAdminClient = FirestoreAdminClient.create(firestoreAdminSettings);
+ * }
+ *
* Please refer to the GitHub repository's samples for more quickstart code snippets.
*/
@Generated("by gapic-generator-java")
public class FirestoreAdminClient implements BackgroundResource {
private final FirestoreAdminSettings settings;
private final FirestoreAdminStub stub;
- private final OperationsClient operationsClient;
+ private final OperationsClient httpJsonOperationsClient;
+ private final com.google.longrunning.OperationsClient operationsClient;
/** Constructs an instance of FirestoreAdminClient with default settings. */
public static final FirestoreAdminClient create() throws IOException {
@@ -183,7 +198,6 @@ public static final FirestoreAdminClient create(FirestoreAdminSettings settings)
* Constructs an instance of FirestoreAdminClient, using the given stub for making calls. This is
* for advanced usage - prefer using create(FirestoreAdminSettings).
*/
- @BetaApi("A restructuring of stub classes is planned, so this may break in the future")
public static final FirestoreAdminClient create(FirestoreAdminStub stub) {
return new FirestoreAdminClient(stub);
}
@@ -196,21 +210,23 @@ public static final FirestoreAdminClient create(FirestoreAdminStub stub) {
protected FirestoreAdminClient(FirestoreAdminSettings settings) throws IOException {
this.settings = settings;
this.stub = ((FirestoreAdminStubSettings) settings.getStubSettings()).createStub();
- this.operationsClient = OperationsClient.create(this.stub.getOperationsStub());
+ this.operationsClient =
+ com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub());
+ this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub());
}
- @BetaApi("A restructuring of stub classes is planned, so this may break in the future")
protected FirestoreAdminClient(FirestoreAdminStub stub) {
this.settings = null;
this.stub = stub;
- this.operationsClient = OperationsClient.create(this.stub.getOperationsStub());
+ this.operationsClient =
+ com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub());
+ this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub());
}
public final FirestoreAdminSettings getSettings() {
return settings;
}
- @BetaApi("A restructuring of stub classes is planned, so this may break in the future")
public FirestoreAdminStub getStub() {
return stub;
}
@@ -219,10 +235,19 @@ public FirestoreAdminStub getStub() {
* Returns the OperationsClient that can be used to query the status of a long-running operation
* returned by another API method call.
*/
- public final OperationsClient getOperationsClient() {
+ public final com.google.longrunning.OperationsClient getOperationsClient() {
return operationsClient;
}
+ /**
+ * Returns the OperationsClient that can be used to query the status of a long-running operation
+ * returned by another API method call.
+ */
+ @BetaApi
+ public final OperationsClient getHttpJsonOperationsClient() {
+ return httpJsonOperationsClient;
+ }
+
// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Creates a composite index. This returns a
@@ -518,7 +543,7 @@ public final ListIndexesPagedResponse listIndexes(ListIndexesRequest request) {
* .build();
* while (true) {
* ListIndexesResponse response = firestoreAdminClient.listIndexesCallable().call(request);
- * for (Index element : response.getResponsesList()) {
+ * for (Index element : response.getIndexesList()) {
* // doThingsWith(element);
* }
* String nextPageToken = response.getNextPageToken();
@@ -1145,7 +1170,7 @@ public final UnaryCallable listField
* .build();
* while (true) {
* ListFieldsResponse response = firestoreAdminClient.listFieldsCallable().call(request);
- * for (Field element : response.getResponsesList()) {
+ * for (Field element : response.getFieldsList()) {
* // doThingsWith(element);
* }
* String nextPageToken = response.getNextPageToken();
diff --git a/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/FirestoreAdminSettings.java b/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/FirestoreAdminSettings.java
index aca16c4ce9..a9f66be1c3 100644
--- a/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/FirestoreAdminSettings.java
+++ b/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/FirestoreAdminSettings.java
@@ -24,6 +24,7 @@
import com.google.api.gax.core.GoogleCredentialsProvider;
import com.google.api.gax.core.InstantiatingExecutorProvider;
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
+import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider;
import com.google.api.gax.rpc.ApiClientHeaderProvider;
import com.google.api.gax.rpc.ClientContext;
import com.google.api.gax.rpc.ClientSettings;
@@ -217,11 +218,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde
return FirestoreAdminStubSettings.defaultCredentialsProviderBuilder();
}
- /** Returns a builder for the default ChannelProvider for this service. */
+ /** Returns a builder for the default gRPC ChannelProvider for this service. */
public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() {
return FirestoreAdminStubSettings.defaultGrpcTransportProviderBuilder();
}
+ /** Returns a builder for the default REST ChannelProvider for this service. */
+ @BetaApi
+ public static InstantiatingHttpJsonChannelProvider.Builder
+ defaultHttpJsonTransportProviderBuilder() {
+ return FirestoreAdminStubSettings.defaultHttpJsonTransportProviderBuilder();
+ }
+
public static TransportChannelProvider defaultTransportChannelProvider() {
return FirestoreAdminStubSettings.defaultTransportChannelProvider();
}
@@ -231,11 +239,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil
return FirestoreAdminStubSettings.defaultApiClientHeaderProviderBuilder();
}
- /** Returns a new builder for this class. */
+ /** Returns a new gRPC builder for this class. */
public static Builder newBuilder() {
return Builder.createDefault();
}
+ /** Returns a new REST builder for this class. */
+ @BetaApi
+ public static Builder newHttpJsonBuilder() {
+ return Builder.createHttpJsonDefault();
+ }
+
/** Returns a new builder for this class. */
public static Builder newBuilder(ClientContext clientContext) {
return new Builder(clientContext);
@@ -273,6 +287,11 @@ private static Builder createDefault() {
return new Builder(FirestoreAdminStubSettings.newBuilder());
}
+ @BetaApi
+ private static Builder createHttpJsonDefault() {
+ return new Builder(FirestoreAdminStubSettings.newHttpJsonBuilder());
+ }
+
public FirestoreAdminStubSettings.Builder getStubSettingsBuilder() {
return ((FirestoreAdminStubSettings.Builder) getStubSettings());
}
diff --git a/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/stub/FirestoreAdminStub.java b/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/stub/FirestoreAdminStub.java
index 8626f778ae..c497c5968f 100644
--- a/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/stub/FirestoreAdminStub.java
+++ b/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/stub/FirestoreAdminStub.java
@@ -61,7 +61,11 @@
public abstract class FirestoreAdminStub implements BackgroundResource {
public OperationsStub getOperationsStub() {
- throw new UnsupportedOperationException("Not implemented: getOperationsStub()");
+ return null;
+ }
+
+ public com.google.api.gax.httpjson.longrunning.stub.OperationsStub getHttpJsonOperationsStub() {
+ return null;
}
public OperationCallable
diff --git a/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/stub/FirestoreAdminStubSettings.java b/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/stub/FirestoreAdminStubSettings.java
index 8c03cef524..46074b6e2c 100644
--- a/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/stub/FirestoreAdminStubSettings.java
+++ b/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/stub/FirestoreAdminStubSettings.java
@@ -29,6 +29,9 @@
import com.google.api.gax.grpc.GrpcTransportChannel;
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
import com.google.api.gax.grpc.ProtoOperationTransformers;
+import com.google.api.gax.httpjson.GaxHttpJsonProperties;
+import com.google.api.gax.httpjson.HttpJsonTransportChannel;
+import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider;
import com.google.api.gax.longrunning.OperationSnapshot;
import com.google.api.gax.longrunning.OperationTimedPollAlgorithm;
import com.google.api.gax.retrying.RetrySettings;
@@ -349,13 +352,17 @@ public UnaryCallSettings updateDatabaseSetting
return updateDatabaseOperationSettings;
}
- @BetaApi("A restructuring of stub classes is planned, so this may break in the future")
public FirestoreAdminStub createStub() throws IOException {
if (getTransportChannelProvider()
.getTransportName()
.equals(GrpcTransportChannel.getGrpcTransportName())) {
return GrpcFirestoreAdminStub.create(this);
}
+ if (getTransportChannelProvider()
+ .getTransportName()
+ .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) {
+ return HttpJsonFirestoreAdminStub.create(this);
+ }
throw new UnsupportedOperationException(
String.format(
"Transport not supported: %s", getTransportChannelProvider().getTransportName()));
@@ -388,18 +395,25 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde
.setUseJwtAccessWithScope(true);
}
- /** Returns a builder for the default ChannelProvider for this service. */
+ /** Returns a builder for the default gRPC ChannelProvider for this service. */
public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() {
return InstantiatingGrpcChannelProvider.newBuilder()
.setMaxInboundMessageSize(Integer.MAX_VALUE);
}
+ /** Returns a builder for the default REST ChannelProvider for this service. */
+ @BetaApi
+ public static InstantiatingHttpJsonChannelProvider.Builder
+ defaultHttpJsonTransportProviderBuilder() {
+ return InstantiatingHttpJsonChannelProvider.newBuilder();
+ }
+
public static TransportChannelProvider defaultTransportChannelProvider() {
return defaultGrpcTransportProviderBuilder().build();
}
@BetaApi("The surface for customizing headers is not stable yet and may change in the future.")
- public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() {
+ public static ApiClientHeaderProvider.Builder defaultGrpcApiClientHeaderProviderBuilder() {
return ApiClientHeaderProvider.newBuilder()
.setGeneratedLibToken(
"gapic", GaxProperties.getLibraryVersion(FirestoreAdminStubSettings.class))
@@ -407,11 +421,30 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil
GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion());
}
- /** Returns a new builder for this class. */
+ @BetaApi("The surface for customizing headers is not stable yet and may change in the future.")
+ public static ApiClientHeaderProvider.Builder defaultHttpJsonApiClientHeaderProviderBuilder() {
+ return ApiClientHeaderProvider.newBuilder()
+ .setGeneratedLibToken(
+ "gapic", GaxProperties.getLibraryVersion(FirestoreAdminStubSettings.class))
+ .setTransportToken(
+ GaxHttpJsonProperties.getHttpJsonTokenName(),
+ GaxHttpJsonProperties.getHttpJsonVersion());
+ }
+
+ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() {
+ return FirestoreAdminStubSettings.defaultGrpcApiClientHeaderProviderBuilder();
+ }
+
+ /** Returns a new gRPC builder for this class. */
public static Builder newBuilder() {
return Builder.createDefault();
}
+ /** Returns a new REST builder for this class. */
+ public static Builder newHttpJsonBuilder() {
+ return Builder.createHttpJsonDefault();
+ }
+
/** Returns a new builder for this class. */
public static Builder newBuilder(ClientContext clientContext) {
return new Builder(clientContext);
@@ -620,6 +653,19 @@ private static Builder createDefault() {
return initDefaults(builder);
}
+ private static Builder createHttpJsonDefault() {
+ Builder builder = new Builder(((ClientContext) null));
+
+ builder.setTransportChannelProvider(defaultHttpJsonTransportProviderBuilder().build());
+ builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build());
+ builder.setInternalHeaderProvider(defaultHttpJsonApiClientHeaderProviderBuilder().build());
+ builder.setEndpoint(getDefaultEndpoint());
+ builder.setMtlsEndpoint(getDefaultMtlsEndpoint());
+ builder.setSwitchToMtlsEndpointAllowed(true);
+
+ return initDefaults(builder);
+ }
+
private static Builder initDefaults(Builder builder) {
builder
.createIndexSettings()
diff --git a/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/stub/HttpJsonFirestoreAdminCallableFactory.java b/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/stub/HttpJsonFirestoreAdminCallableFactory.java
new file mode 100644
index 0000000000..342c32d638
--- /dev/null
+++ b/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/stub/HttpJsonFirestoreAdminCallableFactory.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2022 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.cloud.firestore.v1.stub;
+
+import com.google.api.core.BetaApi;
+import com.google.api.gax.httpjson.HttpJsonCallSettings;
+import com.google.api.gax.httpjson.HttpJsonCallableFactory;
+import com.google.api.gax.httpjson.HttpJsonOperationSnapshotCallable;
+import com.google.api.gax.httpjson.HttpJsonStubCallableFactory;
+import com.google.api.gax.httpjson.longrunning.stub.OperationsStub;
+import com.google.api.gax.rpc.BatchingCallSettings;
+import com.google.api.gax.rpc.ClientContext;
+import com.google.api.gax.rpc.OperationCallSettings;
+import com.google.api.gax.rpc.OperationCallable;
+import com.google.api.gax.rpc.PagedCallSettings;
+import com.google.api.gax.rpc.ServerStreamingCallSettings;
+import com.google.api.gax.rpc.ServerStreamingCallable;
+import com.google.api.gax.rpc.UnaryCallSettings;
+import com.google.api.gax.rpc.UnaryCallable;
+import com.google.longrunning.Operation;
+import javax.annotation.Generated;
+
+// AUTO-GENERATED DOCUMENTATION AND CLASS.
+/**
+ * REST callable factory implementation for the FirestoreAdmin service API.
+ *
+ * This class is for advanced usage.
+ */
+@Generated("by gapic-generator-java")
+@BetaApi
+public class HttpJsonFirestoreAdminCallableFactory
+ implements HttpJsonStubCallableFactory {
+
+ @Override
+ public UnaryCallable createUnaryCallable(
+ HttpJsonCallSettings httpJsonCallSettings,
+ UnaryCallSettings callSettings,
+ ClientContext clientContext) {
+ return HttpJsonCallableFactory.createUnaryCallable(
+ httpJsonCallSettings, callSettings, clientContext);
+ }
+
+ @Override
+ public
+ UnaryCallable createPagedCallable(
+ HttpJsonCallSettings httpJsonCallSettings,
+ PagedCallSettings callSettings,
+ ClientContext clientContext) {
+ return HttpJsonCallableFactory.createPagedCallable(
+ httpJsonCallSettings, callSettings, clientContext);
+ }
+
+ @Override
+ public UnaryCallable createBatchingCallable(
+ HttpJsonCallSettings httpJsonCallSettings,
+ BatchingCallSettings callSettings,
+ ClientContext clientContext) {
+ return HttpJsonCallableFactory.createBatchingCallable(
+ httpJsonCallSettings, callSettings, clientContext);
+ }
+
+ @BetaApi(
+ "The surface for long-running operations is not stable yet and may change in the future.")
+ @Override
+ public
+ OperationCallable createOperationCallable(
+ HttpJsonCallSettings httpJsonCallSettings,
+ OperationCallSettings callSettings,
+ ClientContext clientContext,
+ OperationsStub operationsStub) {
+ UnaryCallable innerCallable =
+ HttpJsonCallableFactory.createBaseUnaryCallable(
+ httpJsonCallSettings, callSettings.getInitialCallSettings(), clientContext);
+ HttpJsonOperationSnapshotCallable initialCallable =
+ new HttpJsonOperationSnapshotCallable(
+ innerCallable,
+ httpJsonCallSettings.getMethodDescriptor().getOperationSnapshotFactory());
+ return HttpJsonCallableFactory.createOperationCallable(
+ callSettings, clientContext, operationsStub.longRunningClient(), initialCallable);
+ }
+
+ @Override
+ public
+ ServerStreamingCallable createServerStreamingCallable(
+ HttpJsonCallSettings httpJsonCallSettings,
+ ServerStreamingCallSettings callSettings,
+ ClientContext clientContext) {
+ return HttpJsonCallableFactory.createServerStreamingCallable(
+ httpJsonCallSettings, callSettings, clientContext);
+ }
+}
diff --git a/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/stub/HttpJsonFirestoreAdminStub.java b/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/stub/HttpJsonFirestoreAdminStub.java
new file mode 100644
index 0000000000..8d71663a48
--- /dev/null
+++ b/google-cloud-firestore-admin/src/main/java/com/google/cloud/firestore/v1/stub/HttpJsonFirestoreAdminStub.java
@@ -0,0 +1,894 @@
+/*
+ * Copyright 2022 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.cloud.firestore.v1.stub;
+
+import static com.google.cloud.firestore.v1.FirestoreAdminClient.ListFieldsPagedResponse;
+import static com.google.cloud.firestore.v1.FirestoreAdminClient.ListIndexesPagedResponse;
+
+import com.google.api.core.BetaApi;
+import com.google.api.core.InternalApi;
+import com.google.api.gax.core.BackgroundResource;
+import com.google.api.gax.core.BackgroundResourceAggregation;
+import com.google.api.gax.httpjson.ApiMethodDescriptor;
+import com.google.api.gax.httpjson.HttpJsonCallSettings;
+import com.google.api.gax.httpjson.HttpJsonOperationSnapshot;
+import com.google.api.gax.httpjson.HttpJsonStubCallableFactory;
+import com.google.api.gax.httpjson.ProtoMessageRequestFormatter;
+import com.google.api.gax.httpjson.ProtoMessageResponseParser;
+import com.google.api.gax.httpjson.ProtoRestSerializer;
+import com.google.api.gax.httpjson.longrunning.stub.HttpJsonOperationsStub;
+import com.google.api.gax.rpc.ClientContext;
+import com.google.api.gax.rpc.OperationCallable;
+import com.google.api.gax.rpc.UnaryCallable;
+import com.google.firestore.admin.v1.CreateIndexRequest;
+import com.google.firestore.admin.v1.Database;
+import com.google.firestore.admin.v1.DeleteIndexRequest;
+import com.google.firestore.admin.v1.ExportDocumentsMetadata;
+import com.google.firestore.admin.v1.ExportDocumentsRequest;
+import com.google.firestore.admin.v1.ExportDocumentsResponse;
+import com.google.firestore.admin.v1.Field;
+import com.google.firestore.admin.v1.FieldOperationMetadata;
+import com.google.firestore.admin.v1.GetDatabaseRequest;
+import com.google.firestore.admin.v1.GetFieldRequest;
+import com.google.firestore.admin.v1.GetIndexRequest;
+import com.google.firestore.admin.v1.ImportDocumentsMetadata;
+import com.google.firestore.admin.v1.ImportDocumentsRequest;
+import com.google.firestore.admin.v1.Index;
+import com.google.firestore.admin.v1.IndexOperationMetadata;
+import com.google.firestore.admin.v1.ListDatabasesRequest;
+import com.google.firestore.admin.v1.ListDatabasesResponse;
+import com.google.firestore.admin.v1.ListFieldsRequest;
+import com.google.firestore.admin.v1.ListFieldsResponse;
+import com.google.firestore.admin.v1.ListIndexesRequest;
+import com.google.firestore.admin.v1.ListIndexesResponse;
+import com.google.firestore.admin.v1.UpdateDatabaseMetadata;
+import com.google.firestore.admin.v1.UpdateDatabaseRequest;
+import com.google.firestore.admin.v1.UpdateFieldRequest;
+import com.google.longrunning.Operation;
+import com.google.protobuf.Empty;
+import com.google.protobuf.TypeRegistry;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import javax.annotation.Generated;
+
+// AUTO-GENERATED DOCUMENTATION AND CLASS.
+/**
+ * REST stub implementation for the FirestoreAdmin service API.
+ *
+ * This class is for advanced usage and reflects the underlying API directly.
+ */
+@Generated("by gapic-generator-java")
+@BetaApi
+public class HttpJsonFirestoreAdminStub extends FirestoreAdminStub {
+ private static final TypeRegistry typeRegistry =
+ TypeRegistry.newBuilder()
+ .add(ExportDocumentsResponse.getDescriptor())
+ .add(UpdateDatabaseMetadata.getDescriptor())
+ .add(Field.getDescriptor())
+ .add(Empty.getDescriptor())
+ .add(ImportDocumentsMetadata.getDescriptor())
+ .add(Database.getDescriptor())
+ .add(Index.getDescriptor())
+ .add(FieldOperationMetadata.getDescriptor())
+ .add(ExportDocumentsMetadata.getDescriptor())
+ .add(IndexOperationMetadata.getDescriptor())
+ .build();
+
+ private static final ApiMethodDescriptor
+ createIndexMethodDescriptor =
+ ApiMethodDescriptor.newBuilder()
+ .setFullMethodName("google.firestore.admin.v1.FirestoreAdmin/CreateIndex")
+ .setHttpMethod("POST")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1/{parent=projects/*/databases/*/collectionGroups/*}/indexes",
+ request -> {
+ Map fields = new HashMap<>();
+ ProtoRestSerializer serializer =
+ ProtoRestSerializer.create();
+ serializer.putPathParam(fields, "parent", request.getParent());
+ return fields;
+ })
+ .setQueryParamsExtractor(
+ request -> {
+ Map> fields = new HashMap<>();
+ ProtoRestSerializer serializer =
+ ProtoRestSerializer.create();
+ return fields;
+ })
+ .setRequestBodyExtractor(
+ request ->
+ ProtoRestSerializer.create().toBody("index", request.getIndex()))
+ .build())
+ .setResponseParser(
+ ProtoMessageResponseParser.newBuilder()
+ .setDefaultInstance(Operation.getDefaultInstance())
+ .setDefaultTypeRegistry(typeRegistry)
+ .build())
+ .setOperationSnapshotFactory(
+ (CreateIndexRequest request, Operation response) ->
+ HttpJsonOperationSnapshot.create(response))
+ .build();
+
+ private static final ApiMethodDescriptor
+ listIndexesMethodDescriptor =
+ ApiMethodDescriptor.newBuilder()
+ .setFullMethodName("google.firestore.admin.v1.FirestoreAdmin/ListIndexes")
+ .setHttpMethod("GET")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1/{parent=projects/*/databases/*/collectionGroups/*}/indexes",
+ request -> {
+ Map fields = new HashMap<>();
+ ProtoRestSerializer serializer =
+ ProtoRestSerializer.create();
+ serializer.putPathParam(fields, "parent", request.getParent());
+ return fields;
+ })
+ .setQueryParamsExtractor(
+ request -> {
+ Map> fields = new HashMap<>();
+ ProtoRestSerializer serializer =
+ ProtoRestSerializer.create();
+ serializer.putQueryParam(fields, "filter", request.getFilter());
+ serializer.putQueryParam(fields, "pageSize", request.getPageSize());
+ serializer.putQueryParam(fields, "pageToken", request.getPageToken());
+ return fields;
+ })
+ .setRequestBodyExtractor(request -> null)
+ .build())
+ .setResponseParser(
+ ProtoMessageResponseParser.newBuilder()
+ .setDefaultInstance(ListIndexesResponse.getDefaultInstance())
+ .setDefaultTypeRegistry(typeRegistry)
+ .build())
+ .build();
+
+ private static final ApiMethodDescriptor getIndexMethodDescriptor =
+ ApiMethodDescriptor.newBuilder()
+ .setFullMethodName("google.firestore.admin.v1.FirestoreAdmin/GetIndex")
+ .setHttpMethod("GET")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1/{name=projects/*/databases/*/collectionGroups/*/indexes/*}",
+ request -> {
+ Map fields = new HashMap<>();
+ ProtoRestSerializer serializer =
+ ProtoRestSerializer.create();
+ serializer.putPathParam(fields, "name", request.getName());
+ return fields;
+ })
+ .setQueryParamsExtractor(
+ request -> {
+ Map> fields = new HashMap<>();
+ ProtoRestSerializer serializer =
+ ProtoRestSerializer.create();
+ return fields;
+ })
+ .setRequestBodyExtractor(request -> null)
+ .build())
+ .setResponseParser(
+ ProtoMessageResponseParser.newBuilder()
+ .setDefaultInstance(Index.getDefaultInstance())
+ .setDefaultTypeRegistry(typeRegistry)
+ .build())
+ .build();
+
+ private static final ApiMethodDescriptor deleteIndexMethodDescriptor =
+ ApiMethodDescriptor.newBuilder()
+ .setFullMethodName("google.firestore.admin.v1.FirestoreAdmin/DeleteIndex")
+ .setHttpMethod("DELETE")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1/{name=projects/*/databases/*/collectionGroups/*/indexes/*}",
+ request -> {
+ Map fields = new HashMap<>();
+ ProtoRestSerializer serializer =
+ ProtoRestSerializer.create();
+ serializer.putPathParam(fields, "name", request.getName());
+ return fields;
+ })
+ .setQueryParamsExtractor(
+ request -> {
+ Map> fields = new HashMap<>();
+ ProtoRestSerializer serializer =
+ ProtoRestSerializer.create();
+ return fields;
+ })
+ .setRequestBodyExtractor(request -> null)
+ .build())
+ .setResponseParser(
+ ProtoMessageResponseParser.newBuilder()
+ .setDefaultInstance(Empty.getDefaultInstance())
+ .setDefaultTypeRegistry(typeRegistry)
+ .build())
+ .build();
+
+ private static final ApiMethodDescriptor getFieldMethodDescriptor =
+ ApiMethodDescriptor.newBuilder()
+ .setFullMethodName("google.firestore.admin.v1.FirestoreAdmin/GetField")
+ .setHttpMethod("GET")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1/{name=projects/*/databases/*/collectionGroups/*/fields/*}",
+ request -> {
+ Map fields = new HashMap<>();
+ ProtoRestSerializer serializer =
+ ProtoRestSerializer.create();
+ serializer.putPathParam(fields, "name", request.getName());
+ return fields;
+ })
+ .setQueryParamsExtractor(
+ request -> {
+ Map> fields = new HashMap<>();
+ ProtoRestSerializer serializer =
+ ProtoRestSerializer.create();
+ return fields;
+ })
+ .setRequestBodyExtractor(request -> null)
+ .build())
+ .setResponseParser(
+ ProtoMessageResponseParser.newBuilder()
+ .setDefaultInstance(Field.getDefaultInstance())
+ .setDefaultTypeRegistry(typeRegistry)
+ .build())
+ .build();
+
+ private static final ApiMethodDescriptor
+ updateFieldMethodDescriptor =
+ ApiMethodDescriptor.newBuilder()
+ .setFullMethodName("google.firestore.admin.v1.FirestoreAdmin/UpdateField")
+ .setHttpMethod("PATCH")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1/{field.name=projects/*/databases/*/collectionGroups/*/fields/*}",
+ request -> {
+ Map fields = new HashMap<>();
+ ProtoRestSerializer serializer =
+ ProtoRestSerializer.create();
+ serializer.putPathParam(
+ fields, "field.name", request.getField().getName());
+ return fields;
+ })
+ .setQueryParamsExtractor(
+ request -> {
+ Map> fields = new HashMap<>();
+ ProtoRestSerializer serializer =
+ ProtoRestSerializer.create();
+ serializer.putQueryParam(fields, "updateMask", request.getUpdateMask());
+ return fields;
+ })
+ .setRequestBodyExtractor(
+ request ->
+ ProtoRestSerializer.create().toBody("field", request.getField()))
+ .build())
+ .setResponseParser(
+ ProtoMessageResponseParser.newBuilder()
+ .setDefaultInstance(Operation.getDefaultInstance())
+ .setDefaultTypeRegistry(typeRegistry)
+ .build())
+ .setOperationSnapshotFactory(
+ (UpdateFieldRequest request, Operation response) ->
+ HttpJsonOperationSnapshot.create(response))
+ .build();
+
+ private static final ApiMethodDescriptor
+ listFieldsMethodDescriptor =
+ ApiMethodDescriptor.newBuilder()
+ .setFullMethodName("google.firestore.admin.v1.FirestoreAdmin/ListFields")
+ .setHttpMethod("GET")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1/{parent=projects/*/databases/*/collectionGroups/*}/fields",
+ request -> {
+ Map fields = new HashMap<>();
+ ProtoRestSerializer serializer =
+ ProtoRestSerializer.create();
+ serializer.putPathParam(fields, "parent", request.getParent());
+ return fields;
+ })
+ .setQueryParamsExtractor(
+ request -> {
+ Map> fields = new HashMap<>();
+ ProtoRestSerializer serializer =
+ ProtoRestSerializer.create();
+ serializer.putQueryParam(fields, "filter", request.getFilter());
+ serializer.putQueryParam(fields, "pageSize", request.getPageSize());
+ serializer.putQueryParam(fields, "pageToken", request.getPageToken());
+ return fields;
+ })
+ .setRequestBodyExtractor(request -> null)
+ .build())
+ .setResponseParser(
+ ProtoMessageResponseParser.newBuilder()
+ .setDefaultInstance(ListFieldsResponse.getDefaultInstance())
+ .setDefaultTypeRegistry(typeRegistry)
+ .build())
+ .build();
+
+ private static final ApiMethodDescriptor
+ exportDocumentsMethodDescriptor =
+ ApiMethodDescriptor.newBuilder()
+ .setFullMethodName("google.firestore.admin.v1.FirestoreAdmin/ExportDocuments")
+ .setHttpMethod("POST")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1/{name=projects/*/databases/*}:exportDocuments",
+ request -> {
+ Map fields = new HashMap<>();
+ ProtoRestSerializer serializer =
+ ProtoRestSerializer.create();
+ serializer.putPathParam(fields, "name", request.getName());
+ return fields;
+ })
+ .setQueryParamsExtractor(
+ request -> {
+ Map> fields = new HashMap<>();
+ ProtoRestSerializer serializer =
+ ProtoRestSerializer.create();
+ return fields;
+ })
+ .setRequestBodyExtractor(
+ request ->
+ ProtoRestSerializer.create()
+ .toBody("*", request.toBuilder().clearName().build()))
+ .build())
+ .setResponseParser(
+ ProtoMessageResponseParser.newBuilder()
+ .setDefaultInstance(Operation.getDefaultInstance())
+ .setDefaultTypeRegistry(typeRegistry)
+ .build())
+ .setOperationSnapshotFactory(
+ (ExportDocumentsRequest request, Operation response) ->
+ HttpJsonOperationSnapshot.create(response))
+ .build();
+
+ private static final ApiMethodDescriptor
+ importDocumentsMethodDescriptor =
+ ApiMethodDescriptor.newBuilder()
+ .setFullMethodName("google.firestore.admin.v1.FirestoreAdmin/ImportDocuments")
+ .setHttpMethod("POST")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1/{name=projects/*/databases/*}:importDocuments",
+ request -> {
+ Map fields = new HashMap<>();
+ ProtoRestSerializer serializer =
+ ProtoRestSerializer.create();
+ serializer.putPathParam(fields, "name", request.getName());
+ return fields;
+ })
+ .setQueryParamsExtractor(
+ request -> {
+ Map> fields = new HashMap<>();
+ ProtoRestSerializer serializer =
+ ProtoRestSerializer.create();
+ return fields;
+ })
+ .setRequestBodyExtractor(
+ request ->
+ ProtoRestSerializer.create()
+ .toBody("*", request.toBuilder().clearName().build()))
+ .build())
+ .setResponseParser(
+ ProtoMessageResponseParser.newBuilder()
+ .setDefaultInstance(Operation.getDefaultInstance())
+ .setDefaultTypeRegistry(typeRegistry)
+ .build())
+ .setOperationSnapshotFactory(
+ (ImportDocumentsRequest request, Operation response) ->
+ HttpJsonOperationSnapshot.create(response))
+ .build();
+
+ private static final ApiMethodDescriptor
+ getDatabaseMethodDescriptor =
+ ApiMethodDescriptor.newBuilder()
+ .setFullMethodName("google.firestore.admin.v1.FirestoreAdmin/GetDatabase")
+ .setHttpMethod("GET")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1/{name=projects/*/databases/*}",
+ request -> {
+ Map fields = new HashMap<>();
+ ProtoRestSerializer serializer =
+ ProtoRestSerializer.create();
+ serializer.putPathParam(fields, "name", request.getName());
+ return fields;
+ })
+ .setQueryParamsExtractor(
+ request -> {
+ Map> fields = new HashMap<>();
+ ProtoRestSerializer serializer =
+ ProtoRestSerializer.create();
+ return fields;
+ })
+ .setRequestBodyExtractor(request -> null)
+ .build())
+ .setResponseParser(
+ ProtoMessageResponseParser.newBuilder()
+ .setDefaultInstance(Database.getDefaultInstance())
+ .setDefaultTypeRegistry(typeRegistry)
+ .build())
+ .build();
+
+ private static final ApiMethodDescriptor
+ listDatabasesMethodDescriptor =
+ ApiMethodDescriptor.newBuilder()
+ .setFullMethodName("google.firestore.admin.v1.FirestoreAdmin/ListDatabases")
+ .setHttpMethod("GET")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1/{parent=projects/*}/databases",
+ request -> {
+ Map fields = new HashMap<>();
+ ProtoRestSerializer serializer =
+ ProtoRestSerializer.create();
+ serializer.putPathParam(fields, "parent", request.getParent());
+ return fields;
+ })
+ .setQueryParamsExtractor(
+ request -> {
+ Map> fields = new HashMap<>();
+ ProtoRestSerializer serializer =
+ ProtoRestSerializer.create();
+ return fields;
+ })
+ .setRequestBodyExtractor(request -> null)
+ .build())
+ .setResponseParser(
+ ProtoMessageResponseParser.newBuilder()
+ .setDefaultInstance(ListDatabasesResponse.getDefaultInstance())
+ .setDefaultTypeRegistry(typeRegistry)
+ .build())
+ .build();
+
+ private static final ApiMethodDescriptor
+ updateDatabaseMethodDescriptor =
+ ApiMethodDescriptor.newBuilder()
+ .setFullMethodName("google.firestore.admin.v1.FirestoreAdmin/UpdateDatabase")
+ .setHttpMethod("PATCH")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1/{database.name=projects/*/databases/*}",
+ request -> {
+ Map fields = new HashMap<>();
+ ProtoRestSerializer serializer =
+ ProtoRestSerializer.create();
+ serializer.putPathParam(
+ fields, "database.name", request.getDatabase().getName());
+ return fields;
+ })
+ .setQueryParamsExtractor(
+ request -> {
+ Map> fields = new HashMap<>();
+ ProtoRestSerializer serializer =
+ ProtoRestSerializer.create();
+ serializer.putQueryParam(fields, "updateMask", request.getUpdateMask());
+ return fields;
+ })
+ .setRequestBodyExtractor(
+ request ->
+ ProtoRestSerializer.create()
+ .toBody("database", request.getDatabase()))
+ .build())
+ .setResponseParser(
+ ProtoMessageResponseParser.newBuilder()
+ .setDefaultInstance(Operation.getDefaultInstance())
+ .setDefaultTypeRegistry(typeRegistry)
+ .build())
+ .setOperationSnapshotFactory(
+ (UpdateDatabaseRequest request, Operation response) ->
+ HttpJsonOperationSnapshot.create(response))
+ .build();
+
+ private final UnaryCallable createIndexCallable;
+ private final OperationCallable
+ createIndexOperationCallable;
+ private final UnaryCallable listIndexesCallable;
+ private final UnaryCallable
+ listIndexesPagedCallable;
+ private final UnaryCallable getIndexCallable;
+ private final UnaryCallable deleteIndexCallable;
+ private final UnaryCallable getFieldCallable;
+ private final UnaryCallable updateFieldCallable;
+ private final OperationCallable
+ updateFieldOperationCallable;
+ private final UnaryCallable listFieldsCallable;
+ private final UnaryCallable listFieldsPagedCallable;
+ private final UnaryCallable exportDocumentsCallable;
+ private final OperationCallable<
+ ExportDocumentsRequest, ExportDocumentsResponse, ExportDocumentsMetadata>
+ exportDocumentsOperationCallable;
+ private final UnaryCallable importDocumentsCallable;
+ private final OperationCallable
+ importDocumentsOperationCallable;
+ private final UnaryCallable getDatabaseCallable;
+ private final UnaryCallable listDatabasesCallable;
+ private final UnaryCallable updateDatabaseCallable;
+ private final OperationCallable
+ updateDatabaseOperationCallable;
+
+ private final BackgroundResource backgroundResources;
+ private final HttpJsonOperationsStub httpJsonOperationsStub;
+ private final HttpJsonStubCallableFactory callableFactory;
+
+ public static final HttpJsonFirestoreAdminStub create(FirestoreAdminStubSettings settings)
+ throws IOException {
+ return new HttpJsonFirestoreAdminStub(settings, ClientContext.create(settings));
+ }
+
+ public static final HttpJsonFirestoreAdminStub create(ClientContext clientContext)
+ throws IOException {
+ return new HttpJsonFirestoreAdminStub(
+ FirestoreAdminStubSettings.newHttpJsonBuilder().build(), clientContext);
+ }
+
+ public static final HttpJsonFirestoreAdminStub create(
+ ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException {
+ return new HttpJsonFirestoreAdminStub(
+ FirestoreAdminStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory);
+ }
+
+ /**
+ * Constructs an instance of HttpJsonFirestoreAdminStub, using the given settings. This is
+ * protected so that it is easy to make a subclass, but otherwise, the static factory methods
+ * should be preferred.
+ */
+ protected HttpJsonFirestoreAdminStub(
+ FirestoreAdminStubSettings settings, ClientContext clientContext) throws IOException {
+ this(settings, clientContext, new HttpJsonFirestoreAdminCallableFactory());
+ }
+
+ /**
+ * Constructs an instance of HttpJsonFirestoreAdminStub, using the given settings. This is
+ * protected so that it is easy to make a subclass, but otherwise, the static factory methods
+ * should be preferred.
+ */
+ protected HttpJsonFirestoreAdminStub(
+ FirestoreAdminStubSettings settings,
+ ClientContext clientContext,
+ HttpJsonStubCallableFactory callableFactory)
+ throws IOException {
+ this.callableFactory = callableFactory;
+ this.httpJsonOperationsStub =
+ HttpJsonOperationsStub.create(clientContext, callableFactory, typeRegistry);
+
+ HttpJsonCallSettings createIndexTransportSettings =
+ HttpJsonCallSettings.newBuilder()
+ .setMethodDescriptor(createIndexMethodDescriptor)
+ .setTypeRegistry(typeRegistry)
+ .build();
+ HttpJsonCallSettings listIndexesTransportSettings =
+ HttpJsonCallSettings.newBuilder()
+ .setMethodDescriptor(listIndexesMethodDescriptor)
+ .setTypeRegistry(typeRegistry)
+ .build();
+ HttpJsonCallSettings getIndexTransportSettings =
+ HttpJsonCallSettings.newBuilder()
+ .setMethodDescriptor(getIndexMethodDescriptor)
+ .setTypeRegistry(typeRegistry)
+ .build();
+ HttpJsonCallSettings deleteIndexTransportSettings =
+ HttpJsonCallSettings.newBuilder()
+ .setMethodDescriptor(deleteIndexMethodDescriptor)
+ .setTypeRegistry(typeRegistry)
+ .build();
+ HttpJsonCallSettings getFieldTransportSettings =
+ HttpJsonCallSettings.newBuilder()
+ .setMethodDescriptor(getFieldMethodDescriptor)
+ .setTypeRegistry(typeRegistry)
+ .build();
+ HttpJsonCallSettings updateFieldTransportSettings =
+ HttpJsonCallSettings.newBuilder()
+ .setMethodDescriptor(updateFieldMethodDescriptor)
+ .setTypeRegistry(typeRegistry)
+ .build();
+ HttpJsonCallSettings listFieldsTransportSettings =
+ HttpJsonCallSettings.newBuilder()
+ .setMethodDescriptor(listFieldsMethodDescriptor)
+ .setTypeRegistry(typeRegistry)
+ .build();
+ HttpJsonCallSettings exportDocumentsTransportSettings =
+ HttpJsonCallSettings.newBuilder()
+ .setMethodDescriptor(exportDocumentsMethodDescriptor)
+ .setTypeRegistry(typeRegistry)
+ .build();
+ HttpJsonCallSettings importDocumentsTransportSettings =
+ HttpJsonCallSettings.newBuilder()
+ .setMethodDescriptor(importDocumentsMethodDescriptor)
+ .setTypeRegistry(typeRegistry)
+ .build();
+ HttpJsonCallSettings getDatabaseTransportSettings =
+ HttpJsonCallSettings.newBuilder()
+ .setMethodDescriptor(getDatabaseMethodDescriptor)
+ .setTypeRegistry(typeRegistry)
+ .build();
+ HttpJsonCallSettings
+ listDatabasesTransportSettings =
+ HttpJsonCallSettings.newBuilder()
+ .setMethodDescriptor(listDatabasesMethodDescriptor)
+ .setTypeRegistry(typeRegistry)
+ .build();
+ HttpJsonCallSettings updateDatabaseTransportSettings =
+ HttpJsonCallSettings.newBuilder()
+ .setMethodDescriptor(updateDatabaseMethodDescriptor)
+ .setTypeRegistry(typeRegistry)
+ .build();
+
+ this.createIndexCallable =
+ callableFactory.createUnaryCallable(
+ createIndexTransportSettings, settings.createIndexSettings(), clientContext);
+ this.createIndexOperationCallable =
+ callableFactory.createOperationCallable(
+ createIndexTransportSettings,
+ settings.createIndexOperationSettings(),
+ clientContext,
+ httpJsonOperationsStub);
+ this.listIndexesCallable =
+ callableFactory.createUnaryCallable(
+ listIndexesTransportSettings, settings.listIndexesSettings(), clientContext);
+ this.listIndexesPagedCallable =
+ callableFactory.createPagedCallable(
+ listIndexesTransportSettings, settings.listIndexesSettings(), clientContext);
+ this.getIndexCallable =
+ callableFactory.createUnaryCallable(
+ getIndexTransportSettings, settings.getIndexSettings(), clientContext);
+ this.deleteIndexCallable =
+ callableFactory.createUnaryCallable(
+ deleteIndexTransportSettings, settings.deleteIndexSettings(), clientContext);
+ this.getFieldCallable =
+ callableFactory.createUnaryCallable(
+ getFieldTransportSettings, settings.getFieldSettings(), clientContext);
+ this.updateFieldCallable =
+ callableFactory.createUnaryCallable(
+ updateFieldTransportSettings, settings.updateFieldSettings(), clientContext);
+ this.updateFieldOperationCallable =
+ callableFactory.createOperationCallable(
+ updateFieldTransportSettings,
+ settings.updateFieldOperationSettings(),
+ clientContext,
+ httpJsonOperationsStub);
+ this.listFieldsCallable =
+ callableFactory.createUnaryCallable(
+ listFieldsTransportSettings, settings.listFieldsSettings(), clientContext);
+ this.listFieldsPagedCallable =
+ callableFactory.createPagedCallable(
+ listFieldsTransportSettings, settings.listFieldsSettings(), clientContext);
+ this.exportDocumentsCallable =
+ callableFactory.createUnaryCallable(
+ exportDocumentsTransportSettings, settings.exportDocumentsSettings(), clientContext);
+ this.exportDocumentsOperationCallable =
+ callableFactory.createOperationCallable(
+ exportDocumentsTransportSettings,
+ settings.exportDocumentsOperationSettings(),
+ clientContext,
+ httpJsonOperationsStub);
+ this.importDocumentsCallable =
+ callableFactory.createUnaryCallable(
+ importDocumentsTransportSettings, settings.importDocumentsSettings(), clientContext);
+ this.importDocumentsOperationCallable =
+ callableFactory.createOperationCallable(
+ importDocumentsTransportSettings,
+ settings.importDocumentsOperationSettings(),
+ clientContext,
+ httpJsonOperationsStub);
+ this.getDatabaseCallable =
+ callableFactory.createUnaryCallable(
+ getDatabaseTransportSettings, settings.getDatabaseSettings(), clientContext);
+ this.listDatabasesCallable =
+ callableFactory.createUnaryCallable(
+ listDatabasesTransportSettings, settings.listDatabasesSettings(), clientContext);
+ this.updateDatabaseCallable =
+ callableFactory.createUnaryCallable(
+ updateDatabaseTransportSettings, settings.updateDatabaseSettings(), clientContext);
+ this.updateDatabaseOperationCallable =
+ callableFactory.createOperationCallable(
+ updateDatabaseTransportSettings,
+ settings.updateDatabaseOperationSettings(),
+ clientContext,
+ httpJsonOperationsStub);
+
+ this.backgroundResources =
+ new BackgroundResourceAggregation(clientContext.getBackgroundResources());
+ }
+
+ @InternalApi
+ public static List getMethodDescriptors() {
+ List methodDescriptors = new ArrayList<>();
+ methodDescriptors.add(createIndexMethodDescriptor);
+ methodDescriptors.add(listIndexesMethodDescriptor);
+ methodDescriptors.add(getIndexMethodDescriptor);
+ methodDescriptors.add(deleteIndexMethodDescriptor);
+ methodDescriptors.add(getFieldMethodDescriptor);
+ methodDescriptors.add(updateFieldMethodDescriptor);
+ methodDescriptors.add(listFieldsMethodDescriptor);
+ methodDescriptors.add(exportDocumentsMethodDescriptor);
+ methodDescriptors.add(importDocumentsMethodDescriptor);
+ methodDescriptors.add(getDatabaseMethodDescriptor);
+ methodDescriptors.add(listDatabasesMethodDescriptor);
+ methodDescriptors.add(updateDatabaseMethodDescriptor);
+ return methodDescriptors;
+ }
+
+ public HttpJsonOperationsStub getHttpJsonOperationsStub() {
+ return httpJsonOperationsStub;
+ }
+
+ @Override
+ public UnaryCallable createIndexCallable() {
+ return createIndexCallable;
+ }
+
+ @Override
+ public OperationCallable
+ createIndexOperationCallable() {
+ return createIndexOperationCallable;
+ }
+
+ @Override
+ public UnaryCallable listIndexesCallable() {
+ return listIndexesCallable;
+ }
+
+ @Override
+ public UnaryCallable listIndexesPagedCallable() {
+ return listIndexesPagedCallable;
+ }
+
+ @Override
+ public UnaryCallable getIndexCallable() {
+ return getIndexCallable;
+ }
+
+ @Override
+ public UnaryCallable deleteIndexCallable() {
+ return deleteIndexCallable;
+ }
+
+ @Override
+ public UnaryCallable getFieldCallable() {
+ return getFieldCallable;
+ }
+
+ @Override
+ public UnaryCallable updateFieldCallable() {
+ return updateFieldCallable;
+ }
+
+ @Override
+ public OperationCallable
+ updateFieldOperationCallable() {
+ return updateFieldOperationCallable;
+ }
+
+ @Override
+ public UnaryCallable listFieldsCallable() {
+ return listFieldsCallable;
+ }
+
+ @Override
+ public UnaryCallable listFieldsPagedCallable() {
+ return listFieldsPagedCallable;
+ }
+
+ @Override
+ public UnaryCallable exportDocumentsCallable() {
+ return exportDocumentsCallable;
+ }
+
+ @Override
+ public OperationCallable
+ exportDocumentsOperationCallable() {
+ return exportDocumentsOperationCallable;
+ }
+
+ @Override
+ public UnaryCallable importDocumentsCallable() {
+ return importDocumentsCallable;
+ }
+
+ @Override
+ public OperationCallable
+ importDocumentsOperationCallable() {
+ return importDocumentsOperationCallable;
+ }
+
+ @Override
+ public UnaryCallable getDatabaseCallable() {
+ return getDatabaseCallable;
+ }
+
+ @Override
+ public UnaryCallable listDatabasesCallable() {
+ return listDatabasesCallable;
+ }
+
+ @Override
+ public UnaryCallable updateDatabaseCallable() {
+ return updateDatabaseCallable;
+ }
+
+ @Override
+ public OperationCallable
+ updateDatabaseOperationCallable() {
+ return updateDatabaseOperationCallable;
+ }
+
+ @Override
+ public final void close() {
+ try {
+ backgroundResources.close();
+ } catch (RuntimeException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new IllegalStateException("Failed to close resource", e);
+ }
+ }
+
+ @Override
+ public void shutdown() {
+ backgroundResources.shutdown();
+ }
+
+ @Override
+ public boolean isShutdown() {
+ return backgroundResources.isShutdown();
+ }
+
+ @Override
+ public boolean isTerminated() {
+ return backgroundResources.isTerminated();
+ }
+
+ @Override
+ public void shutdownNow() {
+ backgroundResources.shutdownNow();
+ }
+
+ @Override
+ public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException {
+ return backgroundResources.awaitTermination(duration, unit);
+ }
+}
diff --git a/google-cloud-firestore-admin/src/test/java/com/google/cloud/firestore/v1/FirestoreAdminClientHttpJsonTest.java b/google-cloud-firestore-admin/src/test/java/com/google/cloud/firestore/v1/FirestoreAdminClientHttpJsonTest.java
new file mode 100644
index 0000000000..aced3bd043
--- /dev/null
+++ b/google-cloud-firestore-admin/src/test/java/com/google/cloud/firestore/v1/FirestoreAdminClientHttpJsonTest.java
@@ -0,0 +1,1167 @@
+/*
+ * Copyright 2022 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.cloud.firestore.v1;
+
+import static com.google.cloud.firestore.v1.FirestoreAdminClient.ListFieldsPagedResponse;
+import static com.google.cloud.firestore.v1.FirestoreAdminClient.ListIndexesPagedResponse;
+
+import com.google.api.gax.core.NoCredentialsProvider;
+import com.google.api.gax.httpjson.GaxHttpJsonProperties;
+import com.google.api.gax.httpjson.testing.MockHttpService;
+import com.google.api.gax.rpc.ApiClientHeaderProvider;
+import com.google.api.gax.rpc.ApiException;
+import com.google.api.gax.rpc.ApiExceptionFactory;
+import com.google.api.gax.rpc.InvalidArgumentException;
+import com.google.api.gax.rpc.StatusCode;
+import com.google.api.gax.rpc.testing.FakeStatusCode;
+import com.google.cloud.firestore.v1.stub.HttpJsonFirestoreAdminStub;
+import com.google.common.collect.Lists;
+import com.google.firestore.admin.v1.CollectionGroupName;
+import com.google.firestore.admin.v1.Database;
+import com.google.firestore.admin.v1.DatabaseName;
+import com.google.firestore.admin.v1.ExportDocumentsResponse;
+import com.google.firestore.admin.v1.Field;
+import com.google.firestore.admin.v1.FieldName;
+import com.google.firestore.admin.v1.Index;
+import com.google.firestore.admin.v1.IndexName;
+import com.google.firestore.admin.v1.ListDatabasesResponse;
+import com.google.firestore.admin.v1.ListFieldsResponse;
+import com.google.firestore.admin.v1.ListIndexesResponse;
+import com.google.firestore.admin.v1.ProjectName;
+import com.google.longrunning.Operation;
+import com.google.protobuf.Any;
+import com.google.protobuf.Empty;
+import com.google.protobuf.FieldMask;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+import javax.annotation.Generated;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+@Generated("by gapic-generator-java")
+public class FirestoreAdminClientHttpJsonTest {
+ private static MockHttpService mockService;
+ private static FirestoreAdminClient client;
+
+ @BeforeClass
+ public static void startStaticServer() throws IOException {
+ mockService =
+ new MockHttpService(
+ HttpJsonFirestoreAdminStub.getMethodDescriptors(),
+ FirestoreAdminSettings.getDefaultEndpoint());
+ FirestoreAdminSettings settings =
+ FirestoreAdminSettings.newHttpJsonBuilder()
+ .setTransportChannelProvider(
+ FirestoreAdminSettings.defaultHttpJsonTransportProviderBuilder()
+ .setHttpTransport(mockService)
+ .build())
+ .setCredentialsProvider(NoCredentialsProvider.create())
+ .build();
+ client = FirestoreAdminClient.create(settings);
+ }
+
+ @AfterClass
+ public static void stopServer() {
+ client.close();
+ }
+
+ @Before
+ public void setUp() {}
+
+ @After
+ public void tearDown() throws Exception {
+ mockService.reset();
+ }
+
+ @Test
+ public void createIndexTest() throws Exception {
+ Index expectedResponse =
+ Index.newBuilder()
+ .setName(IndexName.of("[PROJECT]", "[DATABASE]", "[COLLECTION]", "[INDEX]").toString())
+ .addAllFields(new ArrayList())
+ .build();
+ Operation resultOperation =
+ Operation.newBuilder()
+ .setName("createIndexTest")
+ .setDone(true)
+ .setResponse(Any.pack(expectedResponse))
+ .build();
+ mockService.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 actualRequests = mockService.getRequestPaths();
+ Assert.assertEquals(1, actualRequests.size());
+
+ String apiClientHeaderKey =
+ mockService
+ .getRequestHeaders()
+ .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
+ .iterator()
+ .next();
+ Assert.assertTrue(
+ GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
+ .matcher(apiClientHeaderKey)
+ .matches());
+ }
+
+ @Test
+ public void createIndexExceptionTest() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ CollectionGroupName parent =
+ CollectionGroupName.of("[PROJECT]", "[DATABASE]", "[COLLECTION]");
+ Index index = Index.newBuilder().build();
+ client.createIndexAsync(parent, index).get();
+ Assert.fail("No exception raised");
+ } catch (ExecutionException e) {
+ }
+ }
+
+ @Test
+ public void createIndexTest2() throws Exception {
+ Index expectedResponse =
+ Index.newBuilder()
+ .setName(IndexName.of("[PROJECT]", "[DATABASE]", "[COLLECTION]", "[INDEX]").toString())
+ .addAllFields(new ArrayList())
+ .build();
+ Operation resultOperation =
+ Operation.newBuilder()
+ .setName("createIndexTest")
+ .setDone(true)
+ .setResponse(Any.pack(expectedResponse))
+ .build();
+ mockService.addResponse(resultOperation);
+
+ String parent =
+ "projects/project-1737/databases/database-1737/collectionGroups/collectionGroup-1737";
+ Index index = Index.newBuilder().build();
+
+ Index actualResponse = client.createIndexAsync(parent, index).get();
+ Assert.assertEquals(expectedResponse, actualResponse);
+
+ List actualRequests = mockService.getRequestPaths();
+ Assert.assertEquals(1, actualRequests.size());
+
+ String apiClientHeaderKey =
+ mockService
+ .getRequestHeaders()
+ .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
+ .iterator()
+ .next();
+ Assert.assertTrue(
+ GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
+ .matcher(apiClientHeaderKey)
+ .matches());
+ }
+
+ @Test
+ public void createIndexExceptionTest2() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ String parent =
+ "projects/project-1737/databases/database-1737/collectionGroups/collectionGroup-1737";
+ Index index = Index.newBuilder().build();
+ client.createIndexAsync(parent, index).get();
+ Assert.fail("No exception raised");
+ } catch (ExecutionException e) {
+ }
+ }
+
+ @Test
+ public void listIndexesTest() throws Exception {
+ Index responsesElement = Index.newBuilder().build();
+ ListIndexesResponse expectedResponse =
+ ListIndexesResponse.newBuilder()
+ .setNextPageToken("")
+ .addAllIndexes(Arrays.asList(responsesElement))
+ .build();
+ mockService.addResponse(expectedResponse);
+
+ CollectionGroupName parent = CollectionGroupName.of("[PROJECT]", "[DATABASE]", "[COLLECTION]");
+
+ ListIndexesPagedResponse pagedListResponse = client.listIndexes(parent);
+
+ List resources = Lists.newArrayList(pagedListResponse.iterateAll());
+
+ Assert.assertEquals(1, resources.size());
+ Assert.assertEquals(expectedResponse.getIndexesList().get(0), resources.get(0));
+
+ List actualRequests = mockService.getRequestPaths();
+ Assert.assertEquals(1, actualRequests.size());
+
+ String apiClientHeaderKey =
+ mockService
+ .getRequestHeaders()
+ .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
+ .iterator()
+ .next();
+ Assert.assertTrue(
+ GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
+ .matcher(apiClientHeaderKey)
+ .matches());
+ }
+
+ @Test
+ public void listIndexesExceptionTest() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ CollectionGroupName parent =
+ CollectionGroupName.of("[PROJECT]", "[DATABASE]", "[COLLECTION]");
+ client.listIndexes(parent);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void listIndexesTest2() throws Exception {
+ Index responsesElement = Index.newBuilder().build();
+ ListIndexesResponse expectedResponse =
+ ListIndexesResponse.newBuilder()
+ .setNextPageToken("")
+ .addAllIndexes(Arrays.asList(responsesElement))
+ .build();
+ mockService.addResponse(expectedResponse);
+
+ String parent =
+ "projects/project-1737/databases/database-1737/collectionGroups/collectionGroup-1737";
+
+ ListIndexesPagedResponse pagedListResponse = client.listIndexes(parent);
+
+ List resources = Lists.newArrayList(pagedListResponse.iterateAll());
+
+ Assert.assertEquals(1, resources.size());
+ Assert.assertEquals(expectedResponse.getIndexesList().get(0), resources.get(0));
+
+ List actualRequests = mockService.getRequestPaths();
+ Assert.assertEquals(1, actualRequests.size());
+
+ String apiClientHeaderKey =
+ mockService
+ .getRequestHeaders()
+ .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
+ .iterator()
+ .next();
+ Assert.assertTrue(
+ GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
+ .matcher(apiClientHeaderKey)
+ .matches());
+ }
+
+ @Test
+ public void listIndexesExceptionTest2() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ String parent =
+ "projects/project-1737/databases/database-1737/collectionGroups/collectionGroup-1737";
+ client.listIndexes(parent);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void getIndexTest() throws Exception {
+ Index expectedResponse =
+ Index.newBuilder()
+ .setName(IndexName.of("[PROJECT]", "[DATABASE]", "[COLLECTION]", "[INDEX]").toString())
+ .addAllFields(new ArrayList())
+ .build();
+ mockService.addResponse(expectedResponse);
+
+ IndexName name = IndexName.of("[PROJECT]", "[DATABASE]", "[COLLECTION]", "[INDEX]");
+
+ Index actualResponse = client.getIndex(name);
+ Assert.assertEquals(expectedResponse, actualResponse);
+
+ List actualRequests = mockService.getRequestPaths();
+ Assert.assertEquals(1, actualRequests.size());
+
+ String apiClientHeaderKey =
+ mockService
+ .getRequestHeaders()
+ .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
+ .iterator()
+ .next();
+ Assert.assertTrue(
+ GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
+ .matcher(apiClientHeaderKey)
+ .matches());
+ }
+
+ @Test
+ public void getIndexExceptionTest() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ IndexName name = IndexName.of("[PROJECT]", "[DATABASE]", "[COLLECTION]", "[INDEX]");
+ client.getIndex(name);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void getIndexTest2() throws Exception {
+ Index expectedResponse =
+ Index.newBuilder()
+ .setName(IndexName.of("[PROJECT]", "[DATABASE]", "[COLLECTION]", "[INDEX]").toString())
+ .addAllFields(new ArrayList())
+ .build();
+ mockService.addResponse(expectedResponse);
+
+ String name =
+ "projects/project-5884/databases/database-5884/collectionGroups/collectionGroup-5884/indexes/indexe-5884";
+
+ Index actualResponse = client.getIndex(name);
+ Assert.assertEquals(expectedResponse, actualResponse);
+
+ List actualRequests = mockService.getRequestPaths();
+ Assert.assertEquals(1, actualRequests.size());
+
+ String apiClientHeaderKey =
+ mockService
+ .getRequestHeaders()
+ .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
+ .iterator()
+ .next();
+ Assert.assertTrue(
+ GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
+ .matcher(apiClientHeaderKey)
+ .matches());
+ }
+
+ @Test
+ public void getIndexExceptionTest2() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ String name =
+ "projects/project-5884/databases/database-5884/collectionGroups/collectionGroup-5884/indexes/indexe-5884";
+ client.getIndex(name);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void deleteIndexTest() throws Exception {
+ Empty expectedResponse = Empty.newBuilder().build();
+ mockService.addResponse(expectedResponse);
+
+ IndexName name = IndexName.of("[PROJECT]", "[DATABASE]", "[COLLECTION]", "[INDEX]");
+
+ client.deleteIndex(name);
+
+ List actualRequests = mockService.getRequestPaths();
+ Assert.assertEquals(1, actualRequests.size());
+
+ String apiClientHeaderKey =
+ mockService
+ .getRequestHeaders()
+ .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
+ .iterator()
+ .next();
+ Assert.assertTrue(
+ GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
+ .matcher(apiClientHeaderKey)
+ .matches());
+ }
+
+ @Test
+ public void deleteIndexExceptionTest() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ IndexName name = IndexName.of("[PROJECT]", "[DATABASE]", "[COLLECTION]", "[INDEX]");
+ client.deleteIndex(name);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void deleteIndexTest2() throws Exception {
+ Empty expectedResponse = Empty.newBuilder().build();
+ mockService.addResponse(expectedResponse);
+
+ String name =
+ "projects/project-5884/databases/database-5884/collectionGroups/collectionGroup-5884/indexes/indexe-5884";
+
+ client.deleteIndex(name);
+
+ List actualRequests = mockService.getRequestPaths();
+ Assert.assertEquals(1, actualRequests.size());
+
+ String apiClientHeaderKey =
+ mockService
+ .getRequestHeaders()
+ .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
+ .iterator()
+ .next();
+ Assert.assertTrue(
+ GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
+ .matcher(apiClientHeaderKey)
+ .matches());
+ }
+
+ @Test
+ public void deleteIndexExceptionTest2() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ String name =
+ "projects/project-5884/databases/database-5884/collectionGroups/collectionGroup-5884/indexes/indexe-5884";
+ client.deleteIndex(name);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void getFieldTest() throws Exception {
+ Field expectedResponse =
+ Field.newBuilder()
+ .setName(FieldName.of("[PROJECT]", "[DATABASE]", "[COLLECTION]", "[FIELD]").toString())
+ .setIndexConfig(Field.IndexConfig.newBuilder().build())
+ .setTtlConfig(Field.TtlConfig.newBuilder().build())
+ .build();
+ mockService.addResponse(expectedResponse);
+
+ FieldName name = FieldName.of("[PROJECT]", "[DATABASE]", "[COLLECTION]", "[FIELD]");
+
+ Field actualResponse = client.getField(name);
+ Assert.assertEquals(expectedResponse, actualResponse);
+
+ List actualRequests = mockService.getRequestPaths();
+ Assert.assertEquals(1, actualRequests.size());
+
+ String apiClientHeaderKey =
+ mockService
+ .getRequestHeaders()
+ .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
+ .iterator()
+ .next();
+ Assert.assertTrue(
+ GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
+ .matcher(apiClientHeaderKey)
+ .matches());
+ }
+
+ @Test
+ public void getFieldExceptionTest() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ FieldName name = FieldName.of("[PROJECT]", "[DATABASE]", "[COLLECTION]", "[FIELD]");
+ client.getField(name);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void getFieldTest2() throws Exception {
+ Field expectedResponse =
+ Field.newBuilder()
+ .setName(FieldName.of("[PROJECT]", "[DATABASE]", "[COLLECTION]", "[FIELD]").toString())
+ .setIndexConfig(Field.IndexConfig.newBuilder().build())
+ .setTtlConfig(Field.TtlConfig.newBuilder().build())
+ .build();
+ mockService.addResponse(expectedResponse);
+
+ String name =
+ "projects/project-1275/databases/database-1275/collectionGroups/collectionGroup-1275/fields/field-1275";
+
+ Field actualResponse = client.getField(name);
+ Assert.assertEquals(expectedResponse, actualResponse);
+
+ List actualRequests = mockService.getRequestPaths();
+ Assert.assertEquals(1, actualRequests.size());
+
+ String apiClientHeaderKey =
+ mockService
+ .getRequestHeaders()
+ .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
+ .iterator()
+ .next();
+ Assert.assertTrue(
+ GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
+ .matcher(apiClientHeaderKey)
+ .matches());
+ }
+
+ @Test
+ public void getFieldExceptionTest2() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ String name =
+ "projects/project-1275/databases/database-1275/collectionGroups/collectionGroup-1275/fields/field-1275";
+ client.getField(name);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void updateFieldTest() throws Exception {
+ Field expectedResponse =
+ Field.newBuilder()
+ .setName(FieldName.of("[PROJECT]", "[DATABASE]", "[COLLECTION]", "[FIELD]").toString())
+ .setIndexConfig(Field.IndexConfig.newBuilder().build())
+ .setTtlConfig(Field.TtlConfig.newBuilder().build())
+ .build();
+ Operation resultOperation =
+ Operation.newBuilder()
+ .setName("updateFieldTest")
+ .setDone(true)
+ .setResponse(Any.pack(expectedResponse))
+ .build();
+ mockService.addResponse(resultOperation);
+
+ Field field =
+ Field.newBuilder()
+ .setName(FieldName.of("[PROJECT]", "[DATABASE]", "[COLLECTION]", "[FIELD]").toString())
+ .setIndexConfig(Field.IndexConfig.newBuilder().build())
+ .setTtlConfig(Field.TtlConfig.newBuilder().build())
+ .build();
+
+ Field actualResponse = client.updateFieldAsync(field).get();
+ Assert.assertEquals(expectedResponse, actualResponse);
+
+ List actualRequests = mockService.getRequestPaths();
+ Assert.assertEquals(1, actualRequests.size());
+
+ String apiClientHeaderKey =
+ mockService
+ .getRequestHeaders()
+ .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
+ .iterator()
+ .next();
+ Assert.assertTrue(
+ GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
+ .matcher(apiClientHeaderKey)
+ .matches());
+ }
+
+ @Test
+ public void updateFieldExceptionTest() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ Field field =
+ Field.newBuilder()
+ .setName(
+ FieldName.of("[PROJECT]", "[DATABASE]", "[COLLECTION]", "[FIELD]").toString())
+ .setIndexConfig(Field.IndexConfig.newBuilder().build())
+ .setTtlConfig(Field.TtlConfig.newBuilder().build())
+ .build();
+ client.updateFieldAsync(field).get();
+ Assert.fail("No exception raised");
+ } catch (ExecutionException e) {
+ }
+ }
+
+ @Test
+ public void listFieldsTest() throws Exception {
+ Field responsesElement = Field.newBuilder().build();
+ ListFieldsResponse expectedResponse =
+ ListFieldsResponse.newBuilder()
+ .setNextPageToken("")
+ .addAllFields(Arrays.asList(responsesElement))
+ .build();
+ mockService.addResponse(expectedResponse);
+
+ CollectionGroupName parent = CollectionGroupName.of("[PROJECT]", "[DATABASE]", "[COLLECTION]");
+
+ ListFieldsPagedResponse pagedListResponse = client.listFields(parent);
+
+ List resources = Lists.newArrayList(pagedListResponse.iterateAll());
+
+ Assert.assertEquals(1, resources.size());
+ Assert.assertEquals(expectedResponse.getFieldsList().get(0), resources.get(0));
+
+ List actualRequests = mockService.getRequestPaths();
+ Assert.assertEquals(1, actualRequests.size());
+
+ String apiClientHeaderKey =
+ mockService
+ .getRequestHeaders()
+ .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
+ .iterator()
+ .next();
+ Assert.assertTrue(
+ GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
+ .matcher(apiClientHeaderKey)
+ .matches());
+ }
+
+ @Test
+ public void listFieldsExceptionTest() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ CollectionGroupName parent =
+ CollectionGroupName.of("[PROJECT]", "[DATABASE]", "[COLLECTION]");
+ client.listFields(parent);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void listFieldsTest2() throws Exception {
+ Field responsesElement = Field.newBuilder().build();
+ ListFieldsResponse expectedResponse =
+ ListFieldsResponse.newBuilder()
+ .setNextPageToken("")
+ .addAllFields(Arrays.asList(responsesElement))
+ .build();
+ mockService.addResponse(expectedResponse);
+
+ String parent =
+ "projects/project-1737/databases/database-1737/collectionGroups/collectionGroup-1737";
+
+ ListFieldsPagedResponse pagedListResponse = client.listFields(parent);
+
+ List resources = Lists.newArrayList(pagedListResponse.iterateAll());
+
+ Assert.assertEquals(1, resources.size());
+ Assert.assertEquals(expectedResponse.getFieldsList().get(0), resources.get(0));
+
+ List actualRequests = mockService.getRequestPaths();
+ Assert.assertEquals(1, actualRequests.size());
+
+ String apiClientHeaderKey =
+ mockService
+ .getRequestHeaders()
+ .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
+ .iterator()
+ .next();
+ Assert.assertTrue(
+ GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
+ .matcher(apiClientHeaderKey)
+ .matches());
+ }
+
+ @Test
+ public void listFieldsExceptionTest2() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ String parent =
+ "projects/project-1737/databases/database-1737/collectionGroups/collectionGroup-1737";
+ client.listFields(parent);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void exportDocumentsTest() throws Exception {
+ ExportDocumentsResponse expectedResponse =
+ ExportDocumentsResponse.newBuilder().setOutputUriPrefix("outputUriPrefix499858205").build();
+ Operation resultOperation =
+ Operation.newBuilder()
+ .setName("exportDocumentsTest")
+ .setDone(true)
+ .setResponse(Any.pack(expectedResponse))
+ .build();
+ mockService.addResponse(resultOperation);
+
+ DatabaseName name = DatabaseName.of("[PROJECT]", "[DATABASE]");
+
+ ExportDocumentsResponse actualResponse = client.exportDocumentsAsync(name).get();
+ Assert.assertEquals(expectedResponse, actualResponse);
+
+ List actualRequests = mockService.getRequestPaths();
+ Assert.assertEquals(1, actualRequests.size());
+
+ String apiClientHeaderKey =
+ mockService
+ .getRequestHeaders()
+ .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
+ .iterator()
+ .next();
+ Assert.assertTrue(
+ GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
+ .matcher(apiClientHeaderKey)
+ .matches());
+ }
+
+ @Test
+ public void exportDocumentsExceptionTest() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ DatabaseName name = DatabaseName.of("[PROJECT]", "[DATABASE]");
+ client.exportDocumentsAsync(name).get();
+ Assert.fail("No exception raised");
+ } catch (ExecutionException e) {
+ }
+ }
+
+ @Test
+ public void exportDocumentsTest2() throws Exception {
+ ExportDocumentsResponse expectedResponse =
+ ExportDocumentsResponse.newBuilder().setOutputUriPrefix("outputUriPrefix499858205").build();
+ Operation resultOperation =
+ Operation.newBuilder()
+ .setName("exportDocumentsTest")
+ .setDone(true)
+ .setResponse(Any.pack(expectedResponse))
+ .build();
+ mockService.addResponse(resultOperation);
+
+ String name = "projects/project-2580/databases/database-2580";
+
+ ExportDocumentsResponse actualResponse = client.exportDocumentsAsync(name).get();
+ Assert.assertEquals(expectedResponse, actualResponse);
+
+ List actualRequests = mockService.getRequestPaths();
+ Assert.assertEquals(1, actualRequests.size());
+
+ String apiClientHeaderKey =
+ mockService
+ .getRequestHeaders()
+ .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
+ .iterator()
+ .next();
+ Assert.assertTrue(
+ GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
+ .matcher(apiClientHeaderKey)
+ .matches());
+ }
+
+ @Test
+ public void exportDocumentsExceptionTest2() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ String name = "projects/project-2580/databases/database-2580";
+ client.exportDocumentsAsync(name).get();
+ Assert.fail("No exception raised");
+ } catch (ExecutionException e) {
+ }
+ }
+
+ @Test
+ public void importDocumentsTest() throws Exception {
+ Empty expectedResponse = Empty.newBuilder().build();
+ Operation resultOperation =
+ Operation.newBuilder()
+ .setName("importDocumentsTest")
+ .setDone(true)
+ .setResponse(Any.pack(expectedResponse))
+ .build();
+ mockService.addResponse(resultOperation);
+
+ DatabaseName name = DatabaseName.of("[PROJECT]", "[DATABASE]");
+
+ client.importDocumentsAsync(name).get();
+
+ List actualRequests = mockService.getRequestPaths();
+ Assert.assertEquals(1, actualRequests.size());
+
+ String apiClientHeaderKey =
+ mockService
+ .getRequestHeaders()
+ .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
+ .iterator()
+ .next();
+ Assert.assertTrue(
+ GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
+ .matcher(apiClientHeaderKey)
+ .matches());
+ }
+
+ @Test
+ public void importDocumentsExceptionTest() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ DatabaseName name = DatabaseName.of("[PROJECT]", "[DATABASE]");
+ client.importDocumentsAsync(name).get();
+ Assert.fail("No exception raised");
+ } catch (ExecutionException e) {
+ }
+ }
+
+ @Test
+ public void importDocumentsTest2() throws Exception {
+ Empty expectedResponse = Empty.newBuilder().build();
+ Operation resultOperation =
+ Operation.newBuilder()
+ .setName("importDocumentsTest")
+ .setDone(true)
+ .setResponse(Any.pack(expectedResponse))
+ .build();
+ mockService.addResponse(resultOperation);
+
+ String name = "projects/project-2580/databases/database-2580";
+
+ client.importDocumentsAsync(name).get();
+
+ List actualRequests = mockService.getRequestPaths();
+ Assert.assertEquals(1, actualRequests.size());
+
+ String apiClientHeaderKey =
+ mockService
+ .getRequestHeaders()
+ .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
+ .iterator()
+ .next();
+ Assert.assertTrue(
+ GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
+ .matcher(apiClientHeaderKey)
+ .matches());
+ }
+
+ @Test
+ public void importDocumentsExceptionTest2() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ String name = "projects/project-2580/databases/database-2580";
+ client.importDocumentsAsync(name).get();
+ Assert.fail("No exception raised");
+ } catch (ExecutionException e) {
+ }
+ }
+
+ @Test
+ public void getDatabaseTest() throws Exception {
+ Database expectedResponse =
+ Database.newBuilder()
+ .setName(DatabaseName.of("[PROJECT]", "[DATABASE]").toString())
+ .setLocationId("locationId1541836720")
+ .setKeyPrefix("keyPrefix-2076395055")
+ .setEtag("etag3123477")
+ .build();
+ mockService.addResponse(expectedResponse);
+
+ DatabaseName name = DatabaseName.of("[PROJECT]", "[DATABASE]");
+
+ Database actualResponse = client.getDatabase(name);
+ Assert.assertEquals(expectedResponse, actualResponse);
+
+ List actualRequests = mockService.getRequestPaths();
+ Assert.assertEquals(1, actualRequests.size());
+
+ String apiClientHeaderKey =
+ mockService
+ .getRequestHeaders()
+ .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
+ .iterator()
+ .next();
+ Assert.assertTrue(
+ GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
+ .matcher(apiClientHeaderKey)
+ .matches());
+ }
+
+ @Test
+ public void getDatabaseExceptionTest() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ DatabaseName name = DatabaseName.of("[PROJECT]", "[DATABASE]");
+ client.getDatabase(name);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void getDatabaseTest2() throws Exception {
+ Database expectedResponse =
+ Database.newBuilder()
+ .setName(DatabaseName.of("[PROJECT]", "[DATABASE]").toString())
+ .setLocationId("locationId1541836720")
+ .setKeyPrefix("keyPrefix-2076395055")
+ .setEtag("etag3123477")
+ .build();
+ mockService.addResponse(expectedResponse);
+
+ String name = "projects/project-2580/databases/database-2580";
+
+ Database actualResponse = client.getDatabase(name);
+ Assert.assertEquals(expectedResponse, actualResponse);
+
+ List actualRequests = mockService.getRequestPaths();
+ Assert.assertEquals(1, actualRequests.size());
+
+ String apiClientHeaderKey =
+ mockService
+ .getRequestHeaders()
+ .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
+ .iterator()
+ .next();
+ Assert.assertTrue(
+ GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
+ .matcher(apiClientHeaderKey)
+ .matches());
+ }
+
+ @Test
+ public void getDatabaseExceptionTest2() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ String name = "projects/project-2580/databases/database-2580";
+ client.getDatabase(name);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void listDatabasesTest() throws Exception {
+ ListDatabasesResponse expectedResponse =
+ ListDatabasesResponse.newBuilder().addAllDatabases(new ArrayList()).build();
+ mockService.addResponse(expectedResponse);
+
+ ProjectName parent = ProjectName.of("[PROJECT]");
+
+ ListDatabasesResponse actualResponse = client.listDatabases(parent);
+ Assert.assertEquals(expectedResponse, actualResponse);
+
+ List actualRequests = mockService.getRequestPaths();
+ Assert.assertEquals(1, actualRequests.size());
+
+ String apiClientHeaderKey =
+ mockService
+ .getRequestHeaders()
+ .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
+ .iterator()
+ .next();
+ Assert.assertTrue(
+ GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
+ .matcher(apiClientHeaderKey)
+ .matches());
+ }
+
+ @Test
+ public void listDatabasesExceptionTest() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ ProjectName parent = ProjectName.of("[PROJECT]");
+ client.listDatabases(parent);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void listDatabasesTest2() throws Exception {
+ ListDatabasesResponse expectedResponse =
+ ListDatabasesResponse.newBuilder().addAllDatabases(new ArrayList()).build();
+ mockService.addResponse(expectedResponse);
+
+ String parent = "projects/project-2353";
+
+ ListDatabasesResponse actualResponse = client.listDatabases(parent);
+ Assert.assertEquals(expectedResponse, actualResponse);
+
+ List actualRequests = mockService.getRequestPaths();
+ Assert.assertEquals(1, actualRequests.size());
+
+ String apiClientHeaderKey =
+ mockService
+ .getRequestHeaders()
+ .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
+ .iterator()
+ .next();
+ Assert.assertTrue(
+ GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
+ .matcher(apiClientHeaderKey)
+ .matches());
+ }
+
+ @Test
+ public void listDatabasesExceptionTest2() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ String parent = "projects/project-2353";
+ client.listDatabases(parent);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void updateDatabaseTest() throws Exception {
+ Database expectedResponse =
+ Database.newBuilder()
+ .setName(DatabaseName.of("[PROJECT]", "[DATABASE]").toString())
+ .setLocationId("locationId1541836720")
+ .setKeyPrefix("keyPrefix-2076395055")
+ .setEtag("etag3123477")
+ .build();
+ Operation resultOperation =
+ Operation.newBuilder()
+ .setName("updateDatabaseTest")
+ .setDone(true)
+ .setResponse(Any.pack(expectedResponse))
+ .build();
+ mockService.addResponse(resultOperation);
+
+ Database database =
+ Database.newBuilder()
+ .setName(DatabaseName.of("[PROJECT]", "[DATABASE]").toString())
+ .setLocationId("locationId1541836720")
+ .setKeyPrefix("keyPrefix-2076395055")
+ .setEtag("etag3123477")
+ .build();
+ FieldMask updateMask = FieldMask.newBuilder().build();
+
+ Database actualResponse = client.updateDatabaseAsync(database, updateMask).get();
+ Assert.assertEquals(expectedResponse, actualResponse);
+
+ List actualRequests = mockService.getRequestPaths();
+ Assert.assertEquals(1, actualRequests.size());
+
+ String apiClientHeaderKey =
+ mockService
+ .getRequestHeaders()
+ .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
+ .iterator()
+ .next();
+ Assert.assertTrue(
+ GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
+ .matcher(apiClientHeaderKey)
+ .matches());
+ }
+
+ @Test
+ public void updateDatabaseExceptionTest() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ Database database =
+ Database.newBuilder()
+ .setName(DatabaseName.of("[PROJECT]", "[DATABASE]").toString())
+ .setLocationId("locationId1541836720")
+ .setKeyPrefix("keyPrefix-2076395055")
+ .setEtag("etag3123477")
+ .build();
+ FieldMask updateMask = FieldMask.newBuilder().build();
+ client.updateDatabaseAsync(database, updateMask).get();
+ Assert.fail("No exception raised");
+ } catch (ExecutionException e) {
+ }
+ }
+}
diff --git a/google-cloud-firestore-admin/src/test/java/com/google/cloud/firestore/v1/FirestoreAdminClientTest.java b/google-cloud-firestore-admin/src/test/java/com/google/cloud/firestore/v1/FirestoreAdminClientTest.java
index f8c7c7baba..322489ce3b 100644
--- a/google-cloud-firestore-admin/src/test/java/com/google/cloud/firestore/v1/FirestoreAdminClientTest.java
+++ b/google-cloud-firestore-admin/src/test/java/com/google/cloud/firestore/v1/FirestoreAdminClientTest.java
@@ -452,6 +452,7 @@ public void getFieldTest() throws Exception {
Field.newBuilder()
.setName(FieldName.of("[PROJECT]", "[DATABASE]", "[COLLECTION]", "[FIELD]").toString())
.setIndexConfig(Field.IndexConfig.newBuilder().build())
+ .setTtlConfig(Field.TtlConfig.newBuilder().build())
.build();
mockFirestoreAdmin.addResponse(expectedResponse);
@@ -491,6 +492,7 @@ public void getFieldTest2() throws Exception {
Field.newBuilder()
.setName(FieldName.of("[PROJECT]", "[DATABASE]", "[COLLECTION]", "[FIELD]").toString())
.setIndexConfig(Field.IndexConfig.newBuilder().build())
+ .setTtlConfig(Field.TtlConfig.newBuilder().build())
.build();
mockFirestoreAdmin.addResponse(expectedResponse);
@@ -530,6 +532,7 @@ public void updateFieldTest() throws Exception {
Field.newBuilder()
.setName(FieldName.of("[PROJECT]", "[DATABASE]", "[COLLECTION]", "[FIELD]").toString())
.setIndexConfig(Field.IndexConfig.newBuilder().build())
+ .setTtlConfig(Field.TtlConfig.newBuilder().build())
.build();
Operation resultOperation =
Operation.newBuilder()
@@ -838,6 +841,7 @@ public void getDatabaseTest() throws Exception {
Database.newBuilder()
.setName(DatabaseName.of("[PROJECT]", "[DATABASE]").toString())
.setLocationId("locationId1541836720")
+ .setKeyPrefix("keyPrefix-2076395055")
.setEtag("etag3123477")
.build();
mockFirestoreAdmin.addResponse(expectedResponse);
@@ -878,6 +882,7 @@ public void getDatabaseTest2() throws Exception {
Database.newBuilder()
.setName(DatabaseName.of("[PROJECT]", "[DATABASE]").toString())
.setLocationId("locationId1541836720")
+ .setKeyPrefix("keyPrefix-2076395055")
.setEtag("etag3123477")
.build();
mockFirestoreAdmin.addResponse(expectedResponse);
@@ -990,6 +995,7 @@ public void updateDatabaseTest() throws Exception {
Database.newBuilder()
.setName(DatabaseName.of("[PROJECT]", "[DATABASE]").toString())
.setLocationId("locationId1541836720")
+ .setKeyPrefix("keyPrefix-2076395055")
.setEtag("etag3123477")
.build();
Operation resultOperation =
diff --git a/google-cloud-firestore-bom/pom.xml b/google-cloud-firestore-bom/pom.xml
index f7541447a2..b3ba3c103c 100644
--- a/google-cloud-firestore-bom/pom.xml
+++ b/google-cloud-firestore-bom/pom.xml
@@ -3,12 +3,12 @@
4.0.0
com.google.cloud
google-cloud-firestore-bom
- 3.3.0
+ 3.4.0
pom
com.google.cloud
google-cloud-shared-config
- 1.5.0
+ 1.5.3
Google Cloud Firestore BOM
@@ -52,37 +52,37 @@
com.google.cloud
google-cloud-firestore
- 3.3.0
+ 3.4.0
com.google.cloud
google-cloud-firestore-admin
- 3.3.0
+ 3.4.0
com.google.api.grpc
grpc-google-cloud-firestore-admin-v1
- 3.3.0
+ 3.4.0
com.google.api.grpc
grpc-google-cloud-firestore-v1
- 3.3.0
+ 3.4.0
com.google.api.grpc
proto-google-cloud-firestore-admin-v1
- 3.3.0
+ 3.4.0
com.google.api.grpc
proto-google-cloud-firestore-v1
- 3.3.0
+ 3.4.0
com.google.cloud
proto-google-cloud-firestore-bundle-v1
- 3.3.0
+ 3.4.0
diff --git a/google-cloud-firestore/pom.xml b/google-cloud-firestore/pom.xml
index b2c5ed5b0f..405f6d25d8 100644
--- a/google-cloud-firestore/pom.xml
+++ b/google-cloud-firestore/pom.xml
@@ -2,7 +2,7 @@
4.0.0
google-cloud-firestore
- 3.3.0
+ 3.4.0
jar
Google Cloud Firestore
https://github.com/googleapis/java-firestore
@@ -12,7 +12,7 @@
com.google.cloud
google-cloud-firestore-parent
- 3.3.0
+ 3.4.0
google-cloud-firestore
@@ -79,6 +79,10 @@
com.google.api
gax-grpc
+
+ com.google.api
+ gax-httpjson
+
com.google.guava
guava
@@ -103,10 +107,6 @@
com.google.cloud
google-cloud-core
-
- com.google.code.gson
- gson
-
com.google.protobuf
protobuf-java-util
@@ -130,17 +130,34 @@
1.10.19
test
+
+ com.google.code.gson
+ gson
+ test
+
+
+ com.google.api
+ gax
+ testlib
+ test
+
com.google.api
gax-grpc
testlib
test
+
+ com.google.api
+ gax-httpjson
+ testlib
+ test
+
com.google.cloud
google-cloud-conformance-tests
- 0.3.0
+ 0.3.3
test
diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/BulkWriter.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/BulkWriter.java
index d0c134736c..8c32e0da5c 100644
--- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/BulkWriter.java
+++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/BulkWriter.java
@@ -94,7 +94,7 @@ enum OperationType {
/**
* The starting maximum number of operations per second as allowed by the 500/50/5 rule.
*
- * @see Ramping
+ * @see Ramping
* up traffic
*/
static final int DEFAULT_STARTING_MAXIMUM_OPS_PER_SECOND = 500;
@@ -102,7 +102,7 @@ enum OperationType {
/**
* The rate by which to increase the capacity as specified by the 500/50/5 rule.
*
- * @see Ramping
+ * @see Ramping
* up traffic
*/
private static final double RATE_LIMITER_MULTIPLIER = 1.5;
@@ -111,7 +111,7 @@ enum OperationType {
* How often the operations per second capacity should increase in milliseconds as specified by
* the 500/50/5 rule.
*
- * @see Ramping
+ * @see Ramping
* up traffic
*/
private static final int RATE_LIMITER_MULTIPLIER_MILLIS = 5 * 60 * 1000;
diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Filter.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Filter.java
new file mode 100644
index 0000000000..0e25187dd5
--- /dev/null
+++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Filter.java
@@ -0,0 +1,184 @@
+/*
+ * Copyright 2022 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.cloud.firestore;
+
+import com.google.firestore.v1.StructuredQuery;
+import com.google.firestore.v1.StructuredQuery.FieldFilter.Operator;
+import java.util.Arrays;
+import java.util.List;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+/** @hide */
+public class Filter {
+ static class UnaryFilter extends Filter {
+ private final FieldPath field;
+ private final Operator operator;
+ private final Object value;
+
+ public UnaryFilter(FieldPath field, Operator operator, @Nullable Object value) {
+ this.field = field;
+ this.operator = operator;
+ this.value = value;
+ }
+
+ public FieldPath getField() {
+ return field;
+ }
+
+ public Operator getOperator() {
+ return operator;
+ }
+
+ @Nullable
+ public Object getValue() {
+ return value;
+ }
+ }
+
+ static class CompositeFilter extends Filter {
+ private final List filters;
+ private final StructuredQuery.CompositeFilter.Operator operator;
+
+ public CompositeFilter(
+ @Nonnull List filters, StructuredQuery.CompositeFilter.Operator operator) {
+ this.filters = filters;
+ this.operator = operator;
+ }
+
+ public List getFilters() {
+ return filters;
+ }
+
+ public StructuredQuery.CompositeFilter.Operator getOperator() {
+ return operator;
+ }
+ }
+
+ @Nonnull
+ public static Filter equalTo(@Nonnull String field, @Nullable Object value) {
+ return equalTo(FieldPath.fromDotSeparatedString(field), value);
+ }
+
+ @Nonnull
+ public static Filter equalTo(@Nonnull FieldPath fieldPath, @Nullable Object value) {
+ return new UnaryFilter(fieldPath, Operator.EQUAL, value);
+ }
+
+ @Nonnull
+ public static Filter notEqualTo(@Nonnull String field, @Nullable Object value) {
+ return notEqualTo(FieldPath.fromDotSeparatedString(field), value);
+ }
+
+ @Nonnull
+ public static Filter notEqualTo(@Nonnull FieldPath fieldPath, @Nullable Object value) {
+ return new UnaryFilter(fieldPath, Operator.NOT_EQUAL, value);
+ }
+
+ @Nonnull
+ public static Filter greaterThan(@Nonnull String field, @Nullable Object value) {
+ return greaterThan(FieldPath.fromDotSeparatedString(field), value);
+ }
+
+ @Nonnull
+ public static Filter greaterThan(@Nonnull FieldPath fieldPath, @Nullable Object value) {
+ return new UnaryFilter(fieldPath, Operator.GREATER_THAN, value);
+ }
+
+ @Nonnull
+ public static Filter greaterThanOrEqualTo(@Nonnull String field, @Nullable Object value) {
+ return greaterThanOrEqualTo(FieldPath.fromDotSeparatedString(field), value);
+ }
+
+ @Nonnull
+ public static Filter greaterThanOrEqualTo(@Nonnull FieldPath fieldPath, @Nullable Object value) {
+ return new UnaryFilter(fieldPath, Operator.GREATER_THAN_OR_EQUAL, value);
+ }
+
+ @Nonnull
+ public static Filter lessThan(@Nonnull String field, @Nullable Object value) {
+ return lessThan(FieldPath.fromDotSeparatedString(field), value);
+ }
+
+ @Nonnull
+ public static Filter lessThan(@Nonnull FieldPath fieldPath, @Nullable Object value) {
+ return new UnaryFilter(fieldPath, Operator.LESS_THAN, value);
+ }
+
+ @Nonnull
+ public static Filter lessThanOrEqualTo(@Nonnull String field, @Nullable Object value) {
+ return lessThanOrEqualTo(FieldPath.fromDotSeparatedString(field), value);
+ }
+
+ @Nonnull
+ public static Filter lessThanOrEqualTo(@Nonnull FieldPath fieldPath, @Nullable Object value) {
+ return new UnaryFilter(fieldPath, Operator.LESS_THAN_OR_EQUAL, value);
+ }
+
+ @Nonnull
+ public static Filter arrayContains(@Nonnull String field, @Nullable Object value) {
+ return arrayContains(FieldPath.fromDotSeparatedString(field), value);
+ }
+
+ @Nonnull
+ public static Filter arrayContains(@Nonnull FieldPath fieldPath, @Nullable Object value) {
+ return new UnaryFilter(fieldPath, Operator.ARRAY_CONTAINS, value);
+ }
+
+ @Nonnull
+ public static Filter arrayContainsAny(@Nonnull String field, @Nullable Object value) {
+ return arrayContainsAny(FieldPath.fromDotSeparatedString(field), value);
+ }
+
+ @Nonnull
+ public static Filter arrayContainsAny(@Nonnull FieldPath fieldPath, @Nullable Object value) {
+ return new UnaryFilter(fieldPath, Operator.ARRAY_CONTAINS_ANY, value);
+ }
+
+ @Nonnull
+ public static Filter inArray(@Nonnull String field, @Nullable Object value) {
+ return inArray(FieldPath.fromDotSeparatedString(field), value);
+ }
+
+ @Nonnull
+ public static Filter inArray(@Nonnull FieldPath fieldPath, @Nullable Object value) {
+ return new UnaryFilter(fieldPath, Operator.IN, value);
+ }
+
+ @Nonnull
+ public static Filter notInArray(@Nonnull String field, @Nullable Object value) {
+ return notInArray(FieldPath.fromDotSeparatedString(field), value);
+ }
+
+ @Nonnull
+ public static Filter notInArray(@Nonnull FieldPath fieldPath, @Nullable Object value) {
+ return new UnaryFilter(fieldPath, Operator.NOT_IN, value);
+ }
+
+ @Nonnull
+ public static Filter or(Filter... filters) {
+ // TODO(orquery): Change this to Operator.OR once it is available.
+ return new CompositeFilter(
+ Arrays.asList(filters), StructuredQuery.CompositeFilter.Operator.OPERATOR_UNSPECIFIED);
+ }
+
+ @Nonnull
+ public static Filter and(Filter... filters) {
+ return new CompositeFilter(
+ Arrays.asList(filters), StructuredQuery.CompositeFilter.Operator.AND);
+ }
+}
diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Firestore.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Firestore.java
index 5175fd1b4a..56f1fc65a8 100644
--- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Firestore.java
+++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Firestore.java
@@ -173,7 +173,7 @@ void getAll(
* Creates a {@link BulkWriter} instance, used for performing multiple writes in parallel.
* Gradually ramps up writes as specified by the 500/50/5 rule.
*
- * @see Ramping
+ * @see Ramping
* up traffic
*/
@BetaApi
@@ -185,7 +185,7 @@ void getAll(
* Gradually ramps up writes as specified by the 500/50/5 rule unless otherwise configured by a
* BulkWriterOptions object.
*
- * @see Ramping
+ * @see Ramping
* up traffic
* @param options An options object to configure BulkWriter.
*/
diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java
index 048f5ca695..5218b54e45 100644
--- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java
+++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java
@@ -50,6 +50,7 @@
import com.google.firestore.v1.StructuredQuery;
import com.google.firestore.v1.StructuredQuery.CollectionSelector;
import com.google.firestore.v1.StructuredQuery.CompositeFilter;
+import com.google.firestore.v1.StructuredQuery.FieldFilter.Operator;
import com.google.firestore.v1.StructuredQuery.FieldReference;
import com.google.firestore.v1.StructuredQuery.Filter;
import com.google.firestore.v1.StructuredQuery.Order;
@@ -60,6 +61,7 @@
import io.opencensus.trace.AttributeValue;
import io.opencensus.trace.Tracing;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
@@ -97,38 +99,138 @@ StructuredQuery.Direction getDirection() {
}
}
- abstract static class FieldFilter {
- protected final FieldReference fieldReference;
+ abstract static class FilterInternal {
+ /** Returns a list of all field filters that are contained within this filter */
+ abstract List getFlattenedFilters();
- FieldFilter(FieldReference fieldReference) {
- this.fieldReference = fieldReference;
- }
+ /** Returns a list of all filters that are contained within this filter */
+ abstract List getFilters();
- static FieldFilter fromProto(StructuredQuery.Filter filter) {
- Preconditions.checkArgument(
- !filter.hasCompositeFilter(), "Cannot deserialize nested composite filters");
+ /** Returns the field of the first filter that's an inequality, or null if none. */
+ @Nullable
+ abstract FieldReference getFirstInequalityField();
+
+ /** Returns the proto representation of this filter */
+ abstract Filter toProto();
+
+ static FilterInternal fromProto(StructuredQuery.Filter filter) {
+ if (filter.hasUnaryFilter()) {
+ return new UnaryFilterInternal(
+ filter.getUnaryFilter().getField(), filter.getUnaryFilter().getOp());
+ }
if (filter.hasFieldFilter()) {
- return new ComparisonFilter(
+ return new ComparisonFilterInternal(
filter.getFieldFilter().getField(),
filter.getFieldFilter().getOp(),
filter.getFieldFilter().getValue());
- } else {
- Preconditions.checkState(filter.hasUnaryFilter(), "Expected unary of field filter");
- return new UnaryFilter(filter.getUnaryFilter().getField(), filter.getUnaryFilter().getOp());
}
+
+ // `filter` must be a composite filter.
+ Preconditions.checkArgument(filter.hasCompositeFilter(), "Unknown filter type.");
+ CompositeFilter compositeFilter = filter.getCompositeFilter();
+ // A composite filter with only 1 sub-filter should be reduced to its sub-filter.
+ if (compositeFilter.getFiltersCount() == 1) {
+ return FilterInternal.fromProto(compositeFilter.getFiltersList().get(0));
+ }
+ List filters = new ArrayList<>();
+ for (StructuredQuery.Filter subfilter : compositeFilter.getFiltersList()) {
+ filters.add(FilterInternal.fromProto(subfilter));
+ }
+ return new CompositeFilterInternal(filters, compositeFilter.getOp());
+ }
+ }
+
+ static class CompositeFilterInternal extends FilterInternal {
+ private final List filters;
+ private final StructuredQuery.CompositeFilter.Operator operator;
+
+ // Memoized list of all field filters that can be found by traversing the tree of filters
+ // contained in this composite filter.
+ private List memoizedFlattenedFilters;
+
+ public CompositeFilterInternal(
+ List filters, StructuredQuery.CompositeFilter.Operator operator) {
+ this.filters = filters;
+ this.operator = operator;
+ }
+
+ @Override
+ public List getFilters() {
+ return filters;
+ }
+
+ @Nullable
+ @Override
+ public FieldReference getFirstInequalityField() {
+ for (FieldFilterInternal fieldFilter : getFlattenedFilters()) {
+ if (fieldFilter.isInequalityFilter()) {
+ return fieldFilter.fieldReference;
+ }
+ }
+ return null;
+ }
+
+ public boolean isConjunction() {
+ return operator == CompositeFilter.Operator.AND;
+ }
+
+ @Override
+ public List getFlattenedFilters() {
+ if (memoizedFlattenedFilters != null) {
+ return memoizedFlattenedFilters;
+ }
+ memoizedFlattenedFilters = new ArrayList<>();
+ for (FilterInternal subfilter : filters) {
+ memoizedFlattenedFilters.addAll(subfilter.getFlattenedFilters());
+ }
+ return memoizedFlattenedFilters;
+ }
+
+ @Override
+ Filter toProto() {
+ // A composite filter that contains one sub-filter is equivalent to the sub-filter.
+ if (filters.size() == 1) {
+ return filters.get(0).toProto();
+ }
+
+ Filter.Builder protoFilter = Filter.newBuilder();
+ StructuredQuery.CompositeFilter.Builder compositeFilter =
+ StructuredQuery.CompositeFilter.newBuilder();
+ compositeFilter.setOp(operator);
+ for (FilterInternal filter : filters) {
+ compositeFilter.addFilters(filter.toProto());
+ }
+ protoFilter.setCompositeFilter(compositeFilter.build());
+ return protoFilter.build();
+ }
+ }
+
+ abstract static class FieldFilterInternal extends FilterInternal {
+ protected final FieldReference fieldReference;
+
+ FieldFilterInternal(FieldReference fieldReference) {
+ this.fieldReference = fieldReference;
}
abstract boolean isInequalityFilter();
- abstract Filter toProto();
+ public List getFilters() {
+ return Collections.singletonList(this);
+ }
+
+ @Override
+ public List getFlattenedFilters() {
+ return Collections.singletonList(this);
+ }
}
- private static class UnaryFilter extends FieldFilter {
+ private static class UnaryFilterInternal extends FieldFilterInternal {
private final StructuredQuery.UnaryFilter.Operator operator;
- UnaryFilter(FieldReference fieldReference, StructuredQuery.UnaryFilter.Operator operator) {
+ UnaryFilterInternal(
+ FieldReference fieldReference, StructuredQuery.UnaryFilter.Operator operator) {
super(fieldReference);
this.operator = operator;
}
@@ -138,6 +240,12 @@ boolean isInequalityFilter() {
return false;
}
+ @Nullable
+ @Override
+ public FieldReference getFirstInequalityField() {
+ return null;
+ }
+
Filter toProto() {
Filter.Builder result = Filter.newBuilder();
result.getUnaryFilterBuilder().setField(fieldReference).setOp(operator);
@@ -149,20 +257,20 @@ public boolean equals(Object o) {
if (this == o) {
return true;
}
- if (!(o instanceof UnaryFilter)) {
+ if (!(o instanceof UnaryFilterInternal)) {
return false;
}
- UnaryFilter other = (UnaryFilter) o;
+ UnaryFilterInternal other = (UnaryFilterInternal) o;
return Objects.equals(fieldReference, other.fieldReference)
&& Objects.equals(operator, other.operator);
}
}
- static class ComparisonFilter extends FieldFilter {
+ static class ComparisonFilterInternal extends FieldFilterInternal {
final StructuredQuery.FieldFilter.Operator operator;
final Value value;
- ComparisonFilter(
+ ComparisonFilterInternal(
FieldReference fieldReference, StructuredQuery.FieldFilter.Operator operator, Value value) {
super(fieldReference);
this.value = value;
@@ -177,6 +285,15 @@ boolean isInequalityFilter() {
|| operator.equals(LESS_THAN_OR_EQUAL);
}
+ @Nullable
+ @Override
+ public FieldReference getFirstInequalityField() {
+ if (isInequalityFilter()) {
+ return fieldReference;
+ }
+ return null;
+ }
+
Filter toProto() {
Filter.Builder result = Filter.newBuilder();
result.getFieldFilterBuilder().setField(fieldReference).setValue(value).setOp(operator);
@@ -188,10 +305,10 @@ public boolean equals(Object o) {
if (this == o) {
return true;
}
- if (!(o instanceof ComparisonFilter)) {
+ if (!(o instanceof ComparisonFilterInternal)) {
return false;
}
- ComparisonFilter other = (ComparisonFilter) o;
+ ComparisonFilterInternal other = (ComparisonFilterInternal) o;
return Objects.equals(fieldReference, other.fieldReference)
&& Objects.equals(operator, other.operator)
&& Objects.equals(value, other.value);
@@ -252,7 +369,7 @@ abstract static class QueryOptions {
abstract @Nullable Cursor getEndCursor();
- abstract ImmutableList getFieldFilters();
+ abstract ImmutableList getFilters();
abstract ImmutableList getFieldOrders();
@@ -272,7 +389,7 @@ static Builder builder() {
.setAllDescendants(false)
.setLimitType(LimitType.First)
.setFieldOrders(ImmutableList.of())
- .setFieldFilters(ImmutableList.of())
+ .setFilters(ImmutableList.of())
.setFieldProjections(ImmutableList.of())
.setKindless(false)
.setRequireConsistency(true);
@@ -298,7 +415,7 @@ abstract static class Builder {
abstract Builder setEndCursor(@Nullable Cursor value);
- abstract Builder setFieldFilters(ImmutableList value);
+ abstract Builder setFilters(ImmutableList value);
abstract Builder setFieldOrders(ImmutableList value);
@@ -348,9 +465,10 @@ private ImmutableList createImplicitOrderBy() {
// If no explicit ordering is specified, use the first inequality to define an implicit order.
if (implicitOrders.isEmpty()) {
- for (FieldFilter fieldFilter : options.getFieldFilters()) {
- if (fieldFilter.isInequalityFilter()) {
- implicitOrders.add(new FieldOrder(fieldFilter.fieldReference, Direction.ASCENDING));
+ for (FilterInternal filter : options.getFilters()) {
+ FieldReference fieldReference = filter.getFirstInequalityField();
+ if (fieldReference != null) {
+ implicitOrders.add(new FieldOrder(fieldReference, Direction.ASCENDING));
break;
}
}
@@ -499,23 +617,7 @@ public Query whereEqualTo(@Nonnull String field, @Nullable Object value) {
*/
@Nonnull
public Query whereEqualTo(@Nonnull FieldPath fieldPath, @Nullable Object value) {
- Preconditions.checkState(
- options.getStartCursor() == null && options.getEndCursor() == null,
- "Cannot call whereEqualTo() after defining a boundary with startAt(), "
- + "startAfter(), endBefore() or endAt().");
-
- if (isUnaryComparison(value)) {
- Builder newOptions = options.toBuilder();
- StructuredQuery.UnaryFilter.Operator op =
- value == null
- ? StructuredQuery.UnaryFilter.Operator.IS_NULL
- : StructuredQuery.UnaryFilter.Operator.IS_NAN;
- UnaryFilter newFieldFilter = new UnaryFilter(fieldPath.toProto(), op);
- newOptions.setFieldFilters(append(options.getFieldFilters(), newFieldFilter));
- return new Query(rpcContext, newOptions.build());
- } else {
- return whereHelper(fieldPath, EQUAL, value);
- }
+ return where(new com.google.cloud.firestore.Filter.UnaryFilter(fieldPath, EQUAL, value));
}
/**
@@ -541,23 +643,7 @@ public Query whereNotEqualTo(@Nonnull String field, @Nullable Object value) {
*/
@Nonnull
public Query whereNotEqualTo(@Nonnull FieldPath fieldPath, @Nullable Object value) {
- Preconditions.checkState(
- options.getStartCursor() == null && options.getEndCursor() == null,
- "Cannot call whereNotEqualTo() after defining a boundary with startAt(), "
- + "startAfter(), endBefore() or endAt().");
-
- if (isUnaryComparison(value)) {
- Builder newOptions = options.toBuilder();
- StructuredQuery.UnaryFilter.Operator op =
- value == null
- ? StructuredQuery.UnaryFilter.Operator.IS_NOT_NULL
- : StructuredQuery.UnaryFilter.Operator.IS_NOT_NAN;
- UnaryFilter newFieldFilter = new UnaryFilter(fieldPath.toProto(), op);
- newOptions.setFieldFilters(append(options.getFieldFilters(), newFieldFilter));
- return new Query(rpcContext, newOptions.build());
- } else {
- return whereHelper(fieldPath, NOT_EQUAL, value);
- }
+ return where(new com.google.cloud.firestore.Filter.UnaryFilter(fieldPath, NOT_EQUAL, value));
}
/**
@@ -583,11 +669,7 @@ public Query whereLessThan(@Nonnull String field, @Nonnull Object value) {
*/
@Nonnull
public Query whereLessThan(@Nonnull FieldPath fieldPath, @Nonnull Object value) {
- Preconditions.checkState(
- options.getStartCursor() == null && options.getEndCursor() == null,
- "Cannot call whereLessThan() after defining a boundary with startAt(), "
- + "startAfter(), endBefore() or endAt().");
- return whereHelper(fieldPath, LESS_THAN, value);
+ return where(new com.google.cloud.firestore.Filter.UnaryFilter(fieldPath, LESS_THAN, value));
}
/**
@@ -613,11 +695,8 @@ public Query whereLessThanOrEqualTo(@Nonnull String field, @Nonnull Object value
*/
@Nonnull
public Query whereLessThanOrEqualTo(@Nonnull FieldPath fieldPath, @Nonnull Object value) {
- Preconditions.checkState(
- options.getStartCursor() == null && options.getEndCursor() == null,
- "Cannot call whereLessThanOrEqualTo() after defining a boundary with startAt(), "
- + "startAfter(), endBefore() or endAt().");
- return whereHelper(fieldPath, LESS_THAN_OR_EQUAL, value);
+ return where(
+ new com.google.cloud.firestore.Filter.UnaryFilter(fieldPath, LESS_THAN_OR_EQUAL, value));
}
/**
@@ -643,11 +722,7 @@ public Query whereGreaterThan(@Nonnull String field, @Nonnull Object value) {
*/
@Nonnull
public Query whereGreaterThan(@Nonnull FieldPath fieldPath, @Nonnull Object value) {
- Preconditions.checkState(
- options.getStartCursor() == null && options.getEndCursor() == null,
- "Cannot call whereGreaterThan() after defining a boundary with startAt(), "
- + "startAfter(), endBefore() or endAt().");
- return whereHelper(fieldPath, GREATER_THAN, value);
+ return where(new com.google.cloud.firestore.Filter.UnaryFilter(fieldPath, GREATER_THAN, value));
}
/**
@@ -673,11 +748,8 @@ public Query whereGreaterThanOrEqualTo(@Nonnull String field, @Nonnull Object va
*/
@Nonnull
public Query whereGreaterThanOrEqualTo(@Nonnull FieldPath fieldPath, @Nonnull Object value) {
- Preconditions.checkState(
- options.getStartCursor() == null && options.getEndCursor() == null,
- "Cannot call whereGreaterThanOrEqualTo() after defining a boundary with startAt(), "
- + "startAfter(), endBefore() or endAt().");
- return whereHelper(fieldPath, GREATER_THAN_OR_EQUAL, value);
+ return where(
+ new com.google.cloud.firestore.Filter.UnaryFilter(fieldPath, GREATER_THAN_OR_EQUAL, value));
}
/**
@@ -711,11 +783,8 @@ public Query whereArrayContains(@Nonnull String field, @Nonnull Object value) {
*/
@Nonnull
public Query whereArrayContains(@Nonnull FieldPath fieldPath, @Nonnull Object value) {
- Preconditions.checkState(
- options.getStartCursor() == null && options.getEndCursor() == null,
- "Cannot call whereArrayContains() after defining a boundary with startAt(), "
- + "startAfter(), endBefore() or endAt().");
- return whereHelper(fieldPath, ARRAY_CONTAINS, value);
+ return where(
+ new com.google.cloud.firestore.Filter.UnaryFilter(fieldPath, ARRAY_CONTAINS, value));
}
/**
@@ -733,11 +802,7 @@ public Query whereArrayContains(@Nonnull FieldPath fieldPath, @Nonnull Object va
@Nonnull
public Query whereArrayContainsAny(
@Nonnull String field, @Nonnull List extends Object> values) {
- Preconditions.checkState(
- options.getStartCursor() == null && options.getEndCursor() == null,
- "Cannot call whereArrayContainsAny() after defining a boundary with startAt(), "
- + "startAfter(), endBefore() or endAt().");
- return whereHelper(FieldPath.fromDotSeparatedString(field), ARRAY_CONTAINS_ANY, values);
+ return whereArrayContainsAny(FieldPath.fromDotSeparatedString(field), values);
}
/**
@@ -755,11 +820,8 @@ public Query whereArrayContainsAny(
@Nonnull
public Query whereArrayContainsAny(
@Nonnull FieldPath fieldPath, @Nonnull List extends Object> values) {
- Preconditions.checkState(
- options.getStartCursor() == null && options.getEndCursor() == null,
- "Cannot call whereArrayContainsAny() after defining a boundary with startAt(), "
- + "startAfter(), endBefore() or endAt().");
- return whereHelper(fieldPath, ARRAY_CONTAINS_ANY, values);
+ return where(
+ new com.google.cloud.firestore.Filter.UnaryFilter(fieldPath, ARRAY_CONTAINS_ANY, values));
}
/**
@@ -775,11 +837,7 @@ public Query whereArrayContainsAny(
*/
@Nonnull
public Query whereIn(@Nonnull String field, @Nonnull List extends Object> values) {
- Preconditions.checkState(
- options.getStartCursor() == null && options.getEndCursor() == null,
- "Cannot call whereIn() after defining a boundary with startAt(), "
- + "startAfter(), endBefore() or endAt().");
- return whereHelper(FieldPath.fromDotSeparatedString(field), IN, values);
+ return whereIn(FieldPath.fromDotSeparatedString(field), values);
}
/**
@@ -795,11 +853,7 @@ public Query whereIn(@Nonnull String field, @Nonnull List extends Object> valu
*/
@Nonnull
public Query whereIn(@Nonnull FieldPath fieldPath, @Nonnull List extends Object> values) {
- Preconditions.checkState(
- options.getStartCursor() == null && options.getEndCursor() == null,
- "Cannot call whereIn() after defining a boundary with startAt(), "
- + "startAfter(), endBefore() or endAt().");
- return whereHelper(fieldPath, IN, values);
+ return where(new com.google.cloud.firestore.Filter.UnaryFilter(fieldPath, IN, values));
}
/**
@@ -815,11 +869,7 @@ public Query whereIn(@Nonnull FieldPath fieldPath, @Nonnull List extends Objec
*/
@Nonnull
public Query whereNotIn(@Nonnull String field, @Nonnull List extends Object> values) {
- Preconditions.checkState(
- options.getStartCursor() == null && options.getEndCursor() == null,
- "Cannot call whereNotIn() after defining a boundary with startAt(), "
- + "startAfter(), endBefore() or endAt().");
- return whereHelper(FieldPath.fromDotSeparatedString(field), NOT_IN, values);
+ return whereNotIn(FieldPath.fromDotSeparatedString(field), values);
}
/**
@@ -835,49 +885,99 @@ public Query whereNotIn(@Nonnull String field, @Nonnull List extends Object> v
*/
@Nonnull
public Query whereNotIn(@Nonnull FieldPath fieldPath, @Nonnull List extends Object> values) {
+ return where(new com.google.cloud.firestore.Filter.UnaryFilter(fieldPath, NOT_IN, values));
+ }
+
+ // TODO(orquery): This method will become public API. Change visibility and add documentation.
+ Query where(com.google.cloud.firestore.Filter filter) {
Preconditions.checkState(
options.getStartCursor() == null && options.getEndCursor() == null,
- "Cannot call whereNotIn() after defining a boundary with startAt(), "
+ "Cannot call a where() clause after defining a boundary with startAt(), "
+ "startAfter(), endBefore() or endAt().");
- return whereHelper(fieldPath, NOT_IN, values);
+ FilterInternal parsedFilter = parseFilter(filter);
+ if (parsedFilter.getFilters().isEmpty()) {
+ // Return the existing query if not adding any more filters (e.g. an empty composite filter).
+ return this;
+ }
+ Builder newOptions = options.toBuilder();
+ newOptions.setFilters(append(options.getFilters(), parsedFilter));
+ return new Query(rpcContext, newOptions.build());
}
- private Query whereHelper(
- FieldPath fieldPath, StructuredQuery.FieldFilter.Operator operator, Object value) {
- Preconditions.checkArgument(
- !isUnaryComparison(value),
- "Cannot use '%s' in field comparison. Use an equality filter instead.",
- value);
+ FilterInternal parseFilter(com.google.cloud.firestore.Filter filter) {
+ if (filter instanceof com.google.cloud.firestore.Filter.UnaryFilter) {
+ return parseFieldFilter((com.google.cloud.firestore.Filter.UnaryFilter) filter);
+ }
+ return parseCompositeFilter((com.google.cloud.firestore.Filter.CompositeFilter) filter);
+ }
- if (fieldPath.equals(FieldPath.DOCUMENT_ID)) {
- if (operator == ARRAY_CONTAINS || operator == ARRAY_CONTAINS_ANY) {
+ private FieldFilterInternal parseFieldFilter(
+ com.google.cloud.firestore.Filter.UnaryFilter fieldFilterData) {
+ Object value = fieldFilterData.getValue();
+ Operator operator = fieldFilterData.getOperator();
+ FieldPath fieldPath = fieldFilterData.getField();
+
+ if (isUnaryComparison(value)) {
+ if (operator.equals(EQUAL) || operator.equals(NOT_EQUAL)) {
+ StructuredQuery.UnaryFilter.Operator unaryOp =
+ operator.equals(EQUAL)
+ ? (value == null
+ ? StructuredQuery.UnaryFilter.Operator.IS_NULL
+ : StructuredQuery.UnaryFilter.Operator.IS_NAN)
+ : (value == null
+ ? StructuredQuery.UnaryFilter.Operator.IS_NOT_NULL
+ : StructuredQuery.UnaryFilter.Operator.IS_NOT_NAN);
+ return new UnaryFilterInternal(fieldPath.toProto(), unaryOp);
+ } else {
throw new IllegalArgumentException(
String.format(
- "Invalid query. You cannot perform '%s' queries on FieldPath.documentId().",
- operator.toString()));
- } else if (operator == IN | operator == NOT_IN) {
- if (!(value instanceof List) || ((List>) value).isEmpty()) {
+ "Cannot use '%s' in field comparison. Use an equality filter instead.", value));
+ }
+ } else {
+ if (fieldPath.equals(FieldPath.DOCUMENT_ID)) {
+ if (operator.equals(ARRAY_CONTAINS) || operator.equals(ARRAY_CONTAINS_ANY)) {
throw new IllegalArgumentException(
String.format(
- "Invalid Query. A non-empty array is required for '%s' filters.",
+ "Invalid query. You cannot perform '%s' queries on FieldPath.documentId().",
operator.toString()));
+ } else if (operator.equals(IN) || operator.equals(NOT_IN)) {
+ if (!(value instanceof List) || ((List>) value).isEmpty()) {
+ throw new IllegalArgumentException(
+ String.format(
+ "Invalid Query. A non-empty array is required for '%s' filters.",
+ operator.toString()));
+ }
+ List referenceList = new ArrayList<>();
+ for (Object arrayValue : (List) value) {
+ Object convertedValue = this.convertReference(arrayValue);
+ referenceList.add(convertedValue);
+ }
+ value = referenceList;
+ } else {
+ value = this.convertReference(value);
}
- List referenceList = new ArrayList<>();
- for (Object arrayValue : (List) value) {
- Object convertedValue = this.convertReference(arrayValue);
- referenceList.add(convertedValue);
- }
- value = referenceList;
- } else {
- value = this.convertReference(value);
}
+ return new ComparisonFilterInternal(
+ fieldPath.toProto(), operator, encodeValue(fieldPath, value));
}
+ }
- Builder newOptions = options.toBuilder();
- ComparisonFilter newFieldFilter =
- new ComparisonFilter(fieldPath.toProto(), operator, encodeValue(fieldPath, value));
- newOptions.setFieldFilters(append(options.getFieldFilters(), newFieldFilter));
- return new Query(rpcContext, newOptions.build());
+ private FilterInternal parseCompositeFilter(
+ com.google.cloud.firestore.Filter.CompositeFilter compositeFilterData) {
+ List parsedFilters = new ArrayList<>();
+ for (com.google.cloud.firestore.Filter filter : compositeFilterData.getFilters()) {
+ FilterInternal parsedFilter = parseFilter(filter);
+ if (!parsedFilter.getFilters().isEmpty()) {
+ parsedFilters.add(parsedFilter);
+ }
+ }
+
+ // For composite filters containing 1 filter, return the only filter.
+ // For example: AND(FieldFilter1) == FieldFilter1
+ if (parsedFilters.size() == 1) {
+ return parsedFilters.get(0);
+ }
+ return new CompositeFilterInternal(parsedFilters, compositeFilterData.getOperator());
}
/**
@@ -1264,25 +1364,11 @@ private StructuredQuery.Builder buildWithoutClientTranslation() {
collectionSelector.setAllDescendants(options.getAllDescendants());
structuredQuery.addFrom(collectionSelector);
- if (options.getFieldFilters().size() == 1) {
- Filter filter = options.getFieldFilters().get(0).toProto();
- if (filter.hasFieldFilter()) {
- structuredQuery.getWhereBuilder().setFieldFilter(filter.getFieldFilter());
- } else {
- Preconditions.checkState(
- filter.hasUnaryFilter(), "Expected a UnaryFilter or a FieldFilter.");
- structuredQuery.getWhereBuilder().setUnaryFilter(filter.getUnaryFilter());
- }
- } else if (options.getFieldFilters().size() > 1) {
- Filter.Builder filter = Filter.newBuilder();
- StructuredQuery.CompositeFilter.Builder compositeFilter =
- StructuredQuery.CompositeFilter.newBuilder();
- compositeFilter.setOp(CompositeFilter.Operator.AND);
- for (FieldFilter fieldFilter : options.getFieldFilters()) {
- compositeFilter.addFilters(fieldFilter.toProto());
- }
- filter.setCompositeFilter(compositeFilter.build());
- structuredQuery.setWhere(filter.build());
+ // There's an implicit AND operation between the top-level query filters.
+ if (!options.getFilters().isEmpty()) {
+ FilterInternal filter =
+ new CompositeFilterInternal(options.getFilters(), CompositeFilter.Operator.AND);
+ structuredQuery.setWhere(filter.toProto());
}
if (!options.getFieldOrders().isEmpty()) {
@@ -1409,16 +1495,15 @@ private static Query fromProto(FirestoreRpcContext> rpcContext, RunQueryReques
queryOptions.setAllDescendants(structuredQuery.getFrom(0).getAllDescendants());
if (structuredQuery.hasWhere()) {
- Filter where = structuredQuery.getWhere();
- if (where.hasCompositeFilter()) {
- CompositeFilter compositeFilter = where.getCompositeFilter();
- ImmutableList.Builder fieldFilters = ImmutableList.builder();
- for (Filter filter : compositeFilter.getFiltersList()) {
- fieldFilters.add(FieldFilter.fromProto(filter));
- }
- queryOptions.setFieldFilters(fieldFilters.build());
+ FilterInternal filter = FilterInternal.fromProto(structuredQuery.getWhere());
+
+ // There's an implicit AND operation between the top-level query filters.
+ if (filter instanceof CompositeFilterInternal
+ && ((CompositeFilterInternal) filter).isConjunction()) {
+ queryOptions.setFilters(
+ new ImmutableList.Builder().addAll(filter.getFilters()).build());
} else {
- queryOptions.setFieldFilters(ImmutableList.of(FieldFilter.fromProto(where)));
+ queryOptions.setFilters(ImmutableList.of(filter));
}
}
diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/RateLimiter.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/RateLimiter.java
index d8ad3c674a..bf0e05dce8 100644
--- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/RateLimiter.java
+++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/RateLimiter.java
@@ -30,7 +30,7 @@
*