Class ProductSearchClient (3.1.0)

Stay organized with collections Save and categorize content based on your preferences.
public class ProductSearchClient implements BackgroundResource

Service Description: Manages Products and ProductSets of reference images for use in product search. It uses the following resource model:

- The API has a collection of ProductSet resources, named projects/*/locations/*/productSets/*, which acts as a way to put different products into groups to limit identification.

In parallel,

- The API has a collection of Product resources, named projects/*/locations/*/products/*

- Each Product has a collection of ReferenceImage resources, named projects/*/locations/*/products/*/referenceImages/*

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 for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (ProductSearchClient productSearchClient = ProductSearchClient.create()) {
   LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
   ProductSet productSet = ProductSet.newBuilder().build();
   String productSetId = "productSetId1003042158";
   ProductSet response = productSearchClient.createProductSet(parent, productSet, productSetId);
 }
 

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

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

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

See the individual methods for example code.

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

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

To customize credentials:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 ProductSearchSettings productSearchSettings =
     ProductSearchSettings.newBuilder()
         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
         .build();
 ProductSearchClient productSearchClient = ProductSearchClient.create(productSearchSettings);
 

To customize the endpoint:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 ProductSearchSettings productSearchSettings =
     ProductSearchSettings.newBuilder().setEndpoint(myEndpoint).build();
 ProductSearchClient productSearchClient = ProductSearchClient.create(productSearchSettings);
 

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


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 ProductSearchSettings productSearchSettings =
     ProductSearchSettings.newBuilder()
         .setTransportChannelProvider(
             ProductSearchSettings.defaultHttpJsonTransportProviderBuilder().build())
         .build();
 ProductSearchClient productSearchClient = ProductSearchClient.create(productSearchSettings);
 

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

Inheritance

java.lang.Object > ProductSearchClient

Implements

BackgroundResource

Static Methods

create()

public static final ProductSearchClient create()

Constructs an instance of ProductSearchClient with default settings.

Returns
TypeDescription
ProductSearchClient
Exceptions
TypeDescription
IOException

create(ProductSearchSettings settings)

public static final ProductSearchClient create(ProductSearchSettings settings)

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

Parameter
NameDescription
settingsProductSearchSettings
Returns
TypeDescription
ProductSearchClient
Exceptions
TypeDescription
IOException

create(ProductSearchStub stub)

public static final ProductSearchClient create(ProductSearchStub stub)

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

Parameter
NameDescription
stubProductSearchStub
Returns
TypeDescription
ProductSearchClient

Constructors

ProductSearchClient(ProductSearchSettings settings)

protected ProductSearchClient(ProductSearchSettings settings)

Constructs an instance of ProductSearchClient, 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
NameDescription
settingsProductSearchSettings

ProductSearchClient(ProductSearchStub stub)

protected ProductSearchClient(ProductSearchStub stub)
Parameter
NameDescription
stubProductSearchStub

Methods

addProductToProductSet(AddProductToProductSetRequest request)

public final void addProductToProductSet(AddProductToProductSetRequest request)

Adds a Product to the specified ProductSet. If the Product is already present, no change is made.

One Product can be added to at most 100 ProductSets.

Possible errors:

  • Returns NOT_FOUND if the Product or the ProductSet doesn't exist.

Sample code: