Search in sources :

Example 1 with ProductSet

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()));
        }
    }
}
Also used : ProductSearchClient(com.google.cloud.vision.v1.ProductSearchClient) ProductSet(com.google.cloud.vision.v1.ProductSet)

Example 2 with ProductSet

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()));
    }
}
Also used : ProductSearchClient(com.google.cloud.vision.v1.ProductSearchClient) ProductSet(com.google.cloud.vision.v1.ProductSet)

Example 3 with ProductSet

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());
}
Also used : GetProductSetRequest(com.google.cloud.vision.v1.GetProductSetRequest) ProductSet(com.google.cloud.vision.v1.ProductSet) Test(org.junit.Test)

Example 4 with ProductSet

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()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListProductSetsPagedResponse(com.google.cloud.vision.v1.ProductSearchClient.ListProductSetsPagedResponse) Test(org.junit.Test)

Example 5 with ProductSet

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()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListProductSetsPagedResponse(com.google.cloud.vision.v1.ProductSearchClient.ListProductSetsPagedResponse) Test(org.junit.Test)

Aggregations

ProductSet (com.google.cloud.vision.v1.ProductSet)5 ProductSearchClient (com.google.cloud.vision.v1.ProductSearchClient)3 Test (org.junit.Test)3 CreateProductSetRequest (com.google.cloud.vision.v1.CreateProductSetRequest)2 ListProductSetsPagedResponse (com.google.cloud.vision.v1.ProductSearchClient.ListProductSetsPagedResponse)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 AddProductToProductSetRequest (com.google.cloud.vision.v1.AddProductToProductSetRequest)1 CreateProductRequest (com.google.cloud.vision.v1.CreateProductRequest)1 CreateReferenceImageRequest (com.google.cloud.vision.v1.CreateReferenceImageRequest)1 GetProductSetRequest (com.google.cloud.vision.v1.GetProductSetRequest)1 Product (com.google.cloud.vision.v1.Product)1 ReferenceImage (com.google.cloud.vision.v1.ReferenceImage)1 BeforeClass (org.junit.BeforeClass)1