diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml index a79f0627..f0625e4d 100644 --- a/.github/.OwlBot.lock.yaml +++ b/.github/.OwlBot.lock.yaml @@ -13,5 +13,5 @@ # limitations under the License. docker: image: gcr.io/cloud-devrel-public-resources/owlbot-java:latest - digest: sha256:2567a120ce90fadb6201999b87d649d9f67459de28815ad239bce9ebfaa18a74 -# created: 2022-05-19T15:12:45.278246753Z + digest: sha256:1ec28a46062b19135b11178ceee60231e5f5a92dab454e23ae0aab72cd875906 +# created: 2022-06-27T15:01:06.405564326Z diff --git a/.github/.OwlBot.yaml b/.github/.OwlBot.yaml index d30e942d..74c2fb26 100644 --- a/.github/.OwlBot.yaml +++ b/.github/.OwlBot.yaml @@ -16,6 +16,7 @@ docker: image: "gcr.io/cloud-devrel-public-resources/owlbot-java:latest" deep-remove-regex: +- "/samples/snippets/generated" - "/grpc-google-.*/src" - "/proto-google-.*/src" - "/google-.*/src/com/google/cloud/translate/v3" @@ -31,3 +32,5 @@ deep-copy-regex: dest: "/owl-bot-staging/$1/grpc-google-cloud-translate-$1/src" - source: "/google/cloud/translate/(v.*)/.*-java/gapic-google-.*/src" dest: "/owl-bot-staging/$1/google-cloud-translate/src" +- source: "/google/cloud/translate/(v.*)/.*-java/samples/snippets/generated" + dest: "/owl-bot-staging/$1/samples/snippets/generated" diff --git a/.github/sync-repo-settings.yaml b/.github/sync-repo-settings.yaml index 6f09d695..0181fcd5 100644 --- a/.github/sync-repo-settings.yaml +++ b/.github/sync-repo-settings.yaml @@ -17,6 +17,8 @@ branchProtectionRules: - 'Kokoro - Test: Integration' - cla/google - OwlBot Post Processor + - 'Kokoro - Test: Java GraalVM Native Image' + - 'Kokoro - Test: Java 17 GraalVM Native Image' - pattern: java7 isAdminEnforced: true requiredApprovingReviewCount: 1 diff --git a/.kokoro/common.sh b/.kokoro/common.sh index ace89f45..f8f957af 100644 --- a/.kokoro/common.sh +++ b/.kokoro/common.sh @@ -55,4 +55,6 @@ function retry_with_backoff { ## Helper functionss function now() { date +"%Y-%m-%d %H:%M:%S" | tr -d '\n'; } function msg() { println "$*" >&2; } -function println() { printf '%s\n' "$(now) $*"; } \ No newline at end of file +function println() { printf '%s\n' "$(now) $*"; } + +## Helper comment to trigger updated repo dependency release \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d0fabf1..9cc1256d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,30 @@ # Changelog +## [2.3.0](https://github.com/googleapis/java-translate/compare/v2.2.0...v2.3.0) (2022-06-29) + + +### Features + +* Enable REST transport for most of Java and Go clients ([#1014](https://github.com/googleapis/java-translate/issues/1014)) ([8befc79](https://github.com/googleapis/java-translate/commit/8befc799748f11c15f4e511c8a65a74401638ffa)) + + +### Bug Fixes + +* update gapic-generator-java with mock service generation fixes ([#1016](https://github.com/googleapis/java-translate/issues/1016)) ([ace2700](https://github.com/googleapis/java-translate/commit/ace2700807e5557113bbb1016b54ff7b3d57e59c)) + + +### Dependencies + +* update dependency com.google.cloud:google-cloud-core to v2.7.1 ([#997](https://github.com/googleapis/java-translate/issues/997)) ([e2070a9](https://github.com/googleapis/java-translate/commit/e2070a9785a029772bbb25109a480bd151003843)) +* update dependency com.google.cloud:google-cloud-core to v2.8.0 ([#1012](https://github.com/googleapis/java-translate/issues/1012)) ([0fdb776](https://github.com/googleapis/java-translate/commit/0fdb776115d90ea0894b0bc92d3a59181fd050e3)) +* update dependency com.google.cloud:google-cloud-core to v2.8.1 ([#1017](https://github.com/googleapis/java-translate/issues/1017)) ([d38a566](https://github.com/googleapis/java-translate/commit/d38a566473932796573a1f64ce819358424b4fca)) +* update dependency com.google.cloud:google-cloud-shared-dependencies to v2.13.0 ([#1013](https://github.com/googleapis/java-translate/issues/1013)) ([7b1d5d6](https://github.com/googleapis/java-translate/commit/7b1d5d6542806983815c2b84d847721b1951662a)) +* update dependency com.google.cloud:google-cloud-storage to v2.7.1 ([#1003](https://github.com/googleapis/java-translate/issues/1003)) ([4871284](https://github.com/googleapis/java-translate/commit/4871284229d28fe3993b45af937d31961580a97e)) +* update dependency com.google.cloud:google-cloud-storage to v2.7.2 ([#1005](https://github.com/googleapis/java-translate/issues/1005)) ([1bb4942](https://github.com/googleapis/java-translate/commit/1bb4942ab866f8a82a683880668829e34a64725b)) +* update dependency com.google.cloud:google-cloud-storage to v2.8.0 ([#1007](https://github.com/googleapis/java-translate/issues/1007)) ([d7d9705](https://github.com/googleapis/java-translate/commit/d7d970518dc73ae4e4b61b40f05f9b7baaa000af)) +* update dependency com.google.cloud:google-cloud-storage to v2.8.1 ([#1011](https://github.com/googleapis/java-translate/issues/1011)) ([a5a2a65](https://github.com/googleapis/java-translate/commit/a5a2a657738740b2024f216c0ba5539ba67d4bfb)) +* update dependency com.google.cloud:google-cloud-storage to v2.9.0 ([#1020](https://github.com/googleapis/java-translate/issues/1020)) ([4744233](https://github.com/googleapis/java-translate/commit/47442336a5a2c3f4fde29f6b881b236a1e44cfd6)) + ## [2.2.0](https://github.com/googleapis/java-translate/compare/v2.1.13...v2.2.0) (2022-05-19) diff --git a/README.md b/README.md index 66718519..66449d49 100644 --- a/README.md +++ b/README.md @@ -19,20 +19,20 @@ If you are using Maven, add this to your pom.xml file: com.google.cloud google-cloud-translate - 2.1.13 + 2.2.0 ``` If you are using Gradle without BOM, add this to your dependencies ```Groovy -implementation 'com.google.cloud:google-cloud-translate:2.1.13' +implementation 'com.google.cloud:google-cloud-translate:2.2.0' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-translate" % "2.1.13" +libraryDependencies += "com.google.cloud" % "google-cloud-translate" % "2.2.0" ``` ## Authentication diff --git a/google-cloud-translate-bom/pom.xml b/google-cloud-translate-bom/pom.xml index e0abba0a..c7b0a279 100644 --- a/google-cloud-translate-bom/pom.xml +++ b/google-cloud-translate-bom/pom.xml @@ -3,12 +3,12 @@ 4.0.0 com.google.cloud google-cloud-translate-bom - 2.2.0 + 2.3.0 pom com.google.cloud google-cloud-shared-config - 1.4.0 + 1.5.0 Google Cloud Translate BOM @@ -52,27 +52,27 @@ com.google.cloud google-cloud-translate - 2.2.0 + 2.3.0 com.google.api.grpc grpc-google-cloud-translate-v3beta1 - 0.84.0 + 0.85.0 com.google.api.grpc grpc-google-cloud-translate-v3 - 2.2.0 + 2.3.0 com.google.api.grpc proto-google-cloud-translate-v3beta1 - 0.84.0 + 0.85.0 com.google.api.grpc proto-google-cloud-translate-v3 - 2.2.0 + 2.3.0 diff --git a/google-cloud-translate/pom.xml b/google-cloud-translate/pom.xml index 6f663f47..dd9ad5a2 100644 --- a/google-cloud-translate/pom.xml +++ b/google-cloud-translate/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.google.cloud google-cloud-translate - 2.2.0 + 2.3.0 jar Google Cloud Translate https://github.com/googleapis/java-translate @@ -11,7 +11,7 @@ com.google.cloud google-cloud-translate-parent - 2.2.0 + 2.3.0 google-cloud-translate @@ -61,6 +61,10 @@ com.google.api gax-grpc + + + com.google.api + gax-httpjson org.threeten @@ -123,12 +127,24 @@ test + + com.google.api + gax + testlib + test + com.google.api gax-grpc testlib test + + com.google.api + gax-httpjson + testlib + test + diff --git a/google-cloud-translate/src/main/java/com/google/cloud/translate/v3/TranslationServiceClient.java b/google-cloud-translate/src/main/java/com/google/cloud/translate/v3/TranslationServiceClient.java index 9394f607..851b62b3 100644 --- a/google-cloud-translate/src/main/java/com/google/cloud/translate/v3/TranslationServiceClient.java +++ b/google-cloud-translate/src/main/java/com/google/cloud/translate/v3/TranslationServiceClient.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; @@ -31,7 +32,6 @@ import com.google.cloud.translate.v3.stub.TranslationServiceStubSettings; import com.google.common.util.concurrent.MoreExecutors; import com.google.longrunning.Operation; -import com.google.longrunning.OperationsClient; import java.io.IOException; import java.util.List; import java.util.concurrent.TimeUnit; @@ -107,13 +107,29 @@ * TranslationServiceClient.create(translationServiceSettings); * } * + *

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.
+ * TranslationServiceSettings translationServiceSettings =
+ *     TranslationServiceSettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             TranslationServiceSettings.defaultHttpJsonTransportProviderBuilder().build())
+ *         .build();
+ * TranslationServiceClient translationServiceClient =
+ *     TranslationServiceClient.create(translationServiceSettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @Generated("by gapic-generator-java") public class TranslationServiceClient implements BackgroundResource { private final TranslationServiceSettings settings; private final TranslationServiceStub stub; - private final OperationsClient operationsClient; + private final OperationsClient httpJsonOperationsClient; + private final com.google.longrunning.OperationsClient operationsClient; /** Constructs an instance of TranslationServiceClient with default settings. */ public static final TranslationServiceClient create() throws IOException { @@ -133,7 +149,6 @@ public static final TranslationServiceClient create(TranslationServiceSettings s * Constructs an instance of TranslationServiceClient, using the given stub for making calls. This * is for advanced usage - prefer using create(TranslationServiceSettings). */ - @BetaApi("A restructuring of stub classes is planned, so this may break in the future") public static final TranslationServiceClient create(TranslationServiceStub stub) { return new TranslationServiceClient(stub); } @@ -146,21 +161,23 @@ public static final TranslationServiceClient create(TranslationServiceStub stub) protected TranslationServiceClient(TranslationServiceSettings settings) throws IOException { this.settings = settings; this.stub = ((TranslationServiceStubSettings) 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 TranslationServiceClient(TranslationServiceStub 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 TranslationServiceSettings getSettings() { return settings; } - @BetaApi("A restructuring of stub classes is planned, so this may break in the future") public TranslationServiceStub getStub() { return stub; } @@ -169,10 +186,19 @@ public TranslationServiceStub 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. /** * Translates input text and returns translated text. @@ -1482,7 +1508,7 @@ public final ListGlossariesPagedResponse listGlossaries(ListGlossariesRequest re * while (true) { * ListGlossariesResponse response = * translationServiceClient.listGlossariesCallable().call(request); - * for (Glossary element : response.getResponsesList()) { + * for (Glossary element : response.getGlossariesList()) { * // doThingsWith(element); * } * String nextPageToken = response.getNextPageToken(); diff --git a/google-cloud-translate/src/main/java/com/google/cloud/translate/v3/TranslationServiceSettings.java b/google-cloud-translate/src/main/java/com/google/cloud/translate/v3/TranslationServiceSettings.java index f3b18373..0b1c73e6 100644 --- a/google-cloud-translate/src/main/java/com/google/cloud/translate/v3/TranslationServiceSettings.java +++ b/google-cloud-translate/src/main/java/com/google/cloud/translate/v3/TranslationServiceSettings.java @@ -23,6 +23,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; @@ -185,11 +186,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return TranslationServiceStubSettings.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 TranslationServiceStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return TranslationServiceStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return TranslationServiceStubSettings.defaultTransportChannelProvider(); } @@ -199,11 +207,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return TranslationServiceStubSettings.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); @@ -241,6 +255,11 @@ private static Builder createDefault() { return new Builder(TranslationServiceStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(TranslationServiceStubSettings.newHttpJsonBuilder()); + } + public TranslationServiceStubSettings.Builder getStubSettingsBuilder() { return ((TranslationServiceStubSettings.Builder) getStubSettings()); } diff --git a/google-cloud-translate/src/main/java/com/google/cloud/translate/v3/stub/HttpJsonTranslationServiceCallableFactory.java b/google-cloud-translate/src/main/java/com/google/cloud/translate/v3/stub/HttpJsonTranslationServiceCallableFactory.java new file mode 100644 index 00000000..9c30a3b8 --- /dev/null +++ b/google-cloud-translate/src/main/java/com/google/cloud/translate/v3/stub/HttpJsonTranslationServiceCallableFactory.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.translate.v3.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 TranslationService service API. + * + *

This class is for advanced usage. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonTranslationServiceCallableFactory + 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-translate/src/main/java/com/google/cloud/translate/v3/stub/HttpJsonTranslationServiceStub.java b/google-cloud-translate/src/main/java/com/google/cloud/translate/v3/stub/HttpJsonTranslationServiceStub.java new file mode 100644 index 00000000..147fd458 --- /dev/null +++ b/google-cloud-translate/src/main/java/com/google/cloud/translate/v3/stub/HttpJsonTranslationServiceStub.java @@ -0,0 +1,806 @@ +/* + * 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.translate.v3.stub; + +import static com.google.cloud.translate.v3.TranslationServiceClient.ListGlossariesPagedResponse; + +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.cloud.translate.v3.BatchTranslateDocumentMetadata; +import com.google.cloud.translate.v3.BatchTranslateDocumentRequest; +import com.google.cloud.translate.v3.BatchTranslateDocumentResponse; +import com.google.cloud.translate.v3.BatchTranslateMetadata; +import com.google.cloud.translate.v3.BatchTranslateResponse; +import com.google.cloud.translate.v3.BatchTranslateTextRequest; +import com.google.cloud.translate.v3.CreateGlossaryMetadata; +import com.google.cloud.translate.v3.CreateGlossaryRequest; +import com.google.cloud.translate.v3.DeleteGlossaryMetadata; +import com.google.cloud.translate.v3.DeleteGlossaryRequest; +import com.google.cloud.translate.v3.DeleteGlossaryResponse; +import com.google.cloud.translate.v3.DetectLanguageRequest; +import com.google.cloud.translate.v3.DetectLanguageResponse; +import com.google.cloud.translate.v3.GetGlossaryRequest; +import com.google.cloud.translate.v3.GetSupportedLanguagesRequest; +import com.google.cloud.translate.v3.Glossary; +import com.google.cloud.translate.v3.ListGlossariesRequest; +import com.google.cloud.translate.v3.ListGlossariesResponse; +import com.google.cloud.translate.v3.SupportedLanguages; +import com.google.cloud.translate.v3.TranslateDocumentRequest; +import com.google.cloud.translate.v3.TranslateDocumentResponse; +import com.google.cloud.translate.v3.TranslateTextRequest; +import com.google.cloud.translate.v3.TranslateTextResponse; +import com.google.longrunning.Operation; +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 TranslationService service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonTranslationServiceStub extends TranslationServiceStub { + private static final TypeRegistry typeRegistry = + TypeRegistry.newBuilder() + .add(DeleteGlossaryMetadata.getDescriptor()) + .add(BatchTranslateResponse.getDescriptor()) + .add(BatchTranslateMetadata.getDescriptor()) + .add(Glossary.getDescriptor()) + .add(CreateGlossaryMetadata.getDescriptor()) + .add(BatchTranslateDocumentResponse.getDescriptor()) + .add(DeleteGlossaryResponse.getDescriptor()) + .add(BatchTranslateDocumentMetadata.getDescriptor()) + .build(); + + private static final ApiMethodDescriptor + translateTextMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.translation.v3.TranslationService/TranslateText") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v3/{parent=projects/*/locations/*}:translateText", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setAdditionalPaths("/v3/{parent=projects/*}:translateText") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearParent().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(TranslateTextResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + detectLanguageMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.translation.v3.TranslationService/DetectLanguage") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v3/{parent=projects/*/locations/*}:detectLanguage", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setAdditionalPaths("/v3/{parent=projects/*}:detectLanguage") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearParent().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(DetectLanguageResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getSupportedLanguagesMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.translation.v3.TranslationService/GetSupportedLanguages") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v3/{parent=projects/*/locations/*}/supportedLanguages", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setAdditionalPaths("/v3/{parent=projects/*}/supportedLanguages") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam( + fields, "displayLanguageCode", request.getDisplayLanguageCode()); + serializer.putQueryParam(fields, "model", request.getModel()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(SupportedLanguages.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + translateDocumentMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.translation.v3.TranslationService/TranslateDocument") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v3/{parent=projects/*/locations/*}:translateDocument", + 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("*", request.toBuilder().clearParent().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(TranslateDocumentResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + batchTranslateTextMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.translation.v3.TranslationService/BatchTranslateText") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v3/{parent=projects/*/locations/*}:batchTranslateText", + 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("*", request.toBuilder().clearParent().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (BatchTranslateTextRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + batchTranslateDocumentMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.translation.v3.TranslationService/BatchTranslateDocument") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v3/{parent=projects/*/locations/*}:batchTranslateDocument", + 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("*", request.toBuilder().clearParent().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (BatchTranslateDocumentRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + createGlossaryMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.translation.v3.TranslationService/CreateGlossary") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v3/{parent=projects/*/locations/*}/glossaries", + 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("glossary", request.getGlossary())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (CreateGlossaryRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + listGlossariesMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.translation.v3.TranslationService/ListGlossaries") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v3/{parent=projects/*/locations/*}/glossaries", + 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(ListGlossariesResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getGlossaryMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.translation.v3.TranslationService/GetGlossary") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v3/{name=projects/*/locations/*/glossaries/*}", + 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(Glossary.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + deleteGlossaryMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.translation.v3.TranslationService/DeleteGlossary") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v3/{name=projects/*/locations/*/glossaries/*}", + 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(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (DeleteGlossaryRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private final UnaryCallable translateTextCallable; + private final UnaryCallable detectLanguageCallable; + private final UnaryCallable + getSupportedLanguagesCallable; + private final UnaryCallable + translateDocumentCallable; + private final UnaryCallable batchTranslateTextCallable; + private final OperationCallable< + BatchTranslateTextRequest, BatchTranslateResponse, BatchTranslateMetadata> + batchTranslateTextOperationCallable; + private final UnaryCallable + batchTranslateDocumentCallable; + private final OperationCallable< + BatchTranslateDocumentRequest, + BatchTranslateDocumentResponse, + BatchTranslateDocumentMetadata> + batchTranslateDocumentOperationCallable; + private final UnaryCallable createGlossaryCallable; + private final OperationCallable + createGlossaryOperationCallable; + private final UnaryCallable listGlossariesCallable; + private final UnaryCallable + listGlossariesPagedCallable; + private final UnaryCallable getGlossaryCallable; + private final UnaryCallable deleteGlossaryCallable; + private final OperationCallable< + DeleteGlossaryRequest, DeleteGlossaryResponse, DeleteGlossaryMetadata> + deleteGlossaryOperationCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonOperationsStub httpJsonOperationsStub; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonTranslationServiceStub create(TranslationServiceStubSettings settings) + throws IOException { + return new HttpJsonTranslationServiceStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonTranslationServiceStub create(ClientContext clientContext) + throws IOException { + return new HttpJsonTranslationServiceStub( + TranslationServiceStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonTranslationServiceStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonTranslationServiceStub( + TranslationServiceStubSettings.newHttpJsonBuilder().build(), + clientContext, + callableFactory); + } + + /** + * Constructs an instance of HttpJsonTranslationServiceStub, 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 HttpJsonTranslationServiceStub( + TranslationServiceStubSettings settings, ClientContext clientContext) throws IOException { + this(settings, clientContext, new HttpJsonTranslationServiceCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonTranslationServiceStub, 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 HttpJsonTranslationServiceStub( + TranslationServiceStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.httpJsonOperationsStub = + HttpJsonOperationsStub.create(clientContext, callableFactory, typeRegistry); + + HttpJsonCallSettings + translateTextTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(translateTextMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + detectLanguageTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(detectLanguageMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + getSupportedLanguagesTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getSupportedLanguagesMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + translateDocumentTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(translateDocumentMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings batchTranslateTextTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(batchTranslateTextMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + batchTranslateDocumentTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(batchTranslateDocumentMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings createGlossaryTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createGlossaryMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + listGlossariesTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listGlossariesMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getGlossaryTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getGlossaryMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings deleteGlossaryTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteGlossaryMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.translateTextCallable = + callableFactory.createUnaryCallable( + translateTextTransportSettings, settings.translateTextSettings(), clientContext); + this.detectLanguageCallable = + callableFactory.createUnaryCallable( + detectLanguageTransportSettings, settings.detectLanguageSettings(), clientContext); + this.getSupportedLanguagesCallable = + callableFactory.createUnaryCallable( + getSupportedLanguagesTransportSettings, + settings.getSupportedLanguagesSettings(), + clientContext); + this.translateDocumentCallable = + callableFactory.createUnaryCallable( + translateDocumentTransportSettings, + settings.translateDocumentSettings(), + clientContext); + this.batchTranslateTextCallable = + callableFactory.createUnaryCallable( + batchTranslateTextTransportSettings, + settings.batchTranslateTextSettings(), + clientContext); + this.batchTranslateTextOperationCallable = + callableFactory.createOperationCallable( + batchTranslateTextTransportSettings, + settings.batchTranslateTextOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.batchTranslateDocumentCallable = + callableFactory.createUnaryCallable( + batchTranslateDocumentTransportSettings, + settings.batchTranslateDocumentSettings(), + clientContext); + this.batchTranslateDocumentOperationCallable = + callableFactory.createOperationCallable( + batchTranslateDocumentTransportSettings, + settings.batchTranslateDocumentOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.createGlossaryCallable = + callableFactory.createUnaryCallable( + createGlossaryTransportSettings, settings.createGlossarySettings(), clientContext); + this.createGlossaryOperationCallable = + callableFactory.createOperationCallable( + createGlossaryTransportSettings, + settings.createGlossaryOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.listGlossariesCallable = + callableFactory.createUnaryCallable( + listGlossariesTransportSettings, settings.listGlossariesSettings(), clientContext); + this.listGlossariesPagedCallable = + callableFactory.createPagedCallable( + listGlossariesTransportSettings, settings.listGlossariesSettings(), clientContext); + this.getGlossaryCallable = + callableFactory.createUnaryCallable( + getGlossaryTransportSettings, settings.getGlossarySettings(), clientContext); + this.deleteGlossaryCallable = + callableFactory.createUnaryCallable( + deleteGlossaryTransportSettings, settings.deleteGlossarySettings(), clientContext); + this.deleteGlossaryOperationCallable = + callableFactory.createOperationCallable( + deleteGlossaryTransportSettings, + settings.deleteGlossaryOperationSettings(), + clientContext, + httpJsonOperationsStub); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(translateTextMethodDescriptor); + methodDescriptors.add(detectLanguageMethodDescriptor); + methodDescriptors.add(getSupportedLanguagesMethodDescriptor); + methodDescriptors.add(translateDocumentMethodDescriptor); + methodDescriptors.add(batchTranslateTextMethodDescriptor); + methodDescriptors.add(batchTranslateDocumentMethodDescriptor); + methodDescriptors.add(createGlossaryMethodDescriptor); + methodDescriptors.add(listGlossariesMethodDescriptor); + methodDescriptors.add(getGlossaryMethodDescriptor); + methodDescriptors.add(deleteGlossaryMethodDescriptor); + return methodDescriptors; + } + + public HttpJsonOperationsStub getHttpJsonOperationsStub() { + return httpJsonOperationsStub; + } + + @Override + public UnaryCallable translateTextCallable() { + return translateTextCallable; + } + + @Override + public UnaryCallable detectLanguageCallable() { + return detectLanguageCallable; + } + + @Override + public UnaryCallable + getSupportedLanguagesCallable() { + return getSupportedLanguagesCallable; + } + + @Override + public UnaryCallable + translateDocumentCallable() { + return translateDocumentCallable; + } + + @Override + public UnaryCallable batchTranslateTextCallable() { + return batchTranslateTextCallable; + } + + @Override + public OperationCallable< + BatchTranslateTextRequest, BatchTranslateResponse, BatchTranslateMetadata> + batchTranslateTextOperationCallable() { + return batchTranslateTextOperationCallable; + } + + @Override + public UnaryCallable batchTranslateDocumentCallable() { + return batchTranslateDocumentCallable; + } + + @Override + public OperationCallable< + BatchTranslateDocumentRequest, + BatchTranslateDocumentResponse, + BatchTranslateDocumentMetadata> + batchTranslateDocumentOperationCallable() { + return batchTranslateDocumentOperationCallable; + } + + @Override + public UnaryCallable createGlossaryCallable() { + return createGlossaryCallable; + } + + @Override + public OperationCallable + createGlossaryOperationCallable() { + return createGlossaryOperationCallable; + } + + @Override + public UnaryCallable listGlossariesCallable() { + return listGlossariesCallable; + } + + @Override + public UnaryCallable + listGlossariesPagedCallable() { + return listGlossariesPagedCallable; + } + + @Override + public UnaryCallable getGlossaryCallable() { + return getGlossaryCallable; + } + + @Override + public UnaryCallable deleteGlossaryCallable() { + return deleteGlossaryCallable; + } + + @Override + public OperationCallable + deleteGlossaryOperationCallable() { + return deleteGlossaryOperationCallable; + } + + @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-translate/src/main/java/com/google/cloud/translate/v3/stub/TranslationServiceStub.java b/google-cloud-translate/src/main/java/com/google/cloud/translate/v3/stub/TranslationServiceStub.java index 9beafc60..74e56fe5 100644 --- a/google-cloud-translate/src/main/java/com/google/cloud/translate/v3/stub/TranslationServiceStub.java +++ b/google-cloud-translate/src/main/java/com/google/cloud/translate/v3/stub/TranslationServiceStub.java @@ -58,7 +58,11 @@ public abstract class TranslationServiceStub 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 UnaryCallable translateTextCallable() { diff --git a/google-cloud-translate/src/main/java/com/google/cloud/translate/v3/stub/TranslationServiceStubSettings.java b/google-cloud-translate/src/main/java/com/google/cloud/translate/v3/stub/TranslationServiceStubSettings.java index ea02a17a..8d212900 100644 --- a/google-cloud-translate/src/main/java/com/google/cloud/translate/v3/stub/TranslationServiceStubSettings.java +++ b/google-cloud-translate/src/main/java/com/google/cloud/translate/v3/stub/TranslationServiceStubSettings.java @@ -28,6 +28,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; @@ -290,13 +293,17 @@ public UnaryCallSettings deleteGlossarySetting return deleteGlossaryOperationSettings; } - @BetaApi("A restructuring of stub classes is planned, so this may break in the future") public TranslationServiceStub createStub() throws IOException { if (getTransportChannelProvider() .getTransportName() .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcTranslationServiceStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonTranslationServiceStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -329,18 +336,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(TranslationServiceStubSettings.class)) @@ -348,11 +362,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(TranslationServiceStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return TranslationServiceStubSettings.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); @@ -549,6 +582,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 .translateTextSettings() diff --git a/google-cloud-translate/src/main/java/com/google/cloud/translate/v3beta1/TranslationServiceClient.java b/google-cloud-translate/src/main/java/com/google/cloud/translate/v3beta1/TranslationServiceClient.java index fd2afe94..9672ea88 100644 --- a/google-cloud-translate/src/main/java/com/google/cloud/translate/v3beta1/TranslationServiceClient.java +++ b/google-cloud-translate/src/main/java/com/google/cloud/translate/v3beta1/TranslationServiceClient.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; @@ -31,7 +32,6 @@ import com.google.cloud.translate.v3beta1.stub.TranslationServiceStubSettings; import com.google.common.util.concurrent.MoreExecutors; import com.google.longrunning.Operation; -import com.google.longrunning.OperationsClient; import java.io.IOException; import java.util.List; import java.util.concurrent.TimeUnit; @@ -114,6 +114,21 @@ * TranslationServiceClient.create(translationServiceSettings); * } * + *

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.
+ * TranslationServiceSettings translationServiceSettings =
+ *     TranslationServiceSettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             TranslationServiceSettings.defaultHttpJsonTransportProviderBuilder().build())
+ *         .build();
+ * TranslationServiceClient translationServiceClient =
+ *     TranslationServiceClient.create(translationServiceSettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @BetaApi @@ -121,7 +136,8 @@ public class TranslationServiceClient implements BackgroundResource { private final TranslationServiceSettings settings; private final TranslationServiceStub stub; - private final OperationsClient operationsClient; + private final OperationsClient httpJsonOperationsClient; + private final com.google.longrunning.OperationsClient operationsClient; /** Constructs an instance of TranslationServiceClient with default settings. */ public static final TranslationServiceClient create() throws IOException { @@ -141,7 +157,6 @@ public static final TranslationServiceClient create(TranslationServiceSettings s * Constructs an instance of TranslationServiceClient, using the given stub for making calls. This * is for advanced usage - prefer using create(TranslationServiceSettings). */ - @BetaApi("A restructuring of stub classes is planned, so this may break in the future") public static final TranslationServiceClient create(TranslationServiceStub stub) { return new TranslationServiceClient(stub); } @@ -154,21 +169,23 @@ public static final TranslationServiceClient create(TranslationServiceStub stub) protected TranslationServiceClient(TranslationServiceSettings settings) throws IOException { this.settings = settings; this.stub = ((TranslationServiceStubSettings) 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 TranslationServiceClient(TranslationServiceStub 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 TranslationServiceSettings getSettings() { return settings; } - @BetaApi("A restructuring of stub classes is planned, so this may break in the future") public TranslationServiceStub getStub() { return stub; } @@ -177,10 +194,19 @@ public TranslationServiceStub 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. /** * Translates input text and returns translated text. @@ -1283,7 +1309,7 @@ public final ListGlossariesPagedResponse listGlossaries(ListGlossariesRequest re * while (true) { * ListGlossariesResponse response = * translationServiceClient.listGlossariesCallable().call(request); - * for (Glossary element : response.getResponsesList()) { + * for (Glossary element : response.getGlossariesList()) { * // doThingsWith(element); * } * String nextPageToken = response.getNextPageToken(); diff --git a/google-cloud-translate/src/main/java/com/google/cloud/translate/v3beta1/TranslationServiceSettings.java b/google-cloud-translate/src/main/java/com/google/cloud/translate/v3beta1/TranslationServiceSettings.java index 3417095d..fd89310d 100644 --- a/google-cloud-translate/src/main/java/com/google/cloud/translate/v3beta1/TranslationServiceSettings.java +++ b/google-cloud-translate/src/main/java/com/google/cloud/translate/v3beta1/TranslationServiceSettings.java @@ -23,6 +23,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; @@ -186,11 +187,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return TranslationServiceStubSettings.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 TranslationServiceStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return TranslationServiceStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return TranslationServiceStubSettings.defaultTransportChannelProvider(); } @@ -200,11 +208,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return TranslationServiceStubSettings.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); @@ -242,6 +256,11 @@ private static Builder createDefault() { return new Builder(TranslationServiceStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(TranslationServiceStubSettings.newHttpJsonBuilder()); + } + public TranslationServiceStubSettings.Builder getStubSettingsBuilder() { return ((TranslationServiceStubSettings.Builder) getStubSettings()); } diff --git a/google-cloud-translate/src/main/java/com/google/cloud/translate/v3beta1/stub/HttpJsonTranslationServiceCallableFactory.java b/google-cloud-translate/src/main/java/com/google/cloud/translate/v3beta1/stub/HttpJsonTranslationServiceCallableFactory.java new file mode 100644 index 00000000..4496bf3f --- /dev/null +++ b/google-cloud-translate/src/main/java/com/google/cloud/translate/v3beta1/stub/HttpJsonTranslationServiceCallableFactory.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.translate.v3beta1.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 TranslationService service API. + * + *

This class is for advanced usage. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonTranslationServiceCallableFactory + 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-translate/src/main/java/com/google/cloud/translate/v3beta1/stub/HttpJsonTranslationServiceStub.java b/google-cloud-translate/src/main/java/com/google/cloud/translate/v3beta1/stub/HttpJsonTranslationServiceStub.java new file mode 100644 index 00000000..dddc1b5c --- /dev/null +++ b/google-cloud-translate/src/main/java/com/google/cloud/translate/v3beta1/stub/HttpJsonTranslationServiceStub.java @@ -0,0 +1,812 @@ +/* + * 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.translate.v3beta1.stub; + +import static com.google.cloud.translate.v3beta1.TranslationServiceClient.ListGlossariesPagedResponse; + +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.cloud.translate.v3beta1.BatchTranslateDocumentMetadata; +import com.google.cloud.translate.v3beta1.BatchTranslateDocumentRequest; +import com.google.cloud.translate.v3beta1.BatchTranslateDocumentResponse; +import com.google.cloud.translate.v3beta1.BatchTranslateMetadata; +import com.google.cloud.translate.v3beta1.BatchTranslateResponse; +import com.google.cloud.translate.v3beta1.BatchTranslateTextRequest; +import com.google.cloud.translate.v3beta1.CreateGlossaryMetadata; +import com.google.cloud.translate.v3beta1.CreateGlossaryRequest; +import com.google.cloud.translate.v3beta1.DeleteGlossaryMetadata; +import com.google.cloud.translate.v3beta1.DeleteGlossaryRequest; +import com.google.cloud.translate.v3beta1.DeleteGlossaryResponse; +import com.google.cloud.translate.v3beta1.DetectLanguageRequest; +import com.google.cloud.translate.v3beta1.DetectLanguageResponse; +import com.google.cloud.translate.v3beta1.GetGlossaryRequest; +import com.google.cloud.translate.v3beta1.GetSupportedLanguagesRequest; +import com.google.cloud.translate.v3beta1.Glossary; +import com.google.cloud.translate.v3beta1.ListGlossariesRequest; +import com.google.cloud.translate.v3beta1.ListGlossariesResponse; +import com.google.cloud.translate.v3beta1.SupportedLanguages; +import com.google.cloud.translate.v3beta1.TranslateDocumentRequest; +import com.google.cloud.translate.v3beta1.TranslateDocumentResponse; +import com.google.cloud.translate.v3beta1.TranslateTextRequest; +import com.google.cloud.translate.v3beta1.TranslateTextResponse; +import com.google.longrunning.Operation; +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 TranslationService service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonTranslationServiceStub extends TranslationServiceStub { + private static final TypeRegistry typeRegistry = + TypeRegistry.newBuilder() + .add(BatchTranslateDocumentResponse.getDescriptor()) + .add(Glossary.getDescriptor()) + .add(DeleteGlossaryMetadata.getDescriptor()) + .add(CreateGlossaryMetadata.getDescriptor()) + .add(BatchTranslateMetadata.getDescriptor()) + .add(BatchTranslateDocumentMetadata.getDescriptor()) + .add(DeleteGlossaryResponse.getDescriptor()) + .add(BatchTranslateResponse.getDescriptor()) + .build(); + + private static final ApiMethodDescriptor + translateTextMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.translation.v3beta1.TranslationService/TranslateText") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v3beta1/{parent=projects/*/locations/*}:translateText", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setAdditionalPaths("/v3beta1/{parent=projects/*}:translateText") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearParent().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(TranslateTextResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + detectLanguageMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.translation.v3beta1.TranslationService/DetectLanguage") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v3beta1/{parent=projects/*/locations/*}:detectLanguage", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setAdditionalPaths("/v3beta1/{parent=projects/*}:detectLanguage") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearParent().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(DetectLanguageResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getSupportedLanguagesMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.translation.v3beta1.TranslationService/GetSupportedLanguages") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v3beta1/{parent=projects/*/locations/*}/supportedLanguages", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "parent", request.getParent()); + return fields; + }) + .setAdditionalPaths("/v3beta1/{parent=projects/*}/supportedLanguages") + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam( + fields, "displayLanguageCode", request.getDisplayLanguageCode()); + serializer.putQueryParam(fields, "model", request.getModel()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(SupportedLanguages.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + translateDocumentMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.translation.v3beta1.TranslationService/TranslateDocument") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v3beta1/{parent=projects/*/locations/*}:translateDocument", + 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("*", request.toBuilder().clearParent().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(TranslateDocumentResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + batchTranslateTextMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.translation.v3beta1.TranslationService/BatchTranslateText") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v3beta1/{parent=projects/*/locations/*}:batchTranslateText", + 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("*", request.toBuilder().clearParent().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (BatchTranslateTextRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + batchTranslateDocumentMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.translation.v3beta1.TranslationService/BatchTranslateDocument") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v3beta1/{parent=projects/*/locations/*}:batchTranslateDocument", + 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("*", request.toBuilder().clearParent().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (BatchTranslateDocumentRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + createGlossaryMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.translation.v3beta1.TranslationService/CreateGlossary") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v3beta1/{parent=projects/*/locations/*}/glossaries", + 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("glossary", request.getGlossary())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (CreateGlossaryRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + listGlossariesMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.translation.v3beta1.TranslationService/ListGlossaries") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v3beta1/{parent=projects/*/locations/*}/glossaries", + 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(ListGlossariesResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getGlossaryMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.cloud.translation.v3beta1.TranslationService/GetGlossary") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v3beta1/{name=projects/*/locations/*/glossaries/*}", + 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(Glossary.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + deleteGlossaryMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.translation.v3beta1.TranslationService/DeleteGlossary") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v3beta1/{name=projects/*/locations/*/glossaries/*}", + 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(Operation.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .setOperationSnapshotFactory( + (DeleteGlossaryRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private final UnaryCallable translateTextCallable; + private final UnaryCallable detectLanguageCallable; + private final UnaryCallable + getSupportedLanguagesCallable; + private final UnaryCallable + translateDocumentCallable; + private final UnaryCallable batchTranslateTextCallable; + private final OperationCallable< + BatchTranslateTextRequest, BatchTranslateResponse, BatchTranslateMetadata> + batchTranslateTextOperationCallable; + private final UnaryCallable + batchTranslateDocumentCallable; + private final OperationCallable< + BatchTranslateDocumentRequest, + BatchTranslateDocumentResponse, + BatchTranslateDocumentMetadata> + batchTranslateDocumentOperationCallable; + private final UnaryCallable createGlossaryCallable; + private final OperationCallable + createGlossaryOperationCallable; + private final UnaryCallable listGlossariesCallable; + private final UnaryCallable + listGlossariesPagedCallable; + private final UnaryCallable getGlossaryCallable; + private final UnaryCallable deleteGlossaryCallable; + private final OperationCallable< + DeleteGlossaryRequest, DeleteGlossaryResponse, DeleteGlossaryMetadata> + deleteGlossaryOperationCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonOperationsStub httpJsonOperationsStub; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonTranslationServiceStub create(TranslationServiceStubSettings settings) + throws IOException { + return new HttpJsonTranslationServiceStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonTranslationServiceStub create(ClientContext clientContext) + throws IOException { + return new HttpJsonTranslationServiceStub( + TranslationServiceStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonTranslationServiceStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonTranslationServiceStub( + TranslationServiceStubSettings.newHttpJsonBuilder().build(), + clientContext, + callableFactory); + } + + /** + * Constructs an instance of HttpJsonTranslationServiceStub, 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 HttpJsonTranslationServiceStub( + TranslationServiceStubSettings settings, ClientContext clientContext) throws IOException { + this(settings, clientContext, new HttpJsonTranslationServiceCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonTranslationServiceStub, 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 HttpJsonTranslationServiceStub( + TranslationServiceStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.httpJsonOperationsStub = + HttpJsonOperationsStub.create(clientContext, callableFactory, typeRegistry); + + HttpJsonCallSettings + translateTextTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(translateTextMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + detectLanguageTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(detectLanguageMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + getSupportedLanguagesTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getSupportedLanguagesMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + translateDocumentTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(translateDocumentMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings batchTranslateTextTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(batchTranslateTextMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + batchTranslateDocumentTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(batchTranslateDocumentMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings createGlossaryTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createGlossaryMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + listGlossariesTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listGlossariesMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getGlossaryTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getGlossaryMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings deleteGlossaryTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteGlossaryMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.translateTextCallable = + callableFactory.createUnaryCallable( + translateTextTransportSettings, settings.translateTextSettings(), clientContext); + this.detectLanguageCallable = + callableFactory.createUnaryCallable( + detectLanguageTransportSettings, settings.detectLanguageSettings(), clientContext); + this.getSupportedLanguagesCallable = + callableFactory.createUnaryCallable( + getSupportedLanguagesTransportSettings, + settings.getSupportedLanguagesSettings(), + clientContext); + this.translateDocumentCallable = + callableFactory.createUnaryCallable( + translateDocumentTransportSettings, + settings.translateDocumentSettings(), + clientContext); + this.batchTranslateTextCallable = + callableFactory.createUnaryCallable( + batchTranslateTextTransportSettings, + settings.batchTranslateTextSettings(), + clientContext); + this.batchTranslateTextOperationCallable = + callableFactory.createOperationCallable( + batchTranslateTextTransportSettings, + settings.batchTranslateTextOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.batchTranslateDocumentCallable = + callableFactory.createUnaryCallable( + batchTranslateDocumentTransportSettings, + settings.batchTranslateDocumentSettings(), + clientContext); + this.batchTranslateDocumentOperationCallable = + callableFactory.createOperationCallable( + batchTranslateDocumentTransportSettings, + settings.batchTranslateDocumentOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.createGlossaryCallable = + callableFactory.createUnaryCallable( + createGlossaryTransportSettings, settings.createGlossarySettings(), clientContext); + this.createGlossaryOperationCallable = + callableFactory.createOperationCallable( + createGlossaryTransportSettings, + settings.createGlossaryOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.listGlossariesCallable = + callableFactory.createUnaryCallable( + listGlossariesTransportSettings, settings.listGlossariesSettings(), clientContext); + this.listGlossariesPagedCallable = + callableFactory.createPagedCallable( + listGlossariesTransportSettings, settings.listGlossariesSettings(), clientContext); + this.getGlossaryCallable = + callableFactory.createUnaryCallable( + getGlossaryTransportSettings, settings.getGlossarySettings(), clientContext); + this.deleteGlossaryCallable = + callableFactory.createUnaryCallable( + deleteGlossaryTransportSettings, settings.deleteGlossarySettings(), clientContext); + this.deleteGlossaryOperationCallable = + callableFactory.createOperationCallable( + deleteGlossaryTransportSettings, + settings.deleteGlossaryOperationSettings(), + clientContext, + httpJsonOperationsStub); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(translateTextMethodDescriptor); + methodDescriptors.add(detectLanguageMethodDescriptor); + methodDescriptors.add(getSupportedLanguagesMethodDescriptor); + methodDescriptors.add(translateDocumentMethodDescriptor); + methodDescriptors.add(batchTranslateTextMethodDescriptor); + methodDescriptors.add(batchTranslateDocumentMethodDescriptor); + methodDescriptors.add(createGlossaryMethodDescriptor); + methodDescriptors.add(listGlossariesMethodDescriptor); + methodDescriptors.add(getGlossaryMethodDescriptor); + methodDescriptors.add(deleteGlossaryMethodDescriptor); + return methodDescriptors; + } + + public HttpJsonOperationsStub getHttpJsonOperationsStub() { + return httpJsonOperationsStub; + } + + @Override + public UnaryCallable translateTextCallable() { + return translateTextCallable; + } + + @Override + public UnaryCallable detectLanguageCallable() { + return detectLanguageCallable; + } + + @Override + public UnaryCallable + getSupportedLanguagesCallable() { + return getSupportedLanguagesCallable; + } + + @Override + public UnaryCallable + translateDocumentCallable() { + return translateDocumentCallable; + } + + @Override + public UnaryCallable batchTranslateTextCallable() { + return batchTranslateTextCallable; + } + + @Override + public OperationCallable< + BatchTranslateTextRequest, BatchTranslateResponse, BatchTranslateMetadata> + batchTranslateTextOperationCallable() { + return batchTranslateTextOperationCallable; + } + + @Override + public UnaryCallable batchTranslateDocumentCallable() { + return batchTranslateDocumentCallable; + } + + @Override + public OperationCallable< + BatchTranslateDocumentRequest, + BatchTranslateDocumentResponse, + BatchTranslateDocumentMetadata> + batchTranslateDocumentOperationCallable() { + return batchTranslateDocumentOperationCallable; + } + + @Override + public UnaryCallable createGlossaryCallable() { + return createGlossaryCallable; + } + + @Override + public OperationCallable + createGlossaryOperationCallable() { + return createGlossaryOperationCallable; + } + + @Override + public UnaryCallable listGlossariesCallable() { + return listGlossariesCallable; + } + + @Override + public UnaryCallable + listGlossariesPagedCallable() { + return listGlossariesPagedCallable; + } + + @Override + public UnaryCallable getGlossaryCallable() { + return getGlossaryCallable; + } + + @Override + public UnaryCallable deleteGlossaryCallable() { + return deleteGlossaryCallable; + } + + @Override + public OperationCallable + deleteGlossaryOperationCallable() { + return deleteGlossaryOperationCallable; + } + + @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-translate/src/main/java/com/google/cloud/translate/v3beta1/stub/TranslationServiceStub.java b/google-cloud-translate/src/main/java/com/google/cloud/translate/v3beta1/stub/TranslationServiceStub.java index e7a4135d..ce71df3b 100644 --- a/google-cloud-translate/src/main/java/com/google/cloud/translate/v3beta1/stub/TranslationServiceStub.java +++ b/google-cloud-translate/src/main/java/com/google/cloud/translate/v3beta1/stub/TranslationServiceStub.java @@ -60,7 +60,11 @@ public abstract class TranslationServiceStub 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 UnaryCallable translateTextCallable() { diff --git a/google-cloud-translate/src/main/java/com/google/cloud/translate/v3beta1/stub/TranslationServiceStubSettings.java b/google-cloud-translate/src/main/java/com/google/cloud/translate/v3beta1/stub/TranslationServiceStubSettings.java index 43c44fac..12219409 100644 --- a/google-cloud-translate/src/main/java/com/google/cloud/translate/v3beta1/stub/TranslationServiceStubSettings.java +++ b/google-cloud-translate/src/main/java/com/google/cloud/translate/v3beta1/stub/TranslationServiceStubSettings.java @@ -28,6 +28,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; @@ -291,13 +294,17 @@ public UnaryCallSettings deleteGlossarySetting return deleteGlossaryOperationSettings; } - @BetaApi("A restructuring of stub classes is planned, so this may break in the future") public TranslationServiceStub createStub() throws IOException { if (getTransportChannelProvider() .getTransportName() .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcTranslationServiceStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonTranslationServiceStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -330,18 +337,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(TranslationServiceStubSettings.class)) @@ -349,11 +363,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(TranslationServiceStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return TranslationServiceStubSettings.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); @@ -550,6 +583,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 .translateTextSettings() diff --git a/google-cloud-translate/src/test/java/com/google/cloud/translate/v3/TranslationServiceClientHttpJsonTest.java b/google-cloud-translate/src/test/java/com/google/cloud/translate/v3/TranslationServiceClientHttpJsonTest.java new file mode 100644 index 00000000..b9552e6e --- /dev/null +++ b/google-cloud-translate/src/test/java/com/google/cloud/translate/v3/TranslationServiceClientHttpJsonTest.java @@ -0,0 +1,1187 @@ +/* + * 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.translate.v3; + +import static com.google.cloud.translate.v3.TranslationServiceClient.ListGlossariesPagedResponse; + +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.translate.v3.stub.HttpJsonTranslationServiceStub; +import com.google.common.collect.Lists; +import com.google.longrunning.Operation; +import com.google.protobuf.Any; +import com.google.protobuf.Timestamp; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +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 TranslationServiceClientHttpJsonTest { + private static MockHttpService mockService; + private static TranslationServiceClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonTranslationServiceStub.getMethodDescriptors(), + TranslationServiceSettings.getDefaultEndpoint()); + TranslationServiceSettings settings = + TranslationServiceSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + TranslationServiceSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = TranslationServiceClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void translateTextTest() throws Exception { + TranslateTextResponse expectedResponse = + TranslateTextResponse.newBuilder() + .addAllTranslations(new ArrayList()) + .addAllGlossaryTranslations(new ArrayList()) + .build(); + mockService.addResponse(expectedResponse); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + String targetLanguageCode = "targetLanguageCode-106414698"; + List contents = new ArrayList<>(); + + TranslateTextResponse actualResponse = + client.translateText(parent, targetLanguageCode, contents); + 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 translateTextExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + String targetLanguageCode = "targetLanguageCode-106414698"; + List contents = new ArrayList<>(); + client.translateText(parent, targetLanguageCode, contents); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void translateTextTest2() throws Exception { + TranslateTextResponse expectedResponse = + TranslateTextResponse.newBuilder() + .addAllTranslations(new ArrayList()) + .addAllGlossaryTranslations(new ArrayList()) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-5833/locations/location-5833"; + String targetLanguageCode = "targetLanguageCode-106414698"; + List contents = new ArrayList<>(); + + TranslateTextResponse actualResponse = + client.translateText(parent, targetLanguageCode, contents); + 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 translateTextExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-5833/locations/location-5833"; + String targetLanguageCode = "targetLanguageCode-106414698"; + List contents = new ArrayList<>(); + client.translateText(parent, targetLanguageCode, contents); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void translateTextTest3() throws Exception { + TranslateTextResponse expectedResponse = + TranslateTextResponse.newBuilder() + .addAllTranslations(new ArrayList()) + .addAllGlossaryTranslations(new ArrayList()) + .build(); + mockService.addResponse(expectedResponse); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + String model = "model104069929"; + String mimeType = "mimeType-1392120434"; + String sourceLanguageCode = "sourceLanguageCode1645917472"; + String targetLanguageCode = "targetLanguageCode-106414698"; + List contents = new ArrayList<>(); + + TranslateTextResponse actualResponse = + client.translateText( + parent, model, mimeType, sourceLanguageCode, targetLanguageCode, contents); + 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 translateTextExceptionTest3() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + String model = "model104069929"; + String mimeType = "mimeType-1392120434"; + String sourceLanguageCode = "sourceLanguageCode1645917472"; + String targetLanguageCode = "targetLanguageCode-106414698"; + List contents = new ArrayList<>(); + client.translateText( + parent, model, mimeType, sourceLanguageCode, targetLanguageCode, contents); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void translateTextTest4() throws Exception { + TranslateTextResponse expectedResponse = + TranslateTextResponse.newBuilder() + .addAllTranslations(new ArrayList()) + .addAllGlossaryTranslations(new ArrayList()) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-5833/locations/location-5833"; + String model = "model104069929"; + String mimeType = "mimeType-1392120434"; + String sourceLanguageCode = "sourceLanguageCode1645917472"; + String targetLanguageCode = "targetLanguageCode-106414698"; + List contents = new ArrayList<>(); + + TranslateTextResponse actualResponse = + client.translateText( + parent, model, mimeType, sourceLanguageCode, targetLanguageCode, contents); + 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 translateTextExceptionTest4() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-5833/locations/location-5833"; + String model = "model104069929"; + String mimeType = "mimeType-1392120434"; + String sourceLanguageCode = "sourceLanguageCode1645917472"; + String targetLanguageCode = "targetLanguageCode-106414698"; + List contents = new ArrayList<>(); + client.translateText( + parent, model, mimeType, sourceLanguageCode, targetLanguageCode, contents); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void detectLanguageTest() throws Exception { + DetectLanguageResponse expectedResponse = + DetectLanguageResponse.newBuilder() + .addAllLanguages(new ArrayList()) + .build(); + mockService.addResponse(expectedResponse); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + String model = "model104069929"; + String mimeType = "mimeType-1392120434"; + String content = "content951530617"; + + DetectLanguageResponse actualResponse = client.detectLanguage(parent, model, mimeType, content); + 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 detectLanguageExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + String model = "model104069929"; + String mimeType = "mimeType-1392120434"; + String content = "content951530617"; + client.detectLanguage(parent, model, mimeType, content); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void detectLanguageTest2() throws Exception { + DetectLanguageResponse expectedResponse = + DetectLanguageResponse.newBuilder() + .addAllLanguages(new ArrayList()) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-5833/locations/location-5833"; + String model = "model104069929"; + String mimeType = "mimeType-1392120434"; + String content = "content951530617"; + + DetectLanguageResponse actualResponse = client.detectLanguage(parent, model, mimeType, content); + 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 detectLanguageExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-5833/locations/location-5833"; + String model = "model104069929"; + String mimeType = "mimeType-1392120434"; + String content = "content951530617"; + client.detectLanguage(parent, model, mimeType, content); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getSupportedLanguagesTest() throws Exception { + SupportedLanguages expectedResponse = + SupportedLanguages.newBuilder().addAllLanguages(new ArrayList()).build(); + mockService.addResponse(expectedResponse); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + String model = "model104069929"; + String displayLanguageCode = "displayLanguageCode-1457478841"; + + SupportedLanguages actualResponse = + client.getSupportedLanguages(parent, model, displayLanguageCode); + 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 getSupportedLanguagesExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + String model = "model104069929"; + String displayLanguageCode = "displayLanguageCode-1457478841"; + client.getSupportedLanguages(parent, model, displayLanguageCode); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getSupportedLanguagesTest2() throws Exception { + SupportedLanguages expectedResponse = + SupportedLanguages.newBuilder().addAllLanguages(new ArrayList()).build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-5833/locations/location-5833"; + String model = "model104069929"; + String displayLanguageCode = "displayLanguageCode-1457478841"; + + SupportedLanguages actualResponse = + client.getSupportedLanguages(parent, model, displayLanguageCode); + 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 getSupportedLanguagesExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-5833/locations/location-5833"; + String model = "model104069929"; + String displayLanguageCode = "displayLanguageCode-1457478841"; + client.getSupportedLanguages(parent, model, displayLanguageCode); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void translateDocumentTest() throws Exception { + TranslateDocumentResponse expectedResponse = + TranslateDocumentResponse.newBuilder() + .setDocumentTranslation(DocumentTranslation.newBuilder().build()) + .setGlossaryDocumentTranslation(DocumentTranslation.newBuilder().build()) + .setModel("model104069929") + .setGlossaryConfig(TranslateTextGlossaryConfig.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + TranslateDocumentRequest request = + TranslateDocumentRequest.newBuilder() + .setParent("projects/project-5833/locations/location-5833") + .setSourceLanguageCode("sourceLanguageCode1645917472") + .setTargetLanguageCode("targetLanguageCode-106414698") + .setDocumentInputConfig(DocumentInputConfig.newBuilder().build()) + .setDocumentOutputConfig(DocumentOutputConfig.newBuilder().build()) + .setModel("model104069929") + .setGlossaryConfig(TranslateTextGlossaryConfig.newBuilder().build()) + .putAllLabels(new HashMap()) + .build(); + + TranslateDocumentResponse actualResponse = client.translateDocument(request); + 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 translateDocumentExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + TranslateDocumentRequest request = + TranslateDocumentRequest.newBuilder() + .setParent("projects/project-5833/locations/location-5833") + .setSourceLanguageCode("sourceLanguageCode1645917472") + .setTargetLanguageCode("targetLanguageCode-106414698") + .setDocumentInputConfig(DocumentInputConfig.newBuilder().build()) + .setDocumentOutputConfig(DocumentOutputConfig.newBuilder().build()) + .setModel("model104069929") + .setGlossaryConfig(TranslateTextGlossaryConfig.newBuilder().build()) + .putAllLabels(new HashMap()) + .build(); + client.translateDocument(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void batchTranslateTextTest() throws Exception { + BatchTranslateResponse expectedResponse = + BatchTranslateResponse.newBuilder() + .setTotalCharacters(-1368640955) + .setTranslatedCharacters(-1337326221) + .setFailedCharacters(1723028396) + .setSubmitTime(Timestamp.newBuilder().build()) + .setEndTime(Timestamp.newBuilder().build()) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("batchTranslateTextTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + BatchTranslateTextRequest request = + BatchTranslateTextRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setSourceLanguageCode("sourceLanguageCode1645917472") + .addAllTargetLanguageCodes(new ArrayList()) + .putAllModels(new HashMap()) + .addAllInputConfigs(new ArrayList()) + .setOutputConfig(OutputConfig.newBuilder().build()) + .putAllGlossaries(new HashMap()) + .putAllLabels(new HashMap()) + .build(); + + BatchTranslateResponse actualResponse = client.batchTranslateTextAsync(request).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 batchTranslateTextExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + BatchTranslateTextRequest request = + BatchTranslateTextRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setSourceLanguageCode("sourceLanguageCode1645917472") + .addAllTargetLanguageCodes(new ArrayList()) + .putAllModels(new HashMap()) + .addAllInputConfigs(new ArrayList()) + .setOutputConfig(OutputConfig.newBuilder().build()) + .putAllGlossaries(new HashMap()) + .putAllLabels(new HashMap()) + .build(); + client.batchTranslateTextAsync(request).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void batchTranslateDocumentTest() throws Exception { + BatchTranslateDocumentResponse expectedResponse = + BatchTranslateDocumentResponse.newBuilder() + .setTotalPages(-396186871) + .setTranslatedPages(-1652747493) + .setFailedPages(-2002254526) + .setTotalBillablePages(1292117569) + .setTotalCharacters(-1368640955) + .setTranslatedCharacters(-1337326221) + .setFailedCharacters(1723028396) + .setTotalBillableCharacters(1242495501) + .setSubmitTime(Timestamp.newBuilder().build()) + .setEndTime(Timestamp.newBuilder().build()) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("batchTranslateDocumentTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + String sourceLanguageCode = "sourceLanguageCode1645917472"; + List targetLanguageCodes = new ArrayList<>(); + List inputConfigs = new ArrayList<>(); + BatchDocumentOutputConfig outputConfig = BatchDocumentOutputConfig.newBuilder().build(); + + BatchTranslateDocumentResponse actualResponse = + client + .batchTranslateDocumentAsync( + parent, sourceLanguageCode, targetLanguageCodes, inputConfigs, outputConfig) + .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 batchTranslateDocumentExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + String sourceLanguageCode = "sourceLanguageCode1645917472"; + List targetLanguageCodes = new ArrayList<>(); + List inputConfigs = new ArrayList<>(); + BatchDocumentOutputConfig outputConfig = BatchDocumentOutputConfig.newBuilder().build(); + client + .batchTranslateDocumentAsync( + parent, sourceLanguageCode, targetLanguageCodes, inputConfigs, outputConfig) + .get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void batchTranslateDocumentTest2() throws Exception { + BatchTranslateDocumentResponse expectedResponse = + BatchTranslateDocumentResponse.newBuilder() + .setTotalPages(-396186871) + .setTranslatedPages(-1652747493) + .setFailedPages(-2002254526) + .setTotalBillablePages(1292117569) + .setTotalCharacters(-1368640955) + .setTranslatedCharacters(-1337326221) + .setFailedCharacters(1723028396) + .setTotalBillableCharacters(1242495501) + .setSubmitTime(Timestamp.newBuilder().build()) + .setEndTime(Timestamp.newBuilder().build()) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("batchTranslateDocumentTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String parent = "projects/project-5833/locations/location-5833"; + String sourceLanguageCode = "sourceLanguageCode1645917472"; + List targetLanguageCodes = new ArrayList<>(); + List inputConfigs = new ArrayList<>(); + BatchDocumentOutputConfig outputConfig = BatchDocumentOutputConfig.newBuilder().build(); + + BatchTranslateDocumentResponse actualResponse = + client + .batchTranslateDocumentAsync( + parent, sourceLanguageCode, targetLanguageCodes, inputConfigs, outputConfig) + .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 batchTranslateDocumentExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-5833/locations/location-5833"; + String sourceLanguageCode = "sourceLanguageCode1645917472"; + List targetLanguageCodes = new ArrayList<>(); + List inputConfigs = new ArrayList<>(); + BatchDocumentOutputConfig outputConfig = BatchDocumentOutputConfig.newBuilder().build(); + client + .batchTranslateDocumentAsync( + parent, sourceLanguageCode, targetLanguageCodes, inputConfigs, outputConfig) + .get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void createGlossaryTest() throws Exception { + Glossary expectedResponse = + Glossary.newBuilder() + .setName(GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]").toString()) + .setInputConfig(GlossaryInputConfig.newBuilder().build()) + .setEntryCount(-811131134) + .setSubmitTime(Timestamp.newBuilder().build()) + .setEndTime(Timestamp.newBuilder().build()) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("createGlossaryTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + Glossary glossary = Glossary.newBuilder().build(); + + Glossary actualResponse = client.createGlossaryAsync(parent, glossary).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 createGlossaryExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + Glossary glossary = Glossary.newBuilder().build(); + client.createGlossaryAsync(parent, glossary).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void createGlossaryTest2() throws Exception { + Glossary expectedResponse = + Glossary.newBuilder() + .setName(GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]").toString()) + .setInputConfig(GlossaryInputConfig.newBuilder().build()) + .setEntryCount(-811131134) + .setSubmitTime(Timestamp.newBuilder().build()) + .setEndTime(Timestamp.newBuilder().build()) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("createGlossaryTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String parent = "projects/project-5833/locations/location-5833"; + Glossary glossary = Glossary.newBuilder().build(); + + Glossary actualResponse = client.createGlossaryAsync(parent, glossary).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 createGlossaryExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-5833/locations/location-5833"; + Glossary glossary = Glossary.newBuilder().build(); + client.createGlossaryAsync(parent, glossary).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void listGlossariesTest() throws Exception { + Glossary responsesElement = Glossary.newBuilder().build(); + ListGlossariesResponse expectedResponse = + ListGlossariesResponse.newBuilder() + .setNextPageToken("") + .addAllGlossaries(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + + ListGlossariesPagedResponse pagedListResponse = client.listGlossaries(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getGlossariesList().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 listGlossariesExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + client.listGlossaries(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listGlossariesTest2() throws Exception { + Glossary responsesElement = Glossary.newBuilder().build(); + ListGlossariesResponse expectedResponse = + ListGlossariesResponse.newBuilder() + .setNextPageToken("") + .addAllGlossaries(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-5833/locations/location-5833"; + + ListGlossariesPagedResponse pagedListResponse = client.listGlossaries(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getGlossariesList().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 listGlossariesExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-5833/locations/location-5833"; + client.listGlossaries(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getGlossaryTest() throws Exception { + Glossary expectedResponse = + Glossary.newBuilder() + .setName(GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]").toString()) + .setInputConfig(GlossaryInputConfig.newBuilder().build()) + .setEntryCount(-811131134) + .setSubmitTime(Timestamp.newBuilder().build()) + .setEndTime(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + GlossaryName name = GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]"); + + Glossary actualResponse = client.getGlossary(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 getGlossaryExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + GlossaryName name = GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]"); + client.getGlossary(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getGlossaryTest2() throws Exception { + Glossary expectedResponse = + Glossary.newBuilder() + .setName(GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]").toString()) + .setInputConfig(GlossaryInputConfig.newBuilder().build()) + .setEntryCount(-811131134) + .setSubmitTime(Timestamp.newBuilder().build()) + .setEndTime(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-9868/locations/location-9868/glossaries/glossarie-9868"; + + Glossary actualResponse = client.getGlossary(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 getGlossaryExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-9868/locations/location-9868/glossaries/glossarie-9868"; + client.getGlossary(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteGlossaryTest() throws Exception { + DeleteGlossaryResponse expectedResponse = + DeleteGlossaryResponse.newBuilder() + .setName("name3373707") + .setSubmitTime(Timestamp.newBuilder().build()) + .setEndTime(Timestamp.newBuilder().build()) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("deleteGlossaryTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + GlossaryName name = GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]"); + + DeleteGlossaryResponse actualResponse = client.deleteGlossaryAsync(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 deleteGlossaryExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + GlossaryName name = GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]"); + client.deleteGlossaryAsync(name).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void deleteGlossaryTest2() throws Exception { + DeleteGlossaryResponse expectedResponse = + DeleteGlossaryResponse.newBuilder() + .setName("name3373707") + .setSubmitTime(Timestamp.newBuilder().build()) + .setEndTime(Timestamp.newBuilder().build()) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("deleteGlossaryTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String name = "projects/project-9868/locations/location-9868/glossaries/glossarie-9868"; + + DeleteGlossaryResponse actualResponse = client.deleteGlossaryAsync(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 deleteGlossaryExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-9868/locations/location-9868/glossaries/glossarie-9868"; + client.deleteGlossaryAsync(name).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } +} diff --git a/google-cloud-translate/src/test/java/com/google/cloud/translate/v3beta1/TranslationServiceClientHttpJsonTest.java b/google-cloud-translate/src/test/java/com/google/cloud/translate/v3beta1/TranslationServiceClientHttpJsonTest.java new file mode 100644 index 00000000..c613c472 --- /dev/null +++ b/google-cloud-translate/src/test/java/com/google/cloud/translate/v3beta1/TranslationServiceClientHttpJsonTest.java @@ -0,0 +1,1036 @@ +/* + * 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.translate.v3beta1; + +import static com.google.cloud.translate.v3beta1.TranslationServiceClient.ListGlossariesPagedResponse; + +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.translate.v3beta1.stub.HttpJsonTranslationServiceStub; +import com.google.common.collect.Lists; +import com.google.longrunning.Operation; +import com.google.protobuf.Any; +import com.google.protobuf.Timestamp; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +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 TranslationServiceClientHttpJsonTest { + private static MockHttpService mockService; + private static TranslationServiceClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonTranslationServiceStub.getMethodDescriptors(), + TranslationServiceSettings.getDefaultEndpoint()); + TranslationServiceSettings settings = + TranslationServiceSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + TranslationServiceSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = TranslationServiceClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void translateTextTest() throws Exception { + TranslateTextResponse expectedResponse = + TranslateTextResponse.newBuilder() + .addAllTranslations(new ArrayList()) + .addAllGlossaryTranslations(new ArrayList()) + .build(); + mockService.addResponse(expectedResponse); + + TranslateTextRequest request = + TranslateTextRequest.newBuilder() + .addAllContents(new ArrayList()) + .setMimeType("mimeType-1392120434") + .setSourceLanguageCode("sourceLanguageCode1645917472") + .setTargetLanguageCode("targetLanguageCode-106414698") + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setModel("model104069929") + .setGlossaryConfig(TranslateTextGlossaryConfig.newBuilder().build()) + .putAllLabels(new HashMap()) + .build(); + + TranslateTextResponse actualResponse = client.translateText(request); + 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 translateTextExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + TranslateTextRequest request = + TranslateTextRequest.newBuilder() + .addAllContents(new ArrayList()) + .setMimeType("mimeType-1392120434") + .setSourceLanguageCode("sourceLanguageCode1645917472") + .setTargetLanguageCode("targetLanguageCode-106414698") + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setModel("model104069929") + .setGlossaryConfig(TranslateTextGlossaryConfig.newBuilder().build()) + .putAllLabels(new HashMap()) + .build(); + client.translateText(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void detectLanguageTest() throws Exception { + DetectLanguageResponse expectedResponse = + DetectLanguageResponse.newBuilder() + .addAllLanguages(new ArrayList()) + .build(); + mockService.addResponse(expectedResponse); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + String model = "model104069929"; + String mimeType = "mimeType-1392120434"; + + DetectLanguageResponse actualResponse = client.detectLanguage(parent, model, mimeType); + 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 detectLanguageExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + String model = "model104069929"; + String mimeType = "mimeType-1392120434"; + client.detectLanguage(parent, model, mimeType); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void detectLanguageTest2() throws Exception { + DetectLanguageResponse expectedResponse = + DetectLanguageResponse.newBuilder() + .addAllLanguages(new ArrayList()) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-5833/locations/location-5833"; + String model = "model104069929"; + String mimeType = "mimeType-1392120434"; + + DetectLanguageResponse actualResponse = client.detectLanguage(parent, model, mimeType); + 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 detectLanguageExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-5833/locations/location-5833"; + String model = "model104069929"; + String mimeType = "mimeType-1392120434"; + client.detectLanguage(parent, model, mimeType); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getSupportedLanguagesTest() throws Exception { + SupportedLanguages expectedResponse = + SupportedLanguages.newBuilder().addAllLanguages(new ArrayList()).build(); + mockService.addResponse(expectedResponse); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + String displayLanguageCode = "displayLanguageCode-1457478841"; + String model = "model104069929"; + + SupportedLanguages actualResponse = + client.getSupportedLanguages(parent, displayLanguageCode, model); + 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 getSupportedLanguagesExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + String displayLanguageCode = "displayLanguageCode-1457478841"; + String model = "model104069929"; + client.getSupportedLanguages(parent, displayLanguageCode, model); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getSupportedLanguagesTest2() throws Exception { + SupportedLanguages expectedResponse = + SupportedLanguages.newBuilder().addAllLanguages(new ArrayList()).build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-5833/locations/location-5833"; + String displayLanguageCode = "displayLanguageCode-1457478841"; + String model = "model104069929"; + + SupportedLanguages actualResponse = + client.getSupportedLanguages(parent, displayLanguageCode, model); + 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 getSupportedLanguagesExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-5833/locations/location-5833"; + String displayLanguageCode = "displayLanguageCode-1457478841"; + String model = "model104069929"; + client.getSupportedLanguages(parent, displayLanguageCode, model); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void translateDocumentTest() throws Exception { + TranslateDocumentResponse expectedResponse = + TranslateDocumentResponse.newBuilder() + .setDocumentTranslation(DocumentTranslation.newBuilder().build()) + .setGlossaryDocumentTranslation(DocumentTranslation.newBuilder().build()) + .setModel("model104069929") + .setGlossaryConfig(TranslateTextGlossaryConfig.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + TranslateDocumentRequest request = + TranslateDocumentRequest.newBuilder() + .setParent("projects/project-5833/locations/location-5833") + .setSourceLanguageCode("sourceLanguageCode1645917472") + .setTargetLanguageCode("targetLanguageCode-106414698") + .setDocumentInputConfig(DocumentInputConfig.newBuilder().build()) + .setDocumentOutputConfig(DocumentOutputConfig.newBuilder().build()) + .setModel("model104069929") + .setGlossaryConfig(TranslateTextGlossaryConfig.newBuilder().build()) + .putAllLabels(new HashMap()) + .build(); + + TranslateDocumentResponse actualResponse = client.translateDocument(request); + 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 translateDocumentExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + TranslateDocumentRequest request = + TranslateDocumentRequest.newBuilder() + .setParent("projects/project-5833/locations/location-5833") + .setSourceLanguageCode("sourceLanguageCode1645917472") + .setTargetLanguageCode("targetLanguageCode-106414698") + .setDocumentInputConfig(DocumentInputConfig.newBuilder().build()) + .setDocumentOutputConfig(DocumentOutputConfig.newBuilder().build()) + .setModel("model104069929") + .setGlossaryConfig(TranslateTextGlossaryConfig.newBuilder().build()) + .putAllLabels(new HashMap()) + .build(); + client.translateDocument(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void batchTranslateTextTest() throws Exception { + BatchTranslateResponse expectedResponse = + BatchTranslateResponse.newBuilder() + .setTotalCharacters(-1368640955) + .setTranslatedCharacters(-1337326221) + .setFailedCharacters(1723028396) + .setSubmitTime(Timestamp.newBuilder().build()) + .setEndTime(Timestamp.newBuilder().build()) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("batchTranslateTextTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + BatchTranslateTextRequest request = + BatchTranslateTextRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setSourceLanguageCode("sourceLanguageCode1645917472") + .addAllTargetLanguageCodes(new ArrayList()) + .putAllModels(new HashMap()) + .addAllInputConfigs(new ArrayList()) + .setOutputConfig(OutputConfig.newBuilder().build()) + .putAllGlossaries(new HashMap()) + .putAllLabels(new HashMap()) + .build(); + + BatchTranslateResponse actualResponse = client.batchTranslateTextAsync(request).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 batchTranslateTextExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + BatchTranslateTextRequest request = + BatchTranslateTextRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setSourceLanguageCode("sourceLanguageCode1645917472") + .addAllTargetLanguageCodes(new ArrayList()) + .putAllModels(new HashMap()) + .addAllInputConfigs(new ArrayList()) + .setOutputConfig(OutputConfig.newBuilder().build()) + .putAllGlossaries(new HashMap()) + .putAllLabels(new HashMap()) + .build(); + client.batchTranslateTextAsync(request).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void batchTranslateDocumentTest() throws Exception { + BatchTranslateDocumentResponse expectedResponse = + BatchTranslateDocumentResponse.newBuilder() + .setTotalPages(-396186871) + .setTranslatedPages(-1652747493) + .setFailedPages(-2002254526) + .setTotalBillablePages(1292117569) + .setTotalCharacters(-1368640955) + .setTranslatedCharacters(-1337326221) + .setFailedCharacters(1723028396) + .setTotalBillableCharacters(1242495501) + .setSubmitTime(Timestamp.newBuilder().build()) + .setEndTime(Timestamp.newBuilder().build()) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("batchTranslateDocumentTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + String sourceLanguageCode = "sourceLanguageCode1645917472"; + List targetLanguageCodes = new ArrayList<>(); + List inputConfigs = new ArrayList<>(); + BatchDocumentOutputConfig outputConfig = BatchDocumentOutputConfig.newBuilder().build(); + + BatchTranslateDocumentResponse actualResponse = + client + .batchTranslateDocumentAsync( + parent, sourceLanguageCode, targetLanguageCodes, inputConfigs, outputConfig) + .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 batchTranslateDocumentExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + String sourceLanguageCode = "sourceLanguageCode1645917472"; + List targetLanguageCodes = new ArrayList<>(); + List inputConfigs = new ArrayList<>(); + BatchDocumentOutputConfig outputConfig = BatchDocumentOutputConfig.newBuilder().build(); + client + .batchTranslateDocumentAsync( + parent, sourceLanguageCode, targetLanguageCodes, inputConfigs, outputConfig) + .get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void batchTranslateDocumentTest2() throws Exception { + BatchTranslateDocumentResponse expectedResponse = + BatchTranslateDocumentResponse.newBuilder() + .setTotalPages(-396186871) + .setTranslatedPages(-1652747493) + .setFailedPages(-2002254526) + .setTotalBillablePages(1292117569) + .setTotalCharacters(-1368640955) + .setTranslatedCharacters(-1337326221) + .setFailedCharacters(1723028396) + .setTotalBillableCharacters(1242495501) + .setSubmitTime(Timestamp.newBuilder().build()) + .setEndTime(Timestamp.newBuilder().build()) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("batchTranslateDocumentTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String parent = "projects/project-5833/locations/location-5833"; + String sourceLanguageCode = "sourceLanguageCode1645917472"; + List targetLanguageCodes = new ArrayList<>(); + List inputConfigs = new ArrayList<>(); + BatchDocumentOutputConfig outputConfig = BatchDocumentOutputConfig.newBuilder().build(); + + BatchTranslateDocumentResponse actualResponse = + client + .batchTranslateDocumentAsync( + parent, sourceLanguageCode, targetLanguageCodes, inputConfigs, outputConfig) + .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 batchTranslateDocumentExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-5833/locations/location-5833"; + String sourceLanguageCode = "sourceLanguageCode1645917472"; + List targetLanguageCodes = new ArrayList<>(); + List inputConfigs = new ArrayList<>(); + BatchDocumentOutputConfig outputConfig = BatchDocumentOutputConfig.newBuilder().build(); + client + .batchTranslateDocumentAsync( + parent, sourceLanguageCode, targetLanguageCodes, inputConfigs, outputConfig) + .get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void createGlossaryTest() throws Exception { + Glossary expectedResponse = + Glossary.newBuilder() + .setName(GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]").toString()) + .setInputConfig(GlossaryInputConfig.newBuilder().build()) + .setEntryCount(-811131134) + .setSubmitTime(Timestamp.newBuilder().build()) + .setEndTime(Timestamp.newBuilder().build()) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("createGlossaryTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + Glossary glossary = Glossary.newBuilder().build(); + + Glossary actualResponse = client.createGlossaryAsync(parent, glossary).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 createGlossaryExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + Glossary glossary = Glossary.newBuilder().build(); + client.createGlossaryAsync(parent, glossary).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void createGlossaryTest2() throws Exception { + Glossary expectedResponse = + Glossary.newBuilder() + .setName(GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]").toString()) + .setInputConfig(GlossaryInputConfig.newBuilder().build()) + .setEntryCount(-811131134) + .setSubmitTime(Timestamp.newBuilder().build()) + .setEndTime(Timestamp.newBuilder().build()) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("createGlossaryTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String parent = "projects/project-5833/locations/location-5833"; + Glossary glossary = Glossary.newBuilder().build(); + + Glossary actualResponse = client.createGlossaryAsync(parent, glossary).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 createGlossaryExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-5833/locations/location-5833"; + Glossary glossary = Glossary.newBuilder().build(); + client.createGlossaryAsync(parent, glossary).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void listGlossariesTest() throws Exception { + Glossary responsesElement = Glossary.newBuilder().build(); + ListGlossariesResponse expectedResponse = + ListGlossariesResponse.newBuilder() + .setNextPageToken("") + .addAllGlossaries(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + String filter = "filter-1274492040"; + + ListGlossariesPagedResponse pagedListResponse = client.listGlossaries(parent, filter); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getGlossariesList().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 listGlossariesExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + String filter = "filter-1274492040"; + client.listGlossaries(parent, filter); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listGlossariesTest2() throws Exception { + Glossary responsesElement = Glossary.newBuilder().build(); + ListGlossariesResponse expectedResponse = + ListGlossariesResponse.newBuilder() + .setNextPageToken("") + .addAllGlossaries(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-5833/locations/location-5833"; + String filter = "filter-1274492040"; + + ListGlossariesPagedResponse pagedListResponse = client.listGlossaries(parent, filter); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getGlossariesList().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 listGlossariesExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-5833/locations/location-5833"; + String filter = "filter-1274492040"; + client.listGlossaries(parent, filter); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getGlossaryTest() throws Exception { + Glossary expectedResponse = + Glossary.newBuilder() + .setName(GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]").toString()) + .setInputConfig(GlossaryInputConfig.newBuilder().build()) + .setEntryCount(-811131134) + .setSubmitTime(Timestamp.newBuilder().build()) + .setEndTime(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + GlossaryName name = GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]"); + + Glossary actualResponse = client.getGlossary(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 getGlossaryExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + GlossaryName name = GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]"); + client.getGlossary(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getGlossaryTest2() throws Exception { + Glossary expectedResponse = + Glossary.newBuilder() + .setName(GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]").toString()) + .setInputConfig(GlossaryInputConfig.newBuilder().build()) + .setEntryCount(-811131134) + .setSubmitTime(Timestamp.newBuilder().build()) + .setEndTime(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String name = "projects/project-9868/locations/location-9868/glossaries/glossarie-9868"; + + Glossary actualResponse = client.getGlossary(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 getGlossaryExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-9868/locations/location-9868/glossaries/glossarie-9868"; + client.getGlossary(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteGlossaryTest() throws Exception { + DeleteGlossaryResponse expectedResponse = + DeleteGlossaryResponse.newBuilder() + .setName("name3373707") + .setSubmitTime(Timestamp.newBuilder().build()) + .setEndTime(Timestamp.newBuilder().build()) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("deleteGlossaryTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + GlossaryName name = GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]"); + + DeleteGlossaryResponse actualResponse = client.deleteGlossaryAsync(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 deleteGlossaryExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + GlossaryName name = GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]"); + client.deleteGlossaryAsync(name).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void deleteGlossaryTest2() throws Exception { + DeleteGlossaryResponse expectedResponse = + DeleteGlossaryResponse.newBuilder() + .setName("name3373707") + .setSubmitTime(Timestamp.newBuilder().build()) + .setEndTime(Timestamp.newBuilder().build()) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("deleteGlossaryTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String name = "projects/project-9868/locations/location-9868/glossaries/glossarie-9868"; + + DeleteGlossaryResponse actualResponse = client.deleteGlossaryAsync(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 deleteGlossaryExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = "projects/project-9868/locations/location-9868/glossaries/glossarie-9868"; + client.deleteGlossaryAsync(name).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } +} diff --git a/grpc-google-cloud-translate-v3/pom.xml b/grpc-google-cloud-translate-v3/pom.xml index 98b762b3..99a51987 100644 --- a/grpc-google-cloud-translate-v3/pom.xml +++ b/grpc-google-cloud-translate-v3/pom.xml @@ -4,13 +4,13 @@ 4.0.0 com.google.api.grpc grpc-google-cloud-translate-v3 - 2.2.0 + 2.3.0 grpc-google-cloud-translate-v3 GRPC library for grpc-google-cloud-translate-v3 com.google.cloud google-cloud-translate-parent - 2.2.0 + 2.3.0 diff --git a/grpc-google-cloud-translate-v3beta1/pom.xml b/grpc-google-cloud-translate-v3beta1/pom.xml index cd5e577f..50f6d7ff 100644 --- a/grpc-google-cloud-translate-v3beta1/pom.xml +++ b/grpc-google-cloud-translate-v3beta1/pom.xml @@ -4,13 +4,13 @@ 4.0.0 com.google.api.grpc grpc-google-cloud-translate-v3beta1 - 0.84.0 + 0.85.0 grpc-google-cloud-translate-v3beta1 GRPC library for grpc-google-cloud-translate-v3beta1 com.google.cloud google-cloud-translate-parent - 2.2.0 + 2.3.0 diff --git a/pom.xml b/pom.xml index 38905382..f904e709 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.google.cloud google-cloud-translate-parent pom - 2.2.0 + 2.3.0 Google Cloud Translate Parent https://github.com/googleapis/java-translate @@ -14,7 +14,7 @@ com.google.cloud google-cloud-shared-config - 1.4.0 + 1.5.0 @@ -61,33 +61,33 @@ com.google.api.grpc proto-google-cloud-translate-v3beta1 - 0.84.0 + 0.85.0 com.google.api.grpc proto-google-cloud-translate-v3 - 2.2.0 + 2.3.0 com.google.api.grpc grpc-google-cloud-translate-v3beta1 - 0.84.0 + 0.85.0 com.google.api.grpc grpc-google-cloud-translate-v3 - 2.2.0 + 2.3.0 com.google.cloud google-cloud-translate - 2.2.0 + 2.3.0 com.google.cloud google-cloud-shared-dependencies - 2.12.0 + 2.13.0 pom import diff --git a/proto-google-cloud-translate-v3/pom.xml b/proto-google-cloud-translate-v3/pom.xml index 9eba5c45..7a58f97d 100644 --- a/proto-google-cloud-translate-v3/pom.xml +++ b/proto-google-cloud-translate-v3/pom.xml @@ -4,13 +4,13 @@ 4.0.0 com.google.api.grpc proto-google-cloud-translate-v3 - 2.2.0 + 2.3.0 proto-google-cloud-translate-v3 PROTO library for proto-google-cloud-translate-v3 com.google.cloud google-cloud-translate-parent - 2.2.0 + 2.3.0 diff --git a/proto-google-cloud-translate-v3beta1/pom.xml b/proto-google-cloud-translate-v3beta1/pom.xml index b1e9ed0f..ab729296 100644 --- a/proto-google-cloud-translate-v3beta1/pom.xml +++ b/proto-google-cloud-translate-v3beta1/pom.xml @@ -4,13 +4,13 @@ 4.0.0 com.google.api.grpc proto-google-cloud-translate-v3beta1 - 0.84.0 + 0.85.0 proto-google-cloud-translate-v3beta1 PROTO library for proto-google-cloud-translate-v3beta1 com.google.cloud google-cloud-translate-parent - 2.2.0 + 2.3.0 diff --git a/samples/install-without-bom/pom.xml b/samples/install-without-bom/pom.xml index 86f63ce5..9a996c0d 100644 --- a/samples/install-without-bom/pom.xml +++ b/samples/install-without-bom/pom.xml @@ -29,13 +29,13 @@ com.google.cloud google-cloud-translate - 2.1.13 + 2.2.0 com.google.cloud google-cloud-storage - 2.6.1 + 2.9.0 junit @@ -52,7 +52,7 @@ com.google.cloud google-cloud-core - 2.6.1 + 2.8.1 test tests diff --git a/samples/snapshot/pom.xml b/samples/snapshot/pom.xml index 05bed9d9..2442ee06 100644 --- a/samples/snapshot/pom.xml +++ b/samples/snapshot/pom.xml @@ -28,13 +28,13 @@ com.google.cloud google-cloud-translate - 2.2.0 + 2.3.0 com.google.cloud google-cloud-storage - 2.6.1 + 2.9.0 @@ -52,7 +52,7 @@ com.google.cloud google-cloud-core - 2.6.1 + 2.8.1 test tests diff --git a/samples/snippets/generated/com/google/cloud/translate/v3/stub/translationservicestubsettings/translatetext/SyncTranslateText.java b/samples/snippets/generated/com/google/cloud/translate/v3/stub/translationservicestubsettings/translatetext/SyncTranslateText.java new file mode 100644 index 00000000..12fcf716 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3/stub/translationservicestubsettings/translatetext/SyncTranslateText.java @@ -0,0 +1,47 @@ +/* + * 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.translate.v3.stub.samples; + +// [START translation_v3_generated_translationservicestubsettings_translatetext_sync] +import com.google.cloud.translate.v3.stub.TranslationServiceStubSettings; +import java.time.Duration; + +public class SyncTranslateText { + + public static void main(String[] args) throws Exception { + syncTranslateText(); + } + + public static void syncTranslateText() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + TranslationServiceStubSettings.Builder translationServiceSettingsBuilder = + TranslationServiceStubSettings.newBuilder(); + translationServiceSettingsBuilder + .translateTextSettings() + .setRetrySettings( + translationServiceSettingsBuilder + .translateTextSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + TranslationServiceStubSettings translationServiceSettings = + translationServiceSettingsBuilder.build(); + } +} +// [END translation_v3_generated_translationservicestubsettings_translatetext_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/batchtranslatedocument/AsyncBatchTranslateDocument.java b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/batchtranslatedocument/AsyncBatchTranslateDocument.java new file mode 100644 index 00000000..cdfb6277 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/batchtranslatedocument/AsyncBatchTranslateDocument.java @@ -0,0 +1,59 @@ +/* + * 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.translate.v3.samples; + +// [START translation_v3_generated_translationserviceclient_batchtranslatedocument_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.translate.v3.BatchDocumentInputConfig; +import com.google.cloud.translate.v3.BatchDocumentOutputConfig; +import com.google.cloud.translate.v3.BatchTranslateDocumentRequest; +import com.google.cloud.translate.v3.LocationName; +import com.google.cloud.translate.v3.TranslateTextGlossaryConfig; +import com.google.cloud.translate.v3.TranslationServiceClient; +import com.google.longrunning.Operation; +import java.util.ArrayList; +import java.util.HashMap; + +public class AsyncBatchTranslateDocument { + + public static void main(String[] args) throws Exception { + asyncBatchTranslateDocument(); + } + + public static void asyncBatchTranslateDocument() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + BatchTranslateDocumentRequest request = + BatchTranslateDocumentRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setSourceLanguageCode("sourceLanguageCode1645917472") + .addAllTargetLanguageCodes(new ArrayList()) + .addAllInputConfigs(new ArrayList()) + .setOutputConfig(BatchDocumentOutputConfig.newBuilder().build()) + .putAllModels(new HashMap()) + .putAllGlossaries(new HashMap()) + .putAllFormatConversions(new HashMap()) + .build(); + ApiFuture future = + translationServiceClient.batchTranslateDocumentCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END translation_v3_generated_translationserviceclient_batchtranslatedocument_async] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/batchtranslatedocument/AsyncBatchTranslateDocumentLRO.java b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/batchtranslatedocument/AsyncBatchTranslateDocumentLRO.java new file mode 100644 index 00000000..601e6389 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/batchtranslatedocument/AsyncBatchTranslateDocumentLRO.java @@ -0,0 +1,60 @@ +/* + * 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.translate.v3.samples; + +// [START translation_v3_generated_translationserviceclient_batchtranslatedocument_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.translate.v3.BatchDocumentInputConfig; +import com.google.cloud.translate.v3.BatchDocumentOutputConfig; +import com.google.cloud.translate.v3.BatchTranslateDocumentMetadata; +import com.google.cloud.translate.v3.BatchTranslateDocumentRequest; +import com.google.cloud.translate.v3.BatchTranslateDocumentResponse; +import com.google.cloud.translate.v3.LocationName; +import com.google.cloud.translate.v3.TranslateTextGlossaryConfig; +import com.google.cloud.translate.v3.TranslationServiceClient; +import java.util.ArrayList; +import java.util.HashMap; + +public class AsyncBatchTranslateDocumentLRO { + + public static void main(String[] args) throws Exception { + asyncBatchTranslateDocumentLRO(); + } + + public static void asyncBatchTranslateDocumentLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + BatchTranslateDocumentRequest request = + BatchTranslateDocumentRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setSourceLanguageCode("sourceLanguageCode1645917472") + .addAllTargetLanguageCodes(new ArrayList()) + .addAllInputConfigs(new ArrayList()) + .setOutputConfig(BatchDocumentOutputConfig.newBuilder().build()) + .putAllModels(new HashMap()) + .putAllGlossaries(new HashMap()) + .putAllFormatConversions(new HashMap()) + .build(); + OperationFuture future = + translationServiceClient.batchTranslateDocumentOperationCallable().futureCall(request); + // Do something. + BatchTranslateDocumentResponse response = future.get(); + } + } +} +// [END translation_v3_generated_translationserviceclient_batchtranslatedocument_lro_async] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/batchtranslatedocument/SyncBatchTranslateDocument.java b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/batchtranslatedocument/SyncBatchTranslateDocument.java new file mode 100644 index 00000000..fc26e794 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/batchtranslatedocument/SyncBatchTranslateDocument.java @@ -0,0 +1,56 @@ +/* + * 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.translate.v3.samples; + +// [START translation_v3_generated_translationserviceclient_batchtranslatedocument_sync] +import com.google.cloud.translate.v3.BatchDocumentInputConfig; +import com.google.cloud.translate.v3.BatchDocumentOutputConfig; +import com.google.cloud.translate.v3.BatchTranslateDocumentRequest; +import com.google.cloud.translate.v3.BatchTranslateDocumentResponse; +import com.google.cloud.translate.v3.LocationName; +import com.google.cloud.translate.v3.TranslateTextGlossaryConfig; +import com.google.cloud.translate.v3.TranslationServiceClient; +import java.util.ArrayList; +import java.util.HashMap; + +public class SyncBatchTranslateDocument { + + public static void main(String[] args) throws Exception { + syncBatchTranslateDocument(); + } + + public static void syncBatchTranslateDocument() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + BatchTranslateDocumentRequest request = + BatchTranslateDocumentRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setSourceLanguageCode("sourceLanguageCode1645917472") + .addAllTargetLanguageCodes(new ArrayList()) + .addAllInputConfigs(new ArrayList()) + .setOutputConfig(BatchDocumentOutputConfig.newBuilder().build()) + .putAllModels(new HashMap()) + .putAllGlossaries(new HashMap()) + .putAllFormatConversions(new HashMap()) + .build(); + BatchTranslateDocumentResponse response = + translationServiceClient.batchTranslateDocumentAsync(request).get(); + } + } +} +// [END translation_v3_generated_translationserviceclient_batchtranslatedocument_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/batchtranslatedocument/SyncBatchTranslateDocumentLocationnameStringListstringListbatchdocumentinputconfigBatchdocumentoutputconfig.java b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/batchtranslatedocument/SyncBatchTranslateDocumentLocationnameStringListstringListbatchdocumentinputconfigBatchdocumentoutputconfig.java new file mode 100644 index 00000000..db5954cb --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/batchtranslatedocument/SyncBatchTranslateDocumentLocationnameStringListstringListbatchdocumentinputconfigBatchdocumentoutputconfig.java @@ -0,0 +1,54 @@ +/* + * 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.translate.v3.samples; + +// [START translation_v3_generated_translationserviceclient_batchtranslatedocument_locationnamestringliststringlistbatchdocumentinputconfigbatchdocumentoutputconfig_sync] +import com.google.cloud.translate.v3.BatchDocumentInputConfig; +import com.google.cloud.translate.v3.BatchDocumentOutputConfig; +import com.google.cloud.translate.v3.BatchTranslateDocumentResponse; +import com.google.cloud.translate.v3.LocationName; +import com.google.cloud.translate.v3.TranslationServiceClient; +import java.util.ArrayList; +import java.util.List; + +public +class SyncBatchTranslateDocumentLocationnameStringListstringListbatchdocumentinputconfigBatchdocumentoutputconfig { + + public static void main(String[] args) throws Exception { + syncBatchTranslateDocumentLocationnameStringListstringListbatchdocumentinputconfigBatchdocumentoutputconfig(); + } + + public static void + syncBatchTranslateDocumentLocationnameStringListstringListbatchdocumentinputconfigBatchdocumentoutputconfig() + throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + String sourceLanguageCode = "sourceLanguageCode1645917472"; + List targetLanguageCodes = new ArrayList<>(); + List inputConfigs = new ArrayList<>(); + BatchDocumentOutputConfig outputConfig = BatchDocumentOutputConfig.newBuilder().build(); + BatchTranslateDocumentResponse response = + translationServiceClient + .batchTranslateDocumentAsync( + parent, sourceLanguageCode, targetLanguageCodes, inputConfigs, outputConfig) + .get(); + } + } +} +// [END translation_v3_generated_translationserviceclient_batchtranslatedocument_locationnamestringliststringlistbatchdocumentinputconfigbatchdocumentoutputconfig_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/batchtranslatedocument/SyncBatchTranslateDocumentStringStringListstringListbatchdocumentinputconfigBatchdocumentoutputconfig.java b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/batchtranslatedocument/SyncBatchTranslateDocumentStringStringListstringListbatchdocumentinputconfigBatchdocumentoutputconfig.java new file mode 100644 index 00000000..4e1bf861 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/batchtranslatedocument/SyncBatchTranslateDocumentStringStringListstringListbatchdocumentinputconfigBatchdocumentoutputconfig.java @@ -0,0 +1,54 @@ +/* + * 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.translate.v3.samples; + +// [START translation_v3_generated_translationserviceclient_batchtranslatedocument_stringstringliststringlistbatchdocumentinputconfigbatchdocumentoutputconfig_sync] +import com.google.cloud.translate.v3.BatchDocumentInputConfig; +import com.google.cloud.translate.v3.BatchDocumentOutputConfig; +import com.google.cloud.translate.v3.BatchTranslateDocumentResponse; +import com.google.cloud.translate.v3.LocationName; +import com.google.cloud.translate.v3.TranslationServiceClient; +import java.util.ArrayList; +import java.util.List; + +public +class SyncBatchTranslateDocumentStringStringListstringListbatchdocumentinputconfigBatchdocumentoutputconfig { + + public static void main(String[] args) throws Exception { + syncBatchTranslateDocumentStringStringListstringListbatchdocumentinputconfigBatchdocumentoutputconfig(); + } + + public static void + syncBatchTranslateDocumentStringStringListstringListbatchdocumentinputconfigBatchdocumentoutputconfig() + throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString(); + String sourceLanguageCode = "sourceLanguageCode1645917472"; + List targetLanguageCodes = new ArrayList<>(); + List inputConfigs = new ArrayList<>(); + BatchDocumentOutputConfig outputConfig = BatchDocumentOutputConfig.newBuilder().build(); + BatchTranslateDocumentResponse response = + translationServiceClient + .batchTranslateDocumentAsync( + parent, sourceLanguageCode, targetLanguageCodes, inputConfigs, outputConfig) + .get(); + } + } +} +// [END translation_v3_generated_translationserviceclient_batchtranslatedocument_stringstringliststringlistbatchdocumentinputconfigbatchdocumentoutputconfig_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/batchtranslatetext/AsyncBatchTranslateText.java b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/batchtranslatetext/AsyncBatchTranslateText.java new file mode 100644 index 00000000..4f97afc9 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/batchtranslatetext/AsyncBatchTranslateText.java @@ -0,0 +1,59 @@ +/* + * 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.translate.v3.samples; + +// [START translation_v3_generated_translationserviceclient_batchtranslatetext_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.translate.v3.BatchTranslateTextRequest; +import com.google.cloud.translate.v3.InputConfig; +import com.google.cloud.translate.v3.LocationName; +import com.google.cloud.translate.v3.OutputConfig; +import com.google.cloud.translate.v3.TranslateTextGlossaryConfig; +import com.google.cloud.translate.v3.TranslationServiceClient; +import com.google.longrunning.Operation; +import java.util.ArrayList; +import java.util.HashMap; + +public class AsyncBatchTranslateText { + + public static void main(String[] args) throws Exception { + asyncBatchTranslateText(); + } + + public static void asyncBatchTranslateText() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + BatchTranslateTextRequest request = + BatchTranslateTextRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setSourceLanguageCode("sourceLanguageCode1645917472") + .addAllTargetLanguageCodes(new ArrayList()) + .putAllModels(new HashMap()) + .addAllInputConfigs(new ArrayList()) + .setOutputConfig(OutputConfig.newBuilder().build()) + .putAllGlossaries(new HashMap()) + .putAllLabels(new HashMap()) + .build(); + ApiFuture future = + translationServiceClient.batchTranslateTextCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END translation_v3_generated_translationserviceclient_batchtranslatetext_async] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/batchtranslatetext/AsyncBatchTranslateTextLRO.java b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/batchtranslatetext/AsyncBatchTranslateTextLRO.java new file mode 100644 index 00000000..1201b6ae --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/batchtranslatetext/AsyncBatchTranslateTextLRO.java @@ -0,0 +1,60 @@ +/* + * 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.translate.v3.samples; + +// [START translation_v3_generated_translationserviceclient_batchtranslatetext_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.translate.v3.BatchTranslateMetadata; +import com.google.cloud.translate.v3.BatchTranslateResponse; +import com.google.cloud.translate.v3.BatchTranslateTextRequest; +import com.google.cloud.translate.v3.InputConfig; +import com.google.cloud.translate.v3.LocationName; +import com.google.cloud.translate.v3.OutputConfig; +import com.google.cloud.translate.v3.TranslateTextGlossaryConfig; +import com.google.cloud.translate.v3.TranslationServiceClient; +import java.util.ArrayList; +import java.util.HashMap; + +public class AsyncBatchTranslateTextLRO { + + public static void main(String[] args) throws Exception { + asyncBatchTranslateTextLRO(); + } + + public static void asyncBatchTranslateTextLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + BatchTranslateTextRequest request = + BatchTranslateTextRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setSourceLanguageCode("sourceLanguageCode1645917472") + .addAllTargetLanguageCodes(new ArrayList()) + .putAllModels(new HashMap()) + .addAllInputConfigs(new ArrayList()) + .setOutputConfig(OutputConfig.newBuilder().build()) + .putAllGlossaries(new HashMap()) + .putAllLabels(new HashMap()) + .build(); + OperationFuture future = + translationServiceClient.batchTranslateTextOperationCallable().futureCall(request); + // Do something. + BatchTranslateResponse response = future.get(); + } + } +} +// [END translation_v3_generated_translationserviceclient_batchtranslatetext_lro_async] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/batchtranslatetext/SyncBatchTranslateText.java b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/batchtranslatetext/SyncBatchTranslateText.java new file mode 100644 index 00000000..c947a82e --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/batchtranslatetext/SyncBatchTranslateText.java @@ -0,0 +1,56 @@ +/* + * 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.translate.v3.samples; + +// [START translation_v3_generated_translationserviceclient_batchtranslatetext_sync] +import com.google.cloud.translate.v3.BatchTranslateResponse; +import com.google.cloud.translate.v3.BatchTranslateTextRequest; +import com.google.cloud.translate.v3.InputConfig; +import com.google.cloud.translate.v3.LocationName; +import com.google.cloud.translate.v3.OutputConfig; +import com.google.cloud.translate.v3.TranslateTextGlossaryConfig; +import com.google.cloud.translate.v3.TranslationServiceClient; +import java.util.ArrayList; +import java.util.HashMap; + +public class SyncBatchTranslateText { + + public static void main(String[] args) throws Exception { + syncBatchTranslateText(); + } + + public static void syncBatchTranslateText() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + BatchTranslateTextRequest request = + BatchTranslateTextRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setSourceLanguageCode("sourceLanguageCode1645917472") + .addAllTargetLanguageCodes(new ArrayList()) + .putAllModels(new HashMap()) + .addAllInputConfigs(new ArrayList()) + .setOutputConfig(OutputConfig.newBuilder().build()) + .putAllGlossaries(new HashMap()) + .putAllLabels(new HashMap()) + .build(); + BatchTranslateResponse response = + translationServiceClient.batchTranslateTextAsync(request).get(); + } + } +} +// [END translation_v3_generated_translationserviceclient_batchtranslatetext_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/create/SyncCreateSetCredentialsProvider.java b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/create/SyncCreateSetCredentialsProvider.java new file mode 100644 index 00000000..16a74786 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/create/SyncCreateSetCredentialsProvider.java @@ -0,0 +1,42 @@ +/* + * 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.translate.v3.samples; + +// [START translation_v3_generated_translationserviceclient_create_setcredentialsprovider_sync] +import com.google.api.gax.core.FixedCredentialsProvider; +import com.google.cloud.translate.v3.TranslationServiceClient; +import com.google.cloud.translate.v3.TranslationServiceSettings; +import com.google.cloud.translate.v3.myCredentials; + +public class SyncCreateSetCredentialsProvider { + + public static void main(String[] args) throws Exception { + syncCreateSetCredentialsProvider(); + } + + public static void syncCreateSetCredentialsProvider() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + TranslationServiceSettings translationServiceSettings = + TranslationServiceSettings.newBuilder() + .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) + .build(); + TranslationServiceClient translationServiceClient = + TranslationServiceClient.create(translationServiceSettings); + } +} +// [END translation_v3_generated_translationserviceclient_create_setcredentialsprovider_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/create/SyncCreateSetCredentialsProvider1.java b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/create/SyncCreateSetCredentialsProvider1.java new file mode 100644 index 00000000..2ee09605 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/create/SyncCreateSetCredentialsProvider1.java @@ -0,0 +1,41 @@ +/* + * 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.translate.v3.samples; + +// [START translation_v3_generated_translationserviceclient_create_setcredentialsprovider1_sync] +import com.google.cloud.translate.v3.TranslationServiceClient; +import com.google.cloud.translate.v3.TranslationServiceSettings; + +public class SyncCreateSetCredentialsProvider1 { + + public static void main(String[] args) throws Exception { + syncCreateSetCredentialsProvider1(); + } + + public static void syncCreateSetCredentialsProvider1() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + TranslationServiceSettings translationServiceSettings = + TranslationServiceSettings.newBuilder() + .setTransportChannelProvider( + TranslationServiceSettings.defaultHttpJsonTransportProviderBuilder().build()) + .build(); + TranslationServiceClient translationServiceClient = + TranslationServiceClient.create(translationServiceSettings); + } +} +// [END translation_v3_generated_translationserviceclient_create_setcredentialsprovider1_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/create/SyncCreateSetEndpoint.java b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/create/SyncCreateSetEndpoint.java new file mode 100644 index 00000000..71d0be95 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/create/SyncCreateSetEndpoint.java @@ -0,0 +1,39 @@ +/* + * 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.translate.v3.samples; + +// [START translation_v3_generated_translationserviceclient_create_setendpoint_sync] +import com.google.cloud.translate.v3.TranslationServiceClient; +import com.google.cloud.translate.v3.TranslationServiceSettings; +import com.google.cloud.translate.v3.myEndpoint; + +public class SyncCreateSetEndpoint { + + public static void main(String[] args) throws Exception { + syncCreateSetEndpoint(); + } + + public static void syncCreateSetEndpoint() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + TranslationServiceSettings translationServiceSettings = + TranslationServiceSettings.newBuilder().setEndpoint(myEndpoint).build(); + TranslationServiceClient translationServiceClient = + TranslationServiceClient.create(translationServiceSettings); + } +} +// [END translation_v3_generated_translationserviceclient_create_setendpoint_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/createglossary/AsyncCreateGlossary.java b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/createglossary/AsyncCreateGlossary.java new file mode 100644 index 00000000..12101ab0 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/createglossary/AsyncCreateGlossary.java @@ -0,0 +1,49 @@ +/* + * 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.translate.v3.samples; + +// [START translation_v3_generated_translationserviceclient_createglossary_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.translate.v3.CreateGlossaryRequest; +import com.google.cloud.translate.v3.Glossary; +import com.google.cloud.translate.v3.LocationName; +import com.google.cloud.translate.v3.TranslationServiceClient; +import com.google.longrunning.Operation; + +public class AsyncCreateGlossary { + + public static void main(String[] args) throws Exception { + asyncCreateGlossary(); + } + + public static void asyncCreateGlossary() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + CreateGlossaryRequest request = + CreateGlossaryRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setGlossary(Glossary.newBuilder().build()) + .build(); + ApiFuture future = + translationServiceClient.createGlossaryCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END translation_v3_generated_translationserviceclient_createglossary_async] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/createglossary/AsyncCreateGlossaryLRO.java b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/createglossary/AsyncCreateGlossaryLRO.java new file mode 100644 index 00000000..eb6b8832 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/createglossary/AsyncCreateGlossaryLRO.java @@ -0,0 +1,49 @@ +/* + * 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.translate.v3.samples; + +// [START translation_v3_generated_translationserviceclient_createglossary_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.translate.v3.CreateGlossaryMetadata; +import com.google.cloud.translate.v3.CreateGlossaryRequest; +import com.google.cloud.translate.v3.Glossary; +import com.google.cloud.translate.v3.LocationName; +import com.google.cloud.translate.v3.TranslationServiceClient; + +public class AsyncCreateGlossaryLRO { + + public static void main(String[] args) throws Exception { + asyncCreateGlossaryLRO(); + } + + public static void asyncCreateGlossaryLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + CreateGlossaryRequest request = + CreateGlossaryRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setGlossary(Glossary.newBuilder().build()) + .build(); + OperationFuture future = + translationServiceClient.createGlossaryOperationCallable().futureCall(request); + // Do something. + Glossary response = future.get(); + } + } +} +// [END translation_v3_generated_translationserviceclient_createglossary_lro_async] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/createglossary/SyncCreateGlossary.java b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/createglossary/SyncCreateGlossary.java new file mode 100644 index 00000000..17f5b098 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/createglossary/SyncCreateGlossary.java @@ -0,0 +1,44 @@ +/* + * 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.translate.v3.samples; + +// [START translation_v3_generated_translationserviceclient_createglossary_sync] +import com.google.cloud.translate.v3.CreateGlossaryRequest; +import com.google.cloud.translate.v3.Glossary; +import com.google.cloud.translate.v3.LocationName; +import com.google.cloud.translate.v3.TranslationServiceClient; + +public class SyncCreateGlossary { + + public static void main(String[] args) throws Exception { + syncCreateGlossary(); + } + + public static void syncCreateGlossary() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + CreateGlossaryRequest request = + CreateGlossaryRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setGlossary(Glossary.newBuilder().build()) + .build(); + Glossary response = translationServiceClient.createGlossaryAsync(request).get(); + } + } +} +// [END translation_v3_generated_translationserviceclient_createglossary_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/createglossary/SyncCreateGlossaryLocationnameGlossary.java b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/createglossary/SyncCreateGlossaryLocationnameGlossary.java new file mode 100644 index 00000000..4d689c0f --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/createglossary/SyncCreateGlossaryLocationnameGlossary.java @@ -0,0 +1,40 @@ +/* + * 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.translate.v3.samples; + +// [START translation_v3_generated_translationserviceclient_createglossary_locationnameglossary_sync] +import com.google.cloud.translate.v3.Glossary; +import com.google.cloud.translate.v3.LocationName; +import com.google.cloud.translate.v3.TranslationServiceClient; + +public class SyncCreateGlossaryLocationnameGlossary { + + public static void main(String[] args) throws Exception { + syncCreateGlossaryLocationnameGlossary(); + } + + public static void syncCreateGlossaryLocationnameGlossary() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + Glossary glossary = Glossary.newBuilder().build(); + Glossary response = translationServiceClient.createGlossaryAsync(parent, glossary).get(); + } + } +} +// [END translation_v3_generated_translationserviceclient_createglossary_locationnameglossary_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/createglossary/SyncCreateGlossaryStringGlossary.java b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/createglossary/SyncCreateGlossaryStringGlossary.java new file mode 100644 index 00000000..2e9f301c --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/createglossary/SyncCreateGlossaryStringGlossary.java @@ -0,0 +1,40 @@ +/* + * 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.translate.v3.samples; + +// [START translation_v3_generated_translationserviceclient_createglossary_stringglossary_sync] +import com.google.cloud.translate.v3.Glossary; +import com.google.cloud.translate.v3.LocationName; +import com.google.cloud.translate.v3.TranslationServiceClient; + +public class SyncCreateGlossaryStringGlossary { + + public static void main(String[] args) throws Exception { + syncCreateGlossaryStringGlossary(); + } + + public static void syncCreateGlossaryStringGlossary() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString(); + Glossary glossary = Glossary.newBuilder().build(); + Glossary response = translationServiceClient.createGlossaryAsync(parent, glossary).get(); + } + } +} +// [END translation_v3_generated_translationserviceclient_createglossary_stringglossary_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/deleteglossary/AsyncDeleteGlossary.java b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/deleteglossary/AsyncDeleteGlossary.java new file mode 100644 index 00000000..1ad42b27 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/deleteglossary/AsyncDeleteGlossary.java @@ -0,0 +1,47 @@ +/* + * 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.translate.v3.samples; + +// [START translation_v3_generated_translationserviceclient_deleteglossary_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.translate.v3.DeleteGlossaryRequest; +import com.google.cloud.translate.v3.GlossaryName; +import com.google.cloud.translate.v3.TranslationServiceClient; +import com.google.longrunning.Operation; + +public class AsyncDeleteGlossary { + + public static void main(String[] args) throws Exception { + asyncDeleteGlossary(); + } + + public static void asyncDeleteGlossary() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + DeleteGlossaryRequest request = + DeleteGlossaryRequest.newBuilder() + .setName(GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]").toString()) + .build(); + ApiFuture future = + translationServiceClient.deleteGlossaryCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END translation_v3_generated_translationserviceclient_deleteglossary_async] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/deleteglossary/AsyncDeleteGlossaryLRO.java b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/deleteglossary/AsyncDeleteGlossaryLRO.java new file mode 100644 index 00000000..f94c525f --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/deleteglossary/AsyncDeleteGlossaryLRO.java @@ -0,0 +1,48 @@ +/* + * 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.translate.v3.samples; + +// [START translation_v3_generated_translationserviceclient_deleteglossary_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.translate.v3.DeleteGlossaryMetadata; +import com.google.cloud.translate.v3.DeleteGlossaryRequest; +import com.google.cloud.translate.v3.DeleteGlossaryResponse; +import com.google.cloud.translate.v3.GlossaryName; +import com.google.cloud.translate.v3.TranslationServiceClient; + +public class AsyncDeleteGlossaryLRO { + + public static void main(String[] args) throws Exception { + asyncDeleteGlossaryLRO(); + } + + public static void asyncDeleteGlossaryLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + DeleteGlossaryRequest request = + DeleteGlossaryRequest.newBuilder() + .setName(GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]").toString()) + .build(); + OperationFuture future = + translationServiceClient.deleteGlossaryOperationCallable().futureCall(request); + // Do something. + DeleteGlossaryResponse response = future.get(); + } + } +} +// [END translation_v3_generated_translationserviceclient_deleteglossary_lro_async] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/deleteglossary/SyncDeleteGlossary.java b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/deleteglossary/SyncDeleteGlossary.java new file mode 100644 index 00000000..6bd57c6e --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/deleteglossary/SyncDeleteGlossary.java @@ -0,0 +1,43 @@ +/* + * 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.translate.v3.samples; + +// [START translation_v3_generated_translationserviceclient_deleteglossary_sync] +import com.google.cloud.translate.v3.DeleteGlossaryRequest; +import com.google.cloud.translate.v3.DeleteGlossaryResponse; +import com.google.cloud.translate.v3.GlossaryName; +import com.google.cloud.translate.v3.TranslationServiceClient; + +public class SyncDeleteGlossary { + + public static void main(String[] args) throws Exception { + syncDeleteGlossary(); + } + + public static void syncDeleteGlossary() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + DeleteGlossaryRequest request = + DeleteGlossaryRequest.newBuilder() + .setName(GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]").toString()) + .build(); + DeleteGlossaryResponse response = translationServiceClient.deleteGlossaryAsync(request).get(); + } + } +} +// [END translation_v3_generated_translationserviceclient_deleteglossary_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/deleteglossary/SyncDeleteGlossaryGlossaryname.java b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/deleteglossary/SyncDeleteGlossaryGlossaryname.java new file mode 100644 index 00000000..750faad6 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/deleteglossary/SyncDeleteGlossaryGlossaryname.java @@ -0,0 +1,39 @@ +/* + * 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.translate.v3.samples; + +// [START translation_v3_generated_translationserviceclient_deleteglossary_glossaryname_sync] +import com.google.cloud.translate.v3.DeleteGlossaryResponse; +import com.google.cloud.translate.v3.GlossaryName; +import com.google.cloud.translate.v3.TranslationServiceClient; + +public class SyncDeleteGlossaryGlossaryname { + + public static void main(String[] args) throws Exception { + syncDeleteGlossaryGlossaryname(); + } + + public static void syncDeleteGlossaryGlossaryname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + GlossaryName name = GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]"); + DeleteGlossaryResponse response = translationServiceClient.deleteGlossaryAsync(name).get(); + } + } +} +// [END translation_v3_generated_translationserviceclient_deleteglossary_glossaryname_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/deleteglossary/SyncDeleteGlossaryString.java b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/deleteglossary/SyncDeleteGlossaryString.java new file mode 100644 index 00000000..fe1e6ed9 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/deleteglossary/SyncDeleteGlossaryString.java @@ -0,0 +1,39 @@ +/* + * 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.translate.v3.samples; + +// [START translation_v3_generated_translationserviceclient_deleteglossary_string_sync] +import com.google.cloud.translate.v3.DeleteGlossaryResponse; +import com.google.cloud.translate.v3.GlossaryName; +import com.google.cloud.translate.v3.TranslationServiceClient; + +public class SyncDeleteGlossaryString { + + public static void main(String[] args) throws Exception { + syncDeleteGlossaryString(); + } + + public static void syncDeleteGlossaryString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + String name = GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]").toString(); + DeleteGlossaryResponse response = translationServiceClient.deleteGlossaryAsync(name).get(); + } + } +} +// [END translation_v3_generated_translationserviceclient_deleteglossary_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/detectlanguage/AsyncDetectLanguage.java b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/detectlanguage/AsyncDetectLanguage.java new file mode 100644 index 00000000..4115a959 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/detectlanguage/AsyncDetectLanguage.java @@ -0,0 +1,51 @@ +/* + * 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.translate.v3.samples; + +// [START translation_v3_generated_translationserviceclient_detectlanguage_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.translate.v3.DetectLanguageRequest; +import com.google.cloud.translate.v3.DetectLanguageResponse; +import com.google.cloud.translate.v3.LocationName; +import com.google.cloud.translate.v3.TranslationServiceClient; +import java.util.HashMap; + +public class AsyncDetectLanguage { + + public static void main(String[] args) throws Exception { + asyncDetectLanguage(); + } + + public static void asyncDetectLanguage() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + DetectLanguageRequest request = + DetectLanguageRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setModel("model104069929") + .setMimeType("mimeType-1392120434") + .putAllLabels(new HashMap()) + .build(); + ApiFuture future = + translationServiceClient.detectLanguageCallable().futureCall(request); + // Do something. + DetectLanguageResponse response = future.get(); + } + } +} +// [END translation_v3_generated_translationserviceclient_detectlanguage_async] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/detectlanguage/SyncDetectLanguage.java b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/detectlanguage/SyncDetectLanguage.java new file mode 100644 index 00000000..56f975a6 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/detectlanguage/SyncDetectLanguage.java @@ -0,0 +1,47 @@ +/* + * 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.translate.v3.samples; + +// [START translation_v3_generated_translationserviceclient_detectlanguage_sync] +import com.google.cloud.translate.v3.DetectLanguageRequest; +import com.google.cloud.translate.v3.DetectLanguageResponse; +import com.google.cloud.translate.v3.LocationName; +import com.google.cloud.translate.v3.TranslationServiceClient; +import java.util.HashMap; + +public class SyncDetectLanguage { + + public static void main(String[] args) throws Exception { + syncDetectLanguage(); + } + + public static void syncDetectLanguage() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + DetectLanguageRequest request = + DetectLanguageRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setModel("model104069929") + .setMimeType("mimeType-1392120434") + .putAllLabels(new HashMap()) + .build(); + DetectLanguageResponse response = translationServiceClient.detectLanguage(request); + } + } +} +// [END translation_v3_generated_translationserviceclient_detectlanguage_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/detectlanguage/SyncDetectLanguageLocationnameStringStringString.java b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/detectlanguage/SyncDetectLanguageLocationnameStringStringString.java new file mode 100644 index 00000000..68fb37ff --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/detectlanguage/SyncDetectLanguageLocationnameStringStringString.java @@ -0,0 +1,43 @@ +/* + * 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.translate.v3.samples; + +// [START translation_v3_generated_translationserviceclient_detectlanguage_locationnamestringstringstring_sync] +import com.google.cloud.translate.v3.DetectLanguageResponse; +import com.google.cloud.translate.v3.LocationName; +import com.google.cloud.translate.v3.TranslationServiceClient; + +public class SyncDetectLanguageLocationnameStringStringString { + + public static void main(String[] args) throws Exception { + syncDetectLanguageLocationnameStringStringString(); + } + + public static void syncDetectLanguageLocationnameStringStringString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + String model = "model104069929"; + String mimeType = "mimeType-1392120434"; + String content = "content951530617"; + DetectLanguageResponse response = + translationServiceClient.detectLanguage(parent, model, mimeType, content); + } + } +} +// [END translation_v3_generated_translationserviceclient_detectlanguage_locationnamestringstringstring_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/detectlanguage/SyncDetectLanguageStringStringStringString.java b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/detectlanguage/SyncDetectLanguageStringStringStringString.java new file mode 100644 index 00000000..1201c3ca --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/detectlanguage/SyncDetectLanguageStringStringStringString.java @@ -0,0 +1,43 @@ +/* + * 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.translate.v3.samples; + +// [START translation_v3_generated_translationserviceclient_detectlanguage_stringstringstringstring_sync] +import com.google.cloud.translate.v3.DetectLanguageResponse; +import com.google.cloud.translate.v3.LocationName; +import com.google.cloud.translate.v3.TranslationServiceClient; + +public class SyncDetectLanguageStringStringStringString { + + public static void main(String[] args) throws Exception { + syncDetectLanguageStringStringStringString(); + } + + public static void syncDetectLanguageStringStringStringString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString(); + String model = "model104069929"; + String mimeType = "mimeType-1392120434"; + String content = "content951530617"; + DetectLanguageResponse response = + translationServiceClient.detectLanguage(parent, model, mimeType, content); + } + } +} +// [END translation_v3_generated_translationserviceclient_detectlanguage_stringstringstringstring_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/getglossary/AsyncGetGlossary.java b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/getglossary/AsyncGetGlossary.java new file mode 100644 index 00000000..37a5b2a4 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/getglossary/AsyncGetGlossary.java @@ -0,0 +1,47 @@ +/* + * 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.translate.v3.samples; + +// [START translation_v3_generated_translationserviceclient_getglossary_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.translate.v3.GetGlossaryRequest; +import com.google.cloud.translate.v3.Glossary; +import com.google.cloud.translate.v3.GlossaryName; +import com.google.cloud.translate.v3.TranslationServiceClient; + +public class AsyncGetGlossary { + + public static void main(String[] args) throws Exception { + asyncGetGlossary(); + } + + public static void asyncGetGlossary() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + GetGlossaryRequest request = + GetGlossaryRequest.newBuilder() + .setName(GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]").toString()) + .build(); + ApiFuture future = + translationServiceClient.getGlossaryCallable().futureCall(request); + // Do something. + Glossary response = future.get(); + } + } +} +// [END translation_v3_generated_translationserviceclient_getglossary_async] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/getglossary/SyncGetGlossary.java b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/getglossary/SyncGetGlossary.java new file mode 100644 index 00000000..f626a53d --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/getglossary/SyncGetGlossary.java @@ -0,0 +1,43 @@ +/* + * 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.translate.v3.samples; + +// [START translation_v3_generated_translationserviceclient_getglossary_sync] +import com.google.cloud.translate.v3.GetGlossaryRequest; +import com.google.cloud.translate.v3.Glossary; +import com.google.cloud.translate.v3.GlossaryName; +import com.google.cloud.translate.v3.TranslationServiceClient; + +public class SyncGetGlossary { + + public static void main(String[] args) throws Exception { + syncGetGlossary(); + } + + public static void syncGetGlossary() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + GetGlossaryRequest request = + GetGlossaryRequest.newBuilder() + .setName(GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]").toString()) + .build(); + Glossary response = translationServiceClient.getGlossary(request); + } + } +} +// [END translation_v3_generated_translationserviceclient_getglossary_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/getglossary/SyncGetGlossaryGlossaryname.java b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/getglossary/SyncGetGlossaryGlossaryname.java new file mode 100644 index 00000000..81c6cddf --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/getglossary/SyncGetGlossaryGlossaryname.java @@ -0,0 +1,39 @@ +/* + * 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.translate.v3.samples; + +// [START translation_v3_generated_translationserviceclient_getglossary_glossaryname_sync] +import com.google.cloud.translate.v3.Glossary; +import com.google.cloud.translate.v3.GlossaryName; +import com.google.cloud.translate.v3.TranslationServiceClient; + +public class SyncGetGlossaryGlossaryname { + + public static void main(String[] args) throws Exception { + syncGetGlossaryGlossaryname(); + } + + public static void syncGetGlossaryGlossaryname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + GlossaryName name = GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]"); + Glossary response = translationServiceClient.getGlossary(name); + } + } +} +// [END translation_v3_generated_translationserviceclient_getglossary_glossaryname_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/getglossary/SyncGetGlossaryString.java b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/getglossary/SyncGetGlossaryString.java new file mode 100644 index 00000000..652c5d36 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/getglossary/SyncGetGlossaryString.java @@ -0,0 +1,39 @@ +/* + * 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.translate.v3.samples; + +// [START translation_v3_generated_translationserviceclient_getglossary_string_sync] +import com.google.cloud.translate.v3.Glossary; +import com.google.cloud.translate.v3.GlossaryName; +import com.google.cloud.translate.v3.TranslationServiceClient; + +public class SyncGetGlossaryString { + + public static void main(String[] args) throws Exception { + syncGetGlossaryString(); + } + + public static void syncGetGlossaryString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + String name = GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]").toString(); + Glossary response = translationServiceClient.getGlossary(name); + } + } +} +// [END translation_v3_generated_translationserviceclient_getglossary_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/getsupportedlanguages/AsyncGetSupportedLanguages.java b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/getsupportedlanguages/AsyncGetSupportedLanguages.java new file mode 100644 index 00000000..605430c6 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/getsupportedlanguages/AsyncGetSupportedLanguages.java @@ -0,0 +1,49 @@ +/* + * 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.translate.v3.samples; + +// [START translation_v3_generated_translationserviceclient_getsupportedlanguages_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.translate.v3.GetSupportedLanguagesRequest; +import com.google.cloud.translate.v3.LocationName; +import com.google.cloud.translate.v3.SupportedLanguages; +import com.google.cloud.translate.v3.TranslationServiceClient; + +public class AsyncGetSupportedLanguages { + + public static void main(String[] args) throws Exception { + asyncGetSupportedLanguages(); + } + + public static void asyncGetSupportedLanguages() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + GetSupportedLanguagesRequest request = + GetSupportedLanguagesRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setDisplayLanguageCode("displayLanguageCode-1457478841") + .setModel("model104069929") + .build(); + ApiFuture future = + translationServiceClient.getSupportedLanguagesCallable().futureCall(request); + // Do something. + SupportedLanguages response = future.get(); + } + } +} +// [END translation_v3_generated_translationserviceclient_getsupportedlanguages_async] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/getsupportedlanguages/SyncGetSupportedLanguages.java b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/getsupportedlanguages/SyncGetSupportedLanguages.java new file mode 100644 index 00000000..cb33cf7e --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/getsupportedlanguages/SyncGetSupportedLanguages.java @@ -0,0 +1,45 @@ +/* + * 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.translate.v3.samples; + +// [START translation_v3_generated_translationserviceclient_getsupportedlanguages_sync] +import com.google.cloud.translate.v3.GetSupportedLanguagesRequest; +import com.google.cloud.translate.v3.LocationName; +import com.google.cloud.translate.v3.SupportedLanguages; +import com.google.cloud.translate.v3.TranslationServiceClient; + +public class SyncGetSupportedLanguages { + + public static void main(String[] args) throws Exception { + syncGetSupportedLanguages(); + } + + public static void syncGetSupportedLanguages() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + GetSupportedLanguagesRequest request = + GetSupportedLanguagesRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setDisplayLanguageCode("displayLanguageCode-1457478841") + .setModel("model104069929") + .build(); + SupportedLanguages response = translationServiceClient.getSupportedLanguages(request); + } + } +} +// [END translation_v3_generated_translationserviceclient_getsupportedlanguages_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/getsupportedlanguages/SyncGetSupportedLanguagesLocationnameStringString.java b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/getsupportedlanguages/SyncGetSupportedLanguagesLocationnameStringString.java new file mode 100644 index 00000000..e857149a --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/getsupportedlanguages/SyncGetSupportedLanguagesLocationnameStringString.java @@ -0,0 +1,42 @@ +/* + * 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.translate.v3.samples; + +// [START translation_v3_generated_translationserviceclient_getsupportedlanguages_locationnamestringstring_sync] +import com.google.cloud.translate.v3.LocationName; +import com.google.cloud.translate.v3.SupportedLanguages; +import com.google.cloud.translate.v3.TranslationServiceClient; + +public class SyncGetSupportedLanguagesLocationnameStringString { + + public static void main(String[] args) throws Exception { + syncGetSupportedLanguagesLocationnameStringString(); + } + + public static void syncGetSupportedLanguagesLocationnameStringString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + String model = "model104069929"; + String displayLanguageCode = "displayLanguageCode-1457478841"; + SupportedLanguages response = + translationServiceClient.getSupportedLanguages(parent, model, displayLanguageCode); + } + } +} +// [END translation_v3_generated_translationserviceclient_getsupportedlanguages_locationnamestringstring_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/getsupportedlanguages/SyncGetSupportedLanguagesStringStringString.java b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/getsupportedlanguages/SyncGetSupportedLanguagesStringStringString.java new file mode 100644 index 00000000..0b2eb101 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/getsupportedlanguages/SyncGetSupportedLanguagesStringStringString.java @@ -0,0 +1,42 @@ +/* + * 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.translate.v3.samples; + +// [START translation_v3_generated_translationserviceclient_getsupportedlanguages_stringstringstring_sync] +import com.google.cloud.translate.v3.LocationName; +import com.google.cloud.translate.v3.SupportedLanguages; +import com.google.cloud.translate.v3.TranslationServiceClient; + +public class SyncGetSupportedLanguagesStringStringString { + + public static void main(String[] args) throws Exception { + syncGetSupportedLanguagesStringStringString(); + } + + public static void syncGetSupportedLanguagesStringStringString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString(); + String model = "model104069929"; + String displayLanguageCode = "displayLanguageCode-1457478841"; + SupportedLanguages response = + translationServiceClient.getSupportedLanguages(parent, model, displayLanguageCode); + } + } +} +// [END translation_v3_generated_translationserviceclient_getsupportedlanguages_stringstringstring_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/listglossaries/AsyncListGlossaries.java b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/listglossaries/AsyncListGlossaries.java new file mode 100644 index 00000000..f7f542ab --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/listglossaries/AsyncListGlossaries.java @@ -0,0 +1,52 @@ +/* + * 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.translate.v3.samples; + +// [START translation_v3_generated_translationserviceclient_listglossaries_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.translate.v3.Glossary; +import com.google.cloud.translate.v3.ListGlossariesRequest; +import com.google.cloud.translate.v3.LocationName; +import com.google.cloud.translate.v3.TranslationServiceClient; + +public class AsyncListGlossaries { + + public static void main(String[] args) throws Exception { + asyncListGlossaries(); + } + + public static void asyncListGlossaries() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + ListGlossariesRequest request = + ListGlossariesRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .build(); + ApiFuture future = + translationServiceClient.listGlossariesPagedCallable().futureCall(request); + // Do something. + for (Glossary element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END translation_v3_generated_translationserviceclient_listglossaries_async] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/listglossaries/AsyncListGlossariesPaged.java b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/listglossaries/AsyncListGlossariesPaged.java new file mode 100644 index 00000000..5271aa2c --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/listglossaries/AsyncListGlossariesPaged.java @@ -0,0 +1,60 @@ +/* + * 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.translate.v3.samples; + +// [START translation_v3_generated_translationserviceclient_listglossaries_paged_async] +import com.google.cloud.translate.v3.Glossary; +import com.google.cloud.translate.v3.ListGlossariesRequest; +import com.google.cloud.translate.v3.ListGlossariesResponse; +import com.google.cloud.translate.v3.LocationName; +import com.google.cloud.translate.v3.TranslationServiceClient; +import com.google.common.base.Strings; + +public class AsyncListGlossariesPaged { + + public static void main(String[] args) throws Exception { + asyncListGlossariesPaged(); + } + + public static void asyncListGlossariesPaged() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + ListGlossariesRequest request = + ListGlossariesRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .build(); + while (true) { + ListGlossariesResponse response = + translationServiceClient.listGlossariesCallable().call(request); + for (Glossary element : response.getGlossariesList()) { + // doThingsWith(element); + } + String nextPageToken = response.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + request = request.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END translation_v3_generated_translationserviceclient_listglossaries_paged_async] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/listglossaries/SyncListGlossaries.java b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/listglossaries/SyncListGlossaries.java new file mode 100644 index 00000000..bfa1d27a --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/listglossaries/SyncListGlossaries.java @@ -0,0 +1,48 @@ +/* + * 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.translate.v3.samples; + +// [START translation_v3_generated_translationserviceclient_listglossaries_sync] +import com.google.cloud.translate.v3.Glossary; +import com.google.cloud.translate.v3.ListGlossariesRequest; +import com.google.cloud.translate.v3.LocationName; +import com.google.cloud.translate.v3.TranslationServiceClient; + +public class SyncListGlossaries { + + public static void main(String[] args) throws Exception { + syncListGlossaries(); + } + + public static void syncListGlossaries() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + ListGlossariesRequest request = + ListGlossariesRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .build(); + for (Glossary element : translationServiceClient.listGlossaries(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END translation_v3_generated_translationserviceclient_listglossaries_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/listglossaries/SyncListGlossariesLocationname.java b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/listglossaries/SyncListGlossariesLocationname.java new file mode 100644 index 00000000..8c717701 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/listglossaries/SyncListGlossariesLocationname.java @@ -0,0 +1,41 @@ +/* + * 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.translate.v3.samples; + +// [START translation_v3_generated_translationserviceclient_listglossaries_locationname_sync] +import com.google.cloud.translate.v3.Glossary; +import com.google.cloud.translate.v3.LocationName; +import com.google.cloud.translate.v3.TranslationServiceClient; + +public class SyncListGlossariesLocationname { + + public static void main(String[] args) throws Exception { + syncListGlossariesLocationname(); + } + + public static void syncListGlossariesLocationname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + for (Glossary element : translationServiceClient.listGlossaries(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END translation_v3_generated_translationserviceclient_listglossaries_locationname_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/listglossaries/SyncListGlossariesString.java b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/listglossaries/SyncListGlossariesString.java new file mode 100644 index 00000000..0da16ff5 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/listglossaries/SyncListGlossariesString.java @@ -0,0 +1,41 @@ +/* + * 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.translate.v3.samples; + +// [START translation_v3_generated_translationserviceclient_listglossaries_string_sync] +import com.google.cloud.translate.v3.Glossary; +import com.google.cloud.translate.v3.LocationName; +import com.google.cloud.translate.v3.TranslationServiceClient; + +public class SyncListGlossariesString { + + public static void main(String[] args) throws Exception { + syncListGlossariesString(); + } + + public static void syncListGlossariesString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString(); + for (Glossary element : translationServiceClient.listGlossaries(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END translation_v3_generated_translationserviceclient_listglossaries_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/translatedocument/AsyncTranslateDocument.java b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/translatedocument/AsyncTranslateDocument.java new file mode 100644 index 00000000..6d52ab89 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/translatedocument/AsyncTranslateDocument.java @@ -0,0 +1,57 @@ +/* + * 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.translate.v3.samples; + +// [START translation_v3_generated_translationserviceclient_translatedocument_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.translate.v3.DocumentInputConfig; +import com.google.cloud.translate.v3.DocumentOutputConfig; +import com.google.cloud.translate.v3.TranslateDocumentRequest; +import com.google.cloud.translate.v3.TranslateDocumentResponse; +import com.google.cloud.translate.v3.TranslateTextGlossaryConfig; +import com.google.cloud.translate.v3.TranslationServiceClient; +import java.util.HashMap; + +public class AsyncTranslateDocument { + + public static void main(String[] args) throws Exception { + asyncTranslateDocument(); + } + + public static void asyncTranslateDocument() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + TranslateDocumentRequest request = + TranslateDocumentRequest.newBuilder() + .setParent("parent-995424086") + .setSourceLanguageCode("sourceLanguageCode1645917472") + .setTargetLanguageCode("targetLanguageCode-106414698") + .setDocumentInputConfig(DocumentInputConfig.newBuilder().build()) + .setDocumentOutputConfig(DocumentOutputConfig.newBuilder().build()) + .setModel("model104069929") + .setGlossaryConfig(TranslateTextGlossaryConfig.newBuilder().build()) + .putAllLabels(new HashMap()) + .build(); + ApiFuture future = + translationServiceClient.translateDocumentCallable().futureCall(request); + // Do something. + TranslateDocumentResponse response = future.get(); + } + } +} +// [END translation_v3_generated_translationserviceclient_translatedocument_async] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/translatedocument/SyncTranslateDocument.java b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/translatedocument/SyncTranslateDocument.java new file mode 100644 index 00000000..c9b5ac1e --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/translatedocument/SyncTranslateDocument.java @@ -0,0 +1,53 @@ +/* + * 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.translate.v3.samples; + +// [START translation_v3_generated_translationserviceclient_translatedocument_sync] +import com.google.cloud.translate.v3.DocumentInputConfig; +import com.google.cloud.translate.v3.DocumentOutputConfig; +import com.google.cloud.translate.v3.TranslateDocumentRequest; +import com.google.cloud.translate.v3.TranslateDocumentResponse; +import com.google.cloud.translate.v3.TranslateTextGlossaryConfig; +import com.google.cloud.translate.v3.TranslationServiceClient; +import java.util.HashMap; + +public class SyncTranslateDocument { + + public static void main(String[] args) throws Exception { + syncTranslateDocument(); + } + + public static void syncTranslateDocument() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + TranslateDocumentRequest request = + TranslateDocumentRequest.newBuilder() + .setParent("parent-995424086") + .setSourceLanguageCode("sourceLanguageCode1645917472") + .setTargetLanguageCode("targetLanguageCode-106414698") + .setDocumentInputConfig(DocumentInputConfig.newBuilder().build()) + .setDocumentOutputConfig(DocumentOutputConfig.newBuilder().build()) + .setModel("model104069929") + .setGlossaryConfig(TranslateTextGlossaryConfig.newBuilder().build()) + .putAllLabels(new HashMap()) + .build(); + TranslateDocumentResponse response = translationServiceClient.translateDocument(request); + } + } +} +// [END translation_v3_generated_translationserviceclient_translatedocument_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/translatetext/AsyncTranslateText.java b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/translatetext/AsyncTranslateText.java new file mode 100644 index 00000000..8e3588f3 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/translatetext/AsyncTranslateText.java @@ -0,0 +1,57 @@ +/* + * 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.translate.v3.samples; + +// [START translation_v3_generated_translationserviceclient_translatetext_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.translate.v3.LocationName; +import com.google.cloud.translate.v3.TranslateTextGlossaryConfig; +import com.google.cloud.translate.v3.TranslateTextRequest; +import com.google.cloud.translate.v3.TranslateTextResponse; +import com.google.cloud.translate.v3.TranslationServiceClient; +import java.util.ArrayList; +import java.util.HashMap; + +public class AsyncTranslateText { + + public static void main(String[] args) throws Exception { + asyncTranslateText(); + } + + public static void asyncTranslateText() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + TranslateTextRequest request = + TranslateTextRequest.newBuilder() + .addAllContents(new ArrayList()) + .setMimeType("mimeType-1392120434") + .setSourceLanguageCode("sourceLanguageCode1645917472") + .setTargetLanguageCode("targetLanguageCode-106414698") + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setModel("model104069929") + .setGlossaryConfig(TranslateTextGlossaryConfig.newBuilder().build()) + .putAllLabels(new HashMap()) + .build(); + ApiFuture future = + translationServiceClient.translateTextCallable().futureCall(request); + // Do something. + TranslateTextResponse response = future.get(); + } + } +} +// [END translation_v3_generated_translationserviceclient_translatetext_async] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/translatetext/SyncTranslateText.java b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/translatetext/SyncTranslateText.java new file mode 100644 index 00000000..2f10cdb1 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/translatetext/SyncTranslateText.java @@ -0,0 +1,53 @@ +/* + * 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.translate.v3.samples; + +// [START translation_v3_generated_translationserviceclient_translatetext_sync] +import com.google.cloud.translate.v3.LocationName; +import com.google.cloud.translate.v3.TranslateTextGlossaryConfig; +import com.google.cloud.translate.v3.TranslateTextRequest; +import com.google.cloud.translate.v3.TranslateTextResponse; +import com.google.cloud.translate.v3.TranslationServiceClient; +import java.util.ArrayList; +import java.util.HashMap; + +public class SyncTranslateText { + + public static void main(String[] args) throws Exception { + syncTranslateText(); + } + + public static void syncTranslateText() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + TranslateTextRequest request = + TranslateTextRequest.newBuilder() + .addAllContents(new ArrayList()) + .setMimeType("mimeType-1392120434") + .setSourceLanguageCode("sourceLanguageCode1645917472") + .setTargetLanguageCode("targetLanguageCode-106414698") + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setModel("model104069929") + .setGlossaryConfig(TranslateTextGlossaryConfig.newBuilder().build()) + .putAllLabels(new HashMap()) + .build(); + TranslateTextResponse response = translationServiceClient.translateText(request); + } + } +} +// [END translation_v3_generated_translationserviceclient_translatetext_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/translatetext/SyncTranslateTextLocationnameStringListstring.java b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/translatetext/SyncTranslateTextLocationnameStringListstring.java new file mode 100644 index 00000000..31ae08b8 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/translatetext/SyncTranslateTextLocationnameStringListstring.java @@ -0,0 +1,44 @@ +/* + * 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.translate.v3.samples; + +// [START translation_v3_generated_translationserviceclient_translatetext_locationnamestringliststring_sync] +import com.google.cloud.translate.v3.LocationName; +import com.google.cloud.translate.v3.TranslateTextResponse; +import com.google.cloud.translate.v3.TranslationServiceClient; +import java.util.ArrayList; +import java.util.List; + +public class SyncTranslateTextLocationnameStringListstring { + + public static void main(String[] args) throws Exception { + syncTranslateTextLocationnameStringListstring(); + } + + public static void syncTranslateTextLocationnameStringListstring() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + String targetLanguageCode = "targetLanguageCode-106414698"; + List contents = new ArrayList<>(); + TranslateTextResponse response = + translationServiceClient.translateText(parent, targetLanguageCode, contents); + } + } +} +// [END translation_v3_generated_translationserviceclient_translatetext_locationnamestringliststring_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/translatetext/SyncTranslateTextLocationnameStringStringStringStringListstring.java b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/translatetext/SyncTranslateTextLocationnameStringStringStringStringListstring.java new file mode 100644 index 00000000..0731cf51 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/translatetext/SyncTranslateTextLocationnameStringStringStringStringListstring.java @@ -0,0 +1,49 @@ +/* + * 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.translate.v3.samples; + +// [START translation_v3_generated_translationserviceclient_translatetext_locationnamestringstringstringstringliststring_sync] +import com.google.cloud.translate.v3.LocationName; +import com.google.cloud.translate.v3.TranslateTextResponse; +import com.google.cloud.translate.v3.TranslationServiceClient; +import java.util.ArrayList; +import java.util.List; + +public class SyncTranslateTextLocationnameStringStringStringStringListstring { + + public static void main(String[] args) throws Exception { + syncTranslateTextLocationnameStringStringStringStringListstring(); + } + + public static void syncTranslateTextLocationnameStringStringStringStringListstring() + throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + String model = "model104069929"; + String mimeType = "mimeType-1392120434"; + String sourceLanguageCode = "sourceLanguageCode1645917472"; + String targetLanguageCode = "targetLanguageCode-106414698"; + List contents = new ArrayList<>(); + TranslateTextResponse response = + translationServiceClient.translateText( + parent, model, mimeType, sourceLanguageCode, targetLanguageCode, contents); + } + } +} +// [END translation_v3_generated_translationserviceclient_translatetext_locationnamestringstringstringstringliststring_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/translatetext/SyncTranslateTextStringStringListstring.java b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/translatetext/SyncTranslateTextStringStringListstring.java new file mode 100644 index 00000000..fe7d29cd --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/translatetext/SyncTranslateTextStringStringListstring.java @@ -0,0 +1,44 @@ +/* + * 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.translate.v3.samples; + +// [START translation_v3_generated_translationserviceclient_translatetext_stringstringliststring_sync] +import com.google.cloud.translate.v3.LocationName; +import com.google.cloud.translate.v3.TranslateTextResponse; +import com.google.cloud.translate.v3.TranslationServiceClient; +import java.util.ArrayList; +import java.util.List; + +public class SyncTranslateTextStringStringListstring { + + public static void main(String[] args) throws Exception { + syncTranslateTextStringStringListstring(); + } + + public static void syncTranslateTextStringStringListstring() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString(); + String targetLanguageCode = "targetLanguageCode-106414698"; + List contents = new ArrayList<>(); + TranslateTextResponse response = + translationServiceClient.translateText(parent, targetLanguageCode, contents); + } + } +} +// [END translation_v3_generated_translationserviceclient_translatetext_stringstringliststring_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/translatetext/SyncTranslateTextStringStringStringStringStringListstring.java b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/translatetext/SyncTranslateTextStringStringStringStringStringListstring.java new file mode 100644 index 00000000..bf3fdbb6 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3/translationserviceclient/translatetext/SyncTranslateTextStringStringStringStringStringListstring.java @@ -0,0 +1,48 @@ +/* + * 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.translate.v3.samples; + +// [START translation_v3_generated_translationserviceclient_translatetext_stringstringstringstringstringliststring_sync] +import com.google.cloud.translate.v3.LocationName; +import com.google.cloud.translate.v3.TranslateTextResponse; +import com.google.cloud.translate.v3.TranslationServiceClient; +import java.util.ArrayList; +import java.util.List; + +public class SyncTranslateTextStringStringStringStringStringListstring { + + public static void main(String[] args) throws Exception { + syncTranslateTextStringStringStringStringStringListstring(); + } + + public static void syncTranslateTextStringStringStringStringStringListstring() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString(); + String model = "model104069929"; + String mimeType = "mimeType-1392120434"; + String sourceLanguageCode = "sourceLanguageCode1645917472"; + String targetLanguageCode = "targetLanguageCode-106414698"; + List contents = new ArrayList<>(); + TranslateTextResponse response = + translationServiceClient.translateText( + parent, model, mimeType, sourceLanguageCode, targetLanguageCode, contents); + } + } +} +// [END translation_v3_generated_translationserviceclient_translatetext_stringstringstringstringstringliststring_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3/translationservicesettings/translatetext/SyncTranslateText.java b/samples/snippets/generated/com/google/cloud/translate/v3/translationservicesettings/translatetext/SyncTranslateText.java new file mode 100644 index 00000000..fd4fb672 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3/translationservicesettings/translatetext/SyncTranslateText.java @@ -0,0 +1,47 @@ +/* + * 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.translate.v3.samples; + +// [START translation_v3_generated_translationservicesettings_translatetext_sync] +import com.google.cloud.translate.v3.TranslationServiceSettings; +import java.time.Duration; + +public class SyncTranslateText { + + public static void main(String[] args) throws Exception { + syncTranslateText(); + } + + public static void syncTranslateText() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + TranslationServiceSettings.Builder translationServiceSettingsBuilder = + TranslationServiceSettings.newBuilder(); + translationServiceSettingsBuilder + .translateTextSettings() + .setRetrySettings( + translationServiceSettingsBuilder + .translateTextSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + TranslationServiceSettings translationServiceSettings = + translationServiceSettingsBuilder.build(); + } +} +// [END translation_v3_generated_translationservicesettings_translatetext_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3beta1/stub/translationservicestubsettings/translatetext/SyncTranslateText.java b/samples/snippets/generated/com/google/cloud/translate/v3beta1/stub/translationservicestubsettings/translatetext/SyncTranslateText.java new file mode 100644 index 00000000..373c307a --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3beta1/stub/translationservicestubsettings/translatetext/SyncTranslateText.java @@ -0,0 +1,47 @@ +/* + * 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.translate.v3beta1.stub.samples; + +// [START translation_v3beta1_generated_translationservicestubsettings_translatetext_sync] +import com.google.cloud.translate.v3beta1.stub.TranslationServiceStubSettings; +import java.time.Duration; + +public class SyncTranslateText { + + public static void main(String[] args) throws Exception { + syncTranslateText(); + } + + public static void syncTranslateText() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + TranslationServiceStubSettings.Builder translationServiceSettingsBuilder = + TranslationServiceStubSettings.newBuilder(); + translationServiceSettingsBuilder + .translateTextSettings() + .setRetrySettings( + translationServiceSettingsBuilder + .translateTextSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + TranslationServiceStubSettings translationServiceSettings = + translationServiceSettingsBuilder.build(); + } +} +// [END translation_v3beta1_generated_translationservicestubsettings_translatetext_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/batchtranslatedocument/AsyncBatchTranslateDocument.java b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/batchtranslatedocument/AsyncBatchTranslateDocument.java new file mode 100644 index 00000000..09511cce --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/batchtranslatedocument/AsyncBatchTranslateDocument.java @@ -0,0 +1,59 @@ +/* + * 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.translate.v3beta1.samples; + +// [START translation_v3beta1_generated_translationserviceclient_batchtranslatedocument_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.translate.v3beta1.BatchDocumentInputConfig; +import com.google.cloud.translate.v3beta1.BatchDocumentOutputConfig; +import com.google.cloud.translate.v3beta1.BatchTranslateDocumentRequest; +import com.google.cloud.translate.v3beta1.LocationName; +import com.google.cloud.translate.v3beta1.TranslateTextGlossaryConfig; +import com.google.cloud.translate.v3beta1.TranslationServiceClient; +import com.google.longrunning.Operation; +import java.util.ArrayList; +import java.util.HashMap; + +public class AsyncBatchTranslateDocument { + + public static void main(String[] args) throws Exception { + asyncBatchTranslateDocument(); + } + + public static void asyncBatchTranslateDocument() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + BatchTranslateDocumentRequest request = + BatchTranslateDocumentRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setSourceLanguageCode("sourceLanguageCode1645917472") + .addAllTargetLanguageCodes(new ArrayList()) + .addAllInputConfigs(new ArrayList()) + .setOutputConfig(BatchDocumentOutputConfig.newBuilder().build()) + .putAllModels(new HashMap()) + .putAllGlossaries(new HashMap()) + .putAllFormatConversions(new HashMap()) + .build(); + ApiFuture future = + translationServiceClient.batchTranslateDocumentCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END translation_v3beta1_generated_translationserviceclient_batchtranslatedocument_async] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/batchtranslatedocument/AsyncBatchTranslateDocumentLRO.java b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/batchtranslatedocument/AsyncBatchTranslateDocumentLRO.java new file mode 100644 index 00000000..1ccbfd3d --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/batchtranslatedocument/AsyncBatchTranslateDocumentLRO.java @@ -0,0 +1,60 @@ +/* + * 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.translate.v3beta1.samples; + +// [START translation_v3beta1_generated_translationserviceclient_batchtranslatedocument_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.translate.v3beta1.BatchDocumentInputConfig; +import com.google.cloud.translate.v3beta1.BatchDocumentOutputConfig; +import com.google.cloud.translate.v3beta1.BatchTranslateDocumentMetadata; +import com.google.cloud.translate.v3beta1.BatchTranslateDocumentRequest; +import com.google.cloud.translate.v3beta1.BatchTranslateDocumentResponse; +import com.google.cloud.translate.v3beta1.LocationName; +import com.google.cloud.translate.v3beta1.TranslateTextGlossaryConfig; +import com.google.cloud.translate.v3beta1.TranslationServiceClient; +import java.util.ArrayList; +import java.util.HashMap; + +public class AsyncBatchTranslateDocumentLRO { + + public static void main(String[] args) throws Exception { + asyncBatchTranslateDocumentLRO(); + } + + public static void asyncBatchTranslateDocumentLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + BatchTranslateDocumentRequest request = + BatchTranslateDocumentRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setSourceLanguageCode("sourceLanguageCode1645917472") + .addAllTargetLanguageCodes(new ArrayList()) + .addAllInputConfigs(new ArrayList()) + .setOutputConfig(BatchDocumentOutputConfig.newBuilder().build()) + .putAllModels(new HashMap()) + .putAllGlossaries(new HashMap()) + .putAllFormatConversions(new HashMap()) + .build(); + OperationFuture future = + translationServiceClient.batchTranslateDocumentOperationCallable().futureCall(request); + // Do something. + BatchTranslateDocumentResponse response = future.get(); + } + } +} +// [END translation_v3beta1_generated_translationserviceclient_batchtranslatedocument_lro_async] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/batchtranslatedocument/SyncBatchTranslateDocument.java b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/batchtranslatedocument/SyncBatchTranslateDocument.java new file mode 100644 index 00000000..91c10c50 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/batchtranslatedocument/SyncBatchTranslateDocument.java @@ -0,0 +1,56 @@ +/* + * 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.translate.v3beta1.samples; + +// [START translation_v3beta1_generated_translationserviceclient_batchtranslatedocument_sync] +import com.google.cloud.translate.v3beta1.BatchDocumentInputConfig; +import com.google.cloud.translate.v3beta1.BatchDocumentOutputConfig; +import com.google.cloud.translate.v3beta1.BatchTranslateDocumentRequest; +import com.google.cloud.translate.v3beta1.BatchTranslateDocumentResponse; +import com.google.cloud.translate.v3beta1.LocationName; +import com.google.cloud.translate.v3beta1.TranslateTextGlossaryConfig; +import com.google.cloud.translate.v3beta1.TranslationServiceClient; +import java.util.ArrayList; +import java.util.HashMap; + +public class SyncBatchTranslateDocument { + + public static void main(String[] args) throws Exception { + syncBatchTranslateDocument(); + } + + public static void syncBatchTranslateDocument() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + BatchTranslateDocumentRequest request = + BatchTranslateDocumentRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setSourceLanguageCode("sourceLanguageCode1645917472") + .addAllTargetLanguageCodes(new ArrayList()) + .addAllInputConfigs(new ArrayList()) + .setOutputConfig(BatchDocumentOutputConfig.newBuilder().build()) + .putAllModels(new HashMap()) + .putAllGlossaries(new HashMap()) + .putAllFormatConversions(new HashMap()) + .build(); + BatchTranslateDocumentResponse response = + translationServiceClient.batchTranslateDocumentAsync(request).get(); + } + } +} +// [END translation_v3beta1_generated_translationserviceclient_batchtranslatedocument_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/batchtranslatedocument/SyncBatchTranslateDocumentLocationnameStringListstringListbatchdocumentinputconfigBatchdocumentoutputconfig.java b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/batchtranslatedocument/SyncBatchTranslateDocumentLocationnameStringListstringListbatchdocumentinputconfigBatchdocumentoutputconfig.java new file mode 100644 index 00000000..1ea78bc7 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/batchtranslatedocument/SyncBatchTranslateDocumentLocationnameStringListstringListbatchdocumentinputconfigBatchdocumentoutputconfig.java @@ -0,0 +1,54 @@ +/* + * 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.translate.v3beta1.samples; + +// [START translation_v3beta1_generated_translationserviceclient_batchtranslatedocument_locationnamestringliststringlistbatchdocumentinputconfigbatchdocumentoutputconfig_sync] +import com.google.cloud.translate.v3beta1.BatchDocumentInputConfig; +import com.google.cloud.translate.v3beta1.BatchDocumentOutputConfig; +import com.google.cloud.translate.v3beta1.BatchTranslateDocumentResponse; +import com.google.cloud.translate.v3beta1.LocationName; +import com.google.cloud.translate.v3beta1.TranslationServiceClient; +import java.util.ArrayList; +import java.util.List; + +public +class SyncBatchTranslateDocumentLocationnameStringListstringListbatchdocumentinputconfigBatchdocumentoutputconfig { + + public static void main(String[] args) throws Exception { + syncBatchTranslateDocumentLocationnameStringListstringListbatchdocumentinputconfigBatchdocumentoutputconfig(); + } + + public static void + syncBatchTranslateDocumentLocationnameStringListstringListbatchdocumentinputconfigBatchdocumentoutputconfig() + throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + String sourceLanguageCode = "sourceLanguageCode1645917472"; + List targetLanguageCodes = new ArrayList<>(); + List inputConfigs = new ArrayList<>(); + BatchDocumentOutputConfig outputConfig = BatchDocumentOutputConfig.newBuilder().build(); + BatchTranslateDocumentResponse response = + translationServiceClient + .batchTranslateDocumentAsync( + parent, sourceLanguageCode, targetLanguageCodes, inputConfigs, outputConfig) + .get(); + } + } +} +// [END translation_v3beta1_generated_translationserviceclient_batchtranslatedocument_locationnamestringliststringlistbatchdocumentinputconfigbatchdocumentoutputconfig_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/batchtranslatedocument/SyncBatchTranslateDocumentStringStringListstringListbatchdocumentinputconfigBatchdocumentoutputconfig.java b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/batchtranslatedocument/SyncBatchTranslateDocumentStringStringListstringListbatchdocumentinputconfigBatchdocumentoutputconfig.java new file mode 100644 index 00000000..0fd83e38 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/batchtranslatedocument/SyncBatchTranslateDocumentStringStringListstringListbatchdocumentinputconfigBatchdocumentoutputconfig.java @@ -0,0 +1,54 @@ +/* + * 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.translate.v3beta1.samples; + +// [START translation_v3beta1_generated_translationserviceclient_batchtranslatedocument_stringstringliststringlistbatchdocumentinputconfigbatchdocumentoutputconfig_sync] +import com.google.cloud.translate.v3beta1.BatchDocumentInputConfig; +import com.google.cloud.translate.v3beta1.BatchDocumentOutputConfig; +import com.google.cloud.translate.v3beta1.BatchTranslateDocumentResponse; +import com.google.cloud.translate.v3beta1.LocationName; +import com.google.cloud.translate.v3beta1.TranslationServiceClient; +import java.util.ArrayList; +import java.util.List; + +public +class SyncBatchTranslateDocumentStringStringListstringListbatchdocumentinputconfigBatchdocumentoutputconfig { + + public static void main(String[] args) throws Exception { + syncBatchTranslateDocumentStringStringListstringListbatchdocumentinputconfigBatchdocumentoutputconfig(); + } + + public static void + syncBatchTranslateDocumentStringStringListstringListbatchdocumentinputconfigBatchdocumentoutputconfig() + throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString(); + String sourceLanguageCode = "sourceLanguageCode1645917472"; + List targetLanguageCodes = new ArrayList<>(); + List inputConfigs = new ArrayList<>(); + BatchDocumentOutputConfig outputConfig = BatchDocumentOutputConfig.newBuilder().build(); + BatchTranslateDocumentResponse response = + translationServiceClient + .batchTranslateDocumentAsync( + parent, sourceLanguageCode, targetLanguageCodes, inputConfigs, outputConfig) + .get(); + } + } +} +// [END translation_v3beta1_generated_translationserviceclient_batchtranslatedocument_stringstringliststringlistbatchdocumentinputconfigbatchdocumentoutputconfig_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/batchtranslatetext/AsyncBatchTranslateText.java b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/batchtranslatetext/AsyncBatchTranslateText.java new file mode 100644 index 00000000..2e097d5f --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/batchtranslatetext/AsyncBatchTranslateText.java @@ -0,0 +1,59 @@ +/* + * 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.translate.v3beta1.samples; + +// [START translation_v3beta1_generated_translationserviceclient_batchtranslatetext_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.translate.v3beta1.BatchTranslateTextRequest; +import com.google.cloud.translate.v3beta1.InputConfig; +import com.google.cloud.translate.v3beta1.LocationName; +import com.google.cloud.translate.v3beta1.OutputConfig; +import com.google.cloud.translate.v3beta1.TranslateTextGlossaryConfig; +import com.google.cloud.translate.v3beta1.TranslationServiceClient; +import com.google.longrunning.Operation; +import java.util.ArrayList; +import java.util.HashMap; + +public class AsyncBatchTranslateText { + + public static void main(String[] args) throws Exception { + asyncBatchTranslateText(); + } + + public static void asyncBatchTranslateText() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + BatchTranslateTextRequest request = + BatchTranslateTextRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setSourceLanguageCode("sourceLanguageCode1645917472") + .addAllTargetLanguageCodes(new ArrayList()) + .putAllModels(new HashMap()) + .addAllInputConfigs(new ArrayList()) + .setOutputConfig(OutputConfig.newBuilder().build()) + .putAllGlossaries(new HashMap()) + .putAllLabels(new HashMap()) + .build(); + ApiFuture future = + translationServiceClient.batchTranslateTextCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END translation_v3beta1_generated_translationserviceclient_batchtranslatetext_async] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/batchtranslatetext/AsyncBatchTranslateTextLRO.java b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/batchtranslatetext/AsyncBatchTranslateTextLRO.java new file mode 100644 index 00000000..84a461c3 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/batchtranslatetext/AsyncBatchTranslateTextLRO.java @@ -0,0 +1,60 @@ +/* + * 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.translate.v3beta1.samples; + +// [START translation_v3beta1_generated_translationserviceclient_batchtranslatetext_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.translate.v3beta1.BatchTranslateMetadata; +import com.google.cloud.translate.v3beta1.BatchTranslateResponse; +import com.google.cloud.translate.v3beta1.BatchTranslateTextRequest; +import com.google.cloud.translate.v3beta1.InputConfig; +import com.google.cloud.translate.v3beta1.LocationName; +import com.google.cloud.translate.v3beta1.OutputConfig; +import com.google.cloud.translate.v3beta1.TranslateTextGlossaryConfig; +import com.google.cloud.translate.v3beta1.TranslationServiceClient; +import java.util.ArrayList; +import java.util.HashMap; + +public class AsyncBatchTranslateTextLRO { + + public static void main(String[] args) throws Exception { + asyncBatchTranslateTextLRO(); + } + + public static void asyncBatchTranslateTextLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + BatchTranslateTextRequest request = + BatchTranslateTextRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setSourceLanguageCode("sourceLanguageCode1645917472") + .addAllTargetLanguageCodes(new ArrayList()) + .putAllModels(new HashMap()) + .addAllInputConfigs(new ArrayList()) + .setOutputConfig(OutputConfig.newBuilder().build()) + .putAllGlossaries(new HashMap()) + .putAllLabels(new HashMap()) + .build(); + OperationFuture future = + translationServiceClient.batchTranslateTextOperationCallable().futureCall(request); + // Do something. + BatchTranslateResponse response = future.get(); + } + } +} +// [END translation_v3beta1_generated_translationserviceclient_batchtranslatetext_lro_async] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/batchtranslatetext/SyncBatchTranslateText.java b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/batchtranslatetext/SyncBatchTranslateText.java new file mode 100644 index 00000000..04f0dcea --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/batchtranslatetext/SyncBatchTranslateText.java @@ -0,0 +1,56 @@ +/* + * 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.translate.v3beta1.samples; + +// [START translation_v3beta1_generated_translationserviceclient_batchtranslatetext_sync] +import com.google.cloud.translate.v3beta1.BatchTranslateResponse; +import com.google.cloud.translate.v3beta1.BatchTranslateTextRequest; +import com.google.cloud.translate.v3beta1.InputConfig; +import com.google.cloud.translate.v3beta1.LocationName; +import com.google.cloud.translate.v3beta1.OutputConfig; +import com.google.cloud.translate.v3beta1.TranslateTextGlossaryConfig; +import com.google.cloud.translate.v3beta1.TranslationServiceClient; +import java.util.ArrayList; +import java.util.HashMap; + +public class SyncBatchTranslateText { + + public static void main(String[] args) throws Exception { + syncBatchTranslateText(); + } + + public static void syncBatchTranslateText() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + BatchTranslateTextRequest request = + BatchTranslateTextRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setSourceLanguageCode("sourceLanguageCode1645917472") + .addAllTargetLanguageCodes(new ArrayList()) + .putAllModels(new HashMap()) + .addAllInputConfigs(new ArrayList()) + .setOutputConfig(OutputConfig.newBuilder().build()) + .putAllGlossaries(new HashMap()) + .putAllLabels(new HashMap()) + .build(); + BatchTranslateResponse response = + translationServiceClient.batchTranslateTextAsync(request).get(); + } + } +} +// [END translation_v3beta1_generated_translationserviceclient_batchtranslatetext_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/create/SyncCreateSetCredentialsProvider.java b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/create/SyncCreateSetCredentialsProvider.java new file mode 100644 index 00000000..deb0f696 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/create/SyncCreateSetCredentialsProvider.java @@ -0,0 +1,42 @@ +/* + * 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.translate.v3beta1.samples; + +// [START translation_v3beta1_generated_translationserviceclient_create_setcredentialsprovider_sync] +import com.google.api.gax.core.FixedCredentialsProvider; +import com.google.cloud.translate.v3beta1.TranslationServiceClient; +import com.google.cloud.translate.v3beta1.TranslationServiceSettings; +import com.google.cloud.translate.v3beta1.myCredentials; + +public class SyncCreateSetCredentialsProvider { + + public static void main(String[] args) throws Exception { + syncCreateSetCredentialsProvider(); + } + + public static void syncCreateSetCredentialsProvider() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + TranslationServiceSettings translationServiceSettings = + TranslationServiceSettings.newBuilder() + .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) + .build(); + TranslationServiceClient translationServiceClient = + TranslationServiceClient.create(translationServiceSettings); + } +} +// [END translation_v3beta1_generated_translationserviceclient_create_setcredentialsprovider_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/create/SyncCreateSetCredentialsProvider1.java b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/create/SyncCreateSetCredentialsProvider1.java new file mode 100644 index 00000000..d050696b --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/create/SyncCreateSetCredentialsProvider1.java @@ -0,0 +1,41 @@ +/* + * 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.translate.v3beta1.samples; + +// [START translation_v3beta1_generated_translationserviceclient_create_setcredentialsprovider1_sync] +import com.google.cloud.translate.v3beta1.TranslationServiceClient; +import com.google.cloud.translate.v3beta1.TranslationServiceSettings; + +public class SyncCreateSetCredentialsProvider1 { + + public static void main(String[] args) throws Exception { + syncCreateSetCredentialsProvider1(); + } + + public static void syncCreateSetCredentialsProvider1() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + TranslationServiceSettings translationServiceSettings = + TranslationServiceSettings.newBuilder() + .setTransportChannelProvider( + TranslationServiceSettings.defaultHttpJsonTransportProviderBuilder().build()) + .build(); + TranslationServiceClient translationServiceClient = + TranslationServiceClient.create(translationServiceSettings); + } +} +// [END translation_v3beta1_generated_translationserviceclient_create_setcredentialsprovider1_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/create/SyncCreateSetEndpoint.java b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/create/SyncCreateSetEndpoint.java new file mode 100644 index 00000000..307a43d8 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/create/SyncCreateSetEndpoint.java @@ -0,0 +1,39 @@ +/* + * 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.translate.v3beta1.samples; + +// [START translation_v3beta1_generated_translationserviceclient_create_setendpoint_sync] +import com.google.cloud.translate.v3beta1.TranslationServiceClient; +import com.google.cloud.translate.v3beta1.TranslationServiceSettings; +import com.google.cloud.translate.v3beta1.myEndpoint; + +public class SyncCreateSetEndpoint { + + public static void main(String[] args) throws Exception { + syncCreateSetEndpoint(); + } + + public static void syncCreateSetEndpoint() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + TranslationServiceSettings translationServiceSettings = + TranslationServiceSettings.newBuilder().setEndpoint(myEndpoint).build(); + TranslationServiceClient translationServiceClient = + TranslationServiceClient.create(translationServiceSettings); + } +} +// [END translation_v3beta1_generated_translationserviceclient_create_setendpoint_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/createglossary/AsyncCreateGlossary.java b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/createglossary/AsyncCreateGlossary.java new file mode 100644 index 00000000..0f9a6911 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/createglossary/AsyncCreateGlossary.java @@ -0,0 +1,49 @@ +/* + * 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.translate.v3beta1.samples; + +// [START translation_v3beta1_generated_translationserviceclient_createglossary_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.translate.v3beta1.CreateGlossaryRequest; +import com.google.cloud.translate.v3beta1.Glossary; +import com.google.cloud.translate.v3beta1.LocationName; +import com.google.cloud.translate.v3beta1.TranslationServiceClient; +import com.google.longrunning.Operation; + +public class AsyncCreateGlossary { + + public static void main(String[] args) throws Exception { + asyncCreateGlossary(); + } + + public static void asyncCreateGlossary() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + CreateGlossaryRequest request = + CreateGlossaryRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setGlossary(Glossary.newBuilder().build()) + .build(); + ApiFuture future = + translationServiceClient.createGlossaryCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END translation_v3beta1_generated_translationserviceclient_createglossary_async] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/createglossary/AsyncCreateGlossaryLRO.java b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/createglossary/AsyncCreateGlossaryLRO.java new file mode 100644 index 00000000..cef0e3be --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/createglossary/AsyncCreateGlossaryLRO.java @@ -0,0 +1,49 @@ +/* + * 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.translate.v3beta1.samples; + +// [START translation_v3beta1_generated_translationserviceclient_createglossary_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.translate.v3beta1.CreateGlossaryMetadata; +import com.google.cloud.translate.v3beta1.CreateGlossaryRequest; +import com.google.cloud.translate.v3beta1.Glossary; +import com.google.cloud.translate.v3beta1.LocationName; +import com.google.cloud.translate.v3beta1.TranslationServiceClient; + +public class AsyncCreateGlossaryLRO { + + public static void main(String[] args) throws Exception { + asyncCreateGlossaryLRO(); + } + + public static void asyncCreateGlossaryLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + CreateGlossaryRequest request = + CreateGlossaryRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setGlossary(Glossary.newBuilder().build()) + .build(); + OperationFuture future = + translationServiceClient.createGlossaryOperationCallable().futureCall(request); + // Do something. + Glossary response = future.get(); + } + } +} +// [END translation_v3beta1_generated_translationserviceclient_createglossary_lro_async] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/createglossary/SyncCreateGlossary.java b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/createglossary/SyncCreateGlossary.java new file mode 100644 index 00000000..113054c0 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/createglossary/SyncCreateGlossary.java @@ -0,0 +1,44 @@ +/* + * 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.translate.v3beta1.samples; + +// [START translation_v3beta1_generated_translationserviceclient_createglossary_sync] +import com.google.cloud.translate.v3beta1.CreateGlossaryRequest; +import com.google.cloud.translate.v3beta1.Glossary; +import com.google.cloud.translate.v3beta1.LocationName; +import com.google.cloud.translate.v3beta1.TranslationServiceClient; + +public class SyncCreateGlossary { + + public static void main(String[] args) throws Exception { + syncCreateGlossary(); + } + + public static void syncCreateGlossary() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + CreateGlossaryRequest request = + CreateGlossaryRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setGlossary(Glossary.newBuilder().build()) + .build(); + Glossary response = translationServiceClient.createGlossaryAsync(request).get(); + } + } +} +// [END translation_v3beta1_generated_translationserviceclient_createglossary_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/createglossary/SyncCreateGlossaryLocationnameGlossary.java b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/createglossary/SyncCreateGlossaryLocationnameGlossary.java new file mode 100644 index 00000000..abd73013 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/createglossary/SyncCreateGlossaryLocationnameGlossary.java @@ -0,0 +1,40 @@ +/* + * 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.translate.v3beta1.samples; + +// [START translation_v3beta1_generated_translationserviceclient_createglossary_locationnameglossary_sync] +import com.google.cloud.translate.v3beta1.Glossary; +import com.google.cloud.translate.v3beta1.LocationName; +import com.google.cloud.translate.v3beta1.TranslationServiceClient; + +public class SyncCreateGlossaryLocationnameGlossary { + + public static void main(String[] args) throws Exception { + syncCreateGlossaryLocationnameGlossary(); + } + + public static void syncCreateGlossaryLocationnameGlossary() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + Glossary glossary = Glossary.newBuilder().build(); + Glossary response = translationServiceClient.createGlossaryAsync(parent, glossary).get(); + } + } +} +// [END translation_v3beta1_generated_translationserviceclient_createglossary_locationnameglossary_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/createglossary/SyncCreateGlossaryStringGlossary.java b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/createglossary/SyncCreateGlossaryStringGlossary.java new file mode 100644 index 00000000..8cc1a253 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/createglossary/SyncCreateGlossaryStringGlossary.java @@ -0,0 +1,40 @@ +/* + * 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.translate.v3beta1.samples; + +// [START translation_v3beta1_generated_translationserviceclient_createglossary_stringglossary_sync] +import com.google.cloud.translate.v3beta1.Glossary; +import com.google.cloud.translate.v3beta1.LocationName; +import com.google.cloud.translate.v3beta1.TranslationServiceClient; + +public class SyncCreateGlossaryStringGlossary { + + public static void main(String[] args) throws Exception { + syncCreateGlossaryStringGlossary(); + } + + public static void syncCreateGlossaryStringGlossary() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString(); + Glossary glossary = Glossary.newBuilder().build(); + Glossary response = translationServiceClient.createGlossaryAsync(parent, glossary).get(); + } + } +} +// [END translation_v3beta1_generated_translationserviceclient_createglossary_stringglossary_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/deleteglossary/AsyncDeleteGlossary.java b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/deleteglossary/AsyncDeleteGlossary.java new file mode 100644 index 00000000..60debf32 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/deleteglossary/AsyncDeleteGlossary.java @@ -0,0 +1,47 @@ +/* + * 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.translate.v3beta1.samples; + +// [START translation_v3beta1_generated_translationserviceclient_deleteglossary_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.translate.v3beta1.DeleteGlossaryRequest; +import com.google.cloud.translate.v3beta1.GlossaryName; +import com.google.cloud.translate.v3beta1.TranslationServiceClient; +import com.google.longrunning.Operation; + +public class AsyncDeleteGlossary { + + public static void main(String[] args) throws Exception { + asyncDeleteGlossary(); + } + + public static void asyncDeleteGlossary() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + DeleteGlossaryRequest request = + DeleteGlossaryRequest.newBuilder() + .setName(GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]").toString()) + .build(); + ApiFuture future = + translationServiceClient.deleteGlossaryCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END translation_v3beta1_generated_translationserviceclient_deleteglossary_async] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/deleteglossary/AsyncDeleteGlossaryLRO.java b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/deleteglossary/AsyncDeleteGlossaryLRO.java new file mode 100644 index 00000000..ee99b3ac --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/deleteglossary/AsyncDeleteGlossaryLRO.java @@ -0,0 +1,48 @@ +/* + * 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.translate.v3beta1.samples; + +// [START translation_v3beta1_generated_translationserviceclient_deleteglossary_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.translate.v3beta1.DeleteGlossaryMetadata; +import com.google.cloud.translate.v3beta1.DeleteGlossaryRequest; +import com.google.cloud.translate.v3beta1.DeleteGlossaryResponse; +import com.google.cloud.translate.v3beta1.GlossaryName; +import com.google.cloud.translate.v3beta1.TranslationServiceClient; + +public class AsyncDeleteGlossaryLRO { + + public static void main(String[] args) throws Exception { + asyncDeleteGlossaryLRO(); + } + + public static void asyncDeleteGlossaryLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + DeleteGlossaryRequest request = + DeleteGlossaryRequest.newBuilder() + .setName(GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]").toString()) + .build(); + OperationFuture future = + translationServiceClient.deleteGlossaryOperationCallable().futureCall(request); + // Do something. + DeleteGlossaryResponse response = future.get(); + } + } +} +// [END translation_v3beta1_generated_translationserviceclient_deleteglossary_lro_async] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/deleteglossary/SyncDeleteGlossary.java b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/deleteglossary/SyncDeleteGlossary.java new file mode 100644 index 00000000..a3706b7e --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/deleteglossary/SyncDeleteGlossary.java @@ -0,0 +1,43 @@ +/* + * 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.translate.v3beta1.samples; + +// [START translation_v3beta1_generated_translationserviceclient_deleteglossary_sync] +import com.google.cloud.translate.v3beta1.DeleteGlossaryRequest; +import com.google.cloud.translate.v3beta1.DeleteGlossaryResponse; +import com.google.cloud.translate.v3beta1.GlossaryName; +import com.google.cloud.translate.v3beta1.TranslationServiceClient; + +public class SyncDeleteGlossary { + + public static void main(String[] args) throws Exception { + syncDeleteGlossary(); + } + + public static void syncDeleteGlossary() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + DeleteGlossaryRequest request = + DeleteGlossaryRequest.newBuilder() + .setName(GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]").toString()) + .build(); + DeleteGlossaryResponse response = translationServiceClient.deleteGlossaryAsync(request).get(); + } + } +} +// [END translation_v3beta1_generated_translationserviceclient_deleteglossary_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/deleteglossary/SyncDeleteGlossaryGlossaryname.java b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/deleteglossary/SyncDeleteGlossaryGlossaryname.java new file mode 100644 index 00000000..a860a706 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/deleteglossary/SyncDeleteGlossaryGlossaryname.java @@ -0,0 +1,39 @@ +/* + * 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.translate.v3beta1.samples; + +// [START translation_v3beta1_generated_translationserviceclient_deleteglossary_glossaryname_sync] +import com.google.cloud.translate.v3beta1.DeleteGlossaryResponse; +import com.google.cloud.translate.v3beta1.GlossaryName; +import com.google.cloud.translate.v3beta1.TranslationServiceClient; + +public class SyncDeleteGlossaryGlossaryname { + + public static void main(String[] args) throws Exception { + syncDeleteGlossaryGlossaryname(); + } + + public static void syncDeleteGlossaryGlossaryname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + GlossaryName name = GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]"); + DeleteGlossaryResponse response = translationServiceClient.deleteGlossaryAsync(name).get(); + } + } +} +// [END translation_v3beta1_generated_translationserviceclient_deleteglossary_glossaryname_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/deleteglossary/SyncDeleteGlossaryString.java b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/deleteglossary/SyncDeleteGlossaryString.java new file mode 100644 index 00000000..b064a201 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/deleteglossary/SyncDeleteGlossaryString.java @@ -0,0 +1,39 @@ +/* + * 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.translate.v3beta1.samples; + +// [START translation_v3beta1_generated_translationserviceclient_deleteglossary_string_sync] +import com.google.cloud.translate.v3beta1.DeleteGlossaryResponse; +import com.google.cloud.translate.v3beta1.GlossaryName; +import com.google.cloud.translate.v3beta1.TranslationServiceClient; + +public class SyncDeleteGlossaryString { + + public static void main(String[] args) throws Exception { + syncDeleteGlossaryString(); + } + + public static void syncDeleteGlossaryString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + String name = GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]").toString(); + DeleteGlossaryResponse response = translationServiceClient.deleteGlossaryAsync(name).get(); + } + } +} +// [END translation_v3beta1_generated_translationserviceclient_deleteglossary_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/detectlanguage/AsyncDetectLanguage.java b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/detectlanguage/AsyncDetectLanguage.java new file mode 100644 index 00000000..4a1e54dd --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/detectlanguage/AsyncDetectLanguage.java @@ -0,0 +1,51 @@ +/* + * 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.translate.v3beta1.samples; + +// [START translation_v3beta1_generated_translationserviceclient_detectlanguage_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.translate.v3beta1.DetectLanguageRequest; +import com.google.cloud.translate.v3beta1.DetectLanguageResponse; +import com.google.cloud.translate.v3beta1.LocationName; +import com.google.cloud.translate.v3beta1.TranslationServiceClient; +import java.util.HashMap; + +public class AsyncDetectLanguage { + + public static void main(String[] args) throws Exception { + asyncDetectLanguage(); + } + + public static void asyncDetectLanguage() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + DetectLanguageRequest request = + DetectLanguageRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setModel("model104069929") + .setMimeType("mimeType-1392120434") + .putAllLabels(new HashMap()) + .build(); + ApiFuture future = + translationServiceClient.detectLanguageCallable().futureCall(request); + // Do something. + DetectLanguageResponse response = future.get(); + } + } +} +// [END translation_v3beta1_generated_translationserviceclient_detectlanguage_async] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/detectlanguage/SyncDetectLanguage.java b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/detectlanguage/SyncDetectLanguage.java new file mode 100644 index 00000000..30aa84a8 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/detectlanguage/SyncDetectLanguage.java @@ -0,0 +1,47 @@ +/* + * 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.translate.v3beta1.samples; + +// [START translation_v3beta1_generated_translationserviceclient_detectlanguage_sync] +import com.google.cloud.translate.v3beta1.DetectLanguageRequest; +import com.google.cloud.translate.v3beta1.DetectLanguageResponse; +import com.google.cloud.translate.v3beta1.LocationName; +import com.google.cloud.translate.v3beta1.TranslationServiceClient; +import java.util.HashMap; + +public class SyncDetectLanguage { + + public static void main(String[] args) throws Exception { + syncDetectLanguage(); + } + + public static void syncDetectLanguage() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + DetectLanguageRequest request = + DetectLanguageRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setModel("model104069929") + .setMimeType("mimeType-1392120434") + .putAllLabels(new HashMap()) + .build(); + DetectLanguageResponse response = translationServiceClient.detectLanguage(request); + } + } +} +// [END translation_v3beta1_generated_translationserviceclient_detectlanguage_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/detectlanguage/SyncDetectLanguageLocationnameStringString.java b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/detectlanguage/SyncDetectLanguageLocationnameStringString.java new file mode 100644 index 00000000..deac9beb --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/detectlanguage/SyncDetectLanguageLocationnameStringString.java @@ -0,0 +1,42 @@ +/* + * 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.translate.v3beta1.samples; + +// [START translation_v3beta1_generated_translationserviceclient_detectlanguage_locationnamestringstring_sync] +import com.google.cloud.translate.v3beta1.DetectLanguageResponse; +import com.google.cloud.translate.v3beta1.LocationName; +import com.google.cloud.translate.v3beta1.TranslationServiceClient; + +public class SyncDetectLanguageLocationnameStringString { + + public static void main(String[] args) throws Exception { + syncDetectLanguageLocationnameStringString(); + } + + public static void syncDetectLanguageLocationnameStringString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + String model = "model104069929"; + String mimeType = "mimeType-1392120434"; + DetectLanguageResponse response = + translationServiceClient.detectLanguage(parent, model, mimeType); + } + } +} +// [END translation_v3beta1_generated_translationserviceclient_detectlanguage_locationnamestringstring_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/detectlanguage/SyncDetectLanguageStringStringString.java b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/detectlanguage/SyncDetectLanguageStringStringString.java new file mode 100644 index 00000000..9e8e52f1 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/detectlanguage/SyncDetectLanguageStringStringString.java @@ -0,0 +1,42 @@ +/* + * 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.translate.v3beta1.samples; + +// [START translation_v3beta1_generated_translationserviceclient_detectlanguage_stringstringstring_sync] +import com.google.cloud.translate.v3beta1.DetectLanguageResponse; +import com.google.cloud.translate.v3beta1.LocationName; +import com.google.cloud.translate.v3beta1.TranslationServiceClient; + +public class SyncDetectLanguageStringStringString { + + public static void main(String[] args) throws Exception { + syncDetectLanguageStringStringString(); + } + + public static void syncDetectLanguageStringStringString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString(); + String model = "model104069929"; + String mimeType = "mimeType-1392120434"; + DetectLanguageResponse response = + translationServiceClient.detectLanguage(parent, model, mimeType); + } + } +} +// [END translation_v3beta1_generated_translationserviceclient_detectlanguage_stringstringstring_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/getglossary/AsyncGetGlossary.java b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/getglossary/AsyncGetGlossary.java new file mode 100644 index 00000000..29e1239a --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/getglossary/AsyncGetGlossary.java @@ -0,0 +1,47 @@ +/* + * 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.translate.v3beta1.samples; + +// [START translation_v3beta1_generated_translationserviceclient_getglossary_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.translate.v3beta1.GetGlossaryRequest; +import com.google.cloud.translate.v3beta1.Glossary; +import com.google.cloud.translate.v3beta1.GlossaryName; +import com.google.cloud.translate.v3beta1.TranslationServiceClient; + +public class AsyncGetGlossary { + + public static void main(String[] args) throws Exception { + asyncGetGlossary(); + } + + public static void asyncGetGlossary() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + GetGlossaryRequest request = + GetGlossaryRequest.newBuilder() + .setName(GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]").toString()) + .build(); + ApiFuture future = + translationServiceClient.getGlossaryCallable().futureCall(request); + // Do something. + Glossary response = future.get(); + } + } +} +// [END translation_v3beta1_generated_translationserviceclient_getglossary_async] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/getglossary/SyncGetGlossary.java b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/getglossary/SyncGetGlossary.java new file mode 100644 index 00000000..ecac547f --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/getglossary/SyncGetGlossary.java @@ -0,0 +1,43 @@ +/* + * 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.translate.v3beta1.samples; + +// [START translation_v3beta1_generated_translationserviceclient_getglossary_sync] +import com.google.cloud.translate.v3beta1.GetGlossaryRequest; +import com.google.cloud.translate.v3beta1.Glossary; +import com.google.cloud.translate.v3beta1.GlossaryName; +import com.google.cloud.translate.v3beta1.TranslationServiceClient; + +public class SyncGetGlossary { + + public static void main(String[] args) throws Exception { + syncGetGlossary(); + } + + public static void syncGetGlossary() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + GetGlossaryRequest request = + GetGlossaryRequest.newBuilder() + .setName(GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]").toString()) + .build(); + Glossary response = translationServiceClient.getGlossary(request); + } + } +} +// [END translation_v3beta1_generated_translationserviceclient_getglossary_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/getglossary/SyncGetGlossaryGlossaryname.java b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/getglossary/SyncGetGlossaryGlossaryname.java new file mode 100644 index 00000000..6cbc8ea7 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/getglossary/SyncGetGlossaryGlossaryname.java @@ -0,0 +1,39 @@ +/* + * 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.translate.v3beta1.samples; + +// [START translation_v3beta1_generated_translationserviceclient_getglossary_glossaryname_sync] +import com.google.cloud.translate.v3beta1.Glossary; +import com.google.cloud.translate.v3beta1.GlossaryName; +import com.google.cloud.translate.v3beta1.TranslationServiceClient; + +public class SyncGetGlossaryGlossaryname { + + public static void main(String[] args) throws Exception { + syncGetGlossaryGlossaryname(); + } + + public static void syncGetGlossaryGlossaryname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + GlossaryName name = GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]"); + Glossary response = translationServiceClient.getGlossary(name); + } + } +} +// [END translation_v3beta1_generated_translationserviceclient_getglossary_glossaryname_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/getglossary/SyncGetGlossaryString.java b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/getglossary/SyncGetGlossaryString.java new file mode 100644 index 00000000..538406f5 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/getglossary/SyncGetGlossaryString.java @@ -0,0 +1,39 @@ +/* + * 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.translate.v3beta1.samples; + +// [START translation_v3beta1_generated_translationserviceclient_getglossary_string_sync] +import com.google.cloud.translate.v3beta1.Glossary; +import com.google.cloud.translate.v3beta1.GlossaryName; +import com.google.cloud.translate.v3beta1.TranslationServiceClient; + +public class SyncGetGlossaryString { + + public static void main(String[] args) throws Exception { + syncGetGlossaryString(); + } + + public static void syncGetGlossaryString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + String name = GlossaryName.of("[PROJECT]", "[LOCATION]", "[GLOSSARY]").toString(); + Glossary response = translationServiceClient.getGlossary(name); + } + } +} +// [END translation_v3beta1_generated_translationserviceclient_getglossary_string_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/getsupportedlanguages/AsyncGetSupportedLanguages.java b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/getsupportedlanguages/AsyncGetSupportedLanguages.java new file mode 100644 index 00000000..bf2c5c8e --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/getsupportedlanguages/AsyncGetSupportedLanguages.java @@ -0,0 +1,49 @@ +/* + * 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.translate.v3beta1.samples; + +// [START translation_v3beta1_generated_translationserviceclient_getsupportedlanguages_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.translate.v3beta1.GetSupportedLanguagesRequest; +import com.google.cloud.translate.v3beta1.LocationName; +import com.google.cloud.translate.v3beta1.SupportedLanguages; +import com.google.cloud.translate.v3beta1.TranslationServiceClient; + +public class AsyncGetSupportedLanguages { + + public static void main(String[] args) throws Exception { + asyncGetSupportedLanguages(); + } + + public static void asyncGetSupportedLanguages() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + GetSupportedLanguagesRequest request = + GetSupportedLanguagesRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setDisplayLanguageCode("displayLanguageCode-1457478841") + .setModel("model104069929") + .build(); + ApiFuture future = + translationServiceClient.getSupportedLanguagesCallable().futureCall(request); + // Do something. + SupportedLanguages response = future.get(); + } + } +} +// [END translation_v3beta1_generated_translationserviceclient_getsupportedlanguages_async] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/getsupportedlanguages/SyncGetSupportedLanguages.java b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/getsupportedlanguages/SyncGetSupportedLanguages.java new file mode 100644 index 00000000..141b90da --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/getsupportedlanguages/SyncGetSupportedLanguages.java @@ -0,0 +1,45 @@ +/* + * 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.translate.v3beta1.samples; + +// [START translation_v3beta1_generated_translationserviceclient_getsupportedlanguages_sync] +import com.google.cloud.translate.v3beta1.GetSupportedLanguagesRequest; +import com.google.cloud.translate.v3beta1.LocationName; +import com.google.cloud.translate.v3beta1.SupportedLanguages; +import com.google.cloud.translate.v3beta1.TranslationServiceClient; + +public class SyncGetSupportedLanguages { + + public static void main(String[] args) throws Exception { + syncGetSupportedLanguages(); + } + + public static void syncGetSupportedLanguages() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + GetSupportedLanguagesRequest request = + GetSupportedLanguagesRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setDisplayLanguageCode("displayLanguageCode-1457478841") + .setModel("model104069929") + .build(); + SupportedLanguages response = translationServiceClient.getSupportedLanguages(request); + } + } +} +// [END translation_v3beta1_generated_translationserviceclient_getsupportedlanguages_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/getsupportedlanguages/SyncGetSupportedLanguagesLocationnameStringString.java b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/getsupportedlanguages/SyncGetSupportedLanguagesLocationnameStringString.java new file mode 100644 index 00000000..81072f27 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/getsupportedlanguages/SyncGetSupportedLanguagesLocationnameStringString.java @@ -0,0 +1,42 @@ +/* + * 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.translate.v3beta1.samples; + +// [START translation_v3beta1_generated_translationserviceclient_getsupportedlanguages_locationnamestringstring_sync] +import com.google.cloud.translate.v3beta1.LocationName; +import com.google.cloud.translate.v3beta1.SupportedLanguages; +import com.google.cloud.translate.v3beta1.TranslationServiceClient; + +public class SyncGetSupportedLanguagesLocationnameStringString { + + public static void main(String[] args) throws Exception { + syncGetSupportedLanguagesLocationnameStringString(); + } + + public static void syncGetSupportedLanguagesLocationnameStringString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + String displayLanguageCode = "displayLanguageCode-1457478841"; + String model = "model104069929"; + SupportedLanguages response = + translationServiceClient.getSupportedLanguages(parent, displayLanguageCode, model); + } + } +} +// [END translation_v3beta1_generated_translationserviceclient_getsupportedlanguages_locationnamestringstring_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/getsupportedlanguages/SyncGetSupportedLanguagesStringStringString.java b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/getsupportedlanguages/SyncGetSupportedLanguagesStringStringString.java new file mode 100644 index 00000000..05a8f673 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/getsupportedlanguages/SyncGetSupportedLanguagesStringStringString.java @@ -0,0 +1,42 @@ +/* + * 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.translate.v3beta1.samples; + +// [START translation_v3beta1_generated_translationserviceclient_getsupportedlanguages_stringstringstring_sync] +import com.google.cloud.translate.v3beta1.LocationName; +import com.google.cloud.translate.v3beta1.SupportedLanguages; +import com.google.cloud.translate.v3beta1.TranslationServiceClient; + +public class SyncGetSupportedLanguagesStringStringString { + + public static void main(String[] args) throws Exception { + syncGetSupportedLanguagesStringStringString(); + } + + public static void syncGetSupportedLanguagesStringStringString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString(); + String displayLanguageCode = "displayLanguageCode-1457478841"; + String model = "model104069929"; + SupportedLanguages response = + translationServiceClient.getSupportedLanguages(parent, displayLanguageCode, model); + } + } +} +// [END translation_v3beta1_generated_translationserviceclient_getsupportedlanguages_stringstringstring_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/listglossaries/AsyncListGlossaries.java b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/listglossaries/AsyncListGlossaries.java new file mode 100644 index 00000000..5937cc68 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/listglossaries/AsyncListGlossaries.java @@ -0,0 +1,52 @@ +/* + * 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.translate.v3beta1.samples; + +// [START translation_v3beta1_generated_translationserviceclient_listglossaries_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.translate.v3beta1.Glossary; +import com.google.cloud.translate.v3beta1.ListGlossariesRequest; +import com.google.cloud.translate.v3beta1.LocationName; +import com.google.cloud.translate.v3beta1.TranslationServiceClient; + +public class AsyncListGlossaries { + + public static void main(String[] args) throws Exception { + asyncListGlossaries(); + } + + public static void asyncListGlossaries() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + ListGlossariesRequest request = + ListGlossariesRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .build(); + ApiFuture future = + translationServiceClient.listGlossariesPagedCallable().futureCall(request); + // Do something. + for (Glossary element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END translation_v3beta1_generated_translationserviceclient_listglossaries_async] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/listglossaries/AsyncListGlossariesPaged.java b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/listglossaries/AsyncListGlossariesPaged.java new file mode 100644 index 00000000..b2f7787c --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/listglossaries/AsyncListGlossariesPaged.java @@ -0,0 +1,60 @@ +/* + * 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.translate.v3beta1.samples; + +// [START translation_v3beta1_generated_translationserviceclient_listglossaries_paged_async] +import com.google.cloud.translate.v3beta1.Glossary; +import com.google.cloud.translate.v3beta1.ListGlossariesRequest; +import com.google.cloud.translate.v3beta1.ListGlossariesResponse; +import com.google.cloud.translate.v3beta1.LocationName; +import com.google.cloud.translate.v3beta1.TranslationServiceClient; +import com.google.common.base.Strings; + +public class AsyncListGlossariesPaged { + + public static void main(String[] args) throws Exception { + asyncListGlossariesPaged(); + } + + public static void asyncListGlossariesPaged() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + ListGlossariesRequest request = + ListGlossariesRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .build(); + while (true) { + ListGlossariesResponse response = + translationServiceClient.listGlossariesCallable().call(request); + for (Glossary element : response.getGlossariesList()) { + // doThingsWith(element); + } + String nextPageToken = response.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + request = request.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END translation_v3beta1_generated_translationserviceclient_listglossaries_paged_async] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/listglossaries/SyncListGlossaries.java b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/listglossaries/SyncListGlossaries.java new file mode 100644 index 00000000..db1f97c4 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/listglossaries/SyncListGlossaries.java @@ -0,0 +1,48 @@ +/* + * 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.translate.v3beta1.samples; + +// [START translation_v3beta1_generated_translationserviceclient_listglossaries_sync] +import com.google.cloud.translate.v3beta1.Glossary; +import com.google.cloud.translate.v3beta1.ListGlossariesRequest; +import com.google.cloud.translate.v3beta1.LocationName; +import com.google.cloud.translate.v3beta1.TranslationServiceClient; + +public class SyncListGlossaries { + + public static void main(String[] args) throws Exception { + syncListGlossaries(); + } + + public static void syncListGlossaries() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + ListGlossariesRequest request = + ListGlossariesRequest.newBuilder() + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .build(); + for (Glossary element : translationServiceClient.listGlossaries(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END translation_v3beta1_generated_translationserviceclient_listglossaries_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/listglossaries/SyncListGlossariesLocationnameString.java b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/listglossaries/SyncListGlossariesLocationnameString.java new file mode 100644 index 00000000..ba70bad7 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/listglossaries/SyncListGlossariesLocationnameString.java @@ -0,0 +1,43 @@ +/* + * 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.translate.v3beta1.samples; + +// [START translation_v3beta1_generated_translationserviceclient_listglossaries_locationnamestring_sync] +import com.google.cloud.translate.v3beta1.Glossary; +import com.google.cloud.translate.v3beta1.LocationName; +import com.google.cloud.translate.v3beta1.TranslationServiceClient; + +public class SyncListGlossariesLocationnameString { + + public static void main(String[] args) throws Exception { + syncListGlossariesLocationnameString(); + } + + public static void syncListGlossariesLocationnameString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + String filter = "filter-1274492040"; + for (Glossary element : + translationServiceClient.listGlossaries(parent, filter).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END translation_v3beta1_generated_translationserviceclient_listglossaries_locationnamestring_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/listglossaries/SyncListGlossariesStringString.java b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/listglossaries/SyncListGlossariesStringString.java new file mode 100644 index 00000000..eef3497f --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/listglossaries/SyncListGlossariesStringString.java @@ -0,0 +1,43 @@ +/* + * 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.translate.v3beta1.samples; + +// [START translation_v3beta1_generated_translationserviceclient_listglossaries_stringstring_sync] +import com.google.cloud.translate.v3beta1.Glossary; +import com.google.cloud.translate.v3beta1.LocationName; +import com.google.cloud.translate.v3beta1.TranslationServiceClient; + +public class SyncListGlossariesStringString { + + public static void main(String[] args) throws Exception { + syncListGlossariesStringString(); + } + + public static void syncListGlossariesStringString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString(); + String filter = "filter-1274492040"; + for (Glossary element : + translationServiceClient.listGlossaries(parent, filter).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END translation_v3beta1_generated_translationserviceclient_listglossaries_stringstring_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/translatedocument/AsyncTranslateDocument.java b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/translatedocument/AsyncTranslateDocument.java new file mode 100644 index 00000000..021abde8 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/translatedocument/AsyncTranslateDocument.java @@ -0,0 +1,57 @@ +/* + * 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.translate.v3beta1.samples; + +// [START translation_v3beta1_generated_translationserviceclient_translatedocument_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.translate.v3beta1.DocumentInputConfig; +import com.google.cloud.translate.v3beta1.DocumentOutputConfig; +import com.google.cloud.translate.v3beta1.TranslateDocumentRequest; +import com.google.cloud.translate.v3beta1.TranslateDocumentResponse; +import com.google.cloud.translate.v3beta1.TranslateTextGlossaryConfig; +import com.google.cloud.translate.v3beta1.TranslationServiceClient; +import java.util.HashMap; + +public class AsyncTranslateDocument { + + public static void main(String[] args) throws Exception { + asyncTranslateDocument(); + } + + public static void asyncTranslateDocument() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + TranslateDocumentRequest request = + TranslateDocumentRequest.newBuilder() + .setParent("parent-995424086") + .setSourceLanguageCode("sourceLanguageCode1645917472") + .setTargetLanguageCode("targetLanguageCode-106414698") + .setDocumentInputConfig(DocumentInputConfig.newBuilder().build()) + .setDocumentOutputConfig(DocumentOutputConfig.newBuilder().build()) + .setModel("model104069929") + .setGlossaryConfig(TranslateTextGlossaryConfig.newBuilder().build()) + .putAllLabels(new HashMap()) + .build(); + ApiFuture future = + translationServiceClient.translateDocumentCallable().futureCall(request); + // Do something. + TranslateDocumentResponse response = future.get(); + } + } +} +// [END translation_v3beta1_generated_translationserviceclient_translatedocument_async] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/translatedocument/SyncTranslateDocument.java b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/translatedocument/SyncTranslateDocument.java new file mode 100644 index 00000000..1451afac --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/translatedocument/SyncTranslateDocument.java @@ -0,0 +1,53 @@ +/* + * 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.translate.v3beta1.samples; + +// [START translation_v3beta1_generated_translationserviceclient_translatedocument_sync] +import com.google.cloud.translate.v3beta1.DocumentInputConfig; +import com.google.cloud.translate.v3beta1.DocumentOutputConfig; +import com.google.cloud.translate.v3beta1.TranslateDocumentRequest; +import com.google.cloud.translate.v3beta1.TranslateDocumentResponse; +import com.google.cloud.translate.v3beta1.TranslateTextGlossaryConfig; +import com.google.cloud.translate.v3beta1.TranslationServiceClient; +import java.util.HashMap; + +public class SyncTranslateDocument { + + public static void main(String[] args) throws Exception { + syncTranslateDocument(); + } + + public static void syncTranslateDocument() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + TranslateDocumentRequest request = + TranslateDocumentRequest.newBuilder() + .setParent("parent-995424086") + .setSourceLanguageCode("sourceLanguageCode1645917472") + .setTargetLanguageCode("targetLanguageCode-106414698") + .setDocumentInputConfig(DocumentInputConfig.newBuilder().build()) + .setDocumentOutputConfig(DocumentOutputConfig.newBuilder().build()) + .setModel("model104069929") + .setGlossaryConfig(TranslateTextGlossaryConfig.newBuilder().build()) + .putAllLabels(new HashMap()) + .build(); + TranslateDocumentResponse response = translationServiceClient.translateDocument(request); + } + } +} +// [END translation_v3beta1_generated_translationserviceclient_translatedocument_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/translatetext/AsyncTranslateText.java b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/translatetext/AsyncTranslateText.java new file mode 100644 index 00000000..c50d3092 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/translatetext/AsyncTranslateText.java @@ -0,0 +1,57 @@ +/* + * 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.translate.v3beta1.samples; + +// [START translation_v3beta1_generated_translationserviceclient_translatetext_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.translate.v3beta1.LocationName; +import com.google.cloud.translate.v3beta1.TranslateTextGlossaryConfig; +import com.google.cloud.translate.v3beta1.TranslateTextRequest; +import com.google.cloud.translate.v3beta1.TranslateTextResponse; +import com.google.cloud.translate.v3beta1.TranslationServiceClient; +import java.util.ArrayList; +import java.util.HashMap; + +public class AsyncTranslateText { + + public static void main(String[] args) throws Exception { + asyncTranslateText(); + } + + public static void asyncTranslateText() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + TranslateTextRequest request = + TranslateTextRequest.newBuilder() + .addAllContents(new ArrayList()) + .setMimeType("mimeType-1392120434") + .setSourceLanguageCode("sourceLanguageCode1645917472") + .setTargetLanguageCode("targetLanguageCode-106414698") + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setModel("model104069929") + .setGlossaryConfig(TranslateTextGlossaryConfig.newBuilder().build()) + .putAllLabels(new HashMap()) + .build(); + ApiFuture future = + translationServiceClient.translateTextCallable().futureCall(request); + // Do something. + TranslateTextResponse response = future.get(); + } + } +} +// [END translation_v3beta1_generated_translationserviceclient_translatetext_async] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/translatetext/SyncTranslateText.java b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/translatetext/SyncTranslateText.java new file mode 100644 index 00000000..e9c2ce87 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationserviceclient/translatetext/SyncTranslateText.java @@ -0,0 +1,53 @@ +/* + * 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.translate.v3beta1.samples; + +// [START translation_v3beta1_generated_translationserviceclient_translatetext_sync] +import com.google.cloud.translate.v3beta1.LocationName; +import com.google.cloud.translate.v3beta1.TranslateTextGlossaryConfig; +import com.google.cloud.translate.v3beta1.TranslateTextRequest; +import com.google.cloud.translate.v3beta1.TranslateTextResponse; +import com.google.cloud.translate.v3beta1.TranslationServiceClient; +import java.util.ArrayList; +import java.util.HashMap; + +public class SyncTranslateText { + + public static void main(String[] args) throws Exception { + syncTranslateText(); + } + + public static void syncTranslateText() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) { + TranslateTextRequest request = + TranslateTextRequest.newBuilder() + .addAllContents(new ArrayList()) + .setMimeType("mimeType-1392120434") + .setSourceLanguageCode("sourceLanguageCode1645917472") + .setTargetLanguageCode("targetLanguageCode-106414698") + .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) + .setModel("model104069929") + .setGlossaryConfig(TranslateTextGlossaryConfig.newBuilder().build()) + .putAllLabels(new HashMap()) + .build(); + TranslateTextResponse response = translationServiceClient.translateText(request); + } + } +} +// [END translation_v3beta1_generated_translationserviceclient_translatetext_sync] diff --git a/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationservicesettings/translatetext/SyncTranslateText.java b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationservicesettings/translatetext/SyncTranslateText.java new file mode 100644 index 00000000..3d570006 --- /dev/null +++ b/samples/snippets/generated/com/google/cloud/translate/v3beta1/translationservicesettings/translatetext/SyncTranslateText.java @@ -0,0 +1,47 @@ +/* + * 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.translate.v3beta1.samples; + +// [START translation_v3beta1_generated_translationservicesettings_translatetext_sync] +import com.google.cloud.translate.v3beta1.TranslationServiceSettings; +import java.time.Duration; + +public class SyncTranslateText { + + public static void main(String[] args) throws Exception { + syncTranslateText(); + } + + public static void syncTranslateText() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + TranslationServiceSettings.Builder translationServiceSettingsBuilder = + TranslationServiceSettings.newBuilder(); + translationServiceSettingsBuilder + .translateTextSettings() + .setRetrySettings( + translationServiceSettingsBuilder + .translateTextSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + TranslationServiceSettings translationServiceSettings = + translationServiceSettingsBuilder.build(); + } +} +// [END translation_v3beta1_generated_translationservicesettings_translatetext_sync] diff --git a/samples/snippets/pom.xml b/samples/snippets/pom.xml index 0c0feed1..4bbb5416 100644 --- a/samples/snippets/pom.xml +++ b/samples/snippets/pom.xml @@ -30,7 +30,7 @@ com.google.cloud libraries-bom - 25.3.0 + 25.4.0 pom import @@ -62,7 +62,7 @@ com.google.cloud google-cloud-core - 2.6.1 + 2.8.1 test tests diff --git a/versions.txt b/versions.txt index 7ee9bd14..167c5705 100644 --- a/versions.txt +++ b/versions.txt @@ -1,8 +1,8 @@ # Format: # module:released-version:current-version -google-cloud-translate:2.2.0:2.2.0 -grpc-google-cloud-translate-v3beta1:0.84.0:0.84.0 -grpc-google-cloud-translate-v3:2.2.0:2.2.0 -proto-google-cloud-translate-v3beta1:0.84.0:0.84.0 -proto-google-cloud-translate-v3:2.2.0:2.2.0 +google-cloud-translate:2.3.0:2.3.0 +grpc-google-cloud-translate-v3beta1:0.85.0:0.85.0 +grpc-google-cloud-translate-v3:2.3.0:2.3.0 +proto-google-cloud-translate-v3beta1:0.85.0:0.85.0 +proto-google-cloud-translate-v3:2.3.0:2.3.0