Class CatalogServiceClient

public class CatalogServiceClient implements BackgroundResource

Service Description: Service for managing catalog configuration.

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:


 try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) {
   Catalog catalog = Catalog.newBuilder().build();
   FieldMask updateMask = FieldMask.newBuilder().build();
   Catalog response = catalogServiceClient.updateCatalog(catalog, updateMask);
 }
 

Note: close() needs to be called on the CatalogServiceClient 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 CatalogServiceSettings to create(). For example:

To customize credentials:


 CatalogServiceSettings catalogServiceSettings =
     CatalogServiceSettings.newBuilder()
         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
         .build();
 CatalogServiceClient catalogServiceClient = CatalogServiceClient.create(catalogServiceSettings);
 

To customize the endpoint:


 CatalogServiceSettings catalogServiceSettings =
     CatalogServiceSettings.newBuilder().setEndpoint(myEndpoint).build();
 CatalogServiceClient catalogServiceClient = CatalogServiceClient.create(catalogServiceSettings);
 

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

Inheritance

java.lang.Object > CatalogServiceClient

Implements

BackgroundResource

Constructors

CatalogServiceClient(CatalogServiceSettings settings)

protected CatalogServiceClient(CatalogServiceSettings settings)

Constructs an instance of CatalogServiceClient, 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
settingsCatalogServiceSettings

CatalogServiceClient(CatalogServiceStub stub)

protected CatalogServiceClient(CatalogServiceStub stub)
Parameter
NameDescription
stubCatalogServiceStub

Methods

awaitTermination(long duration, TimeUnit unit)

public boolean awaitTermination(long duration, TimeUnit unit)
Parameters
NameDescription
durationlong
unitTimeUnit
Returns
TypeDescription
boolean
Exceptions
TypeDescription
InterruptedException

close()

public final void close()

create()

public static final CatalogServiceClient create()

Constructs an instance of CatalogServiceClient with default settings.

Returns
TypeDescription
CatalogServiceClient
Exceptions
TypeDescription
IOException

create(CatalogServiceSettings settings)

public static final CatalogServiceClient create(CatalogServiceSettings settings)

Constructs an instance of CatalogServiceClient, 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
settingsCatalogServiceSettings
Returns
TypeDescription
CatalogServiceClient
Exceptions
TypeDescription
IOException

create(CatalogServiceStub stub)

public static final CatalogServiceClient create(CatalogServiceStub stub)

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

Parameter
NameDescription
stubCatalogServiceStub
Returns
TypeDescription
CatalogServiceClient

getDefaultBranch(CatalogName catalog)

public final GetDefaultBranchResponse getDefaultBranch(CatalogName catalog)

Get which branch is currently default branch set by CatalogService.SetDefaultBranch method under a specified parent catalog.

This feature is only available for users who have Retail Search enabled. Please submit a form here to contact cloud sales if you are interested in using Retail Search.

Sample code:


 try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) {
   CatalogName catalog = CatalogName.of("[PROJECT]", "[LOCATION]", "[CATALOG]");
   GetDefaultBranchResponse response = catalogServiceClient.getDefaultBranch(catalog);
 }
 
Parameter
NameDescription
catalogCatalogName

The parent catalog resource name, such as projects/*/locations/global/catalogs/default_catalog.

Returns
TypeDescription
GetDefaultBranchResponse

getDefaultBranch(GetDefaultBranchRequest request)

public final GetDefaultBranchResponse getDefaultBranch(GetDefaultBranchRequest request)

Get which branch is currently default branch set by CatalogService.SetDefaultBranch method under a specified parent catalog.

This feature is only available for users who have Retail Search enabled. Please submit a form here to contact cloud sales if you are interested in using Retail Search.

Sample code:


 try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) {
   GetDefaultBranchRequest request =
       GetDefaultBranchRequest.newBuilder()
           .setCatalog(CatalogName.of("[PROJECT]", "[LOCATION]", "[CATALOG]").toString())
           .build();
   GetDefaultBranchResponse response = catalogServiceClient.getDefaultBranch(request);
 }
 
Parameter
NameDescription
requestGetDefaultBranchRequest

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

Returns
TypeDescription
GetDefaultBranchResponse

getDefaultBranch(String catalog)

public final GetDefaultBranchResponse getDefaultBranch(String catalog)

Get which branch is currently default branch set by CatalogService.SetDefaultBranch method under a specified parent catalog.

This feature is only available for users who have Retail Search enabled. Please submit a form here to contact cloud sales if you are interested in using Retail Search.

Sample code:


 try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) {
   String catalog = CatalogName.of("[PROJECT]", "[LOCATION]", "[CATALOG]").toString();
   GetDefaultBranchResponse response = catalogServiceClient.getDefaultBranch(catalog);
 }
 
Parameter
NameDescription
catalogString

The parent catalog resource name, such as projects/*/locations/global/catalogs/default_catalog.

