Class CollectionServiceClient (0.99.0)

GitHub RepositoryProduct Reference

Service Description: Service for managing Collections.

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


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (CollectionServiceClient collectionServiceClient = CollectionServiceClient.create()) {
   ResourceName resource = CollectionName.of("[PROJECT]", "[LOCATION]", "[COLLECTION]");
   Policy response = collectionServiceClient.getIamPolicy(resource);
 }
 

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

Methods
Method Description Method Variants

DeleteCollection

Deletes a Collection.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • deleteCollectionAsync(DeleteCollectionRequest request)

Methods that return long-running operations have "Async" method variants that return OperationFuture, which is used to track polling of the service.

  • deleteCollectionAsync(CollectionName name)

  • deleteCollectionAsync(String name)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • deleteCollectionOperationCallable()

  • deleteCollectionCallable()

GetIamPolicy

Gets the IAM access control policy for a Collection. A NOT_FOUND error is returned if the resource does not exist. An empty policy is returned if the resource exists but does not have a policy set on it.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • getIamPolicy(GetIamPolicyRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • getIamPolicy(ResourceName resource)

  • getIamPolicy(String resource)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • getIamPolicyCallable()

SetIamPolicy

Sets the IAM access control policy for a Collection. A NOT_FOUND error is returned if the resource does not exist.

**Important:** When setting a policy directly on a Collection resource, the only recommended roles in the bindings are: roles/discoveryengine.admin roles/discoveryengine.agentspaceAdmin roles/discoveryengine.viewer roles/discoveryengine.agentspaceViewer roles/discoveryengine.user roles/discoveryengine.agentspaceUser Attempting to grant any other role will result in a warning in logging.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • setIamPolicy(SetIamPolicyRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • setIamPolicy(ResourceName resource, Policy policy)

  • setIamPolicy(String resource, Policy policy)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • setIamPolicyCallable()

See the individual methods for example code.

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

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

To customize credentials:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 CollectionServiceSettings collectionServiceSettings =
     CollectionServiceSettings.newBuilder()
         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
         .build();
 CollectionServiceClient collectionServiceClient =
     CollectionServiceClient.create(collectionServiceSettings);
 

To customize the endpoint:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 CollectionServiceSettings collectionServiceSettings =
     CollectionServiceSettings.newBuilder().setEndpoint(myEndpoint).build();
 CollectionServiceClient collectionServiceClient =
     CollectionServiceClient.create(collectionServiceSettings);
 

To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over the wire:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 CollectionServiceSettings collectionServiceSettings =
     CollectionServiceSettings.newHttpJsonBuilder().build();
 CollectionServiceClient collectionServiceClient =
     CollectionServiceClient.create(collectionServiceSettings);
 

Please refer to the GitHub repository's samples for more quickstart code snippets.

Inheritance

java.lang.Object > CollectionServiceClient

Static Methods

create()

public static final CollectionServiceClient create()

Constructs an instance of CollectionServiceClient with default settings.

Returns
Type Description
CollectionServiceClient
Exceptions
Type Description
IOException

create(CollectionServiceSettings settings)

public static final CollectionServiceClient create(CollectionServiceSettings settings)

Constructs an instance of CollectionServiceClient, using the given settings. The channels are created based on the settings passed in, or defaults for any settings that are not set.

Parameter
Name Description
settings CollectionServiceSettings
Returns
Type Description
CollectionServiceClient
Exceptions
Type Description
IOException

create(CollectionServiceStub stub)

public static final CollectionServiceClient create(CollectionServiceStub stub)

Constructs an instance of CollectionServiceClient, using the given stub for making calls. This is for advanced usage - prefer using create(CollectionServiceSettings).

Parameter
Name Description
stub CollectionServiceStub
Returns
Type Description
CollectionServiceClient

Constructors

CollectionServiceClient(CollectionServiceSettings settings)

protected CollectionServiceClient(CollectionServiceSettings settings)

Constructs an instance of CollectionServiceClient, 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.

Parameter
Name Description
settings CollectionServiceSettings

CollectionServiceClient(CollectionServiceStub stub)

protected CollectionServiceClient(CollectionServiceStub stub)
Parameter
Name Description
stub CollectionServiceStub

Methods

awaitTermination(long duration, TimeUnit unit)

public boolean awaitTermination(long duration, TimeUnit unit)
Parameters
Name Description
duration long
unit TimeUnit
Returns
Type Description
boolean
Exceptions
Type Description
InterruptedException

close()

public final void close()

deleteCollectionAsync(@Nullable CollectionName name)

public final OperationFuture<Empty,DeleteCollectionMetadata> deleteCollectionAsync(@Nullable CollectionName name)

Deletes a Collection.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (CollectionServiceClient collectionServiceClient = CollectionServiceClient.create()) {
   CollectionName name = CollectionName.of("[PROJECT]", "[LOCATION]", "[COLLECTION]");
   collectionServiceClient.deleteCollectionAsync(name).get();
 }
 
Parameter
Name Description
name @org.jspecify.annotations.Nullable com.google.cloud.discoveryengine.v1.CollectionName

Required. The full resource name of the Collection, in the format of projects/{project}/locations/{location}/collections/{collection}.

Returns
Type Description
OperationFuture<Empty,DeleteCollectionMetadata>

deleteCollectionAsync(DeleteCollectionRequest request)

public final OperationFuture<Empty,DeleteCollectionMetadata> deleteCollectionAsync(DeleteCollectionRequest request)

Deletes a Collection.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (CollectionServiceClient collectionServiceClient = CollectionServiceClient.create()) {
   DeleteCollectionRequest request =
       DeleteCollectionRequest.newBuilder()
           .setName(CollectionName.of("[PROJECT]", "[LOCATION]", "[COLLECTION]").toString())
           .build();
   collectionServiceClient.deleteCollectionAsync(request).get();
 }
 
Parameter
Name Description
request DeleteCollectionRequest

The request object containing all of the parameters for the API call.

Returns
Type Description
OperationFuture<Empty,DeleteCollectionMetadata>

deleteCollectionAsync(String name)

public final OperationFuture<Empty,DeleteCollectionMetadata> deleteCollectionAsync(String name)

Deletes a Collection.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (CollectionServiceClient collectionServiceClient = CollectionServiceClient.create()) {
   String name = CollectionName.of("[PROJECT]", "[LOCATION]", "[COLLECTION]").toString();
   collectionServiceClient.deleteCollectionAsync(name).get();
 }
 
Parameter
Name Description
name String

Required. The full resource name of the Collection, in the format of projects/{project}/locations/{location}/collections/{collection}.

Returns
Type Description
OperationFuture<Empty,DeleteCollectionMetadata>

deleteCollectionCallable()

public final UnaryCallable<DeleteCollectionRequest,Operation> deleteCollectionCallable()

Deletes a Collection.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (CollectionServiceClient collectionServiceClient = CollectionServiceClient.create()) {
   DeleteCollectionRequest request =
       DeleteCollectionRequest.newBuilder()
           .setName(CollectionName.of("[PROJECT]", "[LOCATION]", "[COLLECTION]").toString())
           .build();
   ApiFuture<Operation> future =
       collectionServiceClient.deleteCollectionCallable().futureCall(request);
   // Do something.
   future.get();
 }
 
Returns
Type Description
UnaryCallable<DeleteCollectionRequest,Operation>

deleteCollectionOperationCallable()

public final OperationCallable<DeleteCollectionRequest,Empty,DeleteCollectionMetadata> deleteCollectionOperationCallable()

Deletes a Collection.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (CollectionServiceClient collectionServiceClient = CollectionServiceClient.create()) {
   DeleteCollectionRequest request =
       DeleteCollectionRequest.newBuilder()
           .setName(CollectionName.of("[PROJECT]", "[LOCATION]", "[COLLECTION]").toString())
           .build();
   OperationFuture<Empty, DeleteCollectionMetadata> future =
       collectionServiceClient.deleteCollectionOperationCallable().futureCall(request);
   // Do something.
   future.get();
 }
 
Returns
Type Description
OperationCallable<DeleteCollectionRequest,Empty,DeleteCollectionMetadata>

getHttpJsonOperationsClient()

public final OperationsClient getHttpJsonOperationsClient()

Returns the OperationsClient that can be used to query the status of a long-running operation returned by another API method call.

Returns
Type Description
OperationsClient

getIamPolicy(@Nullable ResourceName resource)

public final Policy getIamPolicy(@Nullable ResourceName resource)

Gets the IAM access control policy for a Collection. A NOT_FOUND error is returned if the resource does not exist. An empty policy is returned if the resource exists but does not have a policy set on it.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (CollectionServiceClient collectionServiceClient = CollectionServiceClient.create()) {
   ResourceName resource = CollectionName.of("[PROJECT]", "[LOCATION]", "[COLLECTION]");
   Policy response = collectionServiceClient.getIamPolicy(resource);
 }
 
Parameter
Name Description
resource @org.jspecify.annotations.Nullable com.google.api.resourcenames.ResourceName

REQUIRED: The resource for which the policy is being requested. See the operation documentation for the appropriate value for this field.

Returns
Type Description
com.google.iam.v1.Policy

getIamPolicy(GetIamPolicyRequest request)

public final Policy getIamPolicy(GetIamPolicyRequest request)

Gets the IAM access control policy for a Collection. A NOT_FOUND error is returned if the resource does not exist. An empty policy is returned if the resource exists but does not have a policy set on it.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (CollectionServiceClient collectionServiceClient = CollectionServiceClient.create()) {
   GetIamPolicyRequest request =
       GetIamPolicyRequest.newBuilder()
           .setResource(CollectionName.of("[PROJECT]", "[LOCATION]", "[COLLECTION]").toString())
           .setOptions(GetPolicyOptions.newBuilder().build())
           .build();
   Policy response = collectionServiceClient.getIamPolicy(request);
 }
 
Parameter
Name Description
request com.google.iam.v1.GetIamPolicyRequest

The request object containing all of the parameters for the API call.

Returns
Type Description
com.google.iam.v1.Policy

getIamPolicy(String resource)

public final Policy getIamPolicy(String resource)

Gets the IAM access control policy for a Collection. A NOT_FOUND error is returned if the resource does not exist. An empty policy is returned if the resource exists but does not have a policy set on it.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (CollectionServiceClient collectionServiceClient = CollectionServiceClient.create()) {
   String resource = AclConfigName.of("[PROJECT]", "[LOCATION]").toString();
   Policy response = collectionServiceClient.getIamPolicy(resource);
 }
 
Parameter
Name Description
resource String

REQUIRED: The resource for which the policy is being requested. See the operation documentation for the appropriate value for this field.

Returns
Type Description
com.google.iam.v1.Policy

getIamPolicyCallable()

public final UnaryCallable<GetIamPolicyRequest,Policy> getIamPolicyCallable()

Gets the IAM access control policy for a Collection. A NOT_FOUND error is returned if the resource does not exist. An empty policy is returned if the resource exists but does not have a policy set on it.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (CollectionServiceClient collectionServiceClient = CollectionServiceClient.create()) {
   GetIamPolicyRequest request =
       GetIamPolicyRequest.newBuilder()
           .setResource(CollectionName.of("[PROJECT]", "[LOCATION]", "[COLLECTION]").toString())
           .setOptions(GetPolicyOptions.newBuilder().build())
           .build();
   ApiFuture<Policy> future = collectionServiceClient.getIamPolicyCallable().futureCall(request);
   // Do something.
   Policy response = future.get();
 }
 
Returns
Type Description
UnaryCallable<com.google.iam.v1.GetIamPolicyRequest,com.google.iam.v1.Policy>

getOperationsClient()

public final OperationsClient getOperationsClient()

Returns the OperationsClient that can be used to query the status of a long-running operation returned by another API method call.

Returns
Type Description
OperationsClient

getSettings()

public final @Nullable CollectionServiceSettings getSettings()
Returns
Type Description
@org.jspecify.annotations.Nullable com.google.cloud.discoveryengine.v1.CollectionServiceSettings

getStub()

public CollectionServiceStub getStub()
Returns
Type Description
CollectionServiceStub

isShutdown()

public boolean isShutdown()
Returns
Type Description
boolean

isTerminated()

public boolean isTerminated()
Returns
Type Description
boolean

setIamPolicy(@Nullable ResourceName resource, Policy policy)

public final Policy setIamPolicy(@Nullable ResourceName resource, Policy policy)

Sets the IAM access control policy for a Collection. A NOT_FOUND error is returned if the resource does not exist.

**Important:** When setting a policy directly on a Collection resource, the only recommended roles in the bindings are: roles/discoveryengine.admin roles/discoveryengine.agentspaceAdmin roles/discoveryengine.viewer roles/discoveryengine.agentspaceViewer roles/discoveryengine.user roles/discoveryengine.agentspaceUser Attempting to grant any other role will result in a warning in logging.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (CollectionServiceClient collectionServiceClient = CollectionServiceClient.create()) {
   ResourceName resource = CollectionName.of("[PROJECT]", "[LOCATION]", "[COLLECTION]");
   Policy policy = Policy.newBuilder().build();
   Policy response = collectionServiceClient.setIamPolicy(resource, policy);
 }
 
Parameters
Name Description
resource @org.jspecify.annotations.Nullable com.google.api.resourcenames.ResourceName

REQUIRED: The resource for which the policy is being specified. See the operation documentation for the appropriate value for this field.

policy com.google.iam.v1.Policy

REQUIRED: The complete policy to be applied to the resource. The size of the policy is limited to a few 10s of KB. An empty policy is a valid policy but certain Cloud Platform services (such as Projects) might reject them.

Returns
Type Description
com.google.iam.v1.Policy

setIamPolicy(SetIamPolicyRequest request)

public final Policy setIamPolicy(SetIamPolicyRequest request)

Sets the IAM access control policy for a Collection. A NOT_FOUND error is returned if the resource does not exist.

**Important:** When setting a policy directly on a Collection resource, the only recommended roles in the bindings are: roles/discoveryengine.admin roles/discoveryengine.agentspaceAdmin roles/discoveryengine.viewer roles/discoveryengine.agentspaceViewer roles/discoveryengine.user roles/discoveryengine.agentspaceUser Attempting to grant any other role will result in a warning in logging.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (CollectionServiceClient collectionServiceClient = CollectionServiceClient.create()) {
   SetIamPolicyRequest request =
       SetIamPolicyRequest.newBuilder()
           .setResource(CollectionName.of("[PROJECT]", "[LOCATION]", "[COLLECTION]").toString())
           .setPolicy(Policy.newBuilder().build())
           .setUpdateMask(FieldMask.newBuilder().build())
           .build();
   Policy response = collectionServiceClient.setIamPolicy(request);
 }
 
Parameter
Name Description
request com.google.iam.v1.SetIamPolicyRequest

The request object containing all of the parameters for the API call.

Returns
Type Description
com.google.iam.v1.Policy

setIamPolicy(String resource, Policy policy)

public final Policy setIamPolicy(String resource, Policy policy)

Sets the IAM access control policy for a Collection. A NOT_FOUND error is returned if the resource does not exist.

**Important:** When setting a policy directly on a Collection resource, the only recommended roles in the bindings are: roles/discoveryengine.admin roles/discoveryengine.agentspaceAdmin roles/discoveryengine.viewer roles/discoveryengine.agentspaceViewer roles/discoveryengine.user roles/discoveryengine.agentspaceUser Attempting to grant any other role will result in a warning in logging.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (CollectionServiceClient collectionServiceClient = CollectionServiceClient.create()) {
   String resource = AclConfigName.of("[PROJECT]", "[LOCATION]").toString();
   Policy policy = Policy.newBuilder().build();
   Policy response = collectionServiceClient.setIamPolicy(resource, policy);
 }
 
Parameters
Name Description
resource String

REQUIRED: The resource for which the policy is being specified. See the operation documentation for the appropriate value for this field.

policy com.google.iam.v1.Policy

REQUIRED: The complete policy to be applied to the resource. The size of the policy is limited to a few 10s of KB. An empty policy is a valid policy but certain Cloud Platform services (such as Projects) might reject them.

Returns
Type Description
com.google.iam.v1.Policy

setIamPolicyCallable()

public final UnaryCallable<SetIamPolicyRequest,Policy> setIamPolicyCallable()

Sets the IAM access control policy for a Collection. A NOT_FOUND error is returned if the resource does not exist.

**Important:** When setting a policy directly on a Collection resource, the only recommended roles in the bindings are: roles/discoveryengine.admin roles/discoveryengine.agentspaceAdmin roles/discoveryengine.viewer roles/discoveryengine.agentspaceViewer roles/discoveryengine.user roles/discoveryengine.agentspaceUser Attempting to grant any other role will result in a warning in logging.

Sample code:


 // This snippet has been automatically generated and should be regarded as a code template only.
 // It will require modifications to work:
 // - It may require correct/in-range values for request initialization.
 // - It may require specifying regional endpoints when creating the service client as shown in
 // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (CollectionServiceClient collectionServiceClient = CollectionServiceClient.create()) {
   SetIamPolicyRequest request =
       SetIamPolicyRequest.newBuilder()
           .setResource(CollectionName.of("[PROJECT]", "[LOCATION]", "[COLLECTION]").toString())
           .setPolicy(Policy.newBuilder().build())
           .setUpdateMask(FieldMask.newBuilder().build())
           .build();
   ApiFuture<Policy> future = collectionServiceClient.setIamPolicyCallable().futureCall(request);
   // Do something.
   Policy response = future.get();
 }
 
Returns
Type Description
UnaryCallable<com.google.iam.v1.SetIamPolicyRequest,com.google.iam.v1.Policy>

shutdown()

public void shutdown()

shutdownNow()

public void shutdownNow()