com.google.cloud.retail.v2beta.stub.HttpJsonUserEventServiceStub Maven / Gradle / Ivy
/*
* Copyright 2024 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.retail.v2beta.stub;
import com.google.api.HttpBody;
import com.google.api.HttpRule;
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.RequestParamsBuilder;
import com.google.api.gax.rpc.UnaryCallable;
import com.google.cloud.retail.v2beta.CollectUserEventRequest;
import com.google.cloud.retail.v2beta.ExportMetadata;
import com.google.cloud.retail.v2beta.ExportUserEventsRequest;
import com.google.cloud.retail.v2beta.ExportUserEventsResponse;
import com.google.cloud.retail.v2beta.ImportMetadata;
import com.google.cloud.retail.v2beta.ImportUserEventsRequest;
import com.google.cloud.retail.v2beta.ImportUserEventsResponse;
import com.google.cloud.retail.v2beta.PurgeMetadata;
import com.google.cloud.retail.v2beta.PurgeUserEventsRequest;
import com.google.cloud.retail.v2beta.PurgeUserEventsResponse;
import com.google.cloud.retail.v2beta.RejoinUserEventsMetadata;
import com.google.cloud.retail.v2beta.RejoinUserEventsRequest;
import com.google.cloud.retail.v2beta.RejoinUserEventsResponse;
import com.google.cloud.retail.v2beta.UserEvent;
import com.google.cloud.retail.v2beta.WriteUserEventRequest;
import com.google.common.collect.ImmutableMap;
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(ExportMetadata.getDescriptor())
.add(ImportMetadata.getDescriptor())
.add(ExportUserEventsResponse.getDescriptor())
.add(PurgeMetadata.getDescriptor())
.add(ImportUserEventsResponse.getDescriptor())
.add(RejoinUserEventsMetadata.getDescriptor())
.add(RejoinUserEventsResponse.getDescriptor())
.add(PurgeUserEventsResponse.getDescriptor())
.build();
private static final ApiMethodDescriptor
writeUserEventMethodDescriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName("google.cloud.retail.v2beta.UserEventService/WriteUserEvent")
.setHttpMethod("POST")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v2beta/{parent=projects/*/locations/*/catalogs/*}/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();
serializer.putQueryParam(fields, "writeAsync", request.getWriteAsync());
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(
request ->
ProtoRestSerializer.create()
.toBody("userEvent", request.getUserEvent(), true))
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(UserEvent.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.build();
private static final ApiMethodDescriptor
collectUserEventMethodDescriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName("google.cloud.retail.v2beta.UserEventService/CollectUserEvent")
.setHttpMethod("GET")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v2beta/{parent=projects/*/locations/*/catalogs/*}/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, "prebuiltRule", request.getPrebuiltRule());
serializer.putQueryParam(fields, "rawJson", request.getRawJson());
serializer.putQueryParam(fields, "uri", request.getUri());
serializer.putQueryParam(fields, "userEvent", request.getUserEvent());
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(request -> null)
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(HttpBody.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.build();
private static final ApiMethodDescriptor
purgeUserEventsMethodDescriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName("google.cloud.retail.v2beta.UserEventService/PurgeUserEvents")
.setHttpMethod("POST")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v2beta/{parent=projects/*/locations/*/catalogs/*}/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();
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(
request ->
ProtoRestSerializer.create()
.toBody("*", request.toBuilder().clearParent().build(), true))
.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.retail.v2beta.UserEventService/ImportUserEvents")
.setHttpMethod("POST")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v2beta/{parent=projects/*/locations/*/catalogs/*}/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();
serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(
request ->
ProtoRestSerializer.create()
.toBody("*", request.toBuilder().clearParent().build(), true))
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(Operation.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.setOperationSnapshotFactory(
(ImportUserEventsRequest request, Operation response) ->
HttpJsonOperationSnapshot.create(response))
.build();
private static final ApiMethodDescriptor
exportUserEventsMethodDescriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName("google.cloud.retail.v2beta.UserEventService/ExportUserEvents")
.setHttpMethod("POST")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v2beta/{parent=projects/*/locations/*/catalogs/*}/userEvents:export",
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, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(
request ->
ProtoRestSerializer.create()
.toBody("*", request.toBuilder().clearParent().build(), true))
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(Operation.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.setOperationSnapshotFactory(
(ExportUserEventsRequest request, Operation response) ->
HttpJsonOperationSnapshot.create(response))
.build();
private static final ApiMethodDescriptor
rejoinUserEventsMethodDescriptor =
ApiMethodDescriptor.newBuilder()
.setFullMethodName("google.cloud.retail.v2beta.UserEventService/RejoinUserEvents")
.setHttpMethod("POST")
.setType(ApiMethodDescriptor.MethodType.UNARY)
.setRequestFormatter(
ProtoMessageRequestFormatter.newBuilder()
.setPath(
"/v2beta/{parent=projects/*/locations/*/catalogs/*}/userEvents:rejoin",
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, "$alt", "json;enum-encoding=int");
return fields;
})
.setRequestBodyExtractor(
request ->
ProtoRestSerializer.create()
.toBody("*", request.toBuilder().clearParent().build(), true))
.build())
.setResponseParser(
ProtoMessageResponseParser.newBuilder()
.setDefaultInstance(Operation.getDefaultInstance())
.setDefaultTypeRegistry(typeRegistry)
.build())
.setOperationSnapshotFactory(
(RejoinUserEventsRequest request, Operation response) ->
HttpJsonOperationSnapshot.create(response))
.build();
private final UnaryCallable writeUserEventCallable;
private final UnaryCallable collectUserEventCallable;
private final UnaryCallable purgeUserEventsCallable;
private final OperationCallable
purgeUserEventsOperationCallable;
private final UnaryCallable importUserEventsCallable;
private final OperationCallable
importUserEventsOperationCallable;
private final UnaryCallable exportUserEventsCallable;
private final OperationCallable
exportUserEventsOperationCallable;
private final UnaryCallable rejoinUserEventsCallable;
private final OperationCallable<
RejoinUserEventsRequest, RejoinUserEventsResponse, RejoinUserEventsMetadata>
rejoinUserEventsOperationCallable;
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,
ImmutableMap.builder()
.put(
"google.longrunning.Operations.GetOperation",
HttpRule.newBuilder()
.setGet(
"/v2beta/{name=projects/*/locations/*/catalogs/*/branches/*/operations/*}")
.addAdditionalBindings(
HttpRule.newBuilder()
.setGet(
"/v2beta/{name=projects/*/locations/*/catalogs/*/operations/*}")
.build())
.addAdditionalBindings(
HttpRule.newBuilder()
.setGet("/v2beta/{name=projects/*/locations/*/operations/*}")
.build())
.addAdditionalBindings(
HttpRule.newBuilder()
.setGet("/v2beta/{name=projects/*/operations/*}")
.build())
.build())
.put(
"google.longrunning.Operations.ListOperations",
HttpRule.newBuilder()
.setGet("/v2beta/{name=projects/*/locations/*/catalogs/*}/operations")
.addAdditionalBindings(
HttpRule.newBuilder()
.setGet("/v2beta/{name=projects/*/locations/*}/operations")
.build())
.addAdditionalBindings(
HttpRule.newBuilder()
.setGet("/v2beta/{name=projects/*}/operations")
.build())
.build())
.build());
HttpJsonCallSettings writeUserEventTransportSettings =
HttpJsonCallSettings.newBuilder()
.setMethodDescriptor(writeUserEventMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("parent", String.valueOf(request.getParent()));
return builder.build();
})
.build();
HttpJsonCallSettings collectUserEventTransportSettings =
HttpJsonCallSettings.newBuilder()
.setMethodDescriptor(collectUserEventMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("parent", String.valueOf(request.getParent()));
return builder.build();
})
.build();
HttpJsonCallSettings purgeUserEventsTransportSettings =
HttpJsonCallSettings.newBuilder()
.setMethodDescriptor(purgeUserEventsMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("parent", String.valueOf(request.getParent()));
return builder.build();
})
.build();
HttpJsonCallSettings importUserEventsTransportSettings =
HttpJsonCallSettings.newBuilder()
.setMethodDescriptor(importUserEventsMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("parent", String.valueOf(request.getParent()));
return builder.build();
})
.build();
HttpJsonCallSettings exportUserEventsTransportSettings =
HttpJsonCallSettings.newBuilder()
.setMethodDescriptor(exportUserEventsMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("parent", String.valueOf(request.getParent()));
return builder.build();
})
.build();
HttpJsonCallSettings rejoinUserEventsTransportSettings =
HttpJsonCallSettings.newBuilder()
.setMethodDescriptor(rejoinUserEventsMethodDescriptor)
.setTypeRegistry(typeRegistry)
.setParamsExtractor(
request -> {
RequestParamsBuilder builder = RequestParamsBuilder.create();
builder.add("parent", String.valueOf(request.getParent()));
return builder.build();
})
.build();
this.writeUserEventCallable =
callableFactory.createUnaryCallable(
writeUserEventTransportSettings, settings.writeUserEventSettings(), clientContext);
this.collectUserEventCallable =
callableFactory.createUnaryCallable(
collectUserEventTransportSettings, settings.collectUserEventSettings(), 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.exportUserEventsCallable =
callableFactory.createUnaryCallable(
exportUserEventsTransportSettings, settings.exportUserEventsSettings(), clientContext);
this.exportUserEventsOperationCallable =
callableFactory.createOperationCallable(
exportUserEventsTransportSettings,
settings.exportUserEventsOperationSettings(),
clientContext,
httpJsonOperationsStub);
this.rejoinUserEventsCallable =
callableFactory.createUnaryCallable(
rejoinUserEventsTransportSettings, settings.rejoinUserEventsSettings(), clientContext);
this.rejoinUserEventsOperationCallable =
callableFactory.createOperationCallable(
rejoinUserEventsTransportSettings,
settings.rejoinUserEventsOperationSettings(),
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(purgeUserEventsMethodDescriptor);
methodDescriptors.add(importUserEventsMethodDescriptor);
methodDescriptors.add(exportUserEventsMethodDescriptor);
methodDescriptors.add(rejoinUserEventsMethodDescriptor);
return methodDescriptors;
}
public HttpJsonOperationsStub getHttpJsonOperationsStub() {
return httpJsonOperationsStub;
}
@Override
public UnaryCallable writeUserEventCallable() {
return writeUserEventCallable;
}
@Override
public UnaryCallable collectUserEventCallable() {
return collectUserEventCallable;
}
@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 UnaryCallable exportUserEventsCallable() {
return exportUserEventsCallable;
}
@Override
public OperationCallable
exportUserEventsOperationCallable() {
return exportUserEventsOperationCallable;
}
@Override
public UnaryCallable rejoinUserEventsCallable() {
return rejoinUserEventsCallable;
}
@Override
public OperationCallable<
RejoinUserEventsRequest, RejoinUserEventsResponse, RejoinUserEventsMetadata>
rejoinUserEventsOperationCallable() {
return rejoinUserEventsOperationCallable;
}
@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);
}
}