Returns
TypeDescription
GetDefaultBranchResponse

getDefaultBranchCallable()

public final UnaryCallable<GetDefaultBranchRequest,GetDefaultBranchResponse> getDefaultBranchCallable()

Get which branch is currently default branch set by CatalogService.SetDefaultBranch method under a specified parent catalog.

This feature is only available for users who have Retail Search enabled. Please submit a form here to contact cloud sales if you are interested in using Retail Search.

Sample code:


 try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) {
   GetDefaultBranchRequest request =
       GetDefaultBranchRequest.newBuilder()
           .setCatalog(CatalogName.of("[PROJECT]", "[LOCATION]", "[CATALOG]").toString())
           .build();
   ApiFuture
Returns
TypeDescription
UnaryCallable<GetDefaultBranchRequest,GetDefaultBranchResponse>

getSettings()

public final CatalogServiceSettings getSettings()
Returns
TypeDescription
CatalogServiceSettings

getStub()

public CatalogServiceStub getStub()
Returns
TypeDescription
CatalogServiceStub

isShutdown()

public boolean isShutdown()
Returns
TypeDescription
boolean

isTerminated()

public boolean isTerminated()
Returns
TypeDescription
boolean

listCatalogs(ListCatalogsRequest request)

public final CatalogServiceClient.ListCatalogsPagedResponse listCatalogs(ListCatalogsRequest request)

Lists all the Catalogs associated with the project.

Sample code:


 try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) {
   ListCatalogsRequest request =
       ListCatalogsRequest.newBuilder()
           .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .build();
   for (Catalog element : catalogServiceClient.listCatalogs(request).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
requestListCatalogsRequest

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

Returns
TypeDescription
CatalogServiceClient.ListCatalogsPagedResponse

listCatalogs(LocationName parent)

public final CatalogServiceClient.ListCatalogsPagedResponse listCatalogs(LocationName parent)

Lists all the Catalogs associated with the project.

Sample code:


 try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) {
   LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
   for (Catalog element : catalogServiceClient.listCatalogs(parent).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
parentLocationName

Required. The account resource name with an associated location.

If the caller does not have permission to list Catalogs under this location, regardless of whether or not this location exists, a PERMISSION_DENIED error is returned.

Returns
TypeDescription
CatalogServiceClient.ListCatalogsPagedResponse

listCatalogs(String parent)

public final CatalogServiceClient.ListCatalogsPagedResponse listCatalogs(String parent)

Lists all the Catalogs associated with the project.

Sample code:


 try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) {
   String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString();
   for (Catalog element : catalogServiceClient.listCatalogs(parent).iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Parameter
NameDescription
parentString

Required. The account resource name with an associated location.

If the caller does not have permission to list Catalogs under this location, regardless of whether or not this location exists, a PERMISSION_DENIED error is returned.

Returns
TypeDescription
CatalogServiceClient.ListCatalogsPagedResponse

listCatalogsCallable()

public final UnaryCallable<ListCatalogsRequest,ListCatalogsResponse> listCatalogsCallable()

Lists all the Catalogs associated with the project.

Sample code:


 try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) {
   ListCatalogsRequest request =
       ListCatalogsRequest.newBuilder()
           .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .build();
   while (true) {
     ListCatalogsResponse response = catalogServiceClient.listCatalogsCallable().call(request);
     for (Catalog element : response.getResponsesList()) {
       // doThingsWith(element);
     }
     String nextPageToken = response.getNextPageToken();
     if (!Strings.isNullOrEmpty(nextPageToken)) {
       request = request.toBuilder().setPageToken(nextPageToken).build();
     } else {
       break;
     }
   }
 }
 
Returns
TypeDescription
UnaryCallable<ListCatalogsRequest,ListCatalogsResponse>

listCatalogsPagedCallable()

public final UnaryCallable<ListCatalogsRequest,CatalogServiceClient.ListCatalogsPagedResponse> listCatalogsPagedCallable()

Lists all the Catalogs associated with the project.

Sample code:


 try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) {
   ListCatalogsRequest request =
       ListCatalogsRequest.newBuilder()
           .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
           .setPageSize(883849137)
           .setPageToken("pageToken873572522")
           .build();
   ApiFuture<Catalog> future =
       catalogServiceClient.listCatalogsPagedCallable().futureCall(request);
   // Do something.
   for (Catalog element : future.get().iterateAll()) {
     // doThingsWith(element);
   }
 }
 
Returns
TypeDescription
UnaryCallable<ListCatalogsRequest,ListCatalogsPagedResponse>

setDefaultBranch(CatalogName catalog)

public final void setDefaultBranch(CatalogName catalog)

Set a specified branch id as default branch. API methods such as SearchService.Search, ProductService.GetProduct, ProductService.ListProducts will treat requests using "default_branch" to the actual branch id set as default.

For example, if projects/*/locations/*/catalogs/*/branches/1 is set as default, setting SearchRequest.branch to projects/*/locations/*/catalogs/*/branches/default_branch is equivalent to setting SearchRequest.branch to projects/*/locations/*/catalogs/*/branches/1.

Using multiple branches can be useful when developers would like to have a staging branch to test and verify for future usage. When it becomes ready, developers switch on the staging branch using this API while keeping using projects/*/locations/*/catalogs/*/branches/default_branch as SearchRequest.branch to route the traffic to this staging branch.

CAUTION: If you have live predict/search traffic, switching the default branch could potentially cause outages if the ID space of the new branch is very different from the old one.

More specifically:

  • PredictionService will only return product IDs from branch {newBranch}.
  • SearchService will only return product IDs from branch {newBranch} (if branch is not explicitly set).
  • UserEventService will only join events with products from branch {newBranch}.

This feature is only available for users who have Retail Search enabled. Please submit a form here to contact cloud sales if you are interested in using Retail Search.

Sample code:


 try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) {
   CatalogName catalog = CatalogName.of("[PROJECT]", "[LOCATION]", "[CATALOG]");
   catalogServiceClient.setDefaultBranch(catalog);
 }
 
Parameter
NameDescription
catalogCatalogName

Full resource name of the catalog, such as projects/*/locations/global/catalogs/default_catalog.

setDefaultBranch(SetDefaultBranchRequest request)

public final void setDefaultBranch(SetDefaultBranchRequest request)

Set a specified branch id as default branch. API methods such as SearchService.Search, ProductService.GetProduct, ProductService.ListProducts will treat requests using "default_branch" to the actual branch id set as default.

For example, if projects/*/locations/*/catalogs/*/branches/1 is set as default, setting SearchRequest.branch to projects/*/locations/*/catalogs/*/branches/default_branch is equivalent to setting SearchRequest.branch to projects/*/locations/*/catalogs/*/branches/1.

Using multiple branches can be useful when developers would like to have a staging branch to test and verify for future usage. When it becomes ready, developers switch on the staging branch using this API while keeping using projects/*/locations/*/catalogs/*/branches/default_branch as SearchRequest.branch to route the traffic to this staging branch.

CAUTION: If you have live predict/search traffic, switching the default branch could potentially cause outages if the ID space of the new branch is very different from the old one.

More specifically:

  • PredictionService will only return product IDs from branch {newBranch}.
  • SearchService will only return product IDs from branch {newBranch} (if branch is not explicitly set).
  • UserEventService will only join events with products from branch {newBranch}.

This feature is only available for users who have Retail Search enabled. Please submit a form here to contact cloud sales if you are interested in using Retail Search.

Sample code:


 try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) {
   SetDefaultBranchRequest request =
       SetDefaultBranchRequest.newBuilder()
           .setCatalog(CatalogName.of("[PROJECT]", "[LOCATION]", "[CATALOG]").toString())
           .setBranchId(
               BranchName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]").toString())
           .setNote("note3387378")
           .build();
   catalogServiceClient.setDefaultBranch(request);
 }
 
Parameter
NameDescription
requestSetDefaultBranchRequest

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

setDefaultBranch(String catalog)

public final void setDefaultBranch(String catalog)

Set a specified branch id as default branch. API methods such as SearchService.Search, ProductService.GetProduct, ProductService.ListProducts will treat requests using "default_branch" to the actual branch id set as default.

For example, if projects/*/locations/*/catalogs/*/branches/1 is set as default, setting SearchRequest.branch to projects/*/locations/*/catalogs/*/branches/default_branch is equivalent to setting SearchRequest.branch to projects/*/locations/*/catalogs/*/branches/1.

Using multiple branches can be useful when developers would like to have a staging branch to test and verify for future usage. When it becomes ready, developers switch on the staging branch using this API while keeping using projects/*/locations/*/catalogs/*/branches/default_branch as SearchRequest.branch to route the traffic to this staging branch.

CAUTION: If you have live predict/search traffic, switching the default branch could potentially cause outages if the ID space of the new branch is very different from the old one.

More specifically:

  • PredictionService will only return product IDs from branch {newBranch}.
  • SearchService will only return product IDs from branch {newBranch} (if branch is not explicitly set).
  • UserEventService will only join events with products from branch {newBranch}.

This feature is only available for users who have Retail Search enabled. Please submit a form here to contact cloud sales if you are interested in using Retail Search.

Sample code:


 try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) {
   String catalog = CatalogName.of("[PROJECT]", "[LOCATION]", "[CATALOG]").toString();
   catalogServiceClient.setDefaultBranch(catalog);
 }
 
Parameter
NameDescription
catalogString

Full resource name of the catalog, such as projects/*/locations/global/catalogs/default_catalog.

setDefaultBranchCallable()

public final UnaryCallable<SetDefaultBranchRequest,Empty> setDefaultBranchCallable()

Set a specified branch id as default branch. API methods such as SearchService.Search, ProductService.GetProduct, ProductService.ListProducts will treat requests using "default_branch" to the actual branch id set as default.

For example, if projects/*/locations/*/catalogs/*/branches/1 is set as default, setting SearchRequest.branch to projects/*/locations/*/catalogs/*/branches/default_branch is equivalent to setting SearchRequest.branch to projects/*/locations/*/catalogs/*/branches/1.

Using multiple branches can be useful when developers would like to have a staging branch to test and verify for future usage. When it becomes ready, developers switch on the staging branch using this API while keeping using projects/*/locations/*/catalogs/*/branches/default_branch as SearchRequest.branch to route the traffic to this staging branch.

CAUTION: If you have live predict/search traffic, switching the default branch could potentially cause outages if the ID space of the new branch is very different from the old one.

More specifically:

  • PredictionService will only return product IDs from branch {newBranch}.
  • SearchService will only return product IDs from branch {newBranch} (if branch is not explicitly set).
  • UserEventService will only join events with products from branch {newBranch}.

This feature is only available for users who have Retail Search enabled. Please submit a form here to contact cloud sales if you are interested in using Retail Search.

Sample code:


 try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) {
   SetDefaultBranchRequest request =
       SetDefaultBranchRequest.newBuilder()
           .setCatalog(CatalogName.of("[PROJECT]", "[LOCATION]", "[CATALOG]").toString())
           .setBranchId(
               BranchName.of("[PROJECT]", "[LOCATION]", "[CATALOG]", "[BRANCH]").toString())
           .setNote("note3387378")
           .build();
   ApiFuture<Empty> future = catalogServiceClient.setDefaultBranchCallable().futureCall(request);
   // Do something.
   future.get();
 }
 
