Search in sources :

Example 6 with ProductSearchClient

use of com.google.cloud.vision.v1.ProductSearchClient 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 7 with ProductSearchClient

use of com.google.cloud.vision.v1.ProductSearchClient in project java-vision by googleapis.

the class PurgeProductsInProductSet method purgeProductsInProductSet.

// Delete all products in a product set.
public static void purgeProductsInProductSet(String projectId, String location, String productSetId) throws Exception {
    try (ProductSearchClient client = ProductSearchClient.create()) {
        String parent = LocationName.format(projectId, location);
        ProductSetPurgeConfig productSetPurgeConfig = ProductSetPurgeConfig.newBuilder().setProductSetId(productSetId).build();
        PurgeProductsRequest request = PurgeProductsRequest.newBuilder().setParent(parent).setProductSetPurgeConfig(productSetPurgeConfig).setForce(true).build();
        OperationFuture<Empty, BatchOperationMetadata> response = client.purgeProductsAsync(request);
        response.getPollingFuture().get(180, TimeUnit.SECONDS);
        System.out.println("Products removed from product set.");
    }
}
Also used : Empty(com.google.protobuf.Empty) PurgeProductsRequest(com.google.cloud.vision.v1.PurgeProductsRequest) ProductSearchClient(com.google.cloud.vision.v1.ProductSearchClient) ProductSetPurgeConfig(com.google.cloud.vision.v1.ProductSetPurgeConfig) BatchOperationMetadata(com.google.cloud.vision.v1.BatchOperationMetadata)

Example 8 with ProductSearchClient

use of com.google.cloud.vision.v1.ProductSearchClient in project java-vision by googleapis.

the class ReferenceImageManagement method listReferenceImagesOfProduct.

// [END vision_product_search_create_reference_image]
// [START vision_product_search_list_reference_images]
/**
 * List all images in a product.
 *
 * @param projectId - Id of the project.
 * @param computeRegion - Region name.
 * @param productId - Id of the product.
 * @throws IOException - on I/O errors.
 */
public static void listReferenceImagesOfProduct(String projectId, String computeRegion, String productId) throws IOException {
    try (ProductSearchClient client = ProductSearchClient.create()) {
        // Get the full path of the product.
        String formattedParent = ProductSearchClient.formatProductName(projectId, computeRegion, productId);
        for (ReferenceImage image : client.listReferenceImages(formattedParent).iterateAll()) {
            // Display the reference image information.
            System.out.println(String.format("Reference image name: %s", image.getName()));
            System.out.println(String.format("Reference image id: %s", image.getName().substring(image.getName().lastIndexOf('/') + 1)));
            System.out.println(String.format("Reference image uri: %s", image.getUri()));
            System.out.println(String.format("Reference image bounding polygons: %s \n", image.getBoundingPolysList().toString()));
        }
    }
}
Also used : ProductSearchClient(com.google.cloud.vision.v1.ProductSearchClient) ReferenceImage(com.google.cloud.vision.v1.ReferenceImage)

Example 9 with ProductSearchClient

use of com.google.cloud.vision.v1.ProductSearchClient in project java-vision by googleapis.

the class ProductInProductSetManagement method addProductToProductSet.

// [START vision_product_search_add_product_to_product_set]
/**
 * Add a product to a product set.
 *
 * @param projectId - Id of the project.
 * @param computeRegion - Region name.
 * @param productId - Id of the product.
 * @param productSetId - Id of the product set.
 * @throws IOException - on I/O errors.
 */
public static void addProductToProductSet(String projectId, String computeRegion, String productId, 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 the full path of the product.
        String productPath = ProductName.of(projectId, computeRegion, productId).toString();
        // Add the product to the product set.
        client.addProductToProductSet(formattedName, productPath);
        System.out.println(String.format("Product added to product set."));
    }
}
Also used : ProductSearchClient(com.google.cloud.vision.v1.ProductSearchClient)

Example 10 with ProductSearchClient

use of com.google.cloud.vision.v1.ProductSearchClient in project java-vision by googleapis.

the class ProductInProductSetManagement method removeProductFromProductSet.

// [END vision_product_search_list_products_in_product_set]
// [START vision_product_search_remove_product_from_product_set]
/**
 * Remove a product from a product set.
 *
 * @param projectId - Id of the project.
 * @param computeRegion - Region name.
 * @param productId - Id of the product.
 * @param productSetId - Id of the product set.
 * @throws IOException - on I/O errors.
 */
public static void removeProductFromProductSet(String projectId, String computeRegion, String productId, String productSetId) throws IOException {
    try (ProductSearchClient client = ProductSearchClient.create()) {
        // Get the full path of the product set.
        String formattedParent = ProductSearchClient.formatProductSetName(projectId, computeRegion, productSetId);
        // Get the full path of the product.
        String formattedName = ProductSearchClient.formatProductName(projectId, computeRegion, productId);
        // Remove the product from the product set.
        client.removeProductFromProductSet(formattedParent, formattedName);
        System.out.println(String.format("Product removed from product set."));
    }
}
Also used : ProductSearchClient(com.google.cloud.vision.v1.ProductSearchClient)

Aggregations

ProductSearchClient (com.google.cloud.vision.v1.ProductSearchClient)19 Product (com.google.cloud.vision.v1.Product)6 ReferenceImage (com.google.cloud.vision.v1.ReferenceImage)5 ProductSet (com.google.cloud.vision.v1.ProductSet)4 BatchOperationMetadata (com.google.cloud.vision.v1.BatchOperationMetadata)2 CreateProductSetRequest (com.google.cloud.vision.v1.CreateProductSetRequest)2 KeyValue (com.google.cloud.vision.v1.Product.KeyValue)2 PurgeProductsRequest (com.google.cloud.vision.v1.PurgeProductsRequest)2 OperationFuture (com.google.api.gax.longrunning.OperationFuture)1 AddProductToProductSetRequest (com.google.cloud.vision.v1.AddProductToProductSetRequest)1 CreateProductRequest (com.google.cloud.vision.v1.CreateProductRequest)1 CreateReferenceImageRequest (com.google.cloud.vision.v1.CreateReferenceImageRequest)1 Builder (com.google.cloud.vision.v1.ImportProductSetsGcsSource.Builder)1 ImportProductSetsInputConfig (com.google.cloud.vision.v1.ImportProductSetsInputConfig)1 ImportProductSetsResponse (com.google.cloud.vision.v1.ImportProductSetsResponse)1 ProductSetPurgeConfig (com.google.cloud.vision.v1.ProductSetPurgeConfig)1 Empty (com.google.protobuf.Empty)1 FieldMask (com.google.protobuf.FieldMask)1 BeforeClass (org.junit.BeforeClass)1