diff --git a/google-cloud-bom/pom.xml b/google-cloud-bom/pom.xml index 0506160c7c03..77aeeab577a8 100644 --- a/google-cloud-bom/pom.xml +++ b/google-cloud-bom/pom.xml @@ -172,8 +172,8 @@ 1.19.0 1.19.0 0.36.0 - 0.3.0 - 1.2.0 + 0.4.0 + 1.3.0 @@ -780,6 +780,16 @@ grpc-google-cloud-vision-v1p1beta1 ${generated-proto-beta.version} + + com.google.api.grpc + proto-google-cloud-vision-v1p2beta1 + ${generated-proto-ga.version} + + + com.google.api.grpc + grpc-google-cloud-vision-v1p2beta1 + ${generated-proto-ga.version} + com.google.cloud google-cloud-video-intelligence diff --git a/google-cloud-vision/pom.xml b/google-cloud-vision/pom.xml index 9f5372b3d1e3..9030bba35865 100644 --- a/google-cloud-vision/pom.xml +++ b/google-cloud-vision/pom.xml @@ -34,6 +34,10 @@ com.google.api.grpc proto-google-cloud-vision-v1p1beta1 + + com.google.api.grpc + proto-google-cloud-vision-v1p2beta1 + io.grpc grpc-netty-shaded @@ -77,6 +81,11 @@ grpc-google-cloud-vision-v1p1beta1 test + + com.google.api.grpc + grpc-google-cloud-vision-v1p2beta1 + test + com.google.api gax-grpc diff --git a/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p2beta1/ImageAnnotatorClient.java b/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p2beta1/ImageAnnotatorClient.java new file mode 100644 index 000000000000..0ccf242c109f --- /dev/null +++ b/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p2beta1/ImageAnnotatorClient.java @@ -0,0 +1,375 @@ +/* + * Copyright 2018 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.vision.v1p2beta1; + +import com.google.api.core.BetaApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.longrunning.OperationFuture; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.vision.v1p2beta1.stub.ImageAnnotatorStub; +import com.google.cloud.vision.v1p2beta1.stub.ImageAnnotatorStubSettings; +import com.google.longrunning.Operation; +import com.google.longrunning.OperationsClient; +import java.io.IOException; +import java.util.List; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND SERVICE +/** + * Service Description: Service that performs Google Cloud Vision API detection tasks over client + * images, such as face, landmark, logo, label, and text detection. The ImageAnnotator service + * returns detected entities from the images. + * + *

This class provides the ability to make remote calls to the backing service through method + * calls that map to API methods. Sample code to get started: + * + *

+ * 
+ * try (ImageAnnotatorClient imageAnnotatorClient = ImageAnnotatorClient.create()) {
+ *   List<AnnotateImageRequest> requests = new ArrayList<>();
+ *   BatchAnnotateImagesResponse response = imageAnnotatorClient.batchAnnotateImages(requests);
+ * }
+ * 
+ * 
+ * + *

Note: close() needs to be called on the imageAnnotatorClient object to clean up resources such + * as threads. In the example above, try-with-resources is used, which automatically calls close(). + * + *

The surface of this class includes several types of Java methods for each of the API's + * methods: + * + *

    + *
  1. A "flattened" method. With this type of method, the fields of the request type have been + * converted into function parameters. It may be the case that not all fields are available as + * parameters, and not every API method will have a flattened method entry point. + *
  2. A "request object" method. This type of method only takes one parameter, a request object, + * which must be constructed before the call. Not every API method will have a request object + * method. + *
  3. A "callable" method. This type of method takes no parameters and returns an immutable API + * callable object, which can be used to initiate calls to the service. + *
+ * + *

See the individual methods for example code. + * + *

Many parameters require resource names to be formatted in a particular way. To assist with + * these names, this class includes a format method for each type of name, and additionally a parse + * method to extract the individual identifiers contained within names that are returned. + * + *

This class can be customized by passing in a custom instance of ImageAnnotatorSettings to + * create(). For example: + * + *

To customize credentials: + * + *

+ * 
+ * ImageAnnotatorSettings imageAnnotatorSettings =
+ *     ImageAnnotatorSettings.newBuilder()
+ *         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
+ *         .build();
+ * ImageAnnotatorClient imageAnnotatorClient =
+ *     ImageAnnotatorClient.create(imageAnnotatorSettings);
+ * 
+ * 
+ * + * To customize the endpoint: + * + *
+ * 
+ * ImageAnnotatorSettings imageAnnotatorSettings =
+ *     ImageAnnotatorSettings.newBuilder().setEndpoint(myEndpoint).build();
+ * ImageAnnotatorClient imageAnnotatorClient =
+ *     ImageAnnotatorClient.create(imageAnnotatorSettings);
+ * 
+ * 
+ */ +@Generated("by GAPIC v0.0.5") +public class ImageAnnotatorClient implements BackgroundResource { + private final ImageAnnotatorSettings settings; + private final ImageAnnotatorStub stub; + private final OperationsClient operationsClient; + + /** Constructs an instance of ImageAnnotatorClient with default settings. */ + public static final ImageAnnotatorClient create() throws IOException { + return create(ImageAnnotatorSettings.newBuilder().build()); + } + + /** + * Constructs an instance of ImageAnnotatorClient, using the given settings. The channels are + * created based on the settings passed in, or defaults for any settings that are not set. + */ + public static final ImageAnnotatorClient create(ImageAnnotatorSettings settings) + throws IOException { + return new ImageAnnotatorClient(settings); + } + + /** + * Constructs an instance of ImageAnnotatorClient, using the given stub for making calls. This is + * for advanced usage - prefer to use ImageAnnotatorSettings}. + */ + @BetaApi("A restructuring of stub classes is planned, so this may break in the future") + public static final ImageAnnotatorClient create(ImageAnnotatorStub stub) { + return new ImageAnnotatorClient(stub); + } + + /** + * Constructs an instance of ImageAnnotatorClient, 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 ImageAnnotatorClient(ImageAnnotatorSettings settings) throws IOException { + this.settings = settings; + this.stub = ((ImageAnnotatorStubSettings) settings.getStubSettings()).createStub(); + this.operationsClient = OperationsClient.create(this.stub.getOperationsStub()); + } + + @BetaApi("A restructuring of stub classes is planned, so this may break in the future") + protected ImageAnnotatorClient(ImageAnnotatorStub stub) { + this.settings = null; + this.stub = stub; + this.operationsClient = OperationsClient.create(this.stub.getOperationsStub()); + } + + public final ImageAnnotatorSettings getSettings() { + return settings; + } + + @BetaApi("A restructuring of stub classes is planned, so this may break in the future") + public ImageAnnotatorStub getStub() { + return stub; + } + + /** + * 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() { + return operationsClient; + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Run image detection and annotation for a batch of images. + * + *

Sample code: + * + *


+   * try (ImageAnnotatorClient imageAnnotatorClient = ImageAnnotatorClient.create()) {
+   *   List<AnnotateImageRequest> requests = new ArrayList<>();
+   *   BatchAnnotateImagesResponse response = imageAnnotatorClient.batchAnnotateImages(requests);
+   * }
+   * 
+ * + * @param requests Individual image annotation requests for this batch. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final BatchAnnotateImagesResponse batchAnnotateImages( + List requests) { + + BatchAnnotateImagesRequest request = + BatchAnnotateImagesRequest.newBuilder().addAllRequests(requests).build(); + return batchAnnotateImages(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Run image detection and annotation for a batch of images. + * + *

Sample code: + * + *


+   * try (ImageAnnotatorClient imageAnnotatorClient = ImageAnnotatorClient.create()) {
+   *   List<AnnotateImageRequest> requests = new ArrayList<>();
+   *   BatchAnnotateImagesRequest request = BatchAnnotateImagesRequest.newBuilder()
+   *     .addAllRequests(requests)
+   *     .build();
+   *   BatchAnnotateImagesResponse response = imageAnnotatorClient.batchAnnotateImages(request);
+   * }
+   * 
+ * + * @param request The request object containing all of the parameters for the API call. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + private final BatchAnnotateImagesResponse batchAnnotateImages( + BatchAnnotateImagesRequest request) { + return batchAnnotateImagesCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Run image detection and annotation for a batch of images. + * + *

Sample code: + * + *


+   * try (ImageAnnotatorClient imageAnnotatorClient = ImageAnnotatorClient.create()) {
+   *   List<AnnotateImageRequest> requests = new ArrayList<>();
+   *   BatchAnnotateImagesRequest request = BatchAnnotateImagesRequest.newBuilder()
+   *     .addAllRequests(requests)
+   *     .build();
+   *   ApiFuture<BatchAnnotateImagesResponse> future = imageAnnotatorClient.batchAnnotateImagesCallable().futureCall(request);
+   *   // Do something
+   *   BatchAnnotateImagesResponse response = future.get();
+   * }
+   * 
+ */ + public final UnaryCallable + batchAnnotateImagesCallable() { + return stub.batchAnnotateImagesCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Run async image detection and annotation for a list of generic files (e.g. PDF) which may + * contain multiple pages and multiple images per page. Progress and results can be retrieved + * through the `google.longrunning.Operations` interface. `Operation.metadata` contains + * `OperationMetadata` (metadata). `Operation.response` contains `AsyncBatchAnnotateFilesResponse` + * (results). + * + *

Sample code: + * + *


+   * try (ImageAnnotatorClient imageAnnotatorClient = ImageAnnotatorClient.create()) {
+   *   List<AsyncAnnotateFileRequest> requests = new ArrayList<>();
+   *   AsyncBatchAnnotateFilesResponse response = imageAnnotatorClient.asyncBatchAnnotateFilesAsync(requests).get();
+   * }
+   * 
+ * + * @param requests Individual async file annotation requests for this batch. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final OperationFuture + asyncBatchAnnotateFilesAsync(List requests) { + + AsyncBatchAnnotateFilesRequest request = + AsyncBatchAnnotateFilesRequest.newBuilder().addAllRequests(requests).build(); + return asyncBatchAnnotateFilesAsync(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Run async image detection and annotation for a list of generic files (e.g. PDF) which may + * contain multiple pages and multiple images per page. Progress and results can be retrieved + * through the `google.longrunning.Operations` interface. `Operation.metadata` contains + * `OperationMetadata` (metadata). `Operation.response` contains `AsyncBatchAnnotateFilesResponse` + * (results). + * + *

Sample code: + * + *


+   * try (ImageAnnotatorClient imageAnnotatorClient = ImageAnnotatorClient.create()) {
+   *   List<AsyncAnnotateFileRequest> requests = new ArrayList<>();
+   *   AsyncBatchAnnotateFilesRequest request = AsyncBatchAnnotateFilesRequest.newBuilder()
+   *     .addAllRequests(requests)
+   *     .build();
+   *   AsyncBatchAnnotateFilesResponse response = imageAnnotatorClient.asyncBatchAnnotateFilesAsync(request).get();
+   * }
+   * 
+ * + * @param request The request object containing all of the parameters for the API call. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + private final OperationFuture + asyncBatchAnnotateFilesAsync(AsyncBatchAnnotateFilesRequest request) { + return asyncBatchAnnotateFilesOperationCallable().futureCall(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Run async image detection and annotation for a list of generic files (e.g. PDF) which may + * contain multiple pages and multiple images per page. Progress and results can be retrieved + * through the `google.longrunning.Operations` interface. `Operation.metadata` contains + * `OperationMetadata` (metadata). `Operation.response` contains `AsyncBatchAnnotateFilesResponse` + * (results). + * + *

Sample code: + * + *


+   * try (ImageAnnotatorClient imageAnnotatorClient = ImageAnnotatorClient.create()) {
+   *   List<AsyncAnnotateFileRequest> requests = new ArrayList<>();
+   *   AsyncBatchAnnotateFilesRequest request = AsyncBatchAnnotateFilesRequest.newBuilder()
+   *     .addAllRequests(requests)
+   *     .build();
+   *   OperationFuture<Operation> future = imageAnnotatorClient.asyncBatchAnnotateFilesOperationCallable().futureCall(request);
+   *   // Do something
+   *   AsyncBatchAnnotateFilesResponse response = future.get();
+   * }
+   * 
+ */ + public final OperationCallable< + AsyncBatchAnnotateFilesRequest, AsyncBatchAnnotateFilesResponse, OperationMetadata> + asyncBatchAnnotateFilesOperationCallable() { + return stub.asyncBatchAnnotateFilesOperationCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD + /** + * Run async image detection and annotation for a list of generic files (e.g. PDF) which may + * contain multiple pages and multiple images per page. Progress and results can be retrieved + * through the `google.longrunning.Operations` interface. `Operation.metadata` contains + * `OperationMetadata` (metadata). `Operation.response` contains `AsyncBatchAnnotateFilesResponse` + * (results). + * + *

Sample code: + * + *


+   * try (ImageAnnotatorClient imageAnnotatorClient = ImageAnnotatorClient.create()) {
+   *   List<AsyncAnnotateFileRequest> requests = new ArrayList<>();
+   *   AsyncBatchAnnotateFilesRequest request = AsyncBatchAnnotateFilesRequest.newBuilder()
+   *     .addAllRequests(requests)
+   *     .build();
+   *   ApiFuture<Operation> future = imageAnnotatorClient.asyncBatchAnnotateFilesCallable().futureCall(request);
+   *   // Do something
+   *   Operation response = future.get();
+   * }
+   * 
+ */ + public final UnaryCallable + asyncBatchAnnotateFilesCallable() { + return stub.asyncBatchAnnotateFilesCallable(); + } + + @Override + public final void close() throws Exception { + stub.close(); + } + + @Override + public void shutdown() { + stub.shutdown(); + } + + @Override + public boolean isShutdown() { + return stub.isShutdown(); + } + + @Override + public boolean isTerminated() { + return stub.isTerminated(); + } + + @Override + public void shutdownNow() { + stub.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return stub.awaitTermination(duration, unit); + } +} diff --git a/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p2beta1/ImageAnnotatorSettings.java b/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p2beta1/ImageAnnotatorSettings.java new file mode 100644 index 000000000000..475f6a56eb43 --- /dev/null +++ b/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p2beta1/ImageAnnotatorSettings.java @@ -0,0 +1,203 @@ +/* + * Copyright 2018 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.vision.v1p2beta1; + +import com.google.api.core.ApiFunction; +import com.google.api.core.BetaApi; +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.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientSettings; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.TransportChannelProvider; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.cloud.vision.v1p2beta1.stub.ImageAnnotatorStubSettings; +import com.google.longrunning.Operation; +import java.io.IOException; +import java.util.List; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * Settings class to configure an instance of {@link ImageAnnotatorClient}. + * + *

The default instance has everything set to sensible defaults: + * + *

    + *
  • The default service address (vision.googleapis.com) and default port (443) are used. + *
  • Credentials are acquired automatically through Application Default Credentials. + *
  • Retries are configured for idempotent methods but not for non-idempotent methods. + *
+ * + *

The builder of this class is recursive, so contained classes are themselves builders. When + * build() is called, the tree of builders is called to create the complete settings object. For + * example, to set the total timeout of batchAnnotateImages to 30 seconds: + * + *

+ * 
+ * ImageAnnotatorSettings.Builder imageAnnotatorSettingsBuilder =
+ *     ImageAnnotatorSettings.newBuilder();
+ * imageAnnotatorSettingsBuilder.batchAnnotateImagesSettings().getRetrySettingsBuilder()
+ *     .setTotalTimeout(Duration.ofSeconds(30));
+ * ImageAnnotatorSettings imageAnnotatorSettings = imageAnnotatorSettingsBuilder.build();
+ * 
+ * 
+ */ +@Generated("by GAPIC v0.0.5") +public class ImageAnnotatorSettings extends ClientSettings { + /** Returns the object with the settings used for calls to batchAnnotateImages. */ + public UnaryCallSettings + batchAnnotateImagesSettings() { + return ((ImageAnnotatorStubSettings) getStubSettings()).batchAnnotateImagesSettings(); + } + + /** Returns the object with the settings used for calls to asyncBatchAnnotateFiles. */ + public UnaryCallSettings + asyncBatchAnnotateFilesSettings() { + return ((ImageAnnotatorStubSettings) getStubSettings()).asyncBatchAnnotateFilesSettings(); + } + + /** Returns the object with the settings used for calls to asyncBatchAnnotateFiles. */ + public OperationCallSettings< + AsyncBatchAnnotateFilesRequest, AsyncBatchAnnotateFilesResponse, OperationMetadata> + asyncBatchAnnotateFilesOperationSettings() { + return ((ImageAnnotatorStubSettings) getStubSettings()) + .asyncBatchAnnotateFilesOperationSettings(); + } + + public static final ImageAnnotatorSettings create(ImageAnnotatorStubSettings stub) + throws IOException { + return new ImageAnnotatorSettings.Builder(stub.toBuilder()).build(); + } + + /** Returns a builder for the default ExecutorProvider for this service. */ + public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() { + return ImageAnnotatorStubSettings.defaultExecutorProviderBuilder(); + } + + /** Returns the default service endpoint. */ + public static String getDefaultEndpoint() { + return ImageAnnotatorStubSettings.getDefaultEndpoint(); + } + + /** Returns the default service scopes. */ + public static List getDefaultServiceScopes() { + return ImageAnnotatorStubSettings.getDefaultServiceScopes(); + } + + /** Returns a builder for the default credentials for this service. */ + public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() { + return ImageAnnotatorStubSettings.defaultCredentialsProviderBuilder(); + } + + /** Returns a builder for the default ChannelProvider for this service. */ + public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { + return ImageAnnotatorStubSettings.defaultGrpcTransportProviderBuilder(); + } + + public static TransportChannelProvider defaultTransportChannelProvider() { + return ImageAnnotatorStubSettings.defaultTransportChannelProvider(); + } + + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return ImageAnnotatorStubSettings.defaultApiClientHeaderProviderBuilder(); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder() { + return Builder.createDefault(); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder(ClientContext clientContext) { + return new Builder(clientContext); + } + + /** Returns a builder containing all the values of this settings class. */ + public Builder toBuilder() { + return new Builder(this); + } + + protected ImageAnnotatorSettings(Builder settingsBuilder) throws IOException { + super(settingsBuilder); + } + + /** Builder for ImageAnnotatorSettings. */ + public static class Builder extends ClientSettings.Builder { + protected Builder() throws IOException { + this((ClientContext) null); + } + + protected Builder(ClientContext clientContext) { + super(ImageAnnotatorStubSettings.newBuilder(clientContext)); + } + + private static Builder createDefault() { + return new Builder(ImageAnnotatorStubSettings.newBuilder()); + } + + protected Builder(ImageAnnotatorSettings settings) { + super(settings.getStubSettings().toBuilder()); + } + + protected Builder(ImageAnnotatorStubSettings.Builder stubSettings) { + super(stubSettings); + } + + public ImageAnnotatorStubSettings.Builder getStubSettingsBuilder() { + return ((ImageAnnotatorStubSettings.Builder) getStubSettings()); + } + + /** + * Applies the given settings updater function to all of the unary API methods in this service. + * + *

Note: This method does not support applying settings to streaming methods. + */ + public Builder applyToAllUnaryMethods( + ApiFunction, Void> settingsUpdater) throws Exception { + super.applyToAllUnaryMethods( + getStubSettingsBuilder().unaryMethodSettingsBuilders(), settingsUpdater); + return this; + } + + /** Returns the builder for the settings used for calls to batchAnnotateImages. */ + public UnaryCallSettings.Builder + batchAnnotateImagesSettings() { + return getStubSettingsBuilder().batchAnnotateImagesSettings(); + } + + /** Returns the builder for the settings used for calls to asyncBatchAnnotateFiles. */ + public UnaryCallSettings.Builder + asyncBatchAnnotateFilesSettings() { + return getStubSettingsBuilder().asyncBatchAnnotateFilesSettings(); + } + + /** Returns the builder for the settings used for calls to asyncBatchAnnotateFiles. */ + public OperationCallSettings.Builder< + AsyncBatchAnnotateFilesRequest, AsyncBatchAnnotateFilesResponse, OperationMetadata> + asyncBatchAnnotateFilesOperationSettings() { + return getStubSettingsBuilder().asyncBatchAnnotateFilesOperationSettings(); + } + + @Override + public ImageAnnotatorSettings build() throws IOException { + return new ImageAnnotatorSettings(this); + } + } +} diff --git a/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p2beta1/package-info.java b/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p2beta1/package-info.java new file mode 100644 index 000000000000..bcd23873e09b --- /dev/null +++ b/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p2beta1/package-info.java @@ -0,0 +1,39 @@ +/* + * Copyright 2018 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. + */ + +/** + * A client to Google Cloud Vision API. + * + *

The interfaces provided are listed below, along with usage samples. + * + *

==================== ImageAnnotatorClient ==================== + * + *

Service Description: Service that performs Google Cloud Vision API detection tasks over client + * images, such as face, landmark, logo, label, and text detection. The ImageAnnotator service + * returns detected entities from the images. + * + *

Sample for ImageAnnotatorClient: + * + *

+ * 
+ * try (ImageAnnotatorClient imageAnnotatorClient = ImageAnnotatorClient.create()) {
+ *   List<AnnotateImageRequest> requests = new ArrayList<>();
+ *   BatchAnnotateImagesResponse response = imageAnnotatorClient.batchAnnotateImages(requests);
+ * }
+ * 
+ * 
+ */ +package com.google.cloud.vision.v1p2beta1; diff --git a/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p2beta1/stub/GrpcImageAnnotatorStub.java b/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p2beta1/stub/GrpcImageAnnotatorStub.java new file mode 100644 index 000000000000..56be8b4a8354 --- /dev/null +++ b/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p2beta1/stub/GrpcImageAnnotatorStub.java @@ -0,0 +1,181 @@ +/* + * Copyright 2018 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.vision.v1p2beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.core.BackgroundResourceAggregation; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.vision.v1p2beta1.AsyncBatchAnnotateFilesRequest; +import com.google.cloud.vision.v1p2beta1.AsyncBatchAnnotateFilesResponse; +import com.google.cloud.vision.v1p2beta1.BatchAnnotateImagesRequest; +import com.google.cloud.vision.v1p2beta1.BatchAnnotateImagesResponse; +import com.google.cloud.vision.v1p2beta1.OperationMetadata; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.GrpcOperationsStub; +import io.grpc.MethodDescriptor; +import io.grpc.protobuf.ProtoUtils; +import java.io.IOException; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * gRPC stub implementation for Google Cloud Vision API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("A restructuring of stub classes is planned, so this may break in the future") +public class GrpcImageAnnotatorStub extends ImageAnnotatorStub { + + private static final MethodDescriptor + batchAnnotateImagesMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.cloud.vision.v1p2beta1.ImageAnnotator/BatchAnnotateImages") + .setRequestMarshaller( + ProtoUtils.marshaller(BatchAnnotateImagesRequest.getDefaultInstance())) + .setResponseMarshaller( + ProtoUtils.marshaller(BatchAnnotateImagesResponse.getDefaultInstance())) + .build(); + private static final MethodDescriptor + asyncBatchAnnotateFilesMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName( + "google.cloud.vision.v1p2beta1.ImageAnnotator/AsyncBatchAnnotateFiles") + .setRequestMarshaller( + ProtoUtils.marshaller(AsyncBatchAnnotateFilesRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(Operation.getDefaultInstance())) + .build(); + + private final BackgroundResource backgroundResources; + private final GrpcOperationsStub operationsStub; + + private final UnaryCallable + batchAnnotateImagesCallable; + private final UnaryCallable + asyncBatchAnnotateFilesCallable; + private final OperationCallable< + AsyncBatchAnnotateFilesRequest, AsyncBatchAnnotateFilesResponse, OperationMetadata> + asyncBatchAnnotateFilesOperationCallable; + + public static final GrpcImageAnnotatorStub create(ImageAnnotatorStubSettings settings) + throws IOException { + return new GrpcImageAnnotatorStub(settings, ClientContext.create(settings)); + } + + public static final GrpcImageAnnotatorStub create(ClientContext clientContext) + throws IOException { + return new GrpcImageAnnotatorStub( + ImageAnnotatorStubSettings.newBuilder().build(), clientContext); + } + + /** + * Constructs an instance of GrpcImageAnnotatorStub, 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 GrpcImageAnnotatorStub(ImageAnnotatorStubSettings settings, ClientContext clientContext) + throws IOException { + this.operationsStub = GrpcOperationsStub.create(clientContext); + + GrpcCallSettings + batchAnnotateImagesTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(batchAnnotateImagesMethodDescriptor) + .build(); + GrpcCallSettings + asyncBatchAnnotateFilesTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(asyncBatchAnnotateFilesMethodDescriptor) + .build(); + + this.batchAnnotateImagesCallable = + GrpcCallableFactory.createUnaryCallable( + batchAnnotateImagesTransportSettings, + settings.batchAnnotateImagesSettings(), + clientContext); + this.asyncBatchAnnotateFilesCallable = + GrpcCallableFactory.createUnaryCallable( + asyncBatchAnnotateFilesTransportSettings, + settings.asyncBatchAnnotateFilesSettings(), + clientContext); + this.asyncBatchAnnotateFilesOperationCallable = + GrpcCallableFactory.createOperationCallable( + asyncBatchAnnotateFilesTransportSettings, + settings.asyncBatchAnnotateFilesOperationSettings(), + clientContext, + this.operationsStub); + + backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + public GrpcOperationsStub getOperationsStub() { + return operationsStub; + } + + public UnaryCallable + batchAnnotateImagesCallable() { + return batchAnnotateImagesCallable; + } + + public OperationCallable< + AsyncBatchAnnotateFilesRequest, AsyncBatchAnnotateFilesResponse, OperationMetadata> + asyncBatchAnnotateFilesOperationCallable() { + return asyncBatchAnnotateFilesOperationCallable; + } + + public UnaryCallable + asyncBatchAnnotateFilesCallable() { + return asyncBatchAnnotateFilesCallable; + } + + @Override + public final void close() throws Exception { + shutdown(); + } + + @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-vision/src/main/java/com/google/cloud/vision/v1p2beta1/stub/ImageAnnotatorStub.java b/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p2beta1/stub/ImageAnnotatorStub.java new file mode 100644 index 000000000000..c7d036f4a91e --- /dev/null +++ b/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p2beta1/stub/ImageAnnotatorStub.java @@ -0,0 +1,61 @@ +/* + * Copyright 2018 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.vision.v1p2beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.vision.v1p2beta1.AsyncBatchAnnotateFilesRequest; +import com.google.cloud.vision.v1p2beta1.AsyncBatchAnnotateFilesResponse; +import com.google.cloud.vision.v1p2beta1.BatchAnnotateImagesRequest; +import com.google.cloud.vision.v1p2beta1.BatchAnnotateImagesResponse; +import com.google.cloud.vision.v1p2beta1.OperationMetadata; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * Base stub class for Google Cloud Vision API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by GAPIC v0.0.5") +@BetaApi("A restructuring of stub classes is planned, so this may break in the future") +public abstract class ImageAnnotatorStub implements BackgroundResource { + + public OperationsStub getOperationsStub() { + throw new UnsupportedOperationException("Not implemented: getOperationsStub()"); + } + + public UnaryCallable + batchAnnotateImagesCallable() { + throw new UnsupportedOperationException("Not implemented: batchAnnotateImagesCallable()"); + } + + public OperationCallable< + AsyncBatchAnnotateFilesRequest, AsyncBatchAnnotateFilesResponse, OperationMetadata> + asyncBatchAnnotateFilesOperationCallable() { + throw new UnsupportedOperationException( + "Not implemented: asyncBatchAnnotateFilesOperationCallable()"); + } + + public UnaryCallable + asyncBatchAnnotateFilesCallable() { + throw new UnsupportedOperationException("Not implemented: asyncBatchAnnotateFilesCallable()"); + } +} diff --git a/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p2beta1/stub/ImageAnnotatorStubSettings.java b/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p2beta1/stub/ImageAnnotatorStubSettings.java new file mode 100644 index 000000000000..aa47bb96c262 --- /dev/null +++ b/google-cloud-vision/src/main/java/com/google/cloud/vision/v1p2beta1/stub/ImageAnnotatorStubSettings.java @@ -0,0 +1,354 @@ +/* + * Copyright 2018 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.vision.v1p2beta1.stub; + +import com.google.api.core.ApiFunction; +import com.google.api.core.BetaApi; +import com.google.api.gax.core.GaxProperties; +import com.google.api.gax.core.GoogleCredentialsProvider; +import com.google.api.gax.core.InstantiatingExecutorProvider; +import com.google.api.gax.grpc.GaxGrpcProperties; +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.longrunning.OperationSnapshot; +import com.google.api.gax.longrunning.OperationTimedPollAlgorithm; +import com.google.api.gax.retrying.RetrySettings; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.StatusCode; +import com.google.api.gax.rpc.StubSettings; +import com.google.api.gax.rpc.TransportChannelProvider; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.cloud.vision.v1p2beta1.AsyncBatchAnnotateFilesRequest; +import com.google.cloud.vision.v1p2beta1.AsyncBatchAnnotateFilesResponse; +import com.google.cloud.vision.v1p2beta1.BatchAnnotateImagesRequest; +import com.google.cloud.vision.v1p2beta1.BatchAnnotateImagesResponse; +import com.google.cloud.vision.v1p2beta1.OperationMetadata; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Lists; +import com.google.longrunning.Operation; +import java.io.IOException; +import java.util.List; +import javax.annotation.Generated; +import org.threeten.bp.Duration; + +// AUTO-GENERATED DOCUMENTATION AND CLASS +/** + * Settings class to configure an instance of {@link ImageAnnotatorStub}. + * + *

The default instance has everything set to sensible defaults: + * + *

    + *
  • The default service address (vision.googleapis.com) and default port (443) are used. + *
  • Credentials are acquired automatically through Application Default Credentials. + *
  • Retries are configured for idempotent methods but not for non-idempotent methods. + *
+ * + *

The builder of this class is recursive, so contained classes are themselves builders. When + * build() is called, the tree of builders is called to create the complete settings object. For + * example, to set the total timeout of batchAnnotateImages to 30 seconds: + * + *

+ * 
+ * ImageAnnotatorStubSettings.Builder imageAnnotatorSettingsBuilder =
+ *     ImageAnnotatorStubSettings.newBuilder();
+ * imageAnnotatorSettingsBuilder.batchAnnotateImagesSettings().getRetrySettingsBuilder()
+ *     .setTotalTimeout(Duration.ofSeconds(30));
+ * ImageAnnotatorStubSettings imageAnnotatorSettings = imageAnnotatorSettingsBuilder.build();
+ * 
+ * 
+ */ +@Generated("by GAPIC v0.0.5") +public class ImageAnnotatorStubSettings extends StubSettings { + /** The default scopes of the service. */ + private static final ImmutableList DEFAULT_SERVICE_SCOPES = + ImmutableList.builder() + .add("https://www.googleapis.com/auth/cloud-platform") + .add("https://www.googleapis.com/auth/cloud-vision") + .build(); + + private final UnaryCallSettings + batchAnnotateImagesSettings; + private final UnaryCallSettings + asyncBatchAnnotateFilesSettings; + private final OperationCallSettings< + AsyncBatchAnnotateFilesRequest, AsyncBatchAnnotateFilesResponse, OperationMetadata> + asyncBatchAnnotateFilesOperationSettings; + + /** Returns the object with the settings used for calls to batchAnnotateImages. */ + public UnaryCallSettings + batchAnnotateImagesSettings() { + return batchAnnotateImagesSettings; + } + + /** Returns the object with the settings used for calls to asyncBatchAnnotateFiles. */ + public UnaryCallSettings + asyncBatchAnnotateFilesSettings() { + return asyncBatchAnnotateFilesSettings; + } + + /** Returns the object with the settings used for calls to asyncBatchAnnotateFiles. */ + public OperationCallSettings< + AsyncBatchAnnotateFilesRequest, AsyncBatchAnnotateFilesResponse, OperationMetadata> + asyncBatchAnnotateFilesOperationSettings() { + return asyncBatchAnnotateFilesOperationSettings; + } + + @BetaApi("A restructuring of stub classes is planned, so this may break in the future") + public ImageAnnotatorStub createStub() throws IOException { + if (getTransportChannelProvider() + .getTransportName() + .equals(GrpcTransportChannel.getGrpcTransportName())) { + return GrpcImageAnnotatorStub.create(this); + } else { + throw new UnsupportedOperationException( + "Transport not supported: " + getTransportChannelProvider().getTransportName()); + } + } + + /** Returns a builder for the default ExecutorProvider for this service. */ + public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() { + return InstantiatingExecutorProvider.newBuilder(); + } + + /** Returns the default service endpoint. */ + public static String getDefaultEndpoint() { + return "vision.googleapis.com:443"; + } + + /** Returns the default service scopes. */ + public static List getDefaultServiceScopes() { + return DEFAULT_SERVICE_SCOPES; + } + + /** Returns a builder for the default credentials for this service. */ + public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() { + return GoogleCredentialsProvider.newBuilder().setScopesToApply(DEFAULT_SERVICE_SCOPES); + } + + /** Returns a builder for the default ChannelProvider for this service. */ + public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { + return InstantiatingGrpcChannelProvider.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() { + return ApiClientHeaderProvider.newBuilder() + .setGeneratedLibToken( + "gapic", GaxProperties.getLibraryVersion(ImageAnnotatorStubSettings.class)) + .setTransportToken( + GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder() { + return Builder.createDefault(); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder(ClientContext clientContext) { + return new Builder(clientContext); + } + + /** Returns a builder containing all the values of this settings class. */ + public Builder toBuilder() { + return new Builder(this); + } + + protected ImageAnnotatorStubSettings(Builder settingsBuilder) throws IOException { + super(settingsBuilder); + + batchAnnotateImagesSettings = settingsBuilder.batchAnnotateImagesSettings().build(); + asyncBatchAnnotateFilesSettings = settingsBuilder.asyncBatchAnnotateFilesSettings().build(); + asyncBatchAnnotateFilesOperationSettings = + settingsBuilder.asyncBatchAnnotateFilesOperationSettings().build(); + } + + /** Builder for ImageAnnotatorStubSettings. */ + public static class Builder extends StubSettings.Builder { + private final ImmutableList> unaryMethodSettingsBuilders; + + private final UnaryCallSettings.Builder + batchAnnotateImagesSettings; + private final UnaryCallSettings.Builder + asyncBatchAnnotateFilesSettings; + private final OperationCallSettings.Builder< + AsyncBatchAnnotateFilesRequest, AsyncBatchAnnotateFilesResponse, OperationMetadata> + asyncBatchAnnotateFilesOperationSettings; + + private static final ImmutableMap> + RETRYABLE_CODE_DEFINITIONS; + + static { + ImmutableMap.Builder> definitions = + ImmutableMap.builder(); + definitions.put( + "idempotent", + ImmutableSet.copyOf( + Lists.newArrayList( + StatusCode.Code.DEADLINE_EXCEEDED, StatusCode.Code.UNAVAILABLE))); + definitions.put("non_idempotent", ImmutableSet.copyOf(Lists.newArrayList())); + RETRYABLE_CODE_DEFINITIONS = definitions.build(); + } + + private static final ImmutableMap RETRY_PARAM_DEFINITIONS; + + static { + ImmutableMap.Builder definitions = ImmutableMap.builder(); + RetrySettings settings = null; + settings = + RetrySettings.newBuilder() + .setInitialRetryDelay(Duration.ofMillis(100L)) + .setRetryDelayMultiplier(1.3) + .setMaxRetryDelay(Duration.ofMillis(60000L)) + .setInitialRpcTimeout(Duration.ofMillis(60000L)) + .setRpcTimeoutMultiplier(1.0) + .setMaxRpcTimeout(Duration.ofMillis(60000L)) + .setTotalTimeout(Duration.ofMillis(600000L)) + .build(); + definitions.put("default", settings); + RETRY_PARAM_DEFINITIONS = definitions.build(); + } + + protected Builder() { + this((ClientContext) null); + } + + protected Builder(ClientContext clientContext) { + super(clientContext); + + batchAnnotateImagesSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + asyncBatchAnnotateFilesSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + asyncBatchAnnotateFilesOperationSettings = OperationCallSettings.newBuilder(); + + unaryMethodSettingsBuilders = + ImmutableList.>of( + batchAnnotateImagesSettings, asyncBatchAnnotateFilesSettings); + + initDefaults(this); + } + + private static Builder createDefault() { + Builder builder = new Builder((ClientContext) null); + builder.setTransportChannelProvider(defaultTransportChannelProvider()); + builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); + builder.setInternalHeaderProvider(defaultApiClientHeaderProviderBuilder().build()); + builder.setEndpoint(getDefaultEndpoint()); + return initDefaults(builder); + } + + private static Builder initDefaults(Builder builder) { + + builder + .batchAnnotateImagesSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + + builder + .asyncBatchAnnotateFilesSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")); + builder + .asyncBatchAnnotateFilesOperationSettings() + .setInitialCallSettings( + UnaryCallSettings + .newUnaryCallSettingsBuilder() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("default")) + .build()) + .setResponseTransformer( + ProtoOperationTransformers.ResponseTransformer.create( + AsyncBatchAnnotateFilesResponse.class)) + .setMetadataTransformer( + ProtoOperationTransformers.MetadataTransformer.create(OperationMetadata.class)) + .setPollingAlgorithm( + OperationTimedPollAlgorithm.create( + RetrySettings.newBuilder() + .setInitialRetryDelay(Duration.ofMillis(20000L)) + .setRetryDelayMultiplier(1.5) + .setMaxRetryDelay(Duration.ofMillis(45000L)) + .setInitialRpcTimeout(Duration.ZERO) // ignored + .setRpcTimeoutMultiplier(1.0) // ignored + .setMaxRpcTimeout(Duration.ZERO) // ignored + .setTotalTimeout(Duration.ofMillis(86400000L)) + .build())); + + return builder; + } + + protected Builder(ImageAnnotatorStubSettings settings) { + super(settings); + + batchAnnotateImagesSettings = settings.batchAnnotateImagesSettings.toBuilder(); + asyncBatchAnnotateFilesSettings = settings.asyncBatchAnnotateFilesSettings.toBuilder(); + asyncBatchAnnotateFilesOperationSettings = + settings.asyncBatchAnnotateFilesOperationSettings.toBuilder(); + + unaryMethodSettingsBuilders = + ImmutableList.>of( + batchAnnotateImagesSettings, asyncBatchAnnotateFilesSettings); + } + + /** + * Applies the given settings updater function to all of the unary API methods in this service. + * + *

Note: This method does not support applying settings to streaming methods. + */ + public Builder applyToAllUnaryMethods( + ApiFunction, Void> settingsUpdater) throws Exception { + super.applyToAllUnaryMethods(unaryMethodSettingsBuilders, settingsUpdater); + return this; + } + + public ImmutableList> unaryMethodSettingsBuilders() { + return unaryMethodSettingsBuilders; + } + + /** Returns the builder for the settings used for calls to batchAnnotateImages. */ + public UnaryCallSettings.Builder + batchAnnotateImagesSettings() { + return batchAnnotateImagesSettings; + } + + /** Returns the builder for the settings used for calls to asyncBatchAnnotateFiles. */ + public UnaryCallSettings.Builder + asyncBatchAnnotateFilesSettings() { + return asyncBatchAnnotateFilesSettings; + } + + /** Returns the builder for the settings used for calls to asyncBatchAnnotateFiles. */ + public OperationCallSettings.Builder< + AsyncBatchAnnotateFilesRequest, AsyncBatchAnnotateFilesResponse, OperationMetadata> + asyncBatchAnnotateFilesOperationSettings() { + return asyncBatchAnnotateFilesOperationSettings; + } + + @Override + public ImageAnnotatorStubSettings build() throws IOException { + return new ImageAnnotatorStubSettings(this); + } + } +} diff --git a/google-cloud-vision/src/test/java/com/google/cloud/vision/v1p2beta1/ImageAnnotatorClientTest.java b/google-cloud-vision/src/test/java/com/google/cloud/vision/v1p2beta1/ImageAnnotatorClientTest.java new file mode 100644 index 000000000000..85c6c962d928 --- /dev/null +++ b/google-cloud-vision/src/test/java/com/google/cloud/vision/v1p2beta1/ImageAnnotatorClientTest.java @@ -0,0 +1,166 @@ +/* + * Copyright 2018 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.vision.v1p2beta1; + +import com.google.api.gax.core.NoCredentialsProvider; +import com.google.api.gax.grpc.GaxGrpcProperties; +import com.google.api.gax.grpc.testing.LocalChannelProvider; +import com.google.api.gax.grpc.testing.MockGrpcService; +import com.google.api.gax.grpc.testing.MockServiceHelper; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.InvalidArgumentException; +import com.google.api.gax.rpc.StatusCode; +import com.google.longrunning.Operation; +import com.google.protobuf.Any; +import com.google.protobuf.GeneratedMessageV3; +import io.grpc.Status; +import io.grpc.StatusRuntimeException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.ExecutionException; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +@javax.annotation.Generated("by GAPIC") +public class ImageAnnotatorClientTest { + private static MockImageAnnotator mockImageAnnotator; + private static MockServiceHelper serviceHelper; + private ImageAnnotatorClient client; + private LocalChannelProvider channelProvider; + + @BeforeClass + public static void startStaticServer() { + mockImageAnnotator = new MockImageAnnotator(); + serviceHelper = + new MockServiceHelper("in-process-1", Arrays.asList(mockImageAnnotator)); + serviceHelper.start(); + } + + @AfterClass + public static void stopServer() { + serviceHelper.stop(); + } + + @Before + public void setUp() throws IOException { + serviceHelper.reset(); + channelProvider = serviceHelper.createChannelProvider(); + ImageAnnotatorSettings settings = + ImageAnnotatorSettings.newBuilder() + .setTransportChannelProvider(channelProvider) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = ImageAnnotatorClient.create(settings); + } + + @After + public void tearDown() throws Exception { + client.close(); + } + + @Test + @SuppressWarnings("all") + public void batchAnnotateImagesTest() { + BatchAnnotateImagesResponse expectedResponse = BatchAnnotateImagesResponse.newBuilder().build(); + mockImageAnnotator.addResponse(expectedResponse); + + List requests = new ArrayList<>(); + + BatchAnnotateImagesResponse actualResponse = client.batchAnnotateImages(requests); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockImageAnnotator.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + BatchAnnotateImagesRequest actualRequest = (BatchAnnotateImagesRequest) actualRequests.get(0); + + Assert.assertEquals(requests, actualRequest.getRequestsList()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + @SuppressWarnings("all") + public void batchAnnotateImagesExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + mockImageAnnotator.addException(exception); + + try { + List requests = new ArrayList<>(); + + client.batchAnnotateImages(requests); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception + } + } + + @Test + @SuppressWarnings("all") + public void asyncBatchAnnotateFilesTest() throws Exception { + AsyncBatchAnnotateFilesResponse expectedResponse = + AsyncBatchAnnotateFilesResponse.newBuilder().build(); + Operation resultOperation = + Operation.newBuilder() + .setName("asyncBatchAnnotateFilesTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockImageAnnotator.addResponse(resultOperation); + + List requests = new ArrayList<>(); + + AsyncBatchAnnotateFilesResponse actualResponse = + client.asyncBatchAnnotateFilesAsync(requests).get(); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockImageAnnotator.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + AsyncBatchAnnotateFilesRequest actualRequest = + (AsyncBatchAnnotateFilesRequest) actualRequests.get(0); + + Assert.assertEquals(requests, actualRequest.getRequestsList()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + @SuppressWarnings("all") + public void asyncBatchAnnotateFilesExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); + mockImageAnnotator.addException(exception); + + try { + List requests = new ArrayList<>(); + + client.asyncBatchAnnotateFilesAsync(requests).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); + InvalidArgumentException apiException = (InvalidArgumentException) e.getCause(); + Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); + } + } +} diff --git a/google-cloud-vision/src/test/java/com/google/cloud/vision/v1p2beta1/MockImageAnnotator.java b/google-cloud-vision/src/test/java/com/google/cloud/vision/v1p2beta1/MockImageAnnotator.java new file mode 100644 index 000000000000..59867209f4ea --- /dev/null +++ b/google-cloud-vision/src/test/java/com/google/cloud/vision/v1p2beta1/MockImageAnnotator.java @@ -0,0 +1,57 @@ +/* + * Copyright 2018 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.vision.v1p2beta1; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.testing.MockGrpcService; +import com.google.protobuf.GeneratedMessageV3; +import io.grpc.ServerServiceDefinition; +import java.util.List; + +@javax.annotation.Generated("by GAPIC") +@BetaApi +public class MockImageAnnotator implements MockGrpcService { + private final MockImageAnnotatorImpl serviceImpl; + + public MockImageAnnotator() { + serviceImpl = new MockImageAnnotatorImpl(); + } + + @Override + public List getRequests() { + return serviceImpl.getRequests(); + } + + @Override + public void addResponse(GeneratedMessageV3 response) { + serviceImpl.addResponse(response); + } + + @Override + public void addException(Exception exception) { + serviceImpl.addException(exception); + } + + @Override + public ServerServiceDefinition getServiceDefinition() { + return serviceImpl.bindService(); + } + + @Override + public void reset() { + serviceImpl.reset(); + } +} diff --git a/google-cloud-vision/src/test/java/com/google/cloud/vision/v1p2beta1/MockImageAnnotatorImpl.java b/google-cloud-vision/src/test/java/com/google/cloud/vision/v1p2beta1/MockImageAnnotatorImpl.java new file mode 100644 index 000000000000..ce9916cc8cc5 --- /dev/null +++ b/google-cloud-vision/src/test/java/com/google/cloud/vision/v1p2beta1/MockImageAnnotatorImpl.java @@ -0,0 +1,90 @@ +/* + * Copyright 2018 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.vision.v1p2beta1; + +import com.google.api.core.BetaApi; +import com.google.cloud.vision.v1p2beta1.ImageAnnotatorGrpc.ImageAnnotatorImplBase; +import com.google.longrunning.Operation; +import com.google.protobuf.GeneratedMessageV3; +import io.grpc.stub.StreamObserver; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; + +@javax.annotation.Generated("by GAPIC") +@BetaApi +public class MockImageAnnotatorImpl extends ImageAnnotatorImplBase { + private ArrayList requests; + private Queue responses; + + public MockImageAnnotatorImpl() { + requests = new ArrayList<>(); + responses = new LinkedList<>(); + } + + public List getRequests() { + return requests; + } + + public void addResponse(GeneratedMessageV3 response) { + responses.add(response); + } + + public void setResponses(List responses) { + this.responses = new LinkedList(responses); + } + + public void addException(Exception exception) { + responses.add(exception); + } + + public void reset() { + requests = new ArrayList<>(); + responses = new LinkedList<>(); + } + + @Override + public void batchAnnotateImages( + BatchAnnotateImagesRequest request, + StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof BatchAnnotateImagesResponse) { + requests.add(request); + responseObserver.onNext((BatchAnnotateImagesResponse) response); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError((Exception) response); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void asyncBatchAnnotateFiles( + AsyncBatchAnnotateFilesRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof Operation) { + requests.add(request); + responseObserver.onNext((Operation) response); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError((Exception) response); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } +} diff --git a/pom.xml b/pom.xml index b385c60564a3..a2609b37ff7f 100644 --- a/pom.xml +++ b/pom.xml @@ -751,7 +751,7 @@ Stub packages - com.google.cloud.bigquerydatatransfer.v1.stub:com.google.cloud.container.v1.stub:com.google.cloud.dlp.v2beta1.stub:com.google.cloud.dialogflow.v2beta1.stub:com.google.cloud.errorreporting.v1beta1.stub:com.google.cloud.firestore.v1beta1.stub:com.google.cloud.language.v1beta2.stub:com.google.cloud.language.v1.stub:com.google.cloud.logging.v2.stub:com.google.cloud.monitoring.v3.stub:com.google.cloud.pubsub.v1.stub:com.google.cloud.speech.v1beta1.stub:com.google.cloud.speech.v1.stub:com.google.cloud.trace.v1.stub:com.google.cloud.trace.v2.stub:com.google.cloud.videointelligence.v1beta1.stub:com.google.cloud.videointelligence.v1beta2.stub:com.google.cloud.videointelligence.v1.stub:com.google.cloud.vision.v1.stub:com.google.cloud.vision.v1p1beta1.stub + com.google.cloud.bigquerydatatransfer.v1.stub:com.google.cloud.container.v1.stub:com.google.cloud.dlp.v2beta1.stub:com.google.cloud.dialogflow.v2beta1.stub:com.google.cloud.errorreporting.v1beta1.stub:com.google.cloud.firestore.v1beta1.stub:com.google.cloud.language.v1beta2.stub:com.google.cloud.language.v1.stub:com.google.cloud.logging.v2.stub:com.google.cloud.monitoring.v3.stub:com.google.cloud.pubsub.v1.stub:com.google.cloud.speech.v1beta1.stub:com.google.cloud.speech.v1.stub:com.google.cloud.trace.v1.stub:com.google.cloud.trace.v2.stub:com.google.cloud.videointelligence.v1beta1.stub:com.google.cloud.videointelligence.v1beta2.stub:com.google.cloud.videointelligence.v1.stub:com.google.cloud.vision.v1.stub:com.google.cloud.vision.v1p1beta1.stub:com.google.cloud.vision.v1p2beta1.stub Deprecated packages