Returns
TypeDescription
UnaryCallable<SetDefaultBranchRequest,Empty>

shutdown()

public void shutdown()

shutdownNow()

public void shutdownNow()

updateCatalog(Catalog catalog, FieldMask updateMask)

public final Catalog updateCatalog(Catalog catalog, FieldMask updateMask)

Updates the Catalogs.

Sample code:


 try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) {
   Catalog catalog = Catalog.newBuilder().build();
   FieldMask updateMask = FieldMask.newBuilder().build();
   Catalog response = catalogServiceClient.updateCatalog(catalog, updateMask);
 }
 
Parameters
NameDescription
catalogCatalog

Required. The Catalog to update.

If the caller does not have permission to update the Catalog, regardless of whether or not it exists, a PERMISSION_DENIED error is returned.

If the Catalog to update does not exist, a NOT_FOUND error is returned.

updateMaskFieldMask

Indicates which fields in the provided Catalog to update.

If an unsupported or unknown field is provided, an INVALID_ARGUMENT error is returned.

Returns
TypeDescription
Catalog

updateCatalog(UpdateCatalogRequest request)

public final Catalog updateCatalog(UpdateCatalogRequest request)

Updates the Catalogs.

Sample code:


 try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) {
   UpdateCatalogRequest request =
       UpdateCatalogRequest.newBuilder()
           .setCatalog(Catalog.newBuilder().build())
           .setUpdateMask(FieldMask.newBuilder().build())
           .build();
   Catalog response = catalogServiceClient.updateCatalog(request);
 }
 
Parameter
NameDescription
requestUpdateCatalogRequest

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

Returns
TypeDescription
Catalog

updateCatalogCallable()

public final UnaryCallable<UpdateCatalogRequest,Catalog> updateCatalogCallable()

Updates the Catalogs.

Sample code:


 try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) {
   UpdateCatalogRequest request =
       UpdateCatalogRequest.newBuilder()
           .setCatalog(Catalog.newBuilder().build())
           .setUpdateMask(FieldMask.newBuilder().build())
           .build();
   ApiFuture<Catalog> future = catalogServiceClient.updateCatalogCallable().futureCall(request);
   // Do something.
   Catalog response = future.get();
 }
 
Returns
TypeDescription
UnaryCallable<UpdateCatalogRequest,Catalog>