Class ProductSearchClient (2.1.4)

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);
 

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:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (ProductSearchClient productSearchClient = ProductSearchClient.create()) {
   AddProductToProductSetRequest request =
       AddProductToProductSetRequest.newBuilder()
           .setName(ProductSetName.of("[PROJECT]", "[LOCATION]", "[PRODUCT_SET]").toString())
           .setProduct(ProductName.of("[PROJECT]", "[LOCATION]", "[PRODUCT]").toString())
           .build();
   productSearchClient.addProductToProductSet(request);
 }
 
Parameter
NameDescription
requestAddProductToProductSetRequest

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

addProductToProductSet(ProductSetName name, ProductName product)

public final void addProductToProductSet(ProductSetName name, ProductName product)

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:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (ProductSearchClient productSearchClient = ProductSearchClient.create()) {
   ProductSetName name = ProductSetName.of("[PROJECT]", "[LOCATION]", "[PRODUCT_SET]");
   ProductName product = ProductName.of("[PROJECT]", "[LOCATION]", "[PRODUCT]");
   productSearchClient.addProductToProductSet(name, product);
 }
 
Parameters
NameDescription
nameProductSetName

Required. The resource name for the ProductSet to modify.

Format is: projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID

productProductName

Required. The resource name for the Product to be added to this ProductSet.

Format is: projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID

addProductToProductSet(ProductSetName name, String product)

public final void addProductToProductSet(ProductSetName name, String product)

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:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (ProductSearchClient productSearchClient = ProductSearchClient.create()) {
   ProductSetName name = ProductSetName.of("[PROJECT]", "[LOCATION]", "[PRODUCT_SET]");
   String product = ProductName.of("[PROJECT]", "[LOCATION]", "[PRODUCT]").toString();
   productSearchClient.addProductToProductSet(name, product);
 }
 
Parameters
NameDescription
nameProductSetName

Required. The resource name for the ProductSet to modify.

Format is: projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID

productString

Required. The resource name for the Product to be added to this ProductSet.

Format is: projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID

addProductToProductSet(String name, ProductName product)

public final void addProductToProductSet(String name, ProductName product)

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:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (ProductSearchClient productSearchClient = ProductSearchClient.create()) {
   String name = ProductSetName.of("[PROJECT]", "[LOCATION]", "[PRODUCT_SET]").toString();
   ProductName product = ProductName.of("[PROJECT]", "[LOCATION]", "[PRODUCT]");
   productSearchClient.addProductToProductSet(name, product);
 }
 
Parameters
NameDescription
nameString

Required. The resource name for the ProductSet to modify.

Format is: projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID

productProductName

Required. The resource name for the Product to be added to this ProductSet.

Format is: projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID

addProductToProductSet(String name, String product)

public final void addProductToProductSet(String name, String product)

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:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (ProductSearchClient productSearchClient = ProductSearchClient.create()) {
   String name = ProductSetName.of("[PROJECT]", "[LOCATION]", "[PRODUCT_SET]").toString();
   String product = ProductName.of("[PROJECT]", "[LOCATION]", "[PRODUCT]").toString();
   productSearchClient.addProductToProductSet(name, product);
 }
 
Parameters
NameDescription
nameString

Required. The resource name for the ProductSet to modify.

Format is: projects/PROJECT_ID/locations/LOC_ID/productSets/PRODUCT_SET_ID

productString

Required. The resource name for the Product to be added to this ProductSet.

Format is: projects/PROJECT_ID/locations/LOC_ID/products/PRODUCT_ID

addProductToProductSetCallable()

public final UnaryCallable<AddProductToProductSetRequest,Empty> addProductToProductSetCallable()

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:


 // This snippet has been automatically generated for illustrative purposes only.
 // It may require modifications to work in your environment.
 try (ProductSearchClient productSearchClient = ProductSearchClient.create()) {
   AddProductToProductSetRequest request =
       AddProductToProductSetRequest.newBuilder()
           .setName(ProductSetName.of("[PROJECT]", "[LOCATION]", "[PRODUCT_SET]").toString())
           .setProduct(ProductName.of("[PROJECT]", "[LOCATION]", "[PRODUCT]").toString())
           .build();
   ApiFuture<Empty> future =
       productSearchClient.addProductToProductSetCallable().futureCall(request);
   // Do something.
   future.get();
 }
 
Returns
TypeDescription
UnaryCallable<