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:
- 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.
- 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.
- 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.
Implements
BackgroundResourceStatic Methods
create()
public static final ProductSearchClient create()
Constructs an instance of ProductSearchClient with default settings.
Type | Description |
ProductSearchClient |
Type | Description |
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.
Name | Description |
settings | ProductSearchSettings |
Type | Description |
ProductSearchClient |
Type | Description |
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).
Name | Description |
stub | ProductSearchStub |
Type | Description |
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.
Name | Description |
settings | ProductSearchSettings |
ProductSearchClient(ProductSearchStub stub)
protected ProductSearchClient(ProductSearchStub stub)
Name | Description |
stub | ProductSearchStub |
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);
}
Name | Description |
request | AddProductToProductSetRequest 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);
}
Name | Description |
name | ProductSetName Required. The resource name for the ProductSet to modify. Format is: |
product | ProductName Required. The resource name for the Product to be added to this ProductSet. Format is: |
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);
}
Name | Description |
name | ProductSetName Required. The resource name for the ProductSet to modify. Format is: |
product | String Required. The resource name for the Product to be added to this ProductSet. Format is: |
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);
}
Name | Description |
name | String Required. The resource name for the ProductSet to modify. Format is: |
product | ProductName Required. The resource name for the Product to be added to this ProductSet. Format is: |
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);
}
Name | Description |
name | String Required. The resource name for the ProductSet to modify. Format is: |
product | String Required. The resource name for the Product to be added to this ProductSet. Format is: |
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();
}
Type | Description |
UnaryCallable< |