diff --git a/java-recommendations-ai/google-cloud-recommendations-ai/pom.xml b/java-recommendations-ai/google-cloud-recommendations-ai/pom.xml index 7779b16b97db..ec214ead806a 100644 --- a/java-recommendations-ai/google-cloud-recommendations-ai/pom.xml +++ b/java-recommendations-ai/google-cloud-recommendations-ai/pom.xml @@ -58,6 +58,10 @@ com.google.api gax-grpc + + com.google.api + gax-httpjson + org.threeten threetenbp @@ -76,12 +80,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/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/CatalogServiceClient.java b/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/CatalogServiceClient.java index 4eaf88a7e07d..5ca969779da5 100644 --- a/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/CatalogServiceClient.java +++ b/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/CatalogServiceClient.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.recommendationengine.v1beta1.stub.CatalogServiceStubSettings; import com.google.common.util.concurrent.MoreExecutors; import com.google.longrunning.Operation; -import com.google.longrunning.OperationsClient; import com.google.protobuf.Empty; import com.google.protobuf.FieldMask; import java.io.IOException; @@ -104,6 +104,20 @@ * CatalogServiceClient catalogServiceClient = CatalogServiceClient.create(catalogServiceSettings); * } * + *

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.
+ * CatalogServiceSettings catalogServiceSettings =
+ *     CatalogServiceSettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             CatalogServiceSettings.defaultHttpJsonTransportProviderBuilder().build())
+ *         .build();
+ * CatalogServiceClient catalogServiceClient = CatalogServiceClient.create(catalogServiceSettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @BetaApi @@ -111,7 +125,8 @@ public class CatalogServiceClient implements BackgroundResource { private final CatalogServiceSettings settings; private final CatalogServiceStub stub; - private final OperationsClient operationsClient; + private final OperationsClient httpJsonOperationsClient; + private final com.google.longrunning.OperationsClient operationsClient; /** Constructs an instance of CatalogServiceClient with default settings. */ public static final CatalogServiceClient create() throws IOException { @@ -143,13 +158,17 @@ public static final CatalogServiceClient create(CatalogServiceStub stub) { protected CatalogServiceClient(CatalogServiceSettings settings) throws IOException { this.settings = settings; this.stub = ((CatalogServiceStubSettings) 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()); } protected CatalogServiceClient(CatalogServiceStub 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 CatalogServiceSettings getSettings() { @@ -164,10 +183,18 @@ public CatalogServiceStub 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. + */ + public final OperationsClient getHttpJsonOperationsClient() { + return httpJsonOperationsClient; + } + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** * Creates a catalog item. diff --git a/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/CatalogServiceSettings.java b/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/CatalogServiceSettings.java index 899c591f8180..22f31b84c882 100644 --- a/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/CatalogServiceSettings.java +++ b/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/CatalogServiceSettings.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; @@ -140,11 +141,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return CatalogServiceStubSettings.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 CatalogServiceStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return CatalogServiceStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return CatalogServiceStubSettings.defaultTransportChannelProvider(); } @@ -154,11 +162,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return CatalogServiceStubSettings.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); @@ -196,6 +210,11 @@ private static Builder createDefault() { return new Builder(CatalogServiceStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(CatalogServiceStubSettings.newHttpJsonBuilder()); + } + public CatalogServiceStubSettings.Builder getStubSettingsBuilder() { return ((CatalogServiceStubSettings.Builder) getStubSettings()); } diff --git a/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/PredictionApiKeyRegistryClient.java b/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/PredictionApiKeyRegistryClient.java index faad742249c4..ce1a01b14113 100644 --- a/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/PredictionApiKeyRegistryClient.java +++ b/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/PredictionApiKeyRegistryClient.java @@ -110,6 +110,21 @@ * PredictionApiKeyRegistryClient.create(predictionApiKeyRegistrySettings); * } * + *

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.
+ * PredictionApiKeyRegistrySettings predictionApiKeyRegistrySettings =
+ *     PredictionApiKeyRegistrySettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             PredictionApiKeyRegistrySettings.defaultHttpJsonTransportProviderBuilder().build())
+ *         .build();
+ * PredictionApiKeyRegistryClient predictionApiKeyRegistryClient =
+ *     PredictionApiKeyRegistryClient.create(predictionApiKeyRegistrySettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @BetaApi diff --git a/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/PredictionApiKeyRegistrySettings.java b/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/PredictionApiKeyRegistrySettings.java index a0fd2fd5b714..568cb6fa2aa3 100644 --- a/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/PredictionApiKeyRegistrySettings.java +++ b/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/PredictionApiKeyRegistrySettings.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; @@ -125,11 +126,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return PredictionApiKeyRegistryStubSettings.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 PredictionApiKeyRegistryStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return PredictionApiKeyRegistryStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return PredictionApiKeyRegistryStubSettings.defaultTransportChannelProvider(); } @@ -139,11 +147,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return PredictionApiKeyRegistryStubSettings.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); @@ -182,6 +196,11 @@ private static Builder createDefault() { return new Builder(PredictionApiKeyRegistryStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(PredictionApiKeyRegistryStubSettings.newHttpJsonBuilder()); + } + public PredictionApiKeyRegistryStubSettings.Builder getStubSettingsBuilder() { return ((PredictionApiKeyRegistryStubSettings.Builder) getStubSettings()); } diff --git a/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/PredictionServiceClient.java b/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/PredictionServiceClient.java index 1c96522749ca..b171c8e2a900 100644 --- a/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/PredictionServiceClient.java +++ b/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/PredictionServiceClient.java @@ -107,6 +107,21 @@ * PredictionServiceClient.create(predictionServiceSettings); * } * + *

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.
+ * PredictionServiceSettings predictionServiceSettings =
+ *     PredictionServiceSettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             PredictionServiceSettings.defaultHttpJsonTransportProviderBuilder().build())
+ *         .build();
+ * PredictionServiceClient predictionServiceClient =
+ *     PredictionServiceClient.create(predictionServiceSettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @BetaApi diff --git a/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/PredictionServiceSettings.java b/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/PredictionServiceSettings.java index b44638738e31..069b74afc4c7 100644 --- a/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/PredictionServiceSettings.java +++ b/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/PredictionServiceSettings.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; @@ -104,11 +105,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return PredictionServiceStubSettings.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 PredictionServiceStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return PredictionServiceStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return PredictionServiceStubSettings.defaultTransportChannelProvider(); } @@ -118,11 +126,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return PredictionServiceStubSettings.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); @@ -160,6 +174,11 @@ private static Builder createDefault() { return new Builder(PredictionServiceStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(PredictionServiceStubSettings.newHttpJsonBuilder()); + } + public PredictionServiceStubSettings.Builder getStubSettingsBuilder() { return ((PredictionServiceStubSettings.Builder) getStubSettings()); } diff --git a/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/UserEventServiceClient.java b/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/UserEventServiceClient.java index f642ed3285ef..525a2f58236a 100644 --- a/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/UserEventServiceClient.java +++ b/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/UserEventServiceClient.java @@ -21,6 +21,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; @@ -32,7 +33,6 @@ import com.google.cloud.recommendationengine.v1beta1.stub.UserEventServiceStubSettings; 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,6 +107,21 @@ * UserEventServiceClient.create(userEventServiceSettings); * } * + *

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.
+ * UserEventServiceSettings userEventServiceSettings =
+ *     UserEventServiceSettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             UserEventServiceSettings.defaultHttpJsonTransportProviderBuilder().build())
+ *         .build();
+ * UserEventServiceClient userEventServiceClient =
+ *     UserEventServiceClient.create(userEventServiceSettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @BetaApi @@ -114,7 +129,8 @@ public class UserEventServiceClient implements BackgroundResource { private final UserEventServiceSettings settings; private final UserEventServiceStub stub; - private final OperationsClient operationsClient; + private final OperationsClient httpJsonOperationsClient; + private final com.google.longrunning.OperationsClient operationsClient; /** Constructs an instance of UserEventServiceClient with default settings. */ public static final UserEventServiceClient create() throws IOException { @@ -146,13 +162,17 @@ public static final UserEventServiceClient create(UserEventServiceStub stub) { protected UserEventServiceClient(UserEventServiceSettings settings) throws IOException { this.settings = settings; this.stub = ((UserEventServiceStubSettings) 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()); } protected UserEventServiceClient(UserEventServiceStub 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 UserEventServiceSettings getSettings() { @@ -167,10 +187,18 @@ public UserEventServiceStub 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. + */ + public final OperationsClient getHttpJsonOperationsClient() { + return httpJsonOperationsClient; + } + // AUTO-GENERATED DOCUMENTATION AND METHOD. /** * Writes a single user event. diff --git a/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/UserEventServiceSettings.java b/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/UserEventServiceSettings.java index 3c727fe03372..7a7787fdc083 100644 --- a/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/UserEventServiceSettings.java +++ b/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/UserEventServiceSettings.java @@ -24,6 +24,7 @@ import com.google.api.gax.core.GoogleCredentialsProvider; import com.google.api.gax.core.InstantiatingExecutorProvider; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; import com.google.api.gax.rpc.ApiClientHeaderProvider; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.ClientSettings; @@ -141,11 +142,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return UserEventServiceStubSettings.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 UserEventServiceStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return UserEventServiceStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return UserEventServiceStubSettings.defaultTransportChannelProvider(); } @@ -155,11 +163,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return UserEventServiceStubSettings.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); @@ -197,6 +211,11 @@ private static Builder createDefault() { return new Builder(UserEventServiceStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(UserEventServiceStubSettings.newHttpJsonBuilder()); + } + public UserEventServiceStubSettings.Builder getStubSettingsBuilder() { return ((UserEventServiceStubSettings.Builder) getStubSettings()); } diff --git a/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/stub/CatalogServiceStub.java b/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/stub/CatalogServiceStub.java index 97ab5aff6e12..8fdd08d7bddf 100644 --- a/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/stub/CatalogServiceStub.java +++ b/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/stub/CatalogServiceStub.java @@ -48,7 +48,11 @@ public abstract class CatalogServiceStub 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 createCatalogItemCallable() { diff --git a/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/stub/CatalogServiceStubSettings.java b/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/stub/CatalogServiceStubSettings.java index 2e81eb72dd8c..460ed0a3d82d 100644 --- a/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/stub/CatalogServiceStubSettings.java +++ b/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/stub/CatalogServiceStubSettings.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; @@ -223,6 +226,11 @@ public CatalogServiceStub createStub() throws IOException { .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcCatalogServiceStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonCatalogServiceStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -255,18 +263,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(CatalogServiceStubSettings.class)) @@ -274,11 +289,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(CatalogServiceStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return CatalogServiceStubSettings.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); @@ -415,6 +449,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 .createCatalogItemSettings() diff --git a/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/stub/HttpJsonCatalogServiceCallableFactory.java b/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/stub/HttpJsonCatalogServiceCallableFactory.java new file mode 100644 index 000000000000..2e9ef4618489 --- /dev/null +++ b/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/stub/HttpJsonCatalogServiceCallableFactory.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.recommendationengine.v1beta1.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 CatalogService service API. + * + *

This class is for advanced usage. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonCatalogServiceCallableFactory + 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/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/stub/HttpJsonCatalogServiceStub.java b/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/stub/HttpJsonCatalogServiceStub.java new file mode 100644 index 000000000000..2062005d917f --- /dev/null +++ b/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/stub/HttpJsonCatalogServiceStub.java @@ -0,0 +1,516 @@ +/* + * 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.recommendationengine.v1beta1.stub; + +import static com.google.cloud.recommendationengine.v1beta1.CatalogServiceClient.ListCatalogItemsPagedResponse; + +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.recommendationengine.v1beta1.CatalogItem; +import com.google.cloud.recommendationengine.v1beta1.CreateCatalogItemRequest; +import com.google.cloud.recommendationengine.v1beta1.DeleteCatalogItemRequest; +import com.google.cloud.recommendationengine.v1beta1.GetCatalogItemRequest; +import com.google.cloud.recommendationengine.v1beta1.ImportCatalogItemsRequest; +import com.google.cloud.recommendationengine.v1beta1.ImportCatalogItemsResponse; +import com.google.cloud.recommendationengine.v1beta1.ImportMetadata; +import com.google.cloud.recommendationengine.v1beta1.ListCatalogItemsRequest; +import com.google.cloud.recommendationengine.v1beta1.ListCatalogItemsResponse; +import com.google.cloud.recommendationengine.v1beta1.UpdateCatalogItemRequest; +import com.google.longrunning.Operation; +import com.google.protobuf.Empty; +import com.google.protobuf.TypeRegistry; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST stub implementation for the CatalogService service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonCatalogServiceStub extends CatalogServiceStub { + private static final TypeRegistry typeRegistry = + TypeRegistry.newBuilder() + .add(ImportCatalogItemsResponse.getDescriptor()) + .add(ImportMetadata.getDescriptor()) + .build(); + + private static final ApiMethodDescriptor + createCatalogItemMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.recommendationengine.v1beta1.CatalogService/CreateCatalogItem") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{parent=projects/*/locations/*/catalogs/*}/catalogItems", + 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("catalogItem", request.getCatalogItem())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(CatalogItem.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + getCatalogItemMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.recommendationengine.v1beta1.CatalogService/GetCatalogItem") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{name=projects/*/locations/*/catalogs/*/catalogItems/**}", + 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(CatalogItem.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + listCatalogItemsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.recommendationengine.v1beta1.CatalogService/ListCatalogItems") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{parent=projects/*/locations/*/catalogs/*}/catalogItems", + 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(ListCatalogItemsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + updateCatalogItemMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.recommendationengine.v1beta1.CatalogService/UpdateCatalogItem") + .setHttpMethod("PATCH") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{name=projects/*/locations/*/catalogs/*/catalogItems/**}", + 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(); + serializer.putQueryParam(fields, "updateMask", request.getUpdateMask()); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("catalogItem", request.getCatalogItem())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(CatalogItem.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + deleteCatalogItemMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.recommendationengine.v1beta1.CatalogService/DeleteCatalogItem") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{name=projects/*/locations/*/catalogs/*/catalogItems/**}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Empty.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + importCatalogItemsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.recommendationengine.v1beta1.CatalogService/ImportCatalogItems") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{parent=projects/*/locations/*/catalogs/*}/catalogItems:import", + 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( + (ImportCatalogItemsRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private final UnaryCallable createCatalogItemCallable; + private final UnaryCallable getCatalogItemCallable; + private final UnaryCallable + listCatalogItemsCallable; + private final UnaryCallable + listCatalogItemsPagedCallable; + private final UnaryCallable updateCatalogItemCallable; + private final UnaryCallable deleteCatalogItemCallable; + private final UnaryCallable importCatalogItemsCallable; + private final OperationCallable< + ImportCatalogItemsRequest, ImportCatalogItemsResponse, ImportMetadata> + importCatalogItemsOperationCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonOperationsStub httpJsonOperationsStub; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonCatalogServiceStub create(CatalogServiceStubSettings settings) + throws IOException { + return new HttpJsonCatalogServiceStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonCatalogServiceStub create(ClientContext clientContext) + throws IOException { + return new HttpJsonCatalogServiceStub( + CatalogServiceStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonCatalogServiceStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonCatalogServiceStub( + CatalogServiceStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of HttpJsonCatalogServiceStub, 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 HttpJsonCatalogServiceStub( + CatalogServiceStubSettings settings, ClientContext clientContext) throws IOException { + this(settings, clientContext, new HttpJsonCatalogServiceCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonCatalogServiceStub, 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 HttpJsonCatalogServiceStub( + CatalogServiceStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.httpJsonOperationsStub = + HttpJsonOperationsStub.create(clientContext, callableFactory, typeRegistry); + + HttpJsonCallSettings createCatalogItemTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(createCatalogItemMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings getCatalogItemTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(getCatalogItemMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + listCatalogItemsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listCatalogItemsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings updateCatalogItemTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(updateCatalogItemMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings deleteCatalogItemTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deleteCatalogItemMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings importCatalogItemsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(importCatalogItemsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.createCatalogItemCallable = + callableFactory.createUnaryCallable( + createCatalogItemTransportSettings, + settings.createCatalogItemSettings(), + clientContext); + this.getCatalogItemCallable = + callableFactory.createUnaryCallable( + getCatalogItemTransportSettings, settings.getCatalogItemSettings(), clientContext); + this.listCatalogItemsCallable = + callableFactory.createUnaryCallable( + listCatalogItemsTransportSettings, settings.listCatalogItemsSettings(), clientContext); + this.listCatalogItemsPagedCallable = + callableFactory.createPagedCallable( + listCatalogItemsTransportSettings, settings.listCatalogItemsSettings(), clientContext); + this.updateCatalogItemCallable = + callableFactory.createUnaryCallable( + updateCatalogItemTransportSettings, + settings.updateCatalogItemSettings(), + clientContext); + this.deleteCatalogItemCallable = + callableFactory.createUnaryCallable( + deleteCatalogItemTransportSettings, + settings.deleteCatalogItemSettings(), + clientContext); + this.importCatalogItemsCallable = + callableFactory.createUnaryCallable( + importCatalogItemsTransportSettings, + settings.importCatalogItemsSettings(), + clientContext); + this.importCatalogItemsOperationCallable = + callableFactory.createOperationCallable( + importCatalogItemsTransportSettings, + settings.importCatalogItemsOperationSettings(), + clientContext, + httpJsonOperationsStub); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(createCatalogItemMethodDescriptor); + methodDescriptors.add(getCatalogItemMethodDescriptor); + methodDescriptors.add(listCatalogItemsMethodDescriptor); + methodDescriptors.add(updateCatalogItemMethodDescriptor); + methodDescriptors.add(deleteCatalogItemMethodDescriptor); + methodDescriptors.add(importCatalogItemsMethodDescriptor); + return methodDescriptors; + } + + public HttpJsonOperationsStub getHttpJsonOperationsStub() { + return httpJsonOperationsStub; + } + + @Override + public UnaryCallable createCatalogItemCallable() { + return createCatalogItemCallable; + } + + @Override + public UnaryCallable getCatalogItemCallable() { + return getCatalogItemCallable; + } + + @Override + public UnaryCallable + listCatalogItemsCallable() { + return listCatalogItemsCallable; + } + + @Override + public UnaryCallable + listCatalogItemsPagedCallable() { + return listCatalogItemsPagedCallable; + } + + @Override + public UnaryCallable updateCatalogItemCallable() { + return updateCatalogItemCallable; + } + + @Override + public UnaryCallable deleteCatalogItemCallable() { + return deleteCatalogItemCallable; + } + + @Override + public UnaryCallable importCatalogItemsCallable() { + return importCatalogItemsCallable; + } + + @Override + public OperationCallable + importCatalogItemsOperationCallable() { + return importCatalogItemsOperationCallable; + } + + @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/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/stub/HttpJsonPredictionApiKeyRegistryCallableFactory.java b/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/stub/HttpJsonPredictionApiKeyRegistryCallableFactory.java new file mode 100644 index 000000000000..0517effb8235 --- /dev/null +++ b/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/stub/HttpJsonPredictionApiKeyRegistryCallableFactory.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.recommendationengine.v1beta1.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 PredictionApiKeyRegistry service API. + * + *

This class is for advanced usage. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonPredictionApiKeyRegistryCallableFactory + 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/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/stub/HttpJsonPredictionApiKeyRegistryStub.java b/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/stub/HttpJsonPredictionApiKeyRegistryStub.java new file mode 100644 index 000000000000..f412c6c4936d --- /dev/null +++ b/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/stub/HttpJsonPredictionApiKeyRegistryStub.java @@ -0,0 +1,352 @@ +/* + * 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.recommendationengine.v1beta1.stub; + +import static com.google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistryClient.ListPredictionApiKeyRegistrationsPagedResponse; + +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.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.rpc.ClientContext; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.recommendationengine.v1beta1.CreatePredictionApiKeyRegistrationRequest; +import com.google.cloud.recommendationengine.v1beta1.DeletePredictionApiKeyRegistrationRequest; +import com.google.cloud.recommendationengine.v1beta1.ListPredictionApiKeyRegistrationsRequest; +import com.google.cloud.recommendationengine.v1beta1.ListPredictionApiKeyRegistrationsResponse; +import com.google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistration; +import com.google.protobuf.Empty; +import com.google.protobuf.TypeRegistry; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST stub implementation for the PredictionApiKeyRegistry service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonPredictionApiKeyRegistryStub extends PredictionApiKeyRegistryStub { + private static final TypeRegistry typeRegistry = TypeRegistry.newBuilder().build(); + + private static final ApiMethodDescriptor< + CreatePredictionApiKeyRegistrationRequest, PredictionApiKeyRegistration> + createPredictionApiKeyRegistrationMethodDescriptor = + ApiMethodDescriptor + .newBuilder() + .setFullMethodName( + "google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistry/CreatePredictionApiKeyRegistration") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter + .newBuilder() + .setPath( + "/v1beta1/{parent=projects/*/locations/*/catalogs/*/eventStores/*}/predictionApiKeyRegistrations", + 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(PredictionApiKeyRegistration.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor< + ListPredictionApiKeyRegistrationsRequest, ListPredictionApiKeyRegistrationsResponse> + listPredictionApiKeyRegistrationsMethodDescriptor = + ApiMethodDescriptor + . + newBuilder() + .setFullMethodName( + "google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistry/ListPredictionApiKeyRegistrations") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter + .newBuilder() + .setPath( + "/v1beta1/{parent=projects/*/locations/*/catalogs/*/eventStores/*}/predictionApiKeyRegistrations", + 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, "pageSize", request.getPageSize()); + serializer.putQueryParam(fields, "pageToken", request.getPageToken()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance( + ListPredictionApiKeyRegistrationsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + deletePredictionApiKeyRegistrationMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistry/DeletePredictionApiKeyRegistration") + .setHttpMethod("DELETE") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter + .newBuilder() + .setPath( + "/v1beta1/{name=projects/*/locations/*/catalogs/*/eventStores/*/predictionApiKeyRegistrations/*}", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer + serializer = ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer + serializer = ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(Empty.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private final UnaryCallable< + CreatePredictionApiKeyRegistrationRequest, PredictionApiKeyRegistration> + createPredictionApiKeyRegistrationCallable; + private final UnaryCallable< + ListPredictionApiKeyRegistrationsRequest, ListPredictionApiKeyRegistrationsResponse> + listPredictionApiKeyRegistrationsCallable; + private final UnaryCallable< + ListPredictionApiKeyRegistrationsRequest, ListPredictionApiKeyRegistrationsPagedResponse> + listPredictionApiKeyRegistrationsPagedCallable; + private final UnaryCallable + deletePredictionApiKeyRegistrationCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonPredictionApiKeyRegistryStub create( + PredictionApiKeyRegistryStubSettings settings) throws IOException { + return new HttpJsonPredictionApiKeyRegistryStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonPredictionApiKeyRegistryStub create(ClientContext clientContext) + throws IOException { + return new HttpJsonPredictionApiKeyRegistryStub( + PredictionApiKeyRegistryStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonPredictionApiKeyRegistryStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonPredictionApiKeyRegistryStub( + PredictionApiKeyRegistryStubSettings.newHttpJsonBuilder().build(), + clientContext, + callableFactory); + } + + /** + * Constructs an instance of HttpJsonPredictionApiKeyRegistryStub, 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 HttpJsonPredictionApiKeyRegistryStub( + PredictionApiKeyRegistryStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new HttpJsonPredictionApiKeyRegistryCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonPredictionApiKeyRegistryStub, 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 HttpJsonPredictionApiKeyRegistryStub( + PredictionApiKeyRegistryStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + + HttpJsonCallSettings + createPredictionApiKeyRegistrationTransportSettings = + HttpJsonCallSettings + . + newBuilder() + .setMethodDescriptor(createPredictionApiKeyRegistrationMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings< + ListPredictionApiKeyRegistrationsRequest, ListPredictionApiKeyRegistrationsResponse> + listPredictionApiKeyRegistrationsTransportSettings = + HttpJsonCallSettings + . + newBuilder() + .setMethodDescriptor(listPredictionApiKeyRegistrationsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + deletePredictionApiKeyRegistrationTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(deletePredictionApiKeyRegistrationMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.createPredictionApiKeyRegistrationCallable = + callableFactory.createUnaryCallable( + createPredictionApiKeyRegistrationTransportSettings, + settings.createPredictionApiKeyRegistrationSettings(), + clientContext); + this.listPredictionApiKeyRegistrationsCallable = + callableFactory.createUnaryCallable( + listPredictionApiKeyRegistrationsTransportSettings, + settings.listPredictionApiKeyRegistrationsSettings(), + clientContext); + this.listPredictionApiKeyRegistrationsPagedCallable = + callableFactory.createPagedCallable( + listPredictionApiKeyRegistrationsTransportSettings, + settings.listPredictionApiKeyRegistrationsSettings(), + clientContext); + this.deletePredictionApiKeyRegistrationCallable = + callableFactory.createUnaryCallable( + deletePredictionApiKeyRegistrationTransportSettings, + settings.deletePredictionApiKeyRegistrationSettings(), + clientContext); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(createPredictionApiKeyRegistrationMethodDescriptor); + methodDescriptors.add(listPredictionApiKeyRegistrationsMethodDescriptor); + methodDescriptors.add(deletePredictionApiKeyRegistrationMethodDescriptor); + return methodDescriptors; + } + + @Override + public UnaryCallable + createPredictionApiKeyRegistrationCallable() { + return createPredictionApiKeyRegistrationCallable; + } + + @Override + public UnaryCallable< + ListPredictionApiKeyRegistrationsRequest, ListPredictionApiKeyRegistrationsResponse> + listPredictionApiKeyRegistrationsCallable() { + return listPredictionApiKeyRegistrationsCallable; + } + + @Override + public UnaryCallable< + ListPredictionApiKeyRegistrationsRequest, ListPredictionApiKeyRegistrationsPagedResponse> + listPredictionApiKeyRegistrationsPagedCallable() { + return listPredictionApiKeyRegistrationsPagedCallable; + } + + @Override + public UnaryCallable + deletePredictionApiKeyRegistrationCallable() { + return deletePredictionApiKeyRegistrationCallable; + } + + @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/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/stub/HttpJsonPredictionServiceCallableFactory.java b/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/stub/HttpJsonPredictionServiceCallableFactory.java new file mode 100644 index 000000000000..fd7da10ddb80 --- /dev/null +++ b/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/stub/HttpJsonPredictionServiceCallableFactory.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.recommendationengine.v1beta1.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 PredictionService service API. + * + *

This class is for advanced usage. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonPredictionServiceCallableFactory + 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/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/stub/HttpJsonPredictionServiceStub.java b/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/stub/HttpJsonPredictionServiceStub.java new file mode 100644 index 000000000000..503f4b519321 --- /dev/null +++ b/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/stub/HttpJsonPredictionServiceStub.java @@ -0,0 +1,206 @@ +/* + * 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.recommendationengine.v1beta1.stub; + +import static com.google.cloud.recommendationengine.v1beta1.PredictionServiceClient.PredictPagedResponse; + +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.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.rpc.ClientContext; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.recommendationengine.v1beta1.PredictRequest; +import com.google.cloud.recommendationengine.v1beta1.PredictResponse; +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 PredictionService service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonPredictionServiceStub extends PredictionServiceStub { + private static final TypeRegistry typeRegistry = TypeRegistry.newBuilder().build(); + + private static final ApiMethodDescriptor + predictMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.recommendationengine.v1beta1.PredictionService/Predict") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{name=projects/*/locations/*/catalogs/*/eventStores/*/placements/*}:predict", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "name", request.getName()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearName().build())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(PredictResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private final UnaryCallable predictCallable; + private final UnaryCallable predictPagedCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonPredictionServiceStub create(PredictionServiceStubSettings settings) + throws IOException { + return new HttpJsonPredictionServiceStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonPredictionServiceStub create(ClientContext clientContext) + throws IOException { + return new HttpJsonPredictionServiceStub( + PredictionServiceStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonPredictionServiceStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonPredictionServiceStub( + PredictionServiceStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of HttpJsonPredictionServiceStub, 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 HttpJsonPredictionServiceStub( + PredictionServiceStubSettings settings, ClientContext clientContext) throws IOException { + this(settings, clientContext, new HttpJsonPredictionServiceCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonPredictionServiceStub, 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 HttpJsonPredictionServiceStub( + PredictionServiceStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + + HttpJsonCallSettings predictTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(predictMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.predictCallable = + callableFactory.createUnaryCallable( + predictTransportSettings, settings.predictSettings(), clientContext); + this.predictPagedCallable = + callableFactory.createPagedCallable( + predictTransportSettings, settings.predictSettings(), clientContext); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(predictMethodDescriptor); + return methodDescriptors; + } + + @Override + public UnaryCallable predictCallable() { + return predictCallable; + } + + @Override + public UnaryCallable predictPagedCallable() { + return predictPagedCallable; + } + + @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/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/stub/HttpJsonUserEventServiceCallableFactory.java b/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/stub/HttpJsonUserEventServiceCallableFactory.java new file mode 100644 index 000000000000..310e107bcf53 --- /dev/null +++ b/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/stub/HttpJsonUserEventServiceCallableFactory.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.recommendationengine.v1beta1.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 UserEventService service API. + * + *

This class is for advanced usage. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonUserEventServiceCallableFactory + 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/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/stub/HttpJsonUserEventServiceStub.java b/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/stub/HttpJsonUserEventServiceStub.java new file mode 100644 index 000000000000..e29d203045f6 --- /dev/null +++ b/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/stub/HttpJsonUserEventServiceStub.java @@ -0,0 +1,479 @@ +/* + * 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.recommendationengine.v1beta1.stub; + +import static com.google.cloud.recommendationengine.v1beta1.UserEventServiceClient.ListUserEventsPagedResponse; + +import com.google.api.HttpBody; +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.recommendationengine.v1beta1.CollectUserEventRequest; +import com.google.cloud.recommendationengine.v1beta1.ImportMetadata; +import com.google.cloud.recommendationengine.v1beta1.ImportUserEventsRequest; +import com.google.cloud.recommendationengine.v1beta1.ImportUserEventsResponse; +import com.google.cloud.recommendationengine.v1beta1.ListUserEventsRequest; +import com.google.cloud.recommendationengine.v1beta1.ListUserEventsResponse; +import com.google.cloud.recommendationengine.v1beta1.PurgeUserEventsMetadata; +import com.google.cloud.recommendationengine.v1beta1.PurgeUserEventsRequest; +import com.google.cloud.recommendationengine.v1beta1.PurgeUserEventsResponse; +import com.google.cloud.recommendationengine.v1beta1.UserEvent; +import com.google.cloud.recommendationengine.v1beta1.WriteUserEventRequest; +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 UserEventService service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonUserEventServiceStub extends UserEventServiceStub { + private static final TypeRegistry typeRegistry = + TypeRegistry.newBuilder() + .add(PurgeUserEventsMetadata.getDescriptor()) + .add(PurgeUserEventsResponse.getDescriptor()) + .add(ImportUserEventsResponse.getDescriptor()) + .add(ImportMetadata.getDescriptor()) + .build(); + + private static final ApiMethodDescriptor + writeUserEventMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.recommendationengine.v1beta1.UserEventService/WriteUserEvent") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{parent=projects/*/locations/*/catalogs/*/eventStores/*}/userEvents:write", + 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("userEvent", request.getUserEvent())) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(UserEvent.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + collectUserEventMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.recommendationengine.v1beta1.UserEventService/CollectUserEvent") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{parent=projects/*/locations/*/catalogs/*/eventStores/*}/userEvents:collect", + 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, "ets", request.getEts()); + serializer.putQueryParam(fields, "uri", request.getUri()); + serializer.putQueryParam(fields, "userEvent", request.getUserEvent()); + return fields; + }) + .setRequestBodyExtractor(request -> null) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(HttpBody.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + listUserEventsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.recommendationengine.v1beta1.UserEventService/ListUserEvents") + .setHttpMethod("GET") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{parent=projects/*/locations/*/catalogs/*/eventStores/*}/userEvents", + 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(ListUserEventsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + purgeUserEventsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.recommendationengine.v1beta1.UserEventService/PurgeUserEvents") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{parent=projects/*/locations/*/catalogs/*/eventStores/*}/userEvents:purge", + 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( + (PurgeUserEventsRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private static final ApiMethodDescriptor + importUserEventsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName( + "google.cloud.recommendationengine.v1beta1.UserEventService/ImportUserEvents") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1beta1/{parent=projects/*/locations/*/catalogs/*/eventStores/*}/userEvents:import", + 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( + (ImportUserEventsRequest request, Operation response) -> + HttpJsonOperationSnapshot.create(response)) + .build(); + + private final UnaryCallable writeUserEventCallable; + private final UnaryCallable collectUserEventCallable; + private final UnaryCallable listUserEventsCallable; + private final UnaryCallable + listUserEventsPagedCallable; + private final UnaryCallable purgeUserEventsCallable; + private final OperationCallable< + PurgeUserEventsRequest, PurgeUserEventsResponse, PurgeUserEventsMetadata> + purgeUserEventsOperationCallable; + private final UnaryCallable importUserEventsCallable; + private final OperationCallable + importUserEventsOperationCallable; + + private final BackgroundResource backgroundResources; + private final HttpJsonOperationsStub httpJsonOperationsStub; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonUserEventServiceStub create(UserEventServiceStubSettings settings) + throws IOException { + return new HttpJsonUserEventServiceStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonUserEventServiceStub create(ClientContext clientContext) + throws IOException { + return new HttpJsonUserEventServiceStub( + UserEventServiceStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonUserEventServiceStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonUserEventServiceStub( + UserEventServiceStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of HttpJsonUserEventServiceStub, 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 HttpJsonUserEventServiceStub( + UserEventServiceStubSettings settings, ClientContext clientContext) throws IOException { + this(settings, clientContext, new HttpJsonUserEventServiceCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonUserEventServiceStub, 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 HttpJsonUserEventServiceStub( + UserEventServiceStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.httpJsonOperationsStub = + HttpJsonOperationsStub.create(clientContext, callableFactory, typeRegistry); + + HttpJsonCallSettings writeUserEventTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(writeUserEventMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings collectUserEventTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(collectUserEventMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings + listUserEventsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(listUserEventsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings purgeUserEventsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(purgeUserEventsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + HttpJsonCallSettings importUserEventsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(importUserEventsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .build(); + + this.writeUserEventCallable = + callableFactory.createUnaryCallable( + writeUserEventTransportSettings, settings.writeUserEventSettings(), clientContext); + this.collectUserEventCallable = + callableFactory.createUnaryCallable( + collectUserEventTransportSettings, settings.collectUserEventSettings(), clientContext); + this.listUserEventsCallable = + callableFactory.createUnaryCallable( + listUserEventsTransportSettings, settings.listUserEventsSettings(), clientContext); + this.listUserEventsPagedCallable = + callableFactory.createPagedCallable( + listUserEventsTransportSettings, settings.listUserEventsSettings(), clientContext); + this.purgeUserEventsCallable = + callableFactory.createUnaryCallable( + purgeUserEventsTransportSettings, settings.purgeUserEventsSettings(), clientContext); + this.purgeUserEventsOperationCallable = + callableFactory.createOperationCallable( + purgeUserEventsTransportSettings, + settings.purgeUserEventsOperationSettings(), + clientContext, + httpJsonOperationsStub); + this.importUserEventsCallable = + callableFactory.createUnaryCallable( + importUserEventsTransportSettings, settings.importUserEventsSettings(), clientContext); + this.importUserEventsOperationCallable = + callableFactory.createOperationCallable( + importUserEventsTransportSettings, + settings.importUserEventsOperationSettings(), + clientContext, + httpJsonOperationsStub); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(writeUserEventMethodDescriptor); + methodDescriptors.add(collectUserEventMethodDescriptor); + methodDescriptors.add(listUserEventsMethodDescriptor); + methodDescriptors.add(purgeUserEventsMethodDescriptor); + methodDescriptors.add(importUserEventsMethodDescriptor); + return methodDescriptors; + } + + public HttpJsonOperationsStub getHttpJsonOperationsStub() { + return httpJsonOperationsStub; + } + + @Override + public UnaryCallable writeUserEventCallable() { + return writeUserEventCallable; + } + + @Override + public UnaryCallable collectUserEventCallable() { + return collectUserEventCallable; + } + + @Override + public UnaryCallable listUserEventsCallable() { + return listUserEventsCallable; + } + + @Override + public UnaryCallable + listUserEventsPagedCallable() { + return listUserEventsPagedCallable; + } + + @Override + public UnaryCallable purgeUserEventsCallable() { + return purgeUserEventsCallable; + } + + @Override + public OperationCallable + purgeUserEventsOperationCallable() { + return purgeUserEventsOperationCallable; + } + + @Override + public UnaryCallable importUserEventsCallable() { + return importUserEventsCallable; + } + + @Override + public OperationCallable + importUserEventsOperationCallable() { + return importUserEventsOperationCallable; + } + + @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/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/stub/PredictionApiKeyRegistryStubSettings.java b/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/stub/PredictionApiKeyRegistryStubSettings.java index e47382472d1e..4d03c9d3f7a8 100644 --- a/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/stub/PredictionApiKeyRegistryStubSettings.java +++ b/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/stub/PredictionApiKeyRegistryStubSettings.java @@ -27,6 +27,9 @@ import com.google.api.gax.grpc.GaxGrpcProperties; import com.google.api.gax.grpc.GrpcTransportChannel; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.HttpJsonTransportChannel; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; import com.google.api.gax.retrying.RetrySettings; import com.google.api.gax.rpc.ApiCallContext; import com.google.api.gax.rpc.ApiClientHeaderProvider; @@ -219,6 +222,11 @@ public PredictionApiKeyRegistryStub createStub() throws IOException { .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcPredictionApiKeyRegistryStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonPredictionApiKeyRegistryStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -251,18 +259,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(PredictionApiKeyRegistryStubSettings.class)) @@ -270,11 +285,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(PredictionApiKeyRegistryStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return PredictionApiKeyRegistryStubSettings.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); @@ -393,6 +427,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 .createPredictionApiKeyRegistrationSettings() diff --git a/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/stub/PredictionServiceStubSettings.java b/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/stub/PredictionServiceStubSettings.java index 6db38c150b25..d9791326dae8 100644 --- a/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/stub/PredictionServiceStubSettings.java +++ b/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/stub/PredictionServiceStubSettings.java @@ -27,6 +27,9 @@ import com.google.api.gax.grpc.GaxGrpcProperties; import com.google.api.gax.grpc.GrpcTransportChannel; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.HttpJsonTransportChannel; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; import com.google.api.gax.retrying.RetrySettings; import com.google.api.gax.rpc.ApiCallContext; import com.google.api.gax.rpc.ApiClientHeaderProvider; @@ -165,6 +168,11 @@ public PredictionServiceStub createStub() throws IOException { .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcPredictionServiceStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonPredictionServiceStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -197,18 +205,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(PredictionServiceStubSettings.class)) @@ -216,11 +231,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(PredictionServiceStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return PredictionServiceStubSettings.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); @@ -311,6 +345,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 .predictSettings() diff --git a/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/stub/UserEventServiceStub.java b/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/stub/UserEventServiceStub.java index 85bb44f0cfed..e95cc3715cbb 100644 --- a/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/stub/UserEventServiceStub.java +++ b/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/stub/UserEventServiceStub.java @@ -49,7 +49,11 @@ public abstract class UserEventServiceStub 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 writeUserEventCallable() { diff --git a/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/stub/UserEventServiceStubSettings.java b/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/stub/UserEventServiceStubSettings.java index b9d6b11d39e9..d5aef443d7eb 100644 --- a/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/stub/UserEventServiceStubSettings.java +++ b/java-recommendations-ai/google-cloud-recommendations-ai/src/main/java/com/google/cloud/recommendationengine/v1beta1/stub/UserEventServiceStubSettings.java @@ -29,6 +29,9 @@ import com.google.api.gax.grpc.GrpcTransportChannel; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; import com.google.api.gax.grpc.ProtoOperationTransformers; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.HttpJsonTransportChannel; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; import com.google.api.gax.longrunning.OperationSnapshot; import com.google.api.gax.longrunning.OperationTimedPollAlgorithm; import com.google.api.gax.retrying.RetrySettings; @@ -222,6 +225,11 @@ public UserEventServiceStub createStub() throws IOException { .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcUserEventServiceStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonUserEventServiceStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -254,18 +262,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(UserEventServiceStubSettings.class)) @@ -273,11 +288,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(UserEventServiceStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return UserEventServiceStubSettings.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); @@ -411,6 +445,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 .writeUserEventSettings() diff --git a/java-recommendations-ai/google-cloud-recommendations-ai/src/test/java/com/google/cloud/recommendationengine/v1beta1/CatalogServiceClientHttpJsonTest.java b/java-recommendations-ai/google-cloud-recommendations-ai/src/test/java/com/google/cloud/recommendationengine/v1beta1/CatalogServiceClientHttpJsonTest.java new file mode 100644 index 000000000000..cb931eabf769 --- /dev/null +++ b/java-recommendations-ai/google-cloud-recommendations-ai/src/test/java/com/google/cloud/recommendationengine/v1beta1/CatalogServiceClientHttpJsonTest.java @@ -0,0 +1,712 @@ +/* + * 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.recommendationengine.v1beta1; + +import static com.google.cloud.recommendationengine.v1beta1.CatalogServiceClient.ListCatalogItemsPagedResponse; + +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.recommendationengine.v1beta1.stub.HttpJsonCatalogServiceStub; +import com.google.common.collect.Lists; +import com.google.longrunning.Operation; +import com.google.protobuf.Any; +import com.google.protobuf.Empty; +import com.google.protobuf.FieldMask; +import com.google.rpc.Status; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.ExecutionException; +import javax.annotation.Generated; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +@Generated("by gapic-generator-java") +public class CatalogServiceClientHttpJsonTest { + private static MockHttpService mockService; + private static CatalogServiceClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonCatalogServiceStub.getMethodDescriptors(), + CatalogServiceSettings.getDefaultEndpoint()); + CatalogServiceSettings settings = + CatalogServiceSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + CatalogServiceSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = CatalogServiceClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void createCatalogItemTest() throws Exception { + CatalogItem expectedResponse = + CatalogItem.newBuilder() + .setId("id3355") + .addAllCategoryHierarchies(new ArrayList()) + .setTitle("title110371416") + .setDescription("description-1724546052") + .setItemAttributes(FeatureMap.newBuilder().build()) + .setLanguageCode("languageCode-2092349083") + .addAllTags(new ArrayList()) + .setItemGroupId("itemGroupId-240489113") + .build(); + mockService.addResponse(expectedResponse); + + CatalogName parent = CatalogName.of("[PROJECT]", "[LOCATION]", "[CATALOG]"); + CatalogItem catalogItem = CatalogItem.newBuilder().build(); + + CatalogItem actualResponse = client.createCatalogItem(parent, catalogItem); + 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 createCatalogItemExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + CatalogName parent = CatalogName.of("[PROJECT]", "[LOCATION]", "[CATALOG]"); + CatalogItem catalogItem = CatalogItem.newBuilder().build(); + client.createCatalogItem(parent, catalogItem); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createCatalogItemTest2() throws Exception { + CatalogItem expectedResponse = + CatalogItem.newBuilder() + .setId("id3355") + .addAllCategoryHierarchies(new ArrayList()) + .setTitle("title110371416") + .setDescription("description-1724546052") + .setItemAttributes(FeatureMap.newBuilder().build()) + .setLanguageCode("languageCode-2092349083") + .addAllTags(new ArrayList()) + .setItemGroupId("itemGroupId-240489113") + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-6267/locations/location-6267/catalogs/catalog-6267"; + CatalogItem catalogItem = CatalogItem.newBuilder().build(); + + CatalogItem actualResponse = client.createCatalogItem(parent, catalogItem); + 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 createCatalogItemExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-6267/locations/location-6267/catalogs/catalog-6267"; + CatalogItem catalogItem = CatalogItem.newBuilder().build(); + client.createCatalogItem(parent, catalogItem); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getCatalogItemTest() throws Exception { + CatalogItem expectedResponse = + CatalogItem.newBuilder() + .setId("id3355") + .addAllCategoryHierarchies(new ArrayList()) + .setTitle("title110371416") + .setDescription("description-1724546052") + .setItemAttributes(FeatureMap.newBuilder().build()) + .setLanguageCode("languageCode-2092349083") + .addAllTags(new ArrayList()) + .setItemGroupId("itemGroupId-240489113") + .build(); + mockService.addResponse(expectedResponse); + + CatalogItemPathName name = + CatalogItemPathName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[CATALOG_ITEM_PATH]"); + + CatalogItem actualResponse = client.getCatalogItem(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 getCatalogItemExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + CatalogItemPathName name = + CatalogItemPathName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[CATALOG_ITEM_PATH]"); + client.getCatalogItem(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getCatalogItemTest2() throws Exception { + CatalogItem expectedResponse = + CatalogItem.newBuilder() + .setId("id3355") + .addAllCategoryHierarchies(new ArrayList()) + .setTitle("title110371416") + .setDescription("description-1724546052") + .setItemAttributes(FeatureMap.newBuilder().build()) + .setLanguageCode("languageCode-2092349083") + .addAllTags(new ArrayList()) + .setItemGroupId("itemGroupId-240489113") + .build(); + mockService.addResponse(expectedResponse); + + String name = + "projects/project-1923/locations/location-1923/catalogs/catalog-1923/catalogItems/catalogItem-1923"; + + CatalogItem actualResponse = client.getCatalogItem(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 getCatalogItemExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-1923/locations/location-1923/catalogs/catalog-1923/catalogItems/catalogItem-1923"; + client.getCatalogItem(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listCatalogItemsTest() throws Exception { + CatalogItem responsesElement = CatalogItem.newBuilder().build(); + ListCatalogItemsResponse expectedResponse = + ListCatalogItemsResponse.newBuilder() + .setNextPageToken("") + .addAllCatalogItems(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + CatalogName parent = CatalogName.of("[PROJECT]", "[LOCATION]", "[CATALOG]"); + String filter = "filter-1274492040"; + + ListCatalogItemsPagedResponse pagedListResponse = client.listCatalogItems(parent, filter); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getCatalogItemsList().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 listCatalogItemsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + CatalogName parent = CatalogName.of("[PROJECT]", "[LOCATION]", "[CATALOG]"); + String filter = "filter-1274492040"; + client.listCatalogItems(parent, filter); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listCatalogItemsTest2() throws Exception { + CatalogItem responsesElement = CatalogItem.newBuilder().build(); + ListCatalogItemsResponse expectedResponse = + ListCatalogItemsResponse.newBuilder() + .setNextPageToken("") + .addAllCatalogItems(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = "projects/project-6267/locations/location-6267/catalogs/catalog-6267"; + String filter = "filter-1274492040"; + + ListCatalogItemsPagedResponse pagedListResponse = client.listCatalogItems(parent, filter); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getCatalogItemsList().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 listCatalogItemsExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-6267/locations/location-6267/catalogs/catalog-6267"; + String filter = "filter-1274492040"; + client.listCatalogItems(parent, filter); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void updateCatalogItemTest() throws Exception { + CatalogItem expectedResponse = + CatalogItem.newBuilder() + .setId("id3355") + .addAllCategoryHierarchies(new ArrayList()) + .setTitle("title110371416") + .setDescription("description-1724546052") + .setItemAttributes(FeatureMap.newBuilder().build()) + .setLanguageCode("languageCode-2092349083") + .addAllTags(new ArrayList()) + .setItemGroupId("itemGroupId-240489113") + .build(); + mockService.addResponse(expectedResponse); + + CatalogItemPathName name = + CatalogItemPathName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[CATALOG_ITEM_PATH]"); + CatalogItem catalogItem = CatalogItem.newBuilder().build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + + CatalogItem actualResponse = client.updateCatalogItem(name, catalogItem, updateMask); + 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 updateCatalogItemExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + CatalogItemPathName name = + CatalogItemPathName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[CATALOG_ITEM_PATH]"); + CatalogItem catalogItem = CatalogItem.newBuilder().build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + client.updateCatalogItem(name, catalogItem, updateMask); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void updateCatalogItemTest2() throws Exception { + CatalogItem expectedResponse = + CatalogItem.newBuilder() + .setId("id3355") + .addAllCategoryHierarchies(new ArrayList()) + .setTitle("title110371416") + .setDescription("description-1724546052") + .setItemAttributes(FeatureMap.newBuilder().build()) + .setLanguageCode("languageCode-2092349083") + .addAllTags(new ArrayList()) + .setItemGroupId("itemGroupId-240489113") + .build(); + mockService.addResponse(expectedResponse); + + String name = + "projects/project-1923/locations/location-1923/catalogs/catalog-1923/catalogItems/catalogItem-1923"; + CatalogItem catalogItem = CatalogItem.newBuilder().build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + + CatalogItem actualResponse = client.updateCatalogItem(name, catalogItem, updateMask); + 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 updateCatalogItemExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-1923/locations/location-1923/catalogs/catalog-1923/catalogItems/catalogItem-1923"; + CatalogItem catalogItem = CatalogItem.newBuilder().build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + client.updateCatalogItem(name, catalogItem, updateMask); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteCatalogItemTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + CatalogItemPathName name = + CatalogItemPathName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[CATALOG_ITEM_PATH]"); + + client.deleteCatalogItem(name); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteCatalogItemExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + CatalogItemPathName name = + CatalogItemPathName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[CATALOG_ITEM_PATH]"); + client.deleteCatalogItem(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteCatalogItemTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + String name = + "projects/project-1923/locations/location-1923/catalogs/catalog-1923/catalogItems/catalogItem-1923"; + + client.deleteCatalogItem(name); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deleteCatalogItemExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-1923/locations/location-1923/catalogs/catalog-1923/catalogItems/catalogItem-1923"; + client.deleteCatalogItem(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void importCatalogItemsTest() throws Exception { + ImportCatalogItemsResponse expectedResponse = + ImportCatalogItemsResponse.newBuilder() + .addAllErrorSamples(new ArrayList()) + .setErrorsConfig(ImportErrorsConfig.newBuilder().build()) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("importCatalogItemsTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + CatalogName parent = CatalogName.of("[PROJECT]", "[LOCATION]", "[CATALOG]"); + String requestId = "requestId693933066"; + InputConfig inputConfig = InputConfig.newBuilder().build(); + ImportErrorsConfig errorsConfig = ImportErrorsConfig.newBuilder().build(); + + ImportCatalogItemsResponse actualResponse = + client.importCatalogItemsAsync(parent, requestId, inputConfig, errorsConfig).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 importCatalogItemsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + CatalogName parent = CatalogName.of("[PROJECT]", "[LOCATION]", "[CATALOG]"); + String requestId = "requestId693933066"; + InputConfig inputConfig = InputConfig.newBuilder().build(); + ImportErrorsConfig errorsConfig = ImportErrorsConfig.newBuilder().build(); + client.importCatalogItemsAsync(parent, requestId, inputConfig, errorsConfig).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void importCatalogItemsTest2() throws Exception { + ImportCatalogItemsResponse expectedResponse = + ImportCatalogItemsResponse.newBuilder() + .addAllErrorSamples(new ArrayList()) + .setErrorsConfig(ImportErrorsConfig.newBuilder().build()) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("importCatalogItemsTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String parent = "projects/project-6267/locations/location-6267/catalogs/catalog-6267"; + String requestId = "requestId693933066"; + InputConfig inputConfig = InputConfig.newBuilder().build(); + ImportErrorsConfig errorsConfig = ImportErrorsConfig.newBuilder().build(); + + ImportCatalogItemsResponse actualResponse = + client.importCatalogItemsAsync(parent, requestId, inputConfig, errorsConfig).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 importCatalogItemsExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = "projects/project-6267/locations/location-6267/catalogs/catalog-6267"; + String requestId = "requestId693933066"; + InputConfig inputConfig = InputConfig.newBuilder().build(); + ImportErrorsConfig errorsConfig = ImportErrorsConfig.newBuilder().build(); + client.importCatalogItemsAsync(parent, requestId, inputConfig, errorsConfig).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } +} diff --git a/java-recommendations-ai/google-cloud-recommendations-ai/src/test/java/com/google/cloud/recommendationengine/v1beta1/PredictionApiKeyRegistryClientHttpJsonTest.java b/java-recommendations-ai/google-cloud-recommendations-ai/src/test/java/com/google/cloud/recommendationengine/v1beta1/PredictionApiKeyRegistryClientHttpJsonTest.java new file mode 100644 index 000000000000..96ba91897d19 --- /dev/null +++ b/java-recommendations-ai/google-cloud-recommendations-ai/src/test/java/com/google/cloud/recommendationengine/v1beta1/PredictionApiKeyRegistryClientHttpJsonTest.java @@ -0,0 +1,382 @@ +/* + * 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.recommendationengine.v1beta1; + +import static com.google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistryClient.ListPredictionApiKeyRegistrationsPagedResponse; + +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.recommendationengine.v1beta1.stub.HttpJsonPredictionApiKeyRegistryStub; +import com.google.common.collect.Lists; +import com.google.protobuf.Empty; +import java.io.IOException; +import java.util.Arrays; +import java.util.List; +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 PredictionApiKeyRegistryClientHttpJsonTest { + private static MockHttpService mockService; + private static PredictionApiKeyRegistryClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonPredictionApiKeyRegistryStub.getMethodDescriptors(), + PredictionApiKeyRegistrySettings.getDefaultEndpoint()); + PredictionApiKeyRegistrySettings settings = + PredictionApiKeyRegistrySettings.newHttpJsonBuilder() + .setTransportChannelProvider( + PredictionApiKeyRegistrySettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = PredictionApiKeyRegistryClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void createPredictionApiKeyRegistrationTest() throws Exception { + PredictionApiKeyRegistration expectedResponse = + PredictionApiKeyRegistration.newBuilder().setApiKey("apiKey-1411301915").build(); + mockService.addResponse(expectedResponse); + + EventStoreName parent = + EventStoreName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]"); + PredictionApiKeyRegistration predictionApiKeyRegistration = + PredictionApiKeyRegistration.newBuilder().build(); + + PredictionApiKeyRegistration actualResponse = + client.createPredictionApiKeyRegistration(parent, predictionApiKeyRegistration); + 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 createPredictionApiKeyRegistrationExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + EventStoreName parent = + EventStoreName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]"); + PredictionApiKeyRegistration predictionApiKeyRegistration = + PredictionApiKeyRegistration.newBuilder().build(); + client.createPredictionApiKeyRegistration(parent, predictionApiKeyRegistration); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createPredictionApiKeyRegistrationTest2() throws Exception { + PredictionApiKeyRegistration expectedResponse = + PredictionApiKeyRegistration.newBuilder().setApiKey("apiKey-1411301915").build(); + mockService.addResponse(expectedResponse); + + String parent = + "projects/project-765/locations/location-765/catalogs/catalog-765/eventStores/eventStore-765"; + PredictionApiKeyRegistration predictionApiKeyRegistration = + PredictionApiKeyRegistration.newBuilder().build(); + + PredictionApiKeyRegistration actualResponse = + client.createPredictionApiKeyRegistration(parent, predictionApiKeyRegistration); + 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 createPredictionApiKeyRegistrationExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = + "projects/project-765/locations/location-765/catalogs/catalog-765/eventStores/eventStore-765"; + PredictionApiKeyRegistration predictionApiKeyRegistration = + PredictionApiKeyRegistration.newBuilder().build(); + client.createPredictionApiKeyRegistration(parent, predictionApiKeyRegistration); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listPredictionApiKeyRegistrationsTest() throws Exception { + PredictionApiKeyRegistration responsesElement = + PredictionApiKeyRegistration.newBuilder().build(); + ListPredictionApiKeyRegistrationsResponse expectedResponse = + ListPredictionApiKeyRegistrationsResponse.newBuilder() + .setNextPageToken("") + .addAllPredictionApiKeyRegistrations(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + EventStoreName parent = + EventStoreName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]"); + + ListPredictionApiKeyRegistrationsPagedResponse pagedListResponse = + client.listPredictionApiKeyRegistrations(parent); + + List resources = + Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals( + expectedResponse.getPredictionApiKeyRegistrationsList().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 listPredictionApiKeyRegistrationsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + EventStoreName parent = + EventStoreName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]"); + client.listPredictionApiKeyRegistrations(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listPredictionApiKeyRegistrationsTest2() throws Exception { + PredictionApiKeyRegistration responsesElement = + PredictionApiKeyRegistration.newBuilder().build(); + ListPredictionApiKeyRegistrationsResponse expectedResponse = + ListPredictionApiKeyRegistrationsResponse.newBuilder() + .setNextPageToken("") + .addAllPredictionApiKeyRegistrations(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = + "projects/project-765/locations/location-765/catalogs/catalog-765/eventStores/eventStore-765"; + + ListPredictionApiKeyRegistrationsPagedResponse pagedListResponse = + client.listPredictionApiKeyRegistrations(parent); + + List resources = + Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals( + expectedResponse.getPredictionApiKeyRegistrationsList().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 listPredictionApiKeyRegistrationsExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = + "projects/project-765/locations/location-765/catalogs/catalog-765/eventStores/eventStore-765"; + client.listPredictionApiKeyRegistrations(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deletePredictionApiKeyRegistrationTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + PredictionApiKeyRegistrationName name = + PredictionApiKeyRegistrationName.of( + "[PROJECT]", + "[LOCATION]", + "[CATALOG]", + "[EVENT_STORE]", + "[PREDICTION_API_KEY_REGISTRATION]"); + + client.deletePredictionApiKeyRegistration(name); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deletePredictionApiKeyRegistrationExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + PredictionApiKeyRegistrationName name = + PredictionApiKeyRegistrationName.of( + "[PROJECT]", + "[LOCATION]", + "[CATALOG]", + "[EVENT_STORE]", + "[PREDICTION_API_KEY_REGISTRATION]"); + client.deletePredictionApiKeyRegistration(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deletePredictionApiKeyRegistrationTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockService.addResponse(expectedResponse); + + String name = + "projects/project-76/locations/location-76/catalogs/catalog-76/eventStores/eventStore-76/predictionApiKeyRegistrations/predictionApiKeyRegistration-76"; + + client.deletePredictionApiKeyRegistration(name); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void deletePredictionApiKeyRegistrationExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-76/locations/location-76/catalogs/catalog-76/eventStores/eventStore-76/predictionApiKeyRegistrations/predictionApiKeyRegistration-76"; + client.deletePredictionApiKeyRegistration(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } +} diff --git a/java-recommendations-ai/google-cloud-recommendations-ai/src/test/java/com/google/cloud/recommendationengine/v1beta1/PredictionServiceClientHttpJsonTest.java b/java-recommendations-ai/google-cloud-recommendations-ai/src/test/java/com/google/cloud/recommendationengine/v1beta1/PredictionServiceClientHttpJsonTest.java new file mode 100644 index 000000000000..c7ad9be972cb --- /dev/null +++ b/java-recommendations-ai/google-cloud-recommendations-ai/src/test/java/com/google/cloud/recommendationengine/v1beta1/PredictionServiceClientHttpJsonTest.java @@ -0,0 +1,189 @@ +/* + * 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.recommendationengine.v1beta1; + +import static com.google.cloud.recommendationengine.v1beta1.PredictionServiceClient.PredictPagedResponse; + +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.recommendationengine.v1beta1.stub.HttpJsonPredictionServiceStub; +import com.google.common.collect.Lists; +import com.google.protobuf.Value; +import java.io.IOException; +import java.util.Collections; +import java.util.List; +import java.util.Map; +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 PredictionServiceClientHttpJsonTest { + private static MockHttpService mockService; + private static PredictionServiceClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonPredictionServiceStub.getMethodDescriptors(), + PredictionServiceSettings.getDefaultEndpoint()); + PredictionServiceSettings settings = + PredictionServiceSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + PredictionServiceSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = PredictionServiceClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void predictTest() throws Exception { + Value responsesElement = Value.newBuilder().setBoolValue(true).build(); + PredictResponse expectedResponse = + PredictResponse.newBuilder() + .setNextPageToken("") + .putAllMetadata(Collections.singletonMap("metadata", responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + PlacementName name = + PlacementName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]", "[PLACEMENT]"); + UserEvent userEvent = UserEvent.newBuilder().build(); + + PredictPagedResponse pagedListResponse = client.predict(name, userEvent); + + List> resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals( + expectedResponse.getMetadataMap().entrySet().iterator().next(), 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 predictExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + PlacementName name = + PlacementName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]", "[PLACEMENT]"); + UserEvent userEvent = UserEvent.newBuilder().build(); + client.predict(name, userEvent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void predictTest2() throws Exception { + Value responsesElement = Value.newBuilder().setBoolValue(true).build(); + PredictResponse expectedResponse = + PredictResponse.newBuilder() + .setNextPageToken("") + .putAllMetadata(Collections.singletonMap("metadata", responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String name = + "projects/project-9174/locations/location-9174/catalogs/catalog-9174/eventStores/eventStore-9174/placements/placement-9174"; + UserEvent userEvent = UserEvent.newBuilder().build(); + + PredictPagedResponse pagedListResponse = client.predict(name, userEvent); + + List> resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals( + expectedResponse.getMetadataMap().entrySet().iterator().next(), 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 predictExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String name = + "projects/project-9174/locations/location-9174/catalogs/catalog-9174/eventStores/eventStore-9174/placements/placement-9174"; + UserEvent userEvent = UserEvent.newBuilder().build(); + client.predict(name, userEvent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } +} diff --git a/java-recommendations-ai/google-cloud-recommendations-ai/src/test/java/com/google/cloud/recommendationengine/v1beta1/UserEventServiceClientHttpJsonTest.java b/java-recommendations-ai/google-cloud-recommendations-ai/src/test/java/com/google/cloud/recommendationengine/v1beta1/UserEventServiceClientHttpJsonTest.java new file mode 100644 index 000000000000..5fff6e46818a --- /dev/null +++ b/java-recommendations-ai/google-cloud-recommendations-ai/src/test/java/com/google/cloud/recommendationengine/v1beta1/UserEventServiceClientHttpJsonTest.java @@ -0,0 +1,639 @@ +/* + * 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.recommendationengine.v1beta1; + +import static com.google.cloud.recommendationengine.v1beta1.UserEventServiceClient.ListUserEventsPagedResponse; + +import com.google.api.HttpBody; +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.recommendationengine.v1beta1.stub.HttpJsonUserEventServiceStub; +import com.google.common.collect.Lists; +import com.google.longrunning.Operation; +import com.google.protobuf.Any; +import com.google.protobuf.ByteString; +import com.google.protobuf.Timestamp; +import com.google.rpc.Status; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.ExecutionException; +import javax.annotation.Generated; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +@Generated("by gapic-generator-java") +public class UserEventServiceClientHttpJsonTest { + private static MockHttpService mockService; + private static UserEventServiceClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonUserEventServiceStub.getMethodDescriptors(), + UserEventServiceSettings.getDefaultEndpoint()); + UserEventServiceSettings settings = + UserEventServiceSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + UserEventServiceSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = UserEventServiceClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void writeUserEventTest() throws Exception { + UserEvent expectedResponse = + UserEvent.newBuilder() + .setEventType("eventType31430900") + .setUserInfo(UserInfo.newBuilder().build()) + .setEventDetail(EventDetail.newBuilder().build()) + .setProductEventDetail(ProductEventDetail.newBuilder().build()) + .setEventTime(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + EventStoreName parent = + EventStoreName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]"); + UserEvent userEvent = UserEvent.newBuilder().build(); + + UserEvent actualResponse = client.writeUserEvent(parent, userEvent); + 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 writeUserEventExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + EventStoreName parent = + EventStoreName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]"); + UserEvent userEvent = UserEvent.newBuilder().build(); + client.writeUserEvent(parent, userEvent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void writeUserEventTest2() throws Exception { + UserEvent expectedResponse = + UserEvent.newBuilder() + .setEventType("eventType31430900") + .setUserInfo(UserInfo.newBuilder().build()) + .setEventDetail(EventDetail.newBuilder().build()) + .setProductEventDetail(ProductEventDetail.newBuilder().build()) + .setEventTime(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String parent = + "projects/project-765/locations/location-765/catalogs/catalog-765/eventStores/eventStore-765"; + UserEvent userEvent = UserEvent.newBuilder().build(); + + UserEvent actualResponse = client.writeUserEvent(parent, userEvent); + 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 writeUserEventExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = + "projects/project-765/locations/location-765/catalogs/catalog-765/eventStores/eventStore-765"; + UserEvent userEvent = UserEvent.newBuilder().build(); + client.writeUserEvent(parent, userEvent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void collectUserEventTest() throws Exception { + HttpBody expectedResponse = + HttpBody.newBuilder() + .setContentType("contentType-389131437") + .setData(ByteString.EMPTY) + .addAllExtensions(new ArrayList()) + .build(); + mockService.addResponse(expectedResponse); + + EventStoreName parent = + EventStoreName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]"); + String userEvent = "userEvent315571599"; + String uri = "uri116076"; + long ets = 100772; + + HttpBody actualResponse = client.collectUserEvent(parent, userEvent, uri, ets); + 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 collectUserEventExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + EventStoreName parent = + EventStoreName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]"); + String userEvent = "userEvent315571599"; + String uri = "uri116076"; + long ets = 100772; + client.collectUserEvent(parent, userEvent, uri, ets); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void collectUserEventTest2() throws Exception { + HttpBody expectedResponse = + HttpBody.newBuilder() + .setContentType("contentType-389131437") + .setData(ByteString.EMPTY) + .addAllExtensions(new ArrayList()) + .build(); + mockService.addResponse(expectedResponse); + + String parent = + "projects/project-765/locations/location-765/catalogs/catalog-765/eventStores/eventStore-765"; + String userEvent = "userEvent315571599"; + String uri = "uri116076"; + long ets = 100772; + + HttpBody actualResponse = client.collectUserEvent(parent, userEvent, uri, ets); + 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 collectUserEventExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = + "projects/project-765/locations/location-765/catalogs/catalog-765/eventStores/eventStore-765"; + String userEvent = "userEvent315571599"; + String uri = "uri116076"; + long ets = 100772; + client.collectUserEvent(parent, userEvent, uri, ets); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listUserEventsTest() throws Exception { + UserEvent responsesElement = UserEvent.newBuilder().build(); + ListUserEventsResponse expectedResponse = + ListUserEventsResponse.newBuilder() + .setNextPageToken("") + .addAllUserEvents(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + EventStoreName parent = + EventStoreName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]"); + String filter = "filter-1274492040"; + + ListUserEventsPagedResponse pagedListResponse = client.listUserEvents(parent, filter); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getUserEventsList().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 listUserEventsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + EventStoreName parent = + EventStoreName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]"); + String filter = "filter-1274492040"; + client.listUserEvents(parent, filter); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listUserEventsTest2() throws Exception { + UserEvent responsesElement = UserEvent.newBuilder().build(); + ListUserEventsResponse expectedResponse = + ListUserEventsResponse.newBuilder() + .setNextPageToken("") + .addAllUserEvents(Arrays.asList(responsesElement)) + .build(); + mockService.addResponse(expectedResponse); + + String parent = + "projects/project-765/locations/location-765/catalogs/catalog-765/eventStores/eventStore-765"; + String filter = "filter-1274492040"; + + ListUserEventsPagedResponse pagedListResponse = client.listUserEvents(parent, filter); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getUserEventsList().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 listUserEventsExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = + "projects/project-765/locations/location-765/catalogs/catalog-765/eventStores/eventStore-765"; + String filter = "filter-1274492040"; + client.listUserEvents(parent, filter); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void purgeUserEventsTest() throws Exception { + PurgeUserEventsResponse expectedResponse = + PurgeUserEventsResponse.newBuilder() + .setPurgedEventsCount(-310774833) + .addAllUserEventsSample(new ArrayList()) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("purgeUserEventsTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + EventStoreName parent = + EventStoreName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]"); + String filter = "filter-1274492040"; + boolean force = true; + + PurgeUserEventsResponse actualResponse = + client.purgeUserEventsAsync(parent, filter, force).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 purgeUserEventsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + EventStoreName parent = + EventStoreName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]"); + String filter = "filter-1274492040"; + boolean force = true; + client.purgeUserEventsAsync(parent, filter, force).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void purgeUserEventsTest2() throws Exception { + PurgeUserEventsResponse expectedResponse = + PurgeUserEventsResponse.newBuilder() + .setPurgedEventsCount(-310774833) + .addAllUserEventsSample(new ArrayList()) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("purgeUserEventsTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String parent = + "projects/project-765/locations/location-765/catalogs/catalog-765/eventStores/eventStore-765"; + String filter = "filter-1274492040"; + boolean force = true; + + PurgeUserEventsResponse actualResponse = + client.purgeUserEventsAsync(parent, filter, force).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 purgeUserEventsExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = + "projects/project-765/locations/location-765/catalogs/catalog-765/eventStores/eventStore-765"; + String filter = "filter-1274492040"; + boolean force = true; + client.purgeUserEventsAsync(parent, filter, force).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void importUserEventsTest() throws Exception { + ImportUserEventsResponse expectedResponse = + ImportUserEventsResponse.newBuilder() + .addAllErrorSamples(new ArrayList()) + .setErrorsConfig(ImportErrorsConfig.newBuilder().build()) + .setImportSummary(UserEventImportSummary.newBuilder().build()) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("importUserEventsTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + EventStoreName parent = + EventStoreName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]"); + String requestId = "requestId693933066"; + InputConfig inputConfig = InputConfig.newBuilder().build(); + ImportErrorsConfig errorsConfig = ImportErrorsConfig.newBuilder().build(); + + ImportUserEventsResponse actualResponse = + client.importUserEventsAsync(parent, requestId, inputConfig, errorsConfig).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 importUserEventsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + EventStoreName parent = + EventStoreName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]"); + String requestId = "requestId693933066"; + InputConfig inputConfig = InputConfig.newBuilder().build(); + ImportErrorsConfig errorsConfig = ImportErrorsConfig.newBuilder().build(); + client.importUserEventsAsync(parent, requestId, inputConfig, errorsConfig).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } + + @Test + public void importUserEventsTest2() throws Exception { + ImportUserEventsResponse expectedResponse = + ImportUserEventsResponse.newBuilder() + .addAllErrorSamples(new ArrayList()) + .setErrorsConfig(ImportErrorsConfig.newBuilder().build()) + .setImportSummary(UserEventImportSummary.newBuilder().build()) + .build(); + Operation resultOperation = + Operation.newBuilder() + .setName("importUserEventsTest") + .setDone(true) + .setResponse(Any.pack(expectedResponse)) + .build(); + mockService.addResponse(resultOperation); + + String parent = + "projects/project-765/locations/location-765/catalogs/catalog-765/eventStores/eventStore-765"; + String requestId = "requestId693933066"; + InputConfig inputConfig = InputConfig.newBuilder().build(); + ImportErrorsConfig errorsConfig = ImportErrorsConfig.newBuilder().build(); + + ImportUserEventsResponse actualResponse = + client.importUserEventsAsync(parent, requestId, inputConfig, errorsConfig).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 importUserEventsExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String parent = + "projects/project-765/locations/location-765/catalogs/catalog-765/eventStores/eventStore-765"; + String requestId = "requestId693933066"; + InputConfig inputConfig = InputConfig.newBuilder().build(); + ImportErrorsConfig errorsConfig = ImportErrorsConfig.newBuilder().build(); + client.importUserEventsAsync(parent, requestId, inputConfig, errorsConfig).get(); + Assert.fail("No exception raised"); + } catch (ExecutionException e) { + } + } +} diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/create/SyncCreateSetCredentialsProvider.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/create/SyncCreateSetCredentialsProvider.java new file mode 100644 index 000000000000..0b3174bd52f2 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/create/SyncCreateSetCredentialsProvider.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.recommendationengine.v1beta1.samples; + +// [START +// recommendationengine_v1beta1_generated_catalogserviceclient_create_setcredentialsprovider_sync] +import com.google.api.gax.core.FixedCredentialsProvider; +import com.google.cloud.recommendationengine.v1beta1.CatalogServiceClient; +import com.google.cloud.recommendationengine.v1beta1.CatalogServiceSettings; +import com.google.cloud.recommendationengine.v1beta1.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. + CatalogServiceSettings catalogServiceSettings = + CatalogServiceSettings.newBuilder() + .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) + .build(); + CatalogServiceClient catalogServiceClient = CatalogServiceClient.create(catalogServiceSettings); + } +} +// [END +// recommendationengine_v1beta1_generated_catalogserviceclient_create_setcredentialsprovider_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/create/SyncCreateSetCredentialsProvider1.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/create/SyncCreateSetCredentialsProvider1.java new file mode 100644 index 000000000000..a90ab8db682b --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/create/SyncCreateSetCredentialsProvider1.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.recommendationengine.v1beta1.samples; + +// [START +// recommendationengine_v1beta1_generated_catalogserviceclient_create_setcredentialsprovider1_sync] +import com.google.cloud.recommendationengine.v1beta1.CatalogServiceClient; +import com.google.cloud.recommendationengine.v1beta1.CatalogServiceSettings; + +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. + CatalogServiceSettings catalogServiceSettings = + CatalogServiceSettings.newBuilder() + .setTransportChannelProvider( + CatalogServiceSettings.defaultHttpJsonTransportProviderBuilder().build()) + .build(); + CatalogServiceClient catalogServiceClient = CatalogServiceClient.create(catalogServiceSettings); + } +} +// [END +// recommendationengine_v1beta1_generated_catalogserviceclient_create_setcredentialsprovider1_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/create/SyncCreateSetEndpoint.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/create/SyncCreateSetEndpoint.java new file mode 100644 index 000000000000..a0e2bb5c7d8f --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/create/SyncCreateSetEndpoint.java @@ -0,0 +1,38 @@ +/* + * 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.recommendationengine.v1beta1.samples; + +// [START recommendationengine_v1beta1_generated_catalogserviceclient_create_setendpoint_sync] +import com.google.cloud.recommendationengine.v1beta1.CatalogServiceClient; +import com.google.cloud.recommendationengine.v1beta1.CatalogServiceSettings; +import com.google.cloud.recommendationengine.v1beta1.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. + CatalogServiceSettings catalogServiceSettings = + CatalogServiceSettings.newBuilder().setEndpoint(myEndpoint).build(); + CatalogServiceClient catalogServiceClient = CatalogServiceClient.create(catalogServiceSettings); + } +} +// [END recommendationengine_v1beta1_generated_catalogserviceclient_create_setendpoint_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/createcatalogitem/AsyncCreateCatalogItem.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/createcatalogitem/AsyncCreateCatalogItem.java new file mode 100644 index 000000000000..88503af6fb57 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/createcatalogitem/AsyncCreateCatalogItem.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.recommendationengine.v1beta1.samples; + +// [START recommendationengine_v1beta1_generated_catalogserviceclient_createcatalogitem_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.recommendationengine.v1beta1.CatalogItem; +import com.google.cloud.recommendationengine.v1beta1.CatalogName; +import com.google.cloud.recommendationengine.v1beta1.CatalogServiceClient; +import com.google.cloud.recommendationengine.v1beta1.CreateCatalogItemRequest; + +public class AsyncCreateCatalogItem { + + public static void main(String[] args) throws Exception { + asyncCreateCatalogItem(); + } + + public static void asyncCreateCatalogItem() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) { + CreateCatalogItemRequest request = + CreateCatalogItemRequest.newBuilder() + .setParent(CatalogName.of("[PROJECT]", "[LOCATION]", "[CATALOG]").toString()) + .setCatalogItem(CatalogItem.newBuilder().build()) + .build(); + ApiFuture future = + catalogServiceClient.createCatalogItemCallable().futureCall(request); + // Do something. + CatalogItem response = future.get(); + } + } +} +// [END recommendationengine_v1beta1_generated_catalogserviceclient_createcatalogitem_async] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/createcatalogitem/SyncCreateCatalogItem.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/createcatalogitem/SyncCreateCatalogItem.java new file mode 100644 index 000000000000..69689076e383 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/createcatalogitem/SyncCreateCatalogItem.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.recommendationengine.v1beta1.samples; + +// [START recommendationengine_v1beta1_generated_catalogserviceclient_createcatalogitem_sync] +import com.google.cloud.recommendationengine.v1beta1.CatalogItem; +import com.google.cloud.recommendationengine.v1beta1.CatalogName; +import com.google.cloud.recommendationengine.v1beta1.CatalogServiceClient; +import com.google.cloud.recommendationengine.v1beta1.CreateCatalogItemRequest; + +public class SyncCreateCatalogItem { + + public static void main(String[] args) throws Exception { + syncCreateCatalogItem(); + } + + public static void syncCreateCatalogItem() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) { + CreateCatalogItemRequest request = + CreateCatalogItemRequest.newBuilder() + .setParent(CatalogName.of("[PROJECT]", "[LOCATION]", "[CATALOG]").toString()) + .setCatalogItem(CatalogItem.newBuilder().build()) + .build(); + CatalogItem response = catalogServiceClient.createCatalogItem(request); + } + } +} +// [END recommendationengine_v1beta1_generated_catalogserviceclient_createcatalogitem_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/createcatalogitem/SyncCreateCatalogItemCatalognameCatalogitem.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/createcatalogitem/SyncCreateCatalogItemCatalognameCatalogitem.java new file mode 100644 index 000000000000..ba83fb64f3c8 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/createcatalogitem/SyncCreateCatalogItemCatalognameCatalogitem.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.recommendationengine.v1beta1.samples; + +// [START +// recommendationengine_v1beta1_generated_catalogserviceclient_createcatalogitem_catalognamecatalogitem_sync] +import com.google.cloud.recommendationengine.v1beta1.CatalogItem; +import com.google.cloud.recommendationengine.v1beta1.CatalogName; +import com.google.cloud.recommendationengine.v1beta1.CatalogServiceClient; + +public class SyncCreateCatalogItemCatalognameCatalogitem { + + public static void main(String[] args) throws Exception { + syncCreateCatalogItemCatalognameCatalogitem(); + } + + public static void syncCreateCatalogItemCatalognameCatalogitem() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) { + CatalogName parent = CatalogName.of("[PROJECT]", "[LOCATION]", "[CATALOG]"); + CatalogItem catalogItem = CatalogItem.newBuilder().build(); + CatalogItem response = catalogServiceClient.createCatalogItem(parent, catalogItem); + } + } +} +// [END +// recommendationengine_v1beta1_generated_catalogserviceclient_createcatalogitem_catalognamecatalogitem_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/createcatalogitem/SyncCreateCatalogItemStringCatalogitem.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/createcatalogitem/SyncCreateCatalogItemStringCatalogitem.java new file mode 100644 index 000000000000..23d64c6a9d0b --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/createcatalogitem/SyncCreateCatalogItemStringCatalogitem.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.recommendationengine.v1beta1.samples; + +// [START +// recommendationengine_v1beta1_generated_catalogserviceclient_createcatalogitem_stringcatalogitem_sync] +import com.google.cloud.recommendationengine.v1beta1.CatalogItem; +import com.google.cloud.recommendationengine.v1beta1.CatalogName; +import com.google.cloud.recommendationengine.v1beta1.CatalogServiceClient; + +public class SyncCreateCatalogItemStringCatalogitem { + + public static void main(String[] args) throws Exception { + syncCreateCatalogItemStringCatalogitem(); + } + + public static void syncCreateCatalogItemStringCatalogitem() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) { + String parent = CatalogName.of("[PROJECT]", "[LOCATION]", "[CATALOG]").toString(); + CatalogItem catalogItem = CatalogItem.newBuilder().build(); + CatalogItem response = catalogServiceClient.createCatalogItem(parent, catalogItem); + } + } +} +// [END +// recommendationengine_v1beta1_generated_catalogserviceclient_createcatalogitem_stringcatalogitem_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/deletecatalogitem/AsyncDeleteCatalogItem.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/deletecatalogitem/AsyncDeleteCatalogItem.java new file mode 100644 index 000000000000..1aaf20dd19a5 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/deletecatalogitem/AsyncDeleteCatalogItem.java @@ -0,0 +1,50 @@ +/* + * 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.recommendationengine.v1beta1.samples; + +// [START recommendationengine_v1beta1_generated_catalogserviceclient_deletecatalogitem_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.recommendationengine.v1beta1.CatalogItemPathName; +import com.google.cloud.recommendationengine.v1beta1.CatalogServiceClient; +import com.google.cloud.recommendationengine.v1beta1.DeleteCatalogItemRequest; +import com.google.protobuf.Empty; + +public class AsyncDeleteCatalogItem { + + public static void main(String[] args) throws Exception { + asyncDeleteCatalogItem(); + } + + public static void asyncDeleteCatalogItem() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) { + DeleteCatalogItemRequest request = + DeleteCatalogItemRequest.newBuilder() + .setName( + CatalogItemPathName.of( + "[PROJECT]", "[LOCATION]", "[CATALOG]", "[CATALOG_ITEM_PATH]") + .toString()) + .build(); + ApiFuture future = + catalogServiceClient.deleteCatalogItemCallable().futureCall(request); + // Do something. + future.get(); + } + } +} +// [END recommendationengine_v1beta1_generated_catalogserviceclient_deletecatalogitem_async] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/deletecatalogitem/SyncDeleteCatalogItem.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/deletecatalogitem/SyncDeleteCatalogItem.java new file mode 100644 index 000000000000..27a4ed225528 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/deletecatalogitem/SyncDeleteCatalogItem.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.recommendationengine.v1beta1.samples; + +// [START recommendationengine_v1beta1_generated_catalogserviceclient_deletecatalogitem_sync] +import com.google.cloud.recommendationengine.v1beta1.CatalogItemPathName; +import com.google.cloud.recommendationengine.v1beta1.CatalogServiceClient; +import com.google.cloud.recommendationengine.v1beta1.DeleteCatalogItemRequest; + +public class SyncDeleteCatalogItem { + + public static void main(String[] args) throws Exception { + syncDeleteCatalogItem(); + } + + public static void syncDeleteCatalogItem() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) { + DeleteCatalogItemRequest request = + DeleteCatalogItemRequest.newBuilder() + .setName( + CatalogItemPathName.of( + "[PROJECT]", "[LOCATION]", "[CATALOG]", "[CATALOG_ITEM_PATH]") + .toString()) + .build(); + catalogServiceClient.deleteCatalogItem(request); + } + } +} +// [END recommendationengine_v1beta1_generated_catalogserviceclient_deletecatalogitem_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/deletecatalogitem/SyncDeleteCatalogItemCatalogitempathname.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/deletecatalogitem/SyncDeleteCatalogItemCatalogitempathname.java new file mode 100644 index 000000000000..73212007a91a --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/deletecatalogitem/SyncDeleteCatalogItemCatalogitempathname.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.recommendationengine.v1beta1.samples; + +// [START +// recommendationengine_v1beta1_generated_catalogserviceclient_deletecatalogitem_catalogitempathname_sync] +import com.google.cloud.recommendationengine.v1beta1.CatalogItemPathName; +import com.google.cloud.recommendationengine.v1beta1.CatalogServiceClient; + +public class SyncDeleteCatalogItemCatalogitempathname { + + public static void main(String[] args) throws Exception { + syncDeleteCatalogItemCatalogitempathname(); + } + + public static void syncDeleteCatalogItemCatalogitempathname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) { + CatalogItemPathName name = + CatalogItemPathName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[CATALOG_ITEM_PATH]"); + catalogServiceClient.deleteCatalogItem(name); + } + } +} +// [END +// recommendationengine_v1beta1_generated_catalogserviceclient_deletecatalogitem_catalogitempathname_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/deletecatalogitem/SyncDeleteCatalogItemString.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/deletecatalogitem/SyncDeleteCatalogItemString.java new file mode 100644 index 000000000000..58bcb48216b5 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/deletecatalogitem/SyncDeleteCatalogItemString.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.recommendationengine.v1beta1.samples; + +// [START recommendationengine_v1beta1_generated_catalogserviceclient_deletecatalogitem_string_sync] +import com.google.cloud.recommendationengine.v1beta1.CatalogItemPathName; +import com.google.cloud.recommendationengine.v1beta1.CatalogServiceClient; + +public class SyncDeleteCatalogItemString { + + public static void main(String[] args) throws Exception { + syncDeleteCatalogItemString(); + } + + public static void syncDeleteCatalogItemString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) { + String name = + CatalogItemPathName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[CATALOG_ITEM_PATH]") + .toString(); + catalogServiceClient.deleteCatalogItem(name); + } + } +} +// [END recommendationengine_v1beta1_generated_catalogserviceclient_deletecatalogitem_string_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/getcatalogitem/AsyncGetCatalogItem.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/getcatalogitem/AsyncGetCatalogItem.java new file mode 100644 index 000000000000..96cf076cb435 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/getcatalogitem/AsyncGetCatalogItem.java @@ -0,0 +1,50 @@ +/* + * 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.recommendationengine.v1beta1.samples; + +// [START recommendationengine_v1beta1_generated_catalogserviceclient_getcatalogitem_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.recommendationengine.v1beta1.CatalogItem; +import com.google.cloud.recommendationengine.v1beta1.CatalogItemPathName; +import com.google.cloud.recommendationengine.v1beta1.CatalogServiceClient; +import com.google.cloud.recommendationengine.v1beta1.GetCatalogItemRequest; + +public class AsyncGetCatalogItem { + + public static void main(String[] args) throws Exception { + asyncGetCatalogItem(); + } + + public static void asyncGetCatalogItem() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) { + GetCatalogItemRequest request = + GetCatalogItemRequest.newBuilder() + .setName( + CatalogItemPathName.of( + "[PROJECT]", "[LOCATION]", "[CATALOG]", "[CATALOG_ITEM_PATH]") + .toString()) + .build(); + ApiFuture future = + catalogServiceClient.getCatalogItemCallable().futureCall(request); + // Do something. + CatalogItem response = future.get(); + } + } +} +// [END recommendationengine_v1beta1_generated_catalogserviceclient_getcatalogitem_async] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/getcatalogitem/SyncGetCatalogItem.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/getcatalogitem/SyncGetCatalogItem.java new file mode 100644 index 000000000000..7afb1145399c --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/getcatalogitem/SyncGetCatalogItem.java @@ -0,0 +1,46 @@ +/* + * 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.recommendationengine.v1beta1.samples; + +// [START recommendationengine_v1beta1_generated_catalogserviceclient_getcatalogitem_sync] +import com.google.cloud.recommendationengine.v1beta1.CatalogItem; +import com.google.cloud.recommendationengine.v1beta1.CatalogItemPathName; +import com.google.cloud.recommendationengine.v1beta1.CatalogServiceClient; +import com.google.cloud.recommendationengine.v1beta1.GetCatalogItemRequest; + +public class SyncGetCatalogItem { + + public static void main(String[] args) throws Exception { + syncGetCatalogItem(); + } + + public static void syncGetCatalogItem() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) { + GetCatalogItemRequest request = + GetCatalogItemRequest.newBuilder() + .setName( + CatalogItemPathName.of( + "[PROJECT]", "[LOCATION]", "[CATALOG]", "[CATALOG_ITEM_PATH]") + .toString()) + .build(); + CatalogItem response = catalogServiceClient.getCatalogItem(request); + } + } +} +// [END recommendationengine_v1beta1_generated_catalogserviceclient_getcatalogitem_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/getcatalogitem/SyncGetCatalogItemCatalogitempathname.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/getcatalogitem/SyncGetCatalogItemCatalogitempathname.java new file mode 100644 index 000000000000..54a4de84060e --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/getcatalogitem/SyncGetCatalogItemCatalogitempathname.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.recommendationengine.v1beta1.samples; + +// [START +// recommendationengine_v1beta1_generated_catalogserviceclient_getcatalogitem_catalogitempathname_sync] +import com.google.cloud.recommendationengine.v1beta1.CatalogItem; +import com.google.cloud.recommendationengine.v1beta1.CatalogItemPathName; +import com.google.cloud.recommendationengine.v1beta1.CatalogServiceClient; + +public class SyncGetCatalogItemCatalogitempathname { + + public static void main(String[] args) throws Exception { + syncGetCatalogItemCatalogitempathname(); + } + + public static void syncGetCatalogItemCatalogitempathname() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) { + CatalogItemPathName name = + CatalogItemPathName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[CATALOG_ITEM_PATH]"); + CatalogItem response = catalogServiceClient.getCatalogItem(name); + } + } +} +// [END +// recommendationengine_v1beta1_generated_catalogserviceclient_getcatalogitem_catalogitempathname_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/getcatalogitem/SyncGetCatalogItemString.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/getcatalogitem/SyncGetCatalogItemString.java new file mode 100644 index 000000000000..c28aec804bb8 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/getcatalogitem/SyncGetCatalogItemString.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.recommendationengine.v1beta1.samples; + +// [START recommendationengine_v1beta1_generated_catalogserviceclient_getcatalogitem_string_sync] +import com.google.cloud.recommendationengine.v1beta1.CatalogItem; +import com.google.cloud.recommendationengine.v1beta1.CatalogItemPathName; +import com.google.cloud.recommendationengine.v1beta1.CatalogServiceClient; + +public class SyncGetCatalogItemString { + + public static void main(String[] args) throws Exception { + syncGetCatalogItemString(); + } + + public static void syncGetCatalogItemString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) { + String name = + CatalogItemPathName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[CATALOG_ITEM_PATH]") + .toString(); + CatalogItem response = catalogServiceClient.getCatalogItem(name); + } + } +} +// [END recommendationengine_v1beta1_generated_catalogserviceclient_getcatalogitem_string_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/importcatalogitems/AsyncImportCatalogItems.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/importcatalogitems/AsyncImportCatalogItems.java new file mode 100644 index 000000000000..dcf138689428 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/importcatalogitems/AsyncImportCatalogItems.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.recommendationengine.v1beta1.samples; + +// [START recommendationengine_v1beta1_generated_catalogserviceclient_importcatalogitems_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.recommendationengine.v1beta1.CatalogName; +import com.google.cloud.recommendationengine.v1beta1.CatalogServiceClient; +import com.google.cloud.recommendationengine.v1beta1.ImportCatalogItemsRequest; +import com.google.cloud.recommendationengine.v1beta1.ImportErrorsConfig; +import com.google.cloud.recommendationengine.v1beta1.InputConfig; +import com.google.longrunning.Operation; + +public class AsyncImportCatalogItems { + + public static void main(String[] args) throws Exception { + asyncImportCatalogItems(); + } + + public static void asyncImportCatalogItems() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) { + ImportCatalogItemsRequest request = + ImportCatalogItemsRequest.newBuilder() + .setParent(CatalogName.of("[PROJECT]", "[LOCATION]", "[CATALOG]").toString()) + .setRequestId("requestId693933066") + .setInputConfig(InputConfig.newBuilder().build()) + .setErrorsConfig(ImportErrorsConfig.newBuilder().build()) + .build(); + ApiFuture future = + catalogServiceClient.importCatalogItemsCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END recommendationengine_v1beta1_generated_catalogserviceclient_importcatalogitems_async] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/importcatalogitems/AsyncImportCatalogItemsLRO.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/importcatalogitems/AsyncImportCatalogItemsLRO.java new file mode 100644 index 000000000000..c5166c682b2c --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/importcatalogitems/AsyncImportCatalogItemsLRO.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.recommendationengine.v1beta1.samples; + +// [START recommendationengine_v1beta1_generated_catalogserviceclient_importcatalogitems_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.recommendationengine.v1beta1.CatalogName; +import com.google.cloud.recommendationengine.v1beta1.CatalogServiceClient; +import com.google.cloud.recommendationengine.v1beta1.ImportCatalogItemsRequest; +import com.google.cloud.recommendationengine.v1beta1.ImportCatalogItemsResponse; +import com.google.cloud.recommendationengine.v1beta1.ImportErrorsConfig; +import com.google.cloud.recommendationengine.v1beta1.ImportMetadata; +import com.google.cloud.recommendationengine.v1beta1.InputConfig; + +public class AsyncImportCatalogItemsLRO { + + public static void main(String[] args) throws Exception { + asyncImportCatalogItemsLRO(); + } + + public static void asyncImportCatalogItemsLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) { + ImportCatalogItemsRequest request = + ImportCatalogItemsRequest.newBuilder() + .setParent(CatalogName.of("[PROJECT]", "[LOCATION]", "[CATALOG]").toString()) + .setRequestId("requestId693933066") + .setInputConfig(InputConfig.newBuilder().build()) + .setErrorsConfig(ImportErrorsConfig.newBuilder().build()) + .build(); + OperationFuture future = + catalogServiceClient.importCatalogItemsOperationCallable().futureCall(request); + // Do something. + ImportCatalogItemsResponse response = future.get(); + } + } +} +// [END recommendationengine_v1beta1_generated_catalogserviceclient_importcatalogitems_lro_async] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/importcatalogitems/SyncImportCatalogItems.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/importcatalogitems/SyncImportCatalogItems.java new file mode 100644 index 000000000000..d2487f20f693 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/importcatalogitems/SyncImportCatalogItems.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.recommendationengine.v1beta1.samples; + +// [START recommendationengine_v1beta1_generated_catalogserviceclient_importcatalogitems_sync] +import com.google.cloud.recommendationengine.v1beta1.CatalogName; +import com.google.cloud.recommendationengine.v1beta1.CatalogServiceClient; +import com.google.cloud.recommendationengine.v1beta1.ImportCatalogItemsRequest; +import com.google.cloud.recommendationengine.v1beta1.ImportCatalogItemsResponse; +import com.google.cloud.recommendationengine.v1beta1.ImportErrorsConfig; +import com.google.cloud.recommendationengine.v1beta1.InputConfig; + +public class SyncImportCatalogItems { + + public static void main(String[] args) throws Exception { + syncImportCatalogItems(); + } + + public static void syncImportCatalogItems() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) { + ImportCatalogItemsRequest request = + ImportCatalogItemsRequest.newBuilder() + .setParent(CatalogName.of("[PROJECT]", "[LOCATION]", "[CATALOG]").toString()) + .setRequestId("requestId693933066") + .setInputConfig(InputConfig.newBuilder().build()) + .setErrorsConfig(ImportErrorsConfig.newBuilder().build()) + .build(); + ImportCatalogItemsResponse response = + catalogServiceClient.importCatalogItemsAsync(request).get(); + } + } +} +// [END recommendationengine_v1beta1_generated_catalogserviceclient_importcatalogitems_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/importcatalogitems/SyncImportCatalogItemsCatalognameStringInputconfigImporterrorsconfig.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/importcatalogitems/SyncImportCatalogItemsCatalognameStringInputconfigImporterrorsconfig.java new file mode 100644 index 000000000000..2829d65234c8 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/importcatalogitems/SyncImportCatalogItemsCatalognameStringInputconfigImporterrorsconfig.java @@ -0,0 +1,50 @@ +/* + * 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.recommendationengine.v1beta1.samples; + +// [START +// recommendationengine_v1beta1_generated_catalogserviceclient_importcatalogitems_catalognamestringinputconfigimporterrorsconfig_sync] +import com.google.cloud.recommendationengine.v1beta1.CatalogName; +import com.google.cloud.recommendationengine.v1beta1.CatalogServiceClient; +import com.google.cloud.recommendationengine.v1beta1.ImportCatalogItemsResponse; +import com.google.cloud.recommendationengine.v1beta1.ImportErrorsConfig; +import com.google.cloud.recommendationengine.v1beta1.InputConfig; + +public class SyncImportCatalogItemsCatalognameStringInputconfigImporterrorsconfig { + + public static void main(String[] args) throws Exception { + syncImportCatalogItemsCatalognameStringInputconfigImporterrorsconfig(); + } + + public static void syncImportCatalogItemsCatalognameStringInputconfigImporterrorsconfig() + throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) { + CatalogName parent = CatalogName.of("[PROJECT]", "[LOCATION]", "[CATALOG]"); + String requestId = "requestId693933066"; + InputConfig inputConfig = InputConfig.newBuilder().build(); + ImportErrorsConfig errorsConfig = ImportErrorsConfig.newBuilder().build(); + ImportCatalogItemsResponse response = + catalogServiceClient + .importCatalogItemsAsync(parent, requestId, inputConfig, errorsConfig) + .get(); + } + } +} +// [END +// recommendationengine_v1beta1_generated_catalogserviceclient_importcatalogitems_catalognamestringinputconfigimporterrorsconfig_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/importcatalogitems/SyncImportCatalogItemsStringStringInputconfigImporterrorsconfig.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/importcatalogitems/SyncImportCatalogItemsStringStringInputconfigImporterrorsconfig.java new file mode 100644 index 000000000000..bece54fa3206 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/importcatalogitems/SyncImportCatalogItemsStringStringInputconfigImporterrorsconfig.java @@ -0,0 +1,50 @@ +/* + * 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.recommendationengine.v1beta1.samples; + +// [START +// recommendationengine_v1beta1_generated_catalogserviceclient_importcatalogitems_stringstringinputconfigimporterrorsconfig_sync] +import com.google.cloud.recommendationengine.v1beta1.CatalogName; +import com.google.cloud.recommendationengine.v1beta1.CatalogServiceClient; +import com.google.cloud.recommendationengine.v1beta1.ImportCatalogItemsResponse; +import com.google.cloud.recommendationengine.v1beta1.ImportErrorsConfig; +import com.google.cloud.recommendationengine.v1beta1.InputConfig; + +public class SyncImportCatalogItemsStringStringInputconfigImporterrorsconfig { + + public static void main(String[] args) throws Exception { + syncImportCatalogItemsStringStringInputconfigImporterrorsconfig(); + } + + public static void syncImportCatalogItemsStringStringInputconfigImporterrorsconfig() + throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) { + String parent = CatalogName.of("[PROJECT]", "[LOCATION]", "[CATALOG]").toString(); + String requestId = "requestId693933066"; + InputConfig inputConfig = InputConfig.newBuilder().build(); + ImportErrorsConfig errorsConfig = ImportErrorsConfig.newBuilder().build(); + ImportCatalogItemsResponse response = + catalogServiceClient + .importCatalogItemsAsync(parent, requestId, inputConfig, errorsConfig) + .get(); + } + } +} +// [END +// recommendationengine_v1beta1_generated_catalogserviceclient_importcatalogitems_stringstringinputconfigimporterrorsconfig_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/listcatalogitems/AsyncListCatalogItems.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/listcatalogitems/AsyncListCatalogItems.java new file mode 100644 index 000000000000..10012053a463 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/listcatalogitems/AsyncListCatalogItems.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.recommendationengine.v1beta1.samples; + +// [START recommendationengine_v1beta1_generated_catalogserviceclient_listcatalogitems_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.recommendationengine.v1beta1.CatalogItem; +import com.google.cloud.recommendationengine.v1beta1.CatalogName; +import com.google.cloud.recommendationengine.v1beta1.CatalogServiceClient; +import com.google.cloud.recommendationengine.v1beta1.ListCatalogItemsRequest; + +public class AsyncListCatalogItems { + + public static void main(String[] args) throws Exception { + asyncListCatalogItems(); + } + + public static void asyncListCatalogItems() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) { + ListCatalogItemsRequest request = + ListCatalogItemsRequest.newBuilder() + .setParent(CatalogName.of("[PROJECT]", "[LOCATION]", "[CATALOG]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .build(); + ApiFuture future = + catalogServiceClient.listCatalogItemsPagedCallable().futureCall(request); + // Do something. + for (CatalogItem element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END recommendationengine_v1beta1_generated_catalogserviceclient_listcatalogitems_async] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/listcatalogitems/AsyncListCatalogItemsPaged.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/listcatalogitems/AsyncListCatalogItemsPaged.java new file mode 100644 index 000000000000..43356e9aa73a --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/listcatalogitems/AsyncListCatalogItemsPaged.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.recommendationengine.v1beta1.samples; + +// [START recommendationengine_v1beta1_generated_catalogserviceclient_listcatalogitems_paged_async] +import com.google.cloud.recommendationengine.v1beta1.CatalogItem; +import com.google.cloud.recommendationengine.v1beta1.CatalogName; +import com.google.cloud.recommendationengine.v1beta1.CatalogServiceClient; +import com.google.cloud.recommendationengine.v1beta1.ListCatalogItemsRequest; +import com.google.cloud.recommendationengine.v1beta1.ListCatalogItemsResponse; +import com.google.common.base.Strings; + +public class AsyncListCatalogItemsPaged { + + public static void main(String[] args) throws Exception { + asyncListCatalogItemsPaged(); + } + + public static void asyncListCatalogItemsPaged() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) { + ListCatalogItemsRequest request = + ListCatalogItemsRequest.newBuilder() + .setParent(CatalogName.of("[PROJECT]", "[LOCATION]", "[CATALOG]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .build(); + while (true) { + ListCatalogItemsResponse response = + catalogServiceClient.listCatalogItemsCallable().call(request); + for (CatalogItem element : response.getCatalogItemsList()) { + // doThingsWith(element); + } + String nextPageToken = response.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + request = request.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END recommendationengine_v1beta1_generated_catalogserviceclient_listcatalogitems_paged_async] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/listcatalogitems/SyncListCatalogItems.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/listcatalogitems/SyncListCatalogItems.java new file mode 100644 index 000000000000..a200effaaf6a --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/listcatalogitems/SyncListCatalogItems.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.recommendationengine.v1beta1.samples; + +// [START recommendationengine_v1beta1_generated_catalogserviceclient_listcatalogitems_sync] +import com.google.cloud.recommendationengine.v1beta1.CatalogItem; +import com.google.cloud.recommendationengine.v1beta1.CatalogName; +import com.google.cloud.recommendationengine.v1beta1.CatalogServiceClient; +import com.google.cloud.recommendationengine.v1beta1.ListCatalogItemsRequest; + +public class SyncListCatalogItems { + + public static void main(String[] args) throws Exception { + syncListCatalogItems(); + } + + public static void syncListCatalogItems() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) { + ListCatalogItemsRequest request = + ListCatalogItemsRequest.newBuilder() + .setParent(CatalogName.of("[PROJECT]", "[LOCATION]", "[CATALOG]").toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .build(); + for (CatalogItem element : catalogServiceClient.listCatalogItems(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END recommendationengine_v1beta1_generated_catalogserviceclient_listcatalogitems_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/listcatalogitems/SyncListCatalogItemsCatalognameString.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/listcatalogitems/SyncListCatalogItemsCatalognameString.java new file mode 100644 index 000000000000..7f327e669d5d --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/listcatalogitems/SyncListCatalogItemsCatalognameString.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.recommendationengine.v1beta1.samples; + +// [START +// recommendationengine_v1beta1_generated_catalogserviceclient_listcatalogitems_catalognamestring_sync] +import com.google.cloud.recommendationengine.v1beta1.CatalogItem; +import com.google.cloud.recommendationengine.v1beta1.CatalogName; +import com.google.cloud.recommendationengine.v1beta1.CatalogServiceClient; + +public class SyncListCatalogItemsCatalognameString { + + public static void main(String[] args) throws Exception { + syncListCatalogItemsCatalognameString(); + } + + public static void syncListCatalogItemsCatalognameString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) { + CatalogName parent = CatalogName.of("[PROJECT]", "[LOCATION]", "[CATALOG]"); + String filter = "filter-1274492040"; + for (CatalogItem element : + catalogServiceClient.listCatalogItems(parent, filter).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END +// recommendationengine_v1beta1_generated_catalogserviceclient_listcatalogitems_catalognamestring_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/listcatalogitems/SyncListCatalogItemsStringString.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/listcatalogitems/SyncListCatalogItemsStringString.java new file mode 100644 index 000000000000..bb3b84d293d6 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/listcatalogitems/SyncListCatalogItemsStringString.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.recommendationengine.v1beta1.samples; + +// [START +// recommendationengine_v1beta1_generated_catalogserviceclient_listcatalogitems_stringstring_sync] +import com.google.cloud.recommendationengine.v1beta1.CatalogItem; +import com.google.cloud.recommendationengine.v1beta1.CatalogName; +import com.google.cloud.recommendationengine.v1beta1.CatalogServiceClient; + +public class SyncListCatalogItemsStringString { + + public static void main(String[] args) throws Exception { + syncListCatalogItemsStringString(); + } + + public static void syncListCatalogItemsStringString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) { + String parent = CatalogName.of("[PROJECT]", "[LOCATION]", "[CATALOG]").toString(); + String filter = "filter-1274492040"; + for (CatalogItem element : + catalogServiceClient.listCatalogItems(parent, filter).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END +// recommendationengine_v1beta1_generated_catalogserviceclient_listcatalogitems_stringstring_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/updatecatalogitem/AsyncUpdateCatalogItem.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/updatecatalogitem/AsyncUpdateCatalogItem.java new file mode 100644 index 000000000000..df12ae963380 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/updatecatalogitem/AsyncUpdateCatalogItem.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.recommendationengine.v1beta1.samples; + +// [START recommendationengine_v1beta1_generated_catalogserviceclient_updatecatalogitem_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.recommendationengine.v1beta1.CatalogItem; +import com.google.cloud.recommendationengine.v1beta1.CatalogItemPathName; +import com.google.cloud.recommendationengine.v1beta1.CatalogServiceClient; +import com.google.cloud.recommendationengine.v1beta1.UpdateCatalogItemRequest; +import com.google.protobuf.FieldMask; + +public class AsyncUpdateCatalogItem { + + public static void main(String[] args) throws Exception { + asyncUpdateCatalogItem(); + } + + public static void asyncUpdateCatalogItem() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) { + UpdateCatalogItemRequest request = + UpdateCatalogItemRequest.newBuilder() + .setName( + CatalogItemPathName.of( + "[PROJECT]", "[LOCATION]", "[CATALOG]", "[CATALOG_ITEM_PATH]") + .toString()) + .setCatalogItem(CatalogItem.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + ApiFuture future = + catalogServiceClient.updateCatalogItemCallable().futureCall(request); + // Do something. + CatalogItem response = future.get(); + } + } +} +// [END recommendationengine_v1beta1_generated_catalogserviceclient_updatecatalogitem_async] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/updatecatalogitem/SyncUpdateCatalogItem.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/updatecatalogitem/SyncUpdateCatalogItem.java new file mode 100644 index 000000000000..ad9a4b94a937 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/updatecatalogitem/SyncUpdateCatalogItem.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.recommendationengine.v1beta1.samples; + +// [START recommendationengine_v1beta1_generated_catalogserviceclient_updatecatalogitem_sync] +import com.google.cloud.recommendationengine.v1beta1.CatalogItem; +import com.google.cloud.recommendationengine.v1beta1.CatalogItemPathName; +import com.google.cloud.recommendationengine.v1beta1.CatalogServiceClient; +import com.google.cloud.recommendationengine.v1beta1.UpdateCatalogItemRequest; +import com.google.protobuf.FieldMask; + +public class SyncUpdateCatalogItem { + + public static void main(String[] args) throws Exception { + syncUpdateCatalogItem(); + } + + public static void syncUpdateCatalogItem() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) { + UpdateCatalogItemRequest request = + UpdateCatalogItemRequest.newBuilder() + .setName( + CatalogItemPathName.of( + "[PROJECT]", "[LOCATION]", "[CATALOG]", "[CATALOG_ITEM_PATH]") + .toString()) + .setCatalogItem(CatalogItem.newBuilder().build()) + .setUpdateMask(FieldMask.newBuilder().build()) + .build(); + CatalogItem response = catalogServiceClient.updateCatalogItem(request); + } + } +} +// [END recommendationengine_v1beta1_generated_catalogserviceclient_updatecatalogitem_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/updatecatalogitem/SyncUpdateCatalogItemCatalogitempathnameCatalogitemFieldmask.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/updatecatalogitem/SyncUpdateCatalogItemCatalogitempathnameCatalogitemFieldmask.java new file mode 100644 index 000000000000..6f2c3d5865bc --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/updatecatalogitem/SyncUpdateCatalogItemCatalogitempathnameCatalogitemFieldmask.java @@ -0,0 +1,46 @@ +/* + * 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.recommendationengine.v1beta1.samples; + +// [START +// recommendationengine_v1beta1_generated_catalogserviceclient_updatecatalogitem_catalogitempathnamecatalogitemfieldmask_sync] +import com.google.cloud.recommendationengine.v1beta1.CatalogItem; +import com.google.cloud.recommendationengine.v1beta1.CatalogItemPathName; +import com.google.cloud.recommendationengine.v1beta1.CatalogServiceClient; +import com.google.protobuf.FieldMask; + +public class SyncUpdateCatalogItemCatalogitempathnameCatalogitemFieldmask { + + public static void main(String[] args) throws Exception { + syncUpdateCatalogItemCatalogitempathnameCatalogitemFieldmask(); + } + + public static void syncUpdateCatalogItemCatalogitempathnameCatalogitemFieldmask() + throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) { + CatalogItemPathName name = + CatalogItemPathName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[CATALOG_ITEM_PATH]"); + CatalogItem catalogItem = CatalogItem.newBuilder().build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + CatalogItem response = catalogServiceClient.updateCatalogItem(name, catalogItem, updateMask); + } + } +} +// [END +// recommendationengine_v1beta1_generated_catalogserviceclient_updatecatalogitem_catalogitempathnamecatalogitemfieldmask_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/updatecatalogitem/SyncUpdateCatalogItemStringCatalogitemFieldmask.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/updatecatalogitem/SyncUpdateCatalogItemStringCatalogitemFieldmask.java new file mode 100644 index 000000000000..b0e3f2748dc7 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogserviceclient/updatecatalogitem/SyncUpdateCatalogItemStringCatalogitemFieldmask.java @@ -0,0 +1,46 @@ +/* + * 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.recommendationengine.v1beta1.samples; + +// [START +// recommendationengine_v1beta1_generated_catalogserviceclient_updatecatalogitem_stringcatalogitemfieldmask_sync] +import com.google.cloud.recommendationengine.v1beta1.CatalogItem; +import com.google.cloud.recommendationengine.v1beta1.CatalogItemPathName; +import com.google.cloud.recommendationengine.v1beta1.CatalogServiceClient; +import com.google.protobuf.FieldMask; + +public class SyncUpdateCatalogItemStringCatalogitemFieldmask { + + public static void main(String[] args) throws Exception { + syncUpdateCatalogItemStringCatalogitemFieldmask(); + } + + public static void syncUpdateCatalogItemStringCatalogitemFieldmask() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) { + String name = + CatalogItemPathName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[CATALOG_ITEM_PATH]") + .toString(); + CatalogItem catalogItem = CatalogItem.newBuilder().build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + CatalogItem response = catalogServiceClient.updateCatalogItem(name, catalogItem, updateMask); + } + } +} +// [END +// recommendationengine_v1beta1_generated_catalogserviceclient_updatecatalogitem_stringcatalogitemfieldmask_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogservicesettings/createcatalogitem/SyncCreateCatalogItem.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogservicesettings/createcatalogitem/SyncCreateCatalogItem.java new file mode 100644 index 000000000000..fb684018136b --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/catalogservicesettings/createcatalogitem/SyncCreateCatalogItem.java @@ -0,0 +1,46 @@ +/* + * 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.recommendationengine.v1beta1.samples; + +// [START recommendationengine_v1beta1_generated_catalogservicesettings_createcatalogitem_sync] +import com.google.cloud.recommendationengine.v1beta1.CatalogServiceSettings; +import java.time.Duration; + +public class SyncCreateCatalogItem { + + public static void main(String[] args) throws Exception { + syncCreateCatalogItem(); + } + + public static void syncCreateCatalogItem() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + CatalogServiceSettings.Builder catalogServiceSettingsBuilder = + CatalogServiceSettings.newBuilder(); + catalogServiceSettingsBuilder + .createCatalogItemSettings() + .setRetrySettings( + catalogServiceSettingsBuilder + .createCatalogItemSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + CatalogServiceSettings catalogServiceSettings = catalogServiceSettingsBuilder.build(); + } +} +// [END recommendationengine_v1beta1_generated_catalogservicesettings_createcatalogitem_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionapikeyregistryclient/create/SyncCreateSetCredentialsProvider.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionapikeyregistryclient/create/SyncCreateSetCredentialsProvider.java new file mode 100644 index 000000000000..be2660f9ce48 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionapikeyregistryclient/create/SyncCreateSetCredentialsProvider.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.recommendationengine.v1beta1.samples; + +// [START +// recommendationengine_v1beta1_generated_predictionapikeyregistryclient_create_setcredentialsprovider_sync] +import com.google.api.gax.core.FixedCredentialsProvider; +import com.google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistryClient; +import com.google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistrySettings; +import com.google.cloud.recommendationengine.v1beta1.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. + PredictionApiKeyRegistrySettings predictionApiKeyRegistrySettings = + PredictionApiKeyRegistrySettings.newBuilder() + .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) + .build(); + PredictionApiKeyRegistryClient predictionApiKeyRegistryClient = + PredictionApiKeyRegistryClient.create(predictionApiKeyRegistrySettings); + } +} +// [END +// recommendationengine_v1beta1_generated_predictionapikeyregistryclient_create_setcredentialsprovider_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionapikeyregistryclient/create/SyncCreateSetCredentialsProvider1.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionapikeyregistryclient/create/SyncCreateSetCredentialsProvider1.java new file mode 100644 index 000000000000..1df36d584612 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionapikeyregistryclient/create/SyncCreateSetCredentialsProvider1.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.recommendationengine.v1beta1.samples; + +// [START +// recommendationengine_v1beta1_generated_predictionapikeyregistryclient_create_setcredentialsprovider1_sync] +import com.google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistryClient; +import com.google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistrySettings; + +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. + PredictionApiKeyRegistrySettings predictionApiKeyRegistrySettings = + PredictionApiKeyRegistrySettings.newBuilder() + .setTransportChannelProvider( + PredictionApiKeyRegistrySettings.defaultHttpJsonTransportProviderBuilder().build()) + .build(); + PredictionApiKeyRegistryClient predictionApiKeyRegistryClient = + PredictionApiKeyRegistryClient.create(predictionApiKeyRegistrySettings); + } +} +// [END +// recommendationengine_v1beta1_generated_predictionapikeyregistryclient_create_setcredentialsprovider1_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionapikeyregistryclient/create/SyncCreateSetEndpoint.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionapikeyregistryclient/create/SyncCreateSetEndpoint.java new file mode 100644 index 000000000000..3f593c0870d1 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionapikeyregistryclient/create/SyncCreateSetEndpoint.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.recommendationengine.v1beta1.samples; + +// [START +// recommendationengine_v1beta1_generated_predictionapikeyregistryclient_create_setendpoint_sync] +import com.google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistryClient; +import com.google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistrySettings; +import com.google.cloud.recommendationengine.v1beta1.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. + PredictionApiKeyRegistrySettings predictionApiKeyRegistrySettings = + PredictionApiKeyRegistrySettings.newBuilder().setEndpoint(myEndpoint).build(); + PredictionApiKeyRegistryClient predictionApiKeyRegistryClient = + PredictionApiKeyRegistryClient.create(predictionApiKeyRegistrySettings); + } +} +// [END +// recommendationengine_v1beta1_generated_predictionapikeyregistryclient_create_setendpoint_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionapikeyregistryclient/createpredictionapikeyregistration/AsyncCreatePredictionApiKeyRegistration.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionapikeyregistryclient/createpredictionapikeyregistration/AsyncCreatePredictionApiKeyRegistration.java new file mode 100644 index 000000000000..9f48a4a7b548 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionapikeyregistryclient/createpredictionapikeyregistration/AsyncCreatePredictionApiKeyRegistration.java @@ -0,0 +1,55 @@ +/* + * 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.recommendationengine.v1beta1.samples; + +// [START +// recommendationengine_v1beta1_generated_predictionapikeyregistryclient_createpredictionapikeyregistration_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.recommendationengine.v1beta1.CreatePredictionApiKeyRegistrationRequest; +import com.google.cloud.recommendationengine.v1beta1.EventStoreName; +import com.google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistration; +import com.google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistryClient; + +public class AsyncCreatePredictionApiKeyRegistration { + + public static void main(String[] args) throws Exception { + asyncCreatePredictionApiKeyRegistration(); + } + + public static void asyncCreatePredictionApiKeyRegistration() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (PredictionApiKeyRegistryClient predictionApiKeyRegistryClient = + PredictionApiKeyRegistryClient.create()) { + CreatePredictionApiKeyRegistrationRequest request = + CreatePredictionApiKeyRegistrationRequest.newBuilder() + .setParent( + EventStoreName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]") + .toString()) + .setPredictionApiKeyRegistration(PredictionApiKeyRegistration.newBuilder().build()) + .build(); + ApiFuture future = + predictionApiKeyRegistryClient + .createPredictionApiKeyRegistrationCallable() + .futureCall(request); + // Do something. + PredictionApiKeyRegistration response = future.get(); + } + } +} +// [END +// recommendationengine_v1beta1_generated_predictionapikeyregistryclient_createpredictionapikeyregistration_async] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionapikeyregistryclient/createpredictionapikeyregistration/SyncCreatePredictionApiKeyRegistration.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionapikeyregistryclient/createpredictionapikeyregistration/SyncCreatePredictionApiKeyRegistration.java new file mode 100644 index 000000000000..3ebd18c2c04a --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionapikeyregistryclient/createpredictionapikeyregistration/SyncCreatePredictionApiKeyRegistration.java @@ -0,0 +1,50 @@ +/* + * 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.recommendationengine.v1beta1.samples; + +// [START +// recommendationengine_v1beta1_generated_predictionapikeyregistryclient_createpredictionapikeyregistration_sync] +import com.google.cloud.recommendationengine.v1beta1.CreatePredictionApiKeyRegistrationRequest; +import com.google.cloud.recommendationengine.v1beta1.EventStoreName; +import com.google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistration; +import com.google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistryClient; + +public class SyncCreatePredictionApiKeyRegistration { + + public static void main(String[] args) throws Exception { + syncCreatePredictionApiKeyRegistration(); + } + + public static void syncCreatePredictionApiKeyRegistration() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (PredictionApiKeyRegistryClient predictionApiKeyRegistryClient = + PredictionApiKeyRegistryClient.create()) { + CreatePredictionApiKeyRegistrationRequest request = + CreatePredictionApiKeyRegistrationRequest.newBuilder() + .setParent( + EventStoreName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]") + .toString()) + .setPredictionApiKeyRegistration(PredictionApiKeyRegistration.newBuilder().build()) + .build(); + PredictionApiKeyRegistration response = + predictionApiKeyRegistryClient.createPredictionApiKeyRegistration(request); + } + } +} +// [END +// recommendationengine_v1beta1_generated_predictionapikeyregistryclient_createpredictionapikeyregistration_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionapikeyregistryclient/createpredictionapikeyregistration/SyncCreatePredictionApiKeyRegistrationEventstorenamePredictionapikeyregistration.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionapikeyregistryclient/createpredictionapikeyregistration/SyncCreatePredictionApiKeyRegistrationEventstorenamePredictionapikeyregistration.java new file mode 100644 index 000000000000..10919a9760e4 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionapikeyregistryclient/createpredictionapikeyregistration/SyncCreatePredictionApiKeyRegistrationEventstorenamePredictionapikeyregistration.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.recommendationengine.v1beta1.samples; + +// [START +// recommendationengine_v1beta1_generated_predictionapikeyregistryclient_createpredictionapikeyregistration_eventstorenamepredictionapikeyregistration_sync] +import com.google.cloud.recommendationengine.v1beta1.EventStoreName; +import com.google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistration; +import com.google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistryClient; + +public class SyncCreatePredictionApiKeyRegistrationEventstorenamePredictionapikeyregistration { + + public static void main(String[] args) throws Exception { + syncCreatePredictionApiKeyRegistrationEventstorenamePredictionapikeyregistration(); + } + + public static void + syncCreatePredictionApiKeyRegistrationEventstorenamePredictionapikeyregistration() + throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (PredictionApiKeyRegistryClient predictionApiKeyRegistryClient = + PredictionApiKeyRegistryClient.create()) { + EventStoreName parent = + EventStoreName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]"); + PredictionApiKeyRegistration predictionApiKeyRegistration = + PredictionApiKeyRegistration.newBuilder().build(); + PredictionApiKeyRegistration response = + predictionApiKeyRegistryClient.createPredictionApiKeyRegistration( + parent, predictionApiKeyRegistration); + } + } +} +// [END +// recommendationengine_v1beta1_generated_predictionapikeyregistryclient_createpredictionapikeyregistration_eventstorenamepredictionapikeyregistration_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionapikeyregistryclient/createpredictionapikeyregistration/SyncCreatePredictionApiKeyRegistrationStringPredictionapikeyregistration.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionapikeyregistryclient/createpredictionapikeyregistration/SyncCreatePredictionApiKeyRegistrationStringPredictionapikeyregistration.java new file mode 100644 index 000000000000..8e46c5bd70a1 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionapikeyregistryclient/createpredictionapikeyregistration/SyncCreatePredictionApiKeyRegistrationStringPredictionapikeyregistration.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.recommendationengine.v1beta1.samples; + +// [START +// recommendationengine_v1beta1_generated_predictionapikeyregistryclient_createpredictionapikeyregistration_stringpredictionapikeyregistration_sync] +import com.google.cloud.recommendationengine.v1beta1.EventStoreName; +import com.google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistration; +import com.google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistryClient; + +public class SyncCreatePredictionApiKeyRegistrationStringPredictionapikeyregistration { + + public static void main(String[] args) throws Exception { + syncCreatePredictionApiKeyRegistrationStringPredictionapikeyregistration(); + } + + public static void syncCreatePredictionApiKeyRegistrationStringPredictionapikeyregistration() + throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (PredictionApiKeyRegistryClient predictionApiKeyRegistryClient = + PredictionApiKeyRegistryClient.create()) { + String parent = + EventStoreName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]").toString(); + PredictionApiKeyRegistration predictionApiKeyRegistration = + PredictionApiKeyRegistration.newBuilder().build(); + PredictionApiKeyRegistration response = + predictionApiKeyRegistryClient.createPredictionApiKeyRegistration( + parent, predictionApiKeyRegistration); + } + } +} +// [END +// recommendationengine_v1beta1_generated_predictionapikeyregistryclient_createpredictionapikeyregistration_stringpredictionapikeyregistration_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionapikeyregistryclient/deletepredictionapikeyregistration/AsyncDeletePredictionApiKeyRegistration.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionapikeyregistryclient/deletepredictionapikeyregistration/AsyncDeletePredictionApiKeyRegistration.java new file mode 100644 index 000000000000..68db66517f6e --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionapikeyregistryclient/deletepredictionapikeyregistration/AsyncDeletePredictionApiKeyRegistration.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.recommendationengine.v1beta1.samples; + +// [START +// recommendationengine_v1beta1_generated_predictionapikeyregistryclient_deletepredictionapikeyregistration_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.recommendationengine.v1beta1.DeletePredictionApiKeyRegistrationRequest; +import com.google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistrationName; +import com.google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistryClient; +import com.google.protobuf.Empty; + +public class AsyncDeletePredictionApiKeyRegistration { + + public static void main(String[] args) throws Exception { + asyncDeletePredictionApiKeyRegistration(); + } + + public static void asyncDeletePredictionApiKeyRegistration() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (PredictionApiKeyRegistryClient predictionApiKeyRegistryClient = + PredictionApiKeyRegistryClient.create()) { + DeletePredictionApiKeyRegistrationRequest request = + DeletePredictionApiKeyRegistrationRequest.newBuilder() + .setName( + PredictionApiKeyRegistrationName.of( + "[PROJECT]", + "[LOCATION]", + "[CATALOG]", + "[EVENT_STORE]", + "[PREDICTION_API_KEY_REGISTRATION]") + .toString()) + .build(); + ApiFuture future = + predictionApiKeyRegistryClient + .deletePredictionApiKeyRegistrationCallable() + .futureCall(request); + // Do something. + future.get(); + } + } +} +// [END +// recommendationengine_v1beta1_generated_predictionapikeyregistryclient_deletepredictionapikeyregistration_async] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionapikeyregistryclient/deletepredictionapikeyregistration/SyncDeletePredictionApiKeyRegistration.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionapikeyregistryclient/deletepredictionapikeyregistration/SyncDeletePredictionApiKeyRegistration.java new file mode 100644 index 000000000000..2ad321c9b477 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionapikeyregistryclient/deletepredictionapikeyregistration/SyncDeletePredictionApiKeyRegistration.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.recommendationengine.v1beta1.samples; + +// [START +// recommendationengine_v1beta1_generated_predictionapikeyregistryclient_deletepredictionapikeyregistration_sync] +import com.google.cloud.recommendationengine.v1beta1.DeletePredictionApiKeyRegistrationRequest; +import com.google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistrationName; +import com.google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistryClient; + +public class SyncDeletePredictionApiKeyRegistration { + + public static void main(String[] args) throws Exception { + syncDeletePredictionApiKeyRegistration(); + } + + public static void syncDeletePredictionApiKeyRegistration() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (PredictionApiKeyRegistryClient predictionApiKeyRegistryClient = + PredictionApiKeyRegistryClient.create()) { + DeletePredictionApiKeyRegistrationRequest request = + DeletePredictionApiKeyRegistrationRequest.newBuilder() + .setName( + PredictionApiKeyRegistrationName.of( + "[PROJECT]", + "[LOCATION]", + "[CATALOG]", + "[EVENT_STORE]", + "[PREDICTION_API_KEY_REGISTRATION]") + .toString()) + .build(); + predictionApiKeyRegistryClient.deletePredictionApiKeyRegistration(request); + } + } +} +// [END +// recommendationengine_v1beta1_generated_predictionapikeyregistryclient_deletepredictionapikeyregistration_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionapikeyregistryclient/deletepredictionapikeyregistration/SyncDeletePredictionApiKeyRegistrationPredictionapikeyregistrationname.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionapikeyregistryclient/deletepredictionapikeyregistration/SyncDeletePredictionApiKeyRegistrationPredictionapikeyregistrationname.java new file mode 100644 index 000000000000..023ca20bc3e6 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionapikeyregistryclient/deletepredictionapikeyregistration/SyncDeletePredictionApiKeyRegistrationPredictionapikeyregistrationname.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.recommendationengine.v1beta1.samples; + +// [START +// recommendationengine_v1beta1_generated_predictionapikeyregistryclient_deletepredictionapikeyregistration_predictionapikeyregistrationname_sync] +import com.google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistrationName; +import com.google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistryClient; + +public class SyncDeletePredictionApiKeyRegistrationPredictionapikeyregistrationname { + + public static void main(String[] args) throws Exception { + syncDeletePredictionApiKeyRegistrationPredictionapikeyregistrationname(); + } + + public static void syncDeletePredictionApiKeyRegistrationPredictionapikeyregistrationname() + throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (PredictionApiKeyRegistryClient predictionApiKeyRegistryClient = + PredictionApiKeyRegistryClient.create()) { + PredictionApiKeyRegistrationName name = + PredictionApiKeyRegistrationName.of( + "[PROJECT]", + "[LOCATION]", + "[CATALOG]", + "[EVENT_STORE]", + "[PREDICTION_API_KEY_REGISTRATION]"); + predictionApiKeyRegistryClient.deletePredictionApiKeyRegistration(name); + } + } +} +// [END +// recommendationengine_v1beta1_generated_predictionapikeyregistryclient_deletepredictionapikeyregistration_predictionapikeyregistrationname_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionapikeyregistryclient/deletepredictionapikeyregistration/SyncDeletePredictionApiKeyRegistrationString.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionapikeyregistryclient/deletepredictionapikeyregistration/SyncDeletePredictionApiKeyRegistrationString.java new file mode 100644 index 000000000000..04a6f533cf69 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionapikeyregistryclient/deletepredictionapikeyregistration/SyncDeletePredictionApiKeyRegistrationString.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.recommendationengine.v1beta1.samples; + +// [START +// recommendationengine_v1beta1_generated_predictionapikeyregistryclient_deletepredictionapikeyregistration_string_sync] +import com.google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistrationName; +import com.google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistryClient; + +public class SyncDeletePredictionApiKeyRegistrationString { + + public static void main(String[] args) throws Exception { + syncDeletePredictionApiKeyRegistrationString(); + } + + public static void syncDeletePredictionApiKeyRegistrationString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (PredictionApiKeyRegistryClient predictionApiKeyRegistryClient = + PredictionApiKeyRegistryClient.create()) { + String name = + PredictionApiKeyRegistrationName.of( + "[PROJECT]", + "[LOCATION]", + "[CATALOG]", + "[EVENT_STORE]", + "[PREDICTION_API_KEY_REGISTRATION]") + .toString(); + predictionApiKeyRegistryClient.deletePredictionApiKeyRegistration(name); + } + } +} +// [END +// recommendationengine_v1beta1_generated_predictionapikeyregistryclient_deletepredictionapikeyregistration_string_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionapikeyregistryclient/listpredictionapikeyregistrations/AsyncListPredictionApiKeyRegistrations.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionapikeyregistryclient/listpredictionapikeyregistrations/AsyncListPredictionApiKeyRegistrations.java new file mode 100644 index 000000000000..d45488cd3f46 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionapikeyregistryclient/listpredictionapikeyregistrations/AsyncListPredictionApiKeyRegistrations.java @@ -0,0 +1,58 @@ +/* + * 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.recommendationengine.v1beta1.samples; + +// [START +// recommendationengine_v1beta1_generated_predictionapikeyregistryclient_listpredictionapikeyregistrations_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.recommendationengine.v1beta1.EventStoreName; +import com.google.cloud.recommendationengine.v1beta1.ListPredictionApiKeyRegistrationsRequest; +import com.google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistration; +import com.google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistryClient; + +public class AsyncListPredictionApiKeyRegistrations { + + public static void main(String[] args) throws Exception { + asyncListPredictionApiKeyRegistrations(); + } + + public static void asyncListPredictionApiKeyRegistrations() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (PredictionApiKeyRegistryClient predictionApiKeyRegistryClient = + PredictionApiKeyRegistryClient.create()) { + ListPredictionApiKeyRegistrationsRequest request = + ListPredictionApiKeyRegistrationsRequest.newBuilder() + .setParent( + EventStoreName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]") + .toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + ApiFuture future = + predictionApiKeyRegistryClient + .listPredictionApiKeyRegistrationsPagedCallable() + .futureCall(request); + // Do something. + for (PredictionApiKeyRegistration element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END +// recommendationengine_v1beta1_generated_predictionapikeyregistryclient_listpredictionapikeyregistrations_async] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionapikeyregistryclient/listpredictionapikeyregistrations/AsyncListPredictionApiKeyRegistrationsPaged.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionapikeyregistryclient/listpredictionapikeyregistrations/AsyncListPredictionApiKeyRegistrationsPaged.java new file mode 100644 index 000000000000..2f5f59442a3b --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionapikeyregistryclient/listpredictionapikeyregistrations/AsyncListPredictionApiKeyRegistrationsPaged.java @@ -0,0 +1,67 @@ +/* + * 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.recommendationengine.v1beta1.samples; + +// [START +// recommendationengine_v1beta1_generated_predictionapikeyregistryclient_listpredictionapikeyregistrations_paged_async] +import com.google.cloud.recommendationengine.v1beta1.EventStoreName; +import com.google.cloud.recommendationengine.v1beta1.ListPredictionApiKeyRegistrationsRequest; +import com.google.cloud.recommendationengine.v1beta1.ListPredictionApiKeyRegistrationsResponse; +import com.google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistration; +import com.google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistryClient; +import com.google.common.base.Strings; + +public class AsyncListPredictionApiKeyRegistrationsPaged { + + public static void main(String[] args) throws Exception { + asyncListPredictionApiKeyRegistrationsPaged(); + } + + public static void asyncListPredictionApiKeyRegistrationsPaged() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (PredictionApiKeyRegistryClient predictionApiKeyRegistryClient = + PredictionApiKeyRegistryClient.create()) { + ListPredictionApiKeyRegistrationsRequest request = + ListPredictionApiKeyRegistrationsRequest.newBuilder() + .setParent( + EventStoreName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]") + .toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + while (true) { + ListPredictionApiKeyRegistrationsResponse response = + predictionApiKeyRegistryClient + .listPredictionApiKeyRegistrationsCallable() + .call(request); + for (PredictionApiKeyRegistration element : + response.getPredictionApiKeyRegistrationsList()) { + // doThingsWith(element); + } + String nextPageToken = response.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + request = request.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END +// recommendationengine_v1beta1_generated_predictionapikeyregistryclient_listpredictionapikeyregistrations_paged_async] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionapikeyregistryclient/listpredictionapikeyregistrations/SyncListPredictionApiKeyRegistrations.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionapikeyregistryclient/listpredictionapikeyregistrations/SyncListPredictionApiKeyRegistrations.java new file mode 100644 index 000000000000..f0a87411ce98 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionapikeyregistryclient/listpredictionapikeyregistrations/SyncListPredictionApiKeyRegistrations.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.recommendationengine.v1beta1.samples; + +// [START +// recommendationengine_v1beta1_generated_predictionapikeyregistryclient_listpredictionapikeyregistrations_sync] +import com.google.cloud.recommendationengine.v1beta1.EventStoreName; +import com.google.cloud.recommendationengine.v1beta1.ListPredictionApiKeyRegistrationsRequest; +import com.google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistration; +import com.google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistryClient; + +public class SyncListPredictionApiKeyRegistrations { + + public static void main(String[] args) throws Exception { + syncListPredictionApiKeyRegistrations(); + } + + public static void syncListPredictionApiKeyRegistrations() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (PredictionApiKeyRegistryClient predictionApiKeyRegistryClient = + PredictionApiKeyRegistryClient.create()) { + ListPredictionApiKeyRegistrationsRequest request = + ListPredictionApiKeyRegistrationsRequest.newBuilder() + .setParent( + EventStoreName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]") + .toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .build(); + for (PredictionApiKeyRegistration element : + predictionApiKeyRegistryClient.listPredictionApiKeyRegistrations(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END +// recommendationengine_v1beta1_generated_predictionapikeyregistryclient_listpredictionapikeyregistrations_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionapikeyregistryclient/listpredictionapikeyregistrations/SyncListPredictionApiKeyRegistrationsEventstorename.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionapikeyregistryclient/listpredictionapikeyregistrations/SyncListPredictionApiKeyRegistrationsEventstorename.java new file mode 100644 index 000000000000..5bcf4a220d65 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionapikeyregistryclient/listpredictionapikeyregistrations/SyncListPredictionApiKeyRegistrationsEventstorename.java @@ -0,0 +1,46 @@ +/* + * 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.recommendationengine.v1beta1.samples; + +// [START +// recommendationengine_v1beta1_generated_predictionapikeyregistryclient_listpredictionapikeyregistrations_eventstorename_sync] +import com.google.cloud.recommendationengine.v1beta1.EventStoreName; +import com.google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistration; +import com.google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistryClient; + +public class SyncListPredictionApiKeyRegistrationsEventstorename { + + public static void main(String[] args) throws Exception { + syncListPredictionApiKeyRegistrationsEventstorename(); + } + + public static void syncListPredictionApiKeyRegistrationsEventstorename() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (PredictionApiKeyRegistryClient predictionApiKeyRegistryClient = + PredictionApiKeyRegistryClient.create()) { + EventStoreName parent = + EventStoreName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]"); + for (PredictionApiKeyRegistration element : + predictionApiKeyRegistryClient.listPredictionApiKeyRegistrations(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END +// recommendationengine_v1beta1_generated_predictionapikeyregistryclient_listpredictionapikeyregistrations_eventstorename_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionapikeyregistryclient/listpredictionapikeyregistrations/SyncListPredictionApiKeyRegistrationsString.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionapikeyregistryclient/listpredictionapikeyregistrations/SyncListPredictionApiKeyRegistrationsString.java new file mode 100644 index 000000000000..302442134c42 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionapikeyregistryclient/listpredictionapikeyregistrations/SyncListPredictionApiKeyRegistrationsString.java @@ -0,0 +1,46 @@ +/* + * 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.recommendationengine.v1beta1.samples; + +// [START +// recommendationengine_v1beta1_generated_predictionapikeyregistryclient_listpredictionapikeyregistrations_string_sync] +import com.google.cloud.recommendationengine.v1beta1.EventStoreName; +import com.google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistration; +import com.google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistryClient; + +public class SyncListPredictionApiKeyRegistrationsString { + + public static void main(String[] args) throws Exception { + syncListPredictionApiKeyRegistrationsString(); + } + + public static void syncListPredictionApiKeyRegistrationsString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (PredictionApiKeyRegistryClient predictionApiKeyRegistryClient = + PredictionApiKeyRegistryClient.create()) { + String parent = + EventStoreName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]").toString(); + for (PredictionApiKeyRegistration element : + predictionApiKeyRegistryClient.listPredictionApiKeyRegistrations(parent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END +// recommendationengine_v1beta1_generated_predictionapikeyregistryclient_listpredictionapikeyregistrations_string_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionapikeyregistrysettings/createpredictionapikeyregistration/SyncCreatePredictionApiKeyRegistration.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionapikeyregistrysettings/createpredictionapikeyregistration/SyncCreatePredictionApiKeyRegistration.java new file mode 100644 index 000000000000..3e3dee770529 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionapikeyregistrysettings/createpredictionapikeyregistration/SyncCreatePredictionApiKeyRegistration.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.recommendationengine.v1beta1.samples; + +// [START +// recommendationengine_v1beta1_generated_predictionapikeyregistrysettings_createpredictionapikeyregistration_sync] +import com.google.cloud.recommendationengine.v1beta1.PredictionApiKeyRegistrySettings; +import java.time.Duration; + +public class SyncCreatePredictionApiKeyRegistration { + + public static void main(String[] args) throws Exception { + syncCreatePredictionApiKeyRegistration(); + } + + public static void syncCreatePredictionApiKeyRegistration() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + PredictionApiKeyRegistrySettings.Builder predictionApiKeyRegistrySettingsBuilder = + PredictionApiKeyRegistrySettings.newBuilder(); + predictionApiKeyRegistrySettingsBuilder + .createPredictionApiKeyRegistrationSettings() + .setRetrySettings( + predictionApiKeyRegistrySettingsBuilder + .createPredictionApiKeyRegistrationSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + PredictionApiKeyRegistrySettings predictionApiKeyRegistrySettings = + predictionApiKeyRegistrySettingsBuilder.build(); + } +} +// [END +// recommendationengine_v1beta1_generated_predictionapikeyregistrysettings_createpredictionapikeyregistration_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionserviceclient/create/SyncCreateSetCredentialsProvider.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionserviceclient/create/SyncCreateSetCredentialsProvider.java new file mode 100644 index 000000000000..8f6528d0b889 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionserviceclient/create/SyncCreateSetCredentialsProvider.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.recommendationengine.v1beta1.samples; + +// [START +// recommendationengine_v1beta1_generated_predictionserviceclient_create_setcredentialsprovider_sync] +import com.google.api.gax.core.FixedCredentialsProvider; +import com.google.cloud.recommendationengine.v1beta1.PredictionServiceClient; +import com.google.cloud.recommendationengine.v1beta1.PredictionServiceSettings; +import com.google.cloud.recommendationengine.v1beta1.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. + PredictionServiceSettings predictionServiceSettings = + PredictionServiceSettings.newBuilder() + .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) + .build(); + PredictionServiceClient predictionServiceClient = + PredictionServiceClient.create(predictionServiceSettings); + } +} +// [END +// recommendationengine_v1beta1_generated_predictionserviceclient_create_setcredentialsprovider_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionserviceclient/create/SyncCreateSetCredentialsProvider1.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionserviceclient/create/SyncCreateSetCredentialsProvider1.java new file mode 100644 index 000000000000..c4148e2f6605 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionserviceclient/create/SyncCreateSetCredentialsProvider1.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.recommendationengine.v1beta1.samples; + +// [START +// recommendationengine_v1beta1_generated_predictionserviceclient_create_setcredentialsprovider1_sync] +import com.google.cloud.recommendationengine.v1beta1.PredictionServiceClient; +import com.google.cloud.recommendationengine.v1beta1.PredictionServiceSettings; + +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. + PredictionServiceSettings predictionServiceSettings = + PredictionServiceSettings.newBuilder() + .setTransportChannelProvider( + PredictionServiceSettings.defaultHttpJsonTransportProviderBuilder().build()) + .build(); + PredictionServiceClient predictionServiceClient = + PredictionServiceClient.create(predictionServiceSettings); + } +} +// [END +// recommendationengine_v1beta1_generated_predictionserviceclient_create_setcredentialsprovider1_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionserviceclient/create/SyncCreateSetEndpoint.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionserviceclient/create/SyncCreateSetEndpoint.java new file mode 100644 index 000000000000..e99a3753da66 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionserviceclient/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.recommendationengine.v1beta1.samples; + +// [START recommendationengine_v1beta1_generated_predictionserviceclient_create_setendpoint_sync] +import com.google.cloud.recommendationengine.v1beta1.PredictionServiceClient; +import com.google.cloud.recommendationengine.v1beta1.PredictionServiceSettings; +import com.google.cloud.recommendationengine.v1beta1.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. + PredictionServiceSettings predictionServiceSettings = + PredictionServiceSettings.newBuilder().setEndpoint(myEndpoint).build(); + PredictionServiceClient predictionServiceClient = + PredictionServiceClient.create(predictionServiceSettings); + } +} +// [END recommendationengine_v1beta1_generated_predictionserviceclient_create_setendpoint_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionserviceclient/predict/AsyncPredict.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionserviceclient/predict/AsyncPredict.java new file mode 100644 index 000000000000..3d1f411b0dce --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionserviceclient/predict/AsyncPredict.java @@ -0,0 +1,62 @@ +/* + * 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.recommendationengine.v1beta1.samples; + +// [START recommendationengine_v1beta1_generated_predictionserviceclient_predict_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.recommendationengine.v1beta1.PlacementName; +import com.google.cloud.recommendationengine.v1beta1.PredictRequest; +import com.google.cloud.recommendationengine.v1beta1.PredictionServiceClient; +import com.google.cloud.recommendationengine.v1beta1.UserEvent; +import com.google.protobuf.Value; +import java.util.HashMap; +import java.util.Map; + +public class AsyncPredict { + + public static void main(String[] args) throws Exception { + asyncPredict(); + } + + public static void asyncPredict() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (PredictionServiceClient predictionServiceClient = PredictionServiceClient.create()) { + PredictRequest request = + PredictRequest.newBuilder() + .setName( + PlacementName.of( + "[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]", "[PLACEMENT]") + .toString()) + .setUserEvent(UserEvent.newBuilder().build()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .setDryRun(true) + .putAllParams(new HashMap()) + .putAllLabels(new HashMap()) + .build(); + ApiFuture> future = + predictionServiceClient.predictPagedCallable().futureCall(request); + // Do something. + for (Map.Entry element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END recommendationengine_v1beta1_generated_predictionserviceclient_predict_async] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionserviceclient/predict/AsyncPredictPaged.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionserviceclient/predict/AsyncPredictPaged.java new file mode 100644 index 000000000000..8f114ea7baad --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionserviceclient/predict/AsyncPredictPaged.java @@ -0,0 +1,69 @@ +/* + * 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.recommendationengine.v1beta1.samples; + +// [START recommendationengine_v1beta1_generated_predictionserviceclient_predict_paged_async] +import com.google.cloud.recommendationengine.v1beta1.PlacementName; +import com.google.cloud.recommendationengine.v1beta1.PredictRequest; +import com.google.cloud.recommendationengine.v1beta1.PredictResponse; +import com.google.cloud.recommendationengine.v1beta1.PredictionServiceClient; +import com.google.cloud.recommendationengine.v1beta1.UserEvent; +import com.google.common.base.Strings; +import com.google.protobuf.Value; +import java.util.HashMap; +import java.util.Map; + +public class AsyncPredictPaged { + + public static void main(String[] args) throws Exception { + asyncPredictPaged(); + } + + public static void asyncPredictPaged() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (PredictionServiceClient predictionServiceClient = PredictionServiceClient.create()) { + PredictRequest request = + PredictRequest.newBuilder() + .setName( + PlacementName.of( + "[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]", "[PLACEMENT]") + .toString()) + .setUserEvent(UserEvent.newBuilder().build()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .setDryRun(true) + .putAllParams(new HashMap()) + .putAllLabels(new HashMap()) + .build(); + while (true) { + PredictResponse response = predictionServiceClient.predictCallable().call(request); + for (Map.Entry element : response.getMetadataList()) { + // doThingsWith(element); + } + String nextPageToken = response.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + request = request.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END recommendationengine_v1beta1_generated_predictionserviceclient_predict_paged_async] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionserviceclient/predict/SyncPredict.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionserviceclient/predict/SyncPredict.java new file mode 100644 index 000000000000..456be7ebe442 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionserviceclient/predict/SyncPredict.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.recommendationengine.v1beta1.samples; + +// [START recommendationengine_v1beta1_generated_predictionserviceclient_predict_sync] +import com.google.cloud.recommendationengine.v1beta1.PlacementName; +import com.google.cloud.recommendationengine.v1beta1.PredictRequest; +import com.google.cloud.recommendationengine.v1beta1.PredictionServiceClient; +import com.google.cloud.recommendationengine.v1beta1.UserEvent; +import com.google.protobuf.Value; +import java.util.HashMap; +import java.util.Map; + +public class SyncPredict { + + public static void main(String[] args) throws Exception { + syncPredict(); + } + + public static void syncPredict() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (PredictionServiceClient predictionServiceClient = PredictionServiceClient.create()) { + PredictRequest request = + PredictRequest.newBuilder() + .setName( + PlacementName.of( + "[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]", "[PLACEMENT]") + .toString()) + .setUserEvent(UserEvent.newBuilder().build()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .setDryRun(true) + .putAllParams(new HashMap()) + .putAllLabels(new HashMap()) + .build(); + for (Map.Entry element : + predictionServiceClient.predict(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END recommendationengine_v1beta1_generated_predictionserviceclient_predict_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionserviceclient/predict/SyncPredictPlacementnameUserevent.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionserviceclient/predict/SyncPredictPlacementnameUserevent.java new file mode 100644 index 000000000000..474044e00239 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionserviceclient/predict/SyncPredictPlacementnameUserevent.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.recommendationengine.v1beta1.samples; + +// [START +// recommendationengine_v1beta1_generated_predictionserviceclient_predict_placementnameuserevent_sync] +import com.google.cloud.recommendationengine.v1beta1.PlacementName; +import com.google.cloud.recommendationengine.v1beta1.PredictionServiceClient; +import com.google.cloud.recommendationengine.v1beta1.UserEvent; +import com.google.protobuf.Value; +import java.util.Map; + +public class SyncPredictPlacementnameUserevent { + + public static void main(String[] args) throws Exception { + syncPredictPlacementnameUserevent(); + } + + public static void syncPredictPlacementnameUserevent() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (PredictionServiceClient predictionServiceClient = PredictionServiceClient.create()) { + PlacementName name = + PlacementName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]", "[PLACEMENT]"); + UserEvent userEvent = UserEvent.newBuilder().build(); + for (Map.Entry element : + predictionServiceClient.predict(name, userEvent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END +// recommendationengine_v1beta1_generated_predictionserviceclient_predict_placementnameuserevent_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionserviceclient/predict/SyncPredictStringUserevent.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionserviceclient/predict/SyncPredictStringUserevent.java new file mode 100644 index 000000000000..a2e61e8ae8f5 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionserviceclient/predict/SyncPredictStringUserevent.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.recommendationengine.v1beta1.samples; + +// [START +// recommendationengine_v1beta1_generated_predictionserviceclient_predict_stringuserevent_sync] +import com.google.cloud.recommendationengine.v1beta1.PlacementName; +import com.google.cloud.recommendationengine.v1beta1.PredictionServiceClient; +import com.google.cloud.recommendationengine.v1beta1.UserEvent; +import com.google.protobuf.Value; +import java.util.Map; + +public class SyncPredictStringUserevent { + + public static void main(String[] args) throws Exception { + syncPredictStringUserevent(); + } + + public static void syncPredictStringUserevent() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (PredictionServiceClient predictionServiceClient = PredictionServiceClient.create()) { + String name = + PlacementName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]", "[PLACEMENT]") + .toString(); + UserEvent userEvent = UserEvent.newBuilder().build(); + for (Map.Entry element : + predictionServiceClient.predict(name, userEvent).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END recommendationengine_v1beta1_generated_predictionserviceclient_predict_stringuserevent_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionservicesettings/predict/SyncPredict.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionservicesettings/predict/SyncPredict.java new file mode 100644 index 000000000000..3e0fb6ccb35d --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/predictionservicesettings/predict/SyncPredict.java @@ -0,0 +1,46 @@ +/* + * 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.recommendationengine.v1beta1.samples; + +// [START recommendationengine_v1beta1_generated_predictionservicesettings_predict_sync] +import com.google.cloud.recommendationengine.v1beta1.PredictionServiceSettings; +import java.time.Duration; + +public class SyncPredict { + + public static void main(String[] args) throws Exception { + syncPredict(); + } + + public static void syncPredict() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + PredictionServiceSettings.Builder predictionServiceSettingsBuilder = + PredictionServiceSettings.newBuilder(); + predictionServiceSettingsBuilder + .predictSettings() + .setRetrySettings( + predictionServiceSettingsBuilder + .predictSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + PredictionServiceSettings predictionServiceSettings = predictionServiceSettingsBuilder.build(); + } +} +// [END recommendationengine_v1beta1_generated_predictionservicesettings_predict_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/stub/catalogservicestubsettings/createcatalogitem/SyncCreateCatalogItem.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/stub/catalogservicestubsettings/createcatalogitem/SyncCreateCatalogItem.java new file mode 100644 index 000000000000..0ed140eeb97c --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/stub/catalogservicestubsettings/createcatalogitem/SyncCreateCatalogItem.java @@ -0,0 +1,46 @@ +/* + * 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.recommendationengine.v1beta1.stub.samples; + +// [START recommendationengine_v1beta1_generated_catalogservicestubsettings_createcatalogitem_sync] +import com.google.cloud.recommendationengine.v1beta1.stub.CatalogServiceStubSettings; +import java.time.Duration; + +public class SyncCreateCatalogItem { + + public static void main(String[] args) throws Exception { + syncCreateCatalogItem(); + } + + public static void syncCreateCatalogItem() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + CatalogServiceStubSettings.Builder catalogServiceSettingsBuilder = + CatalogServiceStubSettings.newBuilder(); + catalogServiceSettingsBuilder + .createCatalogItemSettings() + .setRetrySettings( + catalogServiceSettingsBuilder + .createCatalogItemSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + CatalogServiceStubSettings catalogServiceSettings = catalogServiceSettingsBuilder.build(); + } +} +// [END recommendationengine_v1beta1_generated_catalogservicestubsettings_createcatalogitem_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/stub/predictionapikeyregistrystubsettings/createpredictionapikeyregistration/SyncCreatePredictionApiKeyRegistration.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/stub/predictionapikeyregistrystubsettings/createpredictionapikeyregistration/SyncCreatePredictionApiKeyRegistration.java new file mode 100644 index 000000000000..c74c499d6dbc --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/stub/predictionapikeyregistrystubsettings/createpredictionapikeyregistration/SyncCreatePredictionApiKeyRegistration.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.recommendationengine.v1beta1.stub.samples; + +// [START +// recommendationengine_v1beta1_generated_predictionapikeyregistrystubsettings_createpredictionapikeyregistration_sync] +import com.google.cloud.recommendationengine.v1beta1.stub.PredictionApiKeyRegistryStubSettings; +import java.time.Duration; + +public class SyncCreatePredictionApiKeyRegistration { + + public static void main(String[] args) throws Exception { + syncCreatePredictionApiKeyRegistration(); + } + + public static void syncCreatePredictionApiKeyRegistration() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + PredictionApiKeyRegistryStubSettings.Builder predictionApiKeyRegistrySettingsBuilder = + PredictionApiKeyRegistryStubSettings.newBuilder(); + predictionApiKeyRegistrySettingsBuilder + .createPredictionApiKeyRegistrationSettings() + .setRetrySettings( + predictionApiKeyRegistrySettingsBuilder + .createPredictionApiKeyRegistrationSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + PredictionApiKeyRegistryStubSettings predictionApiKeyRegistrySettings = + predictionApiKeyRegistrySettingsBuilder.build(); + } +} +// [END +// recommendationengine_v1beta1_generated_predictionapikeyregistrystubsettings_createpredictionapikeyregistration_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/stub/predictionservicestubsettings/predict/SyncPredict.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/stub/predictionservicestubsettings/predict/SyncPredict.java new file mode 100644 index 000000000000..59ffcf502e25 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/stub/predictionservicestubsettings/predict/SyncPredict.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.recommendationengine.v1beta1.stub.samples; + +// [START recommendationengine_v1beta1_generated_predictionservicestubsettings_predict_sync] +import com.google.cloud.recommendationengine.v1beta1.stub.PredictionServiceStubSettings; +import java.time.Duration; + +public class SyncPredict { + + public static void main(String[] args) throws Exception { + syncPredict(); + } + + public static void syncPredict() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + PredictionServiceStubSettings.Builder predictionServiceSettingsBuilder = + PredictionServiceStubSettings.newBuilder(); + predictionServiceSettingsBuilder + .predictSettings() + .setRetrySettings( + predictionServiceSettingsBuilder + .predictSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + PredictionServiceStubSettings predictionServiceSettings = + predictionServiceSettingsBuilder.build(); + } +} +// [END recommendationengine_v1beta1_generated_predictionservicestubsettings_predict_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/stub/usereventservicestubsettings/writeuserevent/SyncWriteUserEvent.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/stub/usereventservicestubsettings/writeuserevent/SyncWriteUserEvent.java new file mode 100644 index 000000000000..d38d1acd4fc2 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/stub/usereventservicestubsettings/writeuserevent/SyncWriteUserEvent.java @@ -0,0 +1,46 @@ +/* + * 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.recommendationengine.v1beta1.stub.samples; + +// [START recommendationengine_v1beta1_generated_usereventservicestubsettings_writeuserevent_sync] +import com.google.cloud.recommendationengine.v1beta1.stub.UserEventServiceStubSettings; +import java.time.Duration; + +public class SyncWriteUserEvent { + + public static void main(String[] args) throws Exception { + syncWriteUserEvent(); + } + + public static void syncWriteUserEvent() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + UserEventServiceStubSettings.Builder userEventServiceSettingsBuilder = + UserEventServiceStubSettings.newBuilder(); + userEventServiceSettingsBuilder + .writeUserEventSettings() + .setRetrySettings( + userEventServiceSettingsBuilder + .writeUserEventSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + UserEventServiceStubSettings userEventServiceSettings = userEventServiceSettingsBuilder.build(); + } +} +// [END recommendationengine_v1beta1_generated_usereventservicestubsettings_writeuserevent_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/collectuserevent/AsyncCollectUserEvent.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/collectuserevent/AsyncCollectUserEvent.java new file mode 100644 index 000000000000..ef8f78d45a0c --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/collectuserevent/AsyncCollectUserEvent.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.recommendationengine.v1beta1.samples; + +// [START recommendationengine_v1beta1_generated_usereventserviceclient_collectuserevent_async] +import com.google.api.HttpBody; +import com.google.api.core.ApiFuture; +import com.google.cloud.recommendationengine.v1beta1.CollectUserEventRequest; +import com.google.cloud.recommendationengine.v1beta1.EventStoreName; +import com.google.cloud.recommendationengine.v1beta1.UserEventServiceClient; + +public class AsyncCollectUserEvent { + + public static void main(String[] args) throws Exception { + asyncCollectUserEvent(); + } + + public static void asyncCollectUserEvent() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (UserEventServiceClient userEventServiceClient = UserEventServiceClient.create()) { + CollectUserEventRequest request = + CollectUserEventRequest.newBuilder() + .setParent( + EventStoreName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]") + .toString()) + .setUserEvent("userEvent315571599") + .setUri("uri116076") + .setEts(100772) + .build(); + ApiFuture future = + userEventServiceClient.collectUserEventCallable().futureCall(request); + // Do something. + HttpBody response = future.get(); + } + } +} +// [END recommendationengine_v1beta1_generated_usereventserviceclient_collectuserevent_async] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/collectuserevent/SyncCollectUserEvent.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/collectuserevent/SyncCollectUserEvent.java new file mode 100644 index 000000000000..e6b9cf99bf47 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/collectuserevent/SyncCollectUserEvent.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.recommendationengine.v1beta1.samples; + +// [START recommendationengine_v1beta1_generated_usereventserviceclient_collectuserevent_sync] +import com.google.api.HttpBody; +import com.google.cloud.recommendationengine.v1beta1.CollectUserEventRequest; +import com.google.cloud.recommendationengine.v1beta1.EventStoreName; +import com.google.cloud.recommendationengine.v1beta1.UserEventServiceClient; + +public class SyncCollectUserEvent { + + public static void main(String[] args) throws Exception { + syncCollectUserEvent(); + } + + public static void syncCollectUserEvent() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (UserEventServiceClient userEventServiceClient = UserEventServiceClient.create()) { + CollectUserEventRequest request = + CollectUserEventRequest.newBuilder() + .setParent( + EventStoreName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]") + .toString()) + .setUserEvent("userEvent315571599") + .setUri("uri116076") + .setEts(100772) + .build(); + HttpBody response = userEventServiceClient.collectUserEvent(request); + } + } +} +// [END recommendationengine_v1beta1_generated_usereventserviceclient_collectuserevent_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/collectuserevent/SyncCollectUserEventEventstorenameStringStringLong.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/collectuserevent/SyncCollectUserEventEventstorenameStringStringLong.java new file mode 100644 index 000000000000..bcb96af6e606 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/collectuserevent/SyncCollectUserEventEventstorenameStringStringLong.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.recommendationengine.v1beta1.samples; + +// [START +// recommendationengine_v1beta1_generated_usereventserviceclient_collectuserevent_eventstorenamestringstringlong_sync] +import com.google.api.HttpBody; +import com.google.cloud.recommendationengine.v1beta1.EventStoreName; +import com.google.cloud.recommendationengine.v1beta1.UserEventServiceClient; + +public class SyncCollectUserEventEventstorenameStringStringLong { + + public static void main(String[] args) throws Exception { + syncCollectUserEventEventstorenameStringStringLong(); + } + + public static void syncCollectUserEventEventstorenameStringStringLong() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (UserEventServiceClient userEventServiceClient = UserEventServiceClient.create()) { + EventStoreName parent = + EventStoreName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]"); + String userEvent = "userEvent315571599"; + String uri = "uri116076"; + long ets = 100772; + HttpBody response = userEventServiceClient.collectUserEvent(parent, userEvent, uri, ets); + } + } +} +// [END +// recommendationengine_v1beta1_generated_usereventserviceclient_collectuserevent_eventstorenamestringstringlong_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/collectuserevent/SyncCollectUserEventStringStringStringLong.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/collectuserevent/SyncCollectUserEventStringStringStringLong.java new file mode 100644 index 000000000000..f3ad23e4ea96 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/collectuserevent/SyncCollectUserEventStringStringStringLong.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.recommendationengine.v1beta1.samples; + +// [START +// recommendationengine_v1beta1_generated_usereventserviceclient_collectuserevent_stringstringstringlong_sync] +import com.google.api.HttpBody; +import com.google.cloud.recommendationengine.v1beta1.EventStoreName; +import com.google.cloud.recommendationengine.v1beta1.UserEventServiceClient; + +public class SyncCollectUserEventStringStringStringLong { + + public static void main(String[] args) throws Exception { + syncCollectUserEventStringStringStringLong(); + } + + public static void syncCollectUserEventStringStringStringLong() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (UserEventServiceClient userEventServiceClient = UserEventServiceClient.create()) { + String parent = + EventStoreName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]").toString(); + String userEvent = "userEvent315571599"; + String uri = "uri116076"; + long ets = 100772; + HttpBody response = userEventServiceClient.collectUserEvent(parent, userEvent, uri, ets); + } + } +} +// [END +// recommendationengine_v1beta1_generated_usereventserviceclient_collectuserevent_stringstringstringlong_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/create/SyncCreateSetCredentialsProvider.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/create/SyncCreateSetCredentialsProvider.java new file mode 100644 index 000000000000..f0f8a8014e80 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/create/SyncCreateSetCredentialsProvider.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.recommendationengine.v1beta1.samples; + +// [START +// recommendationengine_v1beta1_generated_usereventserviceclient_create_setcredentialsprovider_sync] +import com.google.api.gax.core.FixedCredentialsProvider; +import com.google.cloud.recommendationengine.v1beta1.UserEventServiceClient; +import com.google.cloud.recommendationengine.v1beta1.UserEventServiceSettings; +import com.google.cloud.recommendationengine.v1beta1.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. + UserEventServiceSettings userEventServiceSettings = + UserEventServiceSettings.newBuilder() + .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) + .build(); + UserEventServiceClient userEventServiceClient = + UserEventServiceClient.create(userEventServiceSettings); + } +} +// [END +// recommendationengine_v1beta1_generated_usereventserviceclient_create_setcredentialsprovider_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/create/SyncCreateSetCredentialsProvider1.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/create/SyncCreateSetCredentialsProvider1.java new file mode 100644 index 000000000000..a2f8a27d5a3d --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/create/SyncCreateSetCredentialsProvider1.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.recommendationengine.v1beta1.samples; + +// [START +// recommendationengine_v1beta1_generated_usereventserviceclient_create_setcredentialsprovider1_sync] +import com.google.cloud.recommendationengine.v1beta1.UserEventServiceClient; +import com.google.cloud.recommendationengine.v1beta1.UserEventServiceSettings; + +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. + UserEventServiceSettings userEventServiceSettings = + UserEventServiceSettings.newBuilder() + .setTransportChannelProvider( + UserEventServiceSettings.defaultHttpJsonTransportProviderBuilder().build()) + .build(); + UserEventServiceClient userEventServiceClient = + UserEventServiceClient.create(userEventServiceSettings); + } +} +// [END +// recommendationengine_v1beta1_generated_usereventserviceclient_create_setcredentialsprovider1_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/create/SyncCreateSetEndpoint.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/create/SyncCreateSetEndpoint.java new file mode 100644 index 000000000000..ffcc7a652450 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/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.recommendationengine.v1beta1.samples; + +// [START recommendationengine_v1beta1_generated_usereventserviceclient_create_setendpoint_sync] +import com.google.cloud.recommendationengine.v1beta1.UserEventServiceClient; +import com.google.cloud.recommendationengine.v1beta1.UserEventServiceSettings; +import com.google.cloud.recommendationengine.v1beta1.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. + UserEventServiceSettings userEventServiceSettings = + UserEventServiceSettings.newBuilder().setEndpoint(myEndpoint).build(); + UserEventServiceClient userEventServiceClient = + UserEventServiceClient.create(userEventServiceSettings); + } +} +// [END recommendationengine_v1beta1_generated_usereventserviceclient_create_setendpoint_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/importuserevents/AsyncImportUserEvents.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/importuserevents/AsyncImportUserEvents.java new file mode 100644 index 000000000000..ce86b3f47463 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/importuserevents/AsyncImportUserEvents.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.recommendationengine.v1beta1.samples; + +// [START recommendationengine_v1beta1_generated_usereventserviceclient_importuserevents_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.recommendationengine.v1beta1.EventStoreName; +import com.google.cloud.recommendationengine.v1beta1.ImportErrorsConfig; +import com.google.cloud.recommendationengine.v1beta1.ImportUserEventsRequest; +import com.google.cloud.recommendationengine.v1beta1.InputConfig; +import com.google.cloud.recommendationengine.v1beta1.UserEventServiceClient; +import com.google.longrunning.Operation; + +public class AsyncImportUserEvents { + + public static void main(String[] args) throws Exception { + asyncImportUserEvents(); + } + + public static void asyncImportUserEvents() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (UserEventServiceClient userEventServiceClient = UserEventServiceClient.create()) { + ImportUserEventsRequest request = + ImportUserEventsRequest.newBuilder() + .setParent( + EventStoreName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]") + .toString()) + .setRequestId("requestId693933066") + .setInputConfig(InputConfig.newBuilder().build()) + .setErrorsConfig(ImportErrorsConfig.newBuilder().build()) + .build(); + ApiFuture future = + userEventServiceClient.importUserEventsCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END recommendationengine_v1beta1_generated_usereventserviceclient_importuserevents_async] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/importuserevents/AsyncImportUserEventsLRO.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/importuserevents/AsyncImportUserEventsLRO.java new file mode 100644 index 000000000000..c7e7726d4594 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/importuserevents/AsyncImportUserEventsLRO.java @@ -0,0 +1,55 @@ +/* + * 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.recommendationengine.v1beta1.samples; + +// [START recommendationengine_v1beta1_generated_usereventserviceclient_importuserevents_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.recommendationengine.v1beta1.EventStoreName; +import com.google.cloud.recommendationengine.v1beta1.ImportErrorsConfig; +import com.google.cloud.recommendationengine.v1beta1.ImportMetadata; +import com.google.cloud.recommendationengine.v1beta1.ImportUserEventsRequest; +import com.google.cloud.recommendationengine.v1beta1.ImportUserEventsResponse; +import com.google.cloud.recommendationengine.v1beta1.InputConfig; +import com.google.cloud.recommendationengine.v1beta1.UserEventServiceClient; + +public class AsyncImportUserEventsLRO { + + public static void main(String[] args) throws Exception { + asyncImportUserEventsLRO(); + } + + public static void asyncImportUserEventsLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (UserEventServiceClient userEventServiceClient = UserEventServiceClient.create()) { + ImportUserEventsRequest request = + ImportUserEventsRequest.newBuilder() + .setParent( + EventStoreName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]") + .toString()) + .setRequestId("requestId693933066") + .setInputConfig(InputConfig.newBuilder().build()) + .setErrorsConfig(ImportErrorsConfig.newBuilder().build()) + .build(); + OperationFuture future = + userEventServiceClient.importUserEventsOperationCallable().futureCall(request); + // Do something. + ImportUserEventsResponse response = future.get(); + } + } +} +// [END recommendationengine_v1beta1_generated_usereventserviceclient_importuserevents_lro_async] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/importuserevents/SyncImportUserEvents.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/importuserevents/SyncImportUserEvents.java new file mode 100644 index 000000000000..814c515815df --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/importuserevents/SyncImportUserEvents.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.recommendationengine.v1beta1.samples; + +// [START recommendationengine_v1beta1_generated_usereventserviceclient_importuserevents_sync] +import com.google.cloud.recommendationengine.v1beta1.EventStoreName; +import com.google.cloud.recommendationengine.v1beta1.ImportErrorsConfig; +import com.google.cloud.recommendationengine.v1beta1.ImportUserEventsRequest; +import com.google.cloud.recommendationengine.v1beta1.ImportUserEventsResponse; +import com.google.cloud.recommendationengine.v1beta1.InputConfig; +import com.google.cloud.recommendationengine.v1beta1.UserEventServiceClient; + +public class SyncImportUserEvents { + + public static void main(String[] args) throws Exception { + syncImportUserEvents(); + } + + public static void syncImportUserEvents() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (UserEventServiceClient userEventServiceClient = UserEventServiceClient.create()) { + ImportUserEventsRequest request = + ImportUserEventsRequest.newBuilder() + .setParent( + EventStoreName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]") + .toString()) + .setRequestId("requestId693933066") + .setInputConfig(InputConfig.newBuilder().build()) + .setErrorsConfig(ImportErrorsConfig.newBuilder().build()) + .build(); + ImportUserEventsResponse response = + userEventServiceClient.importUserEventsAsync(request).get(); + } + } +} +// [END recommendationengine_v1beta1_generated_usereventserviceclient_importuserevents_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/importuserevents/SyncImportUserEventsEventstorenameStringInputconfigImporterrorsconfig.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/importuserevents/SyncImportUserEventsEventstorenameStringInputconfigImporterrorsconfig.java new file mode 100644 index 000000000000..84076ac5ec73 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/importuserevents/SyncImportUserEventsEventstorenameStringInputconfigImporterrorsconfig.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.recommendationengine.v1beta1.samples; + +// [START +// recommendationengine_v1beta1_generated_usereventserviceclient_importuserevents_eventstorenamestringinputconfigimporterrorsconfig_sync] +import com.google.cloud.recommendationengine.v1beta1.EventStoreName; +import com.google.cloud.recommendationengine.v1beta1.ImportErrorsConfig; +import com.google.cloud.recommendationengine.v1beta1.ImportUserEventsResponse; +import com.google.cloud.recommendationengine.v1beta1.InputConfig; +import com.google.cloud.recommendationengine.v1beta1.UserEventServiceClient; + +public class SyncImportUserEventsEventstorenameStringInputconfigImporterrorsconfig { + + public static void main(String[] args) throws Exception { + syncImportUserEventsEventstorenameStringInputconfigImporterrorsconfig(); + } + + public static void syncImportUserEventsEventstorenameStringInputconfigImporterrorsconfig() + throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (UserEventServiceClient userEventServiceClient = UserEventServiceClient.create()) { + EventStoreName parent = + EventStoreName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]"); + String requestId = "requestId693933066"; + InputConfig inputConfig = InputConfig.newBuilder().build(); + ImportErrorsConfig errorsConfig = ImportErrorsConfig.newBuilder().build(); + ImportUserEventsResponse response = + userEventServiceClient + .importUserEventsAsync(parent, requestId, inputConfig, errorsConfig) + .get(); + } + } +} +// [END +// recommendationengine_v1beta1_generated_usereventserviceclient_importuserevents_eventstorenamestringinputconfigimporterrorsconfig_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/importuserevents/SyncImportUserEventsStringStringInputconfigImporterrorsconfig.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/importuserevents/SyncImportUserEventsStringStringInputconfigImporterrorsconfig.java new file mode 100644 index 000000000000..9a61c94b8c14 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/importuserevents/SyncImportUserEventsStringStringInputconfigImporterrorsconfig.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.recommendationengine.v1beta1.samples; + +// [START +// recommendationengine_v1beta1_generated_usereventserviceclient_importuserevents_stringstringinputconfigimporterrorsconfig_sync] +import com.google.cloud.recommendationengine.v1beta1.EventStoreName; +import com.google.cloud.recommendationengine.v1beta1.ImportErrorsConfig; +import com.google.cloud.recommendationengine.v1beta1.ImportUserEventsResponse; +import com.google.cloud.recommendationengine.v1beta1.InputConfig; +import com.google.cloud.recommendationengine.v1beta1.UserEventServiceClient; + +public class SyncImportUserEventsStringStringInputconfigImporterrorsconfig { + + public static void main(String[] args) throws Exception { + syncImportUserEventsStringStringInputconfigImporterrorsconfig(); + } + + public static void syncImportUserEventsStringStringInputconfigImporterrorsconfig() + throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (UserEventServiceClient userEventServiceClient = UserEventServiceClient.create()) { + String parent = + EventStoreName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]").toString(); + String requestId = "requestId693933066"; + InputConfig inputConfig = InputConfig.newBuilder().build(); + ImportErrorsConfig errorsConfig = ImportErrorsConfig.newBuilder().build(); + ImportUserEventsResponse response = + userEventServiceClient + .importUserEventsAsync(parent, requestId, inputConfig, errorsConfig) + .get(); + } + } +} +// [END +// recommendationengine_v1beta1_generated_usereventserviceclient_importuserevents_stringstringinputconfigimporterrorsconfig_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/listuserevents/AsyncListUserEvents.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/listuserevents/AsyncListUserEvents.java new file mode 100644 index 000000000000..4569d08b6aff --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/listuserevents/AsyncListUserEvents.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.recommendationengine.v1beta1.samples; + +// [START recommendationengine_v1beta1_generated_usereventserviceclient_listuserevents_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.recommendationengine.v1beta1.EventStoreName; +import com.google.cloud.recommendationengine.v1beta1.ListUserEventsRequest; +import com.google.cloud.recommendationengine.v1beta1.UserEvent; +import com.google.cloud.recommendationengine.v1beta1.UserEventServiceClient; + +public class AsyncListUserEvents { + + public static void main(String[] args) throws Exception { + asyncListUserEvents(); + } + + public static void asyncListUserEvents() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (UserEventServiceClient userEventServiceClient = UserEventServiceClient.create()) { + ListUserEventsRequest request = + ListUserEventsRequest.newBuilder() + .setParent( + EventStoreName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]") + .toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .build(); + ApiFuture future = + userEventServiceClient.listUserEventsPagedCallable().futureCall(request); + // Do something. + for (UserEvent element : future.get().iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END recommendationengine_v1beta1_generated_usereventserviceclient_listuserevents_async] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/listuserevents/AsyncListUserEventsPaged.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/listuserevents/AsyncListUserEventsPaged.java new file mode 100644 index 000000000000..3b49148a5eb5 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/listuserevents/AsyncListUserEventsPaged.java @@ -0,0 +1,62 @@ +/* + * 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.recommendationengine.v1beta1.samples; + +// [START recommendationengine_v1beta1_generated_usereventserviceclient_listuserevents_paged_async] +import com.google.cloud.recommendationengine.v1beta1.EventStoreName; +import com.google.cloud.recommendationengine.v1beta1.ListUserEventsRequest; +import com.google.cloud.recommendationengine.v1beta1.ListUserEventsResponse; +import com.google.cloud.recommendationengine.v1beta1.UserEvent; +import com.google.cloud.recommendationengine.v1beta1.UserEventServiceClient; +import com.google.common.base.Strings; + +public class AsyncListUserEventsPaged { + + public static void main(String[] args) throws Exception { + asyncListUserEventsPaged(); + } + + public static void asyncListUserEventsPaged() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (UserEventServiceClient userEventServiceClient = UserEventServiceClient.create()) { + ListUserEventsRequest request = + ListUserEventsRequest.newBuilder() + .setParent( + EventStoreName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]") + .toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .build(); + while (true) { + ListUserEventsResponse response = + userEventServiceClient.listUserEventsCallable().call(request); + for (UserEvent element : response.getUserEventsList()) { + // doThingsWith(element); + } + String nextPageToken = response.getNextPageToken(); + if (!Strings.isNullOrEmpty(nextPageToken)) { + request = request.toBuilder().setPageToken(nextPageToken).build(); + } else { + break; + } + } + } + } +} +// [END recommendationengine_v1beta1_generated_usereventserviceclient_listuserevents_paged_async] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/listuserevents/SyncListUserEvents.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/listuserevents/SyncListUserEvents.java new file mode 100644 index 000000000000..b477446c2ce8 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/listuserevents/SyncListUserEvents.java @@ -0,0 +1,50 @@ +/* + * 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.recommendationengine.v1beta1.samples; + +// [START recommendationengine_v1beta1_generated_usereventserviceclient_listuserevents_sync] +import com.google.cloud.recommendationengine.v1beta1.EventStoreName; +import com.google.cloud.recommendationengine.v1beta1.ListUserEventsRequest; +import com.google.cloud.recommendationengine.v1beta1.UserEvent; +import com.google.cloud.recommendationengine.v1beta1.UserEventServiceClient; + +public class SyncListUserEvents { + + public static void main(String[] args) throws Exception { + syncListUserEvents(); + } + + public static void syncListUserEvents() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (UserEventServiceClient userEventServiceClient = UserEventServiceClient.create()) { + ListUserEventsRequest request = + ListUserEventsRequest.newBuilder() + .setParent( + EventStoreName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]") + .toString()) + .setPageSize(883849137) + .setPageToken("pageToken873572522") + .setFilter("filter-1274492040") + .build(); + for (UserEvent element : userEventServiceClient.listUserEvents(request).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END recommendationengine_v1beta1_generated_usereventserviceclient_listuserevents_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/listuserevents/SyncListUserEventsEventstorenameString.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/listuserevents/SyncListUserEventsEventstorenameString.java new file mode 100644 index 000000000000..836094e8ec3c --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/listuserevents/SyncListUserEventsEventstorenameString.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.recommendationengine.v1beta1.samples; + +// [START +// recommendationengine_v1beta1_generated_usereventserviceclient_listuserevents_eventstorenamestring_sync] +import com.google.cloud.recommendationengine.v1beta1.EventStoreName; +import com.google.cloud.recommendationengine.v1beta1.UserEvent; +import com.google.cloud.recommendationengine.v1beta1.UserEventServiceClient; + +public class SyncListUserEventsEventstorenameString { + + public static void main(String[] args) throws Exception { + syncListUserEventsEventstorenameString(); + } + + public static void syncListUserEventsEventstorenameString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (UserEventServiceClient userEventServiceClient = UserEventServiceClient.create()) { + EventStoreName parent = + EventStoreName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]"); + String filter = "filter-1274492040"; + for (UserEvent element : userEventServiceClient.listUserEvents(parent, filter).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END +// recommendationengine_v1beta1_generated_usereventserviceclient_listuserevents_eventstorenamestring_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/listuserevents/SyncListUserEventsStringString.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/listuserevents/SyncListUserEventsStringString.java new file mode 100644 index 000000000000..77f8bab2990b --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/listuserevents/SyncListUserEventsStringString.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.recommendationengine.v1beta1.samples; + +// [START +// recommendationengine_v1beta1_generated_usereventserviceclient_listuserevents_stringstring_sync] +import com.google.cloud.recommendationengine.v1beta1.EventStoreName; +import com.google.cloud.recommendationengine.v1beta1.UserEvent; +import com.google.cloud.recommendationengine.v1beta1.UserEventServiceClient; + +public class SyncListUserEventsStringString { + + public static void main(String[] args) throws Exception { + syncListUserEventsStringString(); + } + + public static void syncListUserEventsStringString() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (UserEventServiceClient userEventServiceClient = UserEventServiceClient.create()) { + String parent = + EventStoreName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]").toString(); + String filter = "filter-1274492040"; + for (UserEvent element : userEventServiceClient.listUserEvents(parent, filter).iterateAll()) { + // doThingsWith(element); + } + } + } +} +// [END +// recommendationengine_v1beta1_generated_usereventserviceclient_listuserevents_stringstring_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/purgeuserevents/AsyncPurgeUserEvents.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/purgeuserevents/AsyncPurgeUserEvents.java new file mode 100644 index 000000000000..ab08593d8667 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/purgeuserevents/AsyncPurgeUserEvents.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.recommendationengine.v1beta1.samples; + +// [START recommendationengine_v1beta1_generated_usereventserviceclient_purgeuserevents_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.recommendationengine.v1beta1.EventStoreName; +import com.google.cloud.recommendationengine.v1beta1.PurgeUserEventsRequest; +import com.google.cloud.recommendationengine.v1beta1.UserEventServiceClient; +import com.google.longrunning.Operation; + +public class AsyncPurgeUserEvents { + + public static void main(String[] args) throws Exception { + asyncPurgeUserEvents(); + } + + public static void asyncPurgeUserEvents() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (UserEventServiceClient userEventServiceClient = UserEventServiceClient.create()) { + PurgeUserEventsRequest request = + PurgeUserEventsRequest.newBuilder() + .setParent( + EventStoreName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]") + .toString()) + .setFilter("filter-1274492040") + .setForce(true) + .build(); + ApiFuture future = + userEventServiceClient.purgeUserEventsCallable().futureCall(request); + // Do something. + Operation response = future.get(); + } + } +} +// [END recommendationengine_v1beta1_generated_usereventserviceclient_purgeuserevents_async] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/purgeuserevents/AsyncPurgeUserEventsLRO.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/purgeuserevents/AsyncPurgeUserEventsLRO.java new file mode 100644 index 000000000000..acc01ce04bf1 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/purgeuserevents/AsyncPurgeUserEventsLRO.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.recommendationengine.v1beta1.samples; + +// [START recommendationengine_v1beta1_generated_usereventserviceclient_purgeuserevents_lro_async] +import com.google.api.gax.longrunning.OperationFuture; +import com.google.cloud.recommendationengine.v1beta1.EventStoreName; +import com.google.cloud.recommendationengine.v1beta1.PurgeUserEventsMetadata; +import com.google.cloud.recommendationengine.v1beta1.PurgeUserEventsRequest; +import com.google.cloud.recommendationengine.v1beta1.PurgeUserEventsResponse; +import com.google.cloud.recommendationengine.v1beta1.UserEventServiceClient; + +public class AsyncPurgeUserEventsLRO { + + public static void main(String[] args) throws Exception { + asyncPurgeUserEventsLRO(); + } + + public static void asyncPurgeUserEventsLRO() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (UserEventServiceClient userEventServiceClient = UserEventServiceClient.create()) { + PurgeUserEventsRequest request = + PurgeUserEventsRequest.newBuilder() + .setParent( + EventStoreName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]") + .toString()) + .setFilter("filter-1274492040") + .setForce(true) + .build(); + OperationFuture future = + userEventServiceClient.purgeUserEventsOperationCallable().futureCall(request); + // Do something. + PurgeUserEventsResponse response = future.get(); + } + } +} +// [END recommendationengine_v1beta1_generated_usereventserviceclient_purgeuserevents_lro_async] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/purgeuserevents/SyncPurgeUserEvents.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/purgeuserevents/SyncPurgeUserEvents.java new file mode 100644 index 000000000000..02631fddd6b5 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/purgeuserevents/SyncPurgeUserEvents.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.recommendationengine.v1beta1.samples; + +// [START recommendationengine_v1beta1_generated_usereventserviceclient_purgeuserevents_sync] +import com.google.cloud.recommendationengine.v1beta1.EventStoreName; +import com.google.cloud.recommendationengine.v1beta1.PurgeUserEventsRequest; +import com.google.cloud.recommendationengine.v1beta1.PurgeUserEventsResponse; +import com.google.cloud.recommendationengine.v1beta1.UserEventServiceClient; + +public class SyncPurgeUserEvents { + + public static void main(String[] args) throws Exception { + syncPurgeUserEvents(); + } + + public static void syncPurgeUserEvents() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (UserEventServiceClient userEventServiceClient = UserEventServiceClient.create()) { + PurgeUserEventsRequest request = + PurgeUserEventsRequest.newBuilder() + .setParent( + EventStoreName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]") + .toString()) + .setFilter("filter-1274492040") + .setForce(true) + .build(); + PurgeUserEventsResponse response = userEventServiceClient.purgeUserEventsAsync(request).get(); + } + } +} +// [END recommendationengine_v1beta1_generated_usereventserviceclient_purgeuserevents_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/purgeuserevents/SyncPurgeUserEventsEventstorenameStringBoolean.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/purgeuserevents/SyncPurgeUserEventsEventstorenameStringBoolean.java new file mode 100644 index 000000000000..c31ace75d06e --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/purgeuserevents/SyncPurgeUserEventsEventstorenameStringBoolean.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.recommendationengine.v1beta1.samples; + +// [START +// recommendationengine_v1beta1_generated_usereventserviceclient_purgeuserevents_eventstorenamestringboolean_sync] +import com.google.cloud.recommendationengine.v1beta1.EventStoreName; +import com.google.cloud.recommendationengine.v1beta1.PurgeUserEventsResponse; +import com.google.cloud.recommendationengine.v1beta1.UserEventServiceClient; + +public class SyncPurgeUserEventsEventstorenameStringBoolean { + + public static void main(String[] args) throws Exception { + syncPurgeUserEventsEventstorenameStringBoolean(); + } + + public static void syncPurgeUserEventsEventstorenameStringBoolean() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (UserEventServiceClient userEventServiceClient = UserEventServiceClient.create()) { + EventStoreName parent = + EventStoreName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]"); + String filter = "filter-1274492040"; + boolean force = true; + PurgeUserEventsResponse response = + userEventServiceClient.purgeUserEventsAsync(parent, filter, force).get(); + } + } +} +// [END +// recommendationengine_v1beta1_generated_usereventserviceclient_purgeuserevents_eventstorenamestringboolean_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/purgeuserevents/SyncPurgeUserEventsStringStringBoolean.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/purgeuserevents/SyncPurgeUserEventsStringStringBoolean.java new file mode 100644 index 000000000000..a784172f684c --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/purgeuserevents/SyncPurgeUserEventsStringStringBoolean.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.recommendationengine.v1beta1.samples; + +// [START +// recommendationengine_v1beta1_generated_usereventserviceclient_purgeuserevents_stringstringboolean_sync] +import com.google.cloud.recommendationengine.v1beta1.EventStoreName; +import com.google.cloud.recommendationengine.v1beta1.PurgeUserEventsResponse; +import com.google.cloud.recommendationengine.v1beta1.UserEventServiceClient; + +public class SyncPurgeUserEventsStringStringBoolean { + + public static void main(String[] args) throws Exception { + syncPurgeUserEventsStringStringBoolean(); + } + + public static void syncPurgeUserEventsStringStringBoolean() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (UserEventServiceClient userEventServiceClient = UserEventServiceClient.create()) { + String parent = + EventStoreName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]").toString(); + String filter = "filter-1274492040"; + boolean force = true; + PurgeUserEventsResponse response = + userEventServiceClient.purgeUserEventsAsync(parent, filter, force).get(); + } + } +} +// [END +// recommendationengine_v1beta1_generated_usereventserviceclient_purgeuserevents_stringstringboolean_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/writeuserevent/AsyncWriteUserEvent.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/writeuserevent/AsyncWriteUserEvent.java new file mode 100644 index 000000000000..6f8a04c799e3 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/writeuserevent/AsyncWriteUserEvent.java @@ -0,0 +1,50 @@ +/* + * 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.recommendationengine.v1beta1.samples; + +// [START recommendationengine_v1beta1_generated_usereventserviceclient_writeuserevent_async] +import com.google.api.core.ApiFuture; +import com.google.cloud.recommendationengine.v1beta1.EventStoreName; +import com.google.cloud.recommendationengine.v1beta1.UserEvent; +import com.google.cloud.recommendationengine.v1beta1.UserEventServiceClient; +import com.google.cloud.recommendationengine.v1beta1.WriteUserEventRequest; + +public class AsyncWriteUserEvent { + + public static void main(String[] args) throws Exception { + asyncWriteUserEvent(); + } + + public static void asyncWriteUserEvent() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (UserEventServiceClient userEventServiceClient = UserEventServiceClient.create()) { + WriteUserEventRequest request = + WriteUserEventRequest.newBuilder() + .setParent( + EventStoreName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]") + .toString()) + .setUserEvent(UserEvent.newBuilder().build()) + .build(); + ApiFuture future = + userEventServiceClient.writeUserEventCallable().futureCall(request); + // Do something. + UserEvent response = future.get(); + } + } +} +// [END recommendationengine_v1beta1_generated_usereventserviceclient_writeuserevent_async] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/writeuserevent/SyncWriteUserEvent.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/writeuserevent/SyncWriteUserEvent.java new file mode 100644 index 000000000000..2dff34ee7e9f --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/writeuserevent/SyncWriteUserEvent.java @@ -0,0 +1,46 @@ +/* + * 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.recommendationengine.v1beta1.samples; + +// [START recommendationengine_v1beta1_generated_usereventserviceclient_writeuserevent_sync] +import com.google.cloud.recommendationengine.v1beta1.EventStoreName; +import com.google.cloud.recommendationengine.v1beta1.UserEvent; +import com.google.cloud.recommendationengine.v1beta1.UserEventServiceClient; +import com.google.cloud.recommendationengine.v1beta1.WriteUserEventRequest; + +public class SyncWriteUserEvent { + + public static void main(String[] args) throws Exception { + syncWriteUserEvent(); + } + + public static void syncWriteUserEvent() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (UserEventServiceClient userEventServiceClient = UserEventServiceClient.create()) { + WriteUserEventRequest request = + WriteUserEventRequest.newBuilder() + .setParent( + EventStoreName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]") + .toString()) + .setUserEvent(UserEvent.newBuilder().build()) + .build(); + UserEvent response = userEventServiceClient.writeUserEvent(request); + } + } +} +// [END recommendationengine_v1beta1_generated_usereventserviceclient_writeuserevent_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/writeuserevent/SyncWriteUserEventEventstorenameUserevent.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/writeuserevent/SyncWriteUserEventEventstorenameUserevent.java new file mode 100644 index 000000000000..52aa8255e124 --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/writeuserevent/SyncWriteUserEventEventstorenameUserevent.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.recommendationengine.v1beta1.samples; + +// [START +// recommendationengine_v1beta1_generated_usereventserviceclient_writeuserevent_eventstorenameuserevent_sync] +import com.google.cloud.recommendationengine.v1beta1.EventStoreName; +import com.google.cloud.recommendationengine.v1beta1.UserEvent; +import com.google.cloud.recommendationengine.v1beta1.UserEventServiceClient; + +public class SyncWriteUserEventEventstorenameUserevent { + + public static void main(String[] args) throws Exception { + syncWriteUserEventEventstorenameUserevent(); + } + + public static void syncWriteUserEventEventstorenameUserevent() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (UserEventServiceClient userEventServiceClient = UserEventServiceClient.create()) { + EventStoreName parent = + EventStoreName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]"); + UserEvent userEvent = UserEvent.newBuilder().build(); + UserEvent response = userEventServiceClient.writeUserEvent(parent, userEvent); + } + } +} +// [END +// recommendationengine_v1beta1_generated_usereventserviceclient_writeuserevent_eventstorenameuserevent_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/writeuserevent/SyncWriteUserEventStringUserevent.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/writeuserevent/SyncWriteUserEventStringUserevent.java new file mode 100644 index 000000000000..9cdcc22e9a6f --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventserviceclient/writeuserevent/SyncWriteUserEventStringUserevent.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.recommendationengine.v1beta1.samples; + +// [START +// recommendationengine_v1beta1_generated_usereventserviceclient_writeuserevent_stringuserevent_sync] +import com.google.cloud.recommendationengine.v1beta1.EventStoreName; +import com.google.cloud.recommendationengine.v1beta1.UserEvent; +import com.google.cloud.recommendationengine.v1beta1.UserEventServiceClient; + +public class SyncWriteUserEventStringUserevent { + + public static void main(String[] args) throws Exception { + syncWriteUserEventStringUserevent(); + } + + public static void syncWriteUserEventStringUserevent() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (UserEventServiceClient userEventServiceClient = UserEventServiceClient.create()) { + String parent = + EventStoreName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[EVENT_STORE]").toString(); + UserEvent userEvent = UserEvent.newBuilder().build(); + UserEvent response = userEventServiceClient.writeUserEvent(parent, userEvent); + } + } +} +// [END +// recommendationengine_v1beta1_generated_usereventserviceclient_writeuserevent_stringuserevent_sync] diff --git a/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventservicesettings/writeuserevent/SyncWriteUserEvent.java b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventservicesettings/writeuserevent/SyncWriteUserEvent.java new file mode 100644 index 000000000000..a7f7a581346a --- /dev/null +++ b/java-recommendations-ai/samples/snippets/generated/com/google/cloud/recommendationengine/v1beta1/usereventservicesettings/writeuserevent/SyncWriteUserEvent.java @@ -0,0 +1,46 @@ +/* + * 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.recommendationengine.v1beta1.samples; + +// [START recommendationengine_v1beta1_generated_usereventservicesettings_writeuserevent_sync] +import com.google.cloud.recommendationengine.v1beta1.UserEventServiceSettings; +import java.time.Duration; + +public class SyncWriteUserEvent { + + public static void main(String[] args) throws Exception { + syncWriteUserEvent(); + } + + public static void syncWriteUserEvent() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + UserEventServiceSettings.Builder userEventServiceSettingsBuilder = + UserEventServiceSettings.newBuilder(); + userEventServiceSettingsBuilder + .writeUserEventSettings() + .setRetrySettings( + userEventServiceSettingsBuilder + .writeUserEventSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + UserEventServiceSettings userEventServiceSettings = userEventServiceSettingsBuilder.build(); + } +} +// [END recommendationengine_v1beta1_generated_usereventservicesettings_writeuserevent_sync]