use of com.google.cloud.vision.v1.ProductSet in project java-vision by googleapis.
the class ProductSetManagement method listProductSets.
// [END vision_product_search_create_product_set]
// [START vision_product_search_list_product_sets]
/**
* List all product sets
*
* @param projectId - Id of the project.
* @param computeRegion - Region name.
* @throws IOException - on I/O errors.
*/
public static void listProductSets(String projectId, String computeRegion) throws IOException {
try (ProductSearchClient client = ProductSearchClient.create()) {
// A resource that represents Google Cloud Platform location.
String formattedParent = ProductSearchClient.formatLocationName(projectId, computeRegion);
// List all the product sets available in the region.
for (ProductSet productSet : client.listProductSets(formattedParent).iterateAll()) {
// Display the product set information
System.out.println(String.format("Product set name: %s", productSet.getName()));
System.out.println(String.format("Product set id: %s", productSet.getName().substring(productSet.getName().lastIndexOf('/') + 1)));
System.out.println(String.format("Product set display name: %s", productSet.getDisplayName()));
System.out.println("Product set index time:");
System.out.println(String.format("\tseconds: %s", productSet.getIndexTime().getSeconds()));
System.out.println(String.format("\tnanos: %s", productSet.getIndexTime().getNanos()));
}
}
}
use of com.google.cloud.vision.v1.ProductSet in project java-vision by googleapis.
the class ProductSetManagement method getProductSet.
// [END vision_product_search_list_product_sets]
// [START vision_product_search_get_product_set]
/**
* Get info about the product set.
*
* @param projectId - Id of the project.
* @param computeRegion - Region name.
* @param productSetId - Id of the product set.
* @throws IOException - on I/O errors.
*/
public static void getProductSet(String projectId, String computeRegion, String productSetId) throws IOException {
try (ProductSearchClient client = ProductSearchClient.create()) {
// Get the full path of the product set.
String formattedName = ProductSearchClient.formatProductSetName(projectId, computeRegion, productSetId);
// Get complete detail of the product set.
ProductSet productSet = client.getProductSet(formattedName);
// Display the product set information
System.out.println(String.format("Product set name: %s", productSet.getName()));
System.out.println(String.format("Product set id: %s", productSet.getName().substring(productSet.getName().lastIndexOf('/') + 1)));
System.out.println(String.format("Product set display name: %s", productSet.getDisplayName()));
System.out.println("Product set index time:");
System.out.println(String.format("\tseconds: %s", productSet.getIndexTime().getSeconds()));
System.out.println(String.format("\tnanos: %s", productSet.getIndexTime().getNanos()));
}
}
use of com.google.cloud.vision.v1.ProductSet in project java-vision by googleapis.
the class ITSystemTest method getProductSetTest.
@Test
public void getProductSetTest() {
GetProductSetRequest request = GetProductSetRequest.newBuilder().setName(formatProductSetName).build();
ProductSet actualProductSet = productSearchClient.getProductSet(request);
assertEquals(productSet.getName(), actualProductSet.getName());
assertEquals(PRODUCT_SET_DISPLAY_NAME, actualProductSet.getDisplayName());
}
use of com.google.cloud.vision.v1.ProductSet in project java-vision by googleapis.
the class ProductSearchClientTest method listProductSetsTest2.
@Test
public void listProductSetsTest2() throws Exception {
ProductSet responsesElement = ProductSet.newBuilder().build();
ListProductSetsResponse expectedResponse = ListProductSetsResponse.newBuilder().setNextPageToken("").addAllProductSets(Arrays.asList(responsesElement)).build();
mockProductSearch.addResponse(expectedResponse);
String parent = "parent-995424086";
ListProductSetsPagedResponse pagedListResponse = client.listProductSets(parent);
List<ProductSet> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getProductSetsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockProductSearch.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListProductSetsRequest actualRequest = ((ListProductSetsRequest) actualRequests.get(0));
Assert.assertEquals(parent, actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.vision.v1.ProductSet in project java-vision by googleapis.
the class ProductSearchClientTest method listProductSetsTest.
@Test
public void listProductSetsTest() throws Exception {
ProductSet responsesElement = ProductSet.newBuilder().build();
ListProductSetsResponse expectedResponse = ListProductSetsResponse.newBuilder().setNextPageToken("").addAllProductSets(Arrays.asList(responsesElement)).build();
mockProductSearch.addResponse(expectedResponse);
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
ListProductSetsPagedResponse pagedListResponse = client.listProductSets(parent);
List<ProductSet> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getProductSetsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockProductSearch.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListProductSetsRequest actualRequest = ((ListProductSetsRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Aggregations