Search in sources :

Example 1 with ProductSearchClient

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

the class ProductManagement method createProduct.

// [START vision_product_search_create_product]
/**
 * Create one product.
 *
 * @param projectId - Id of the project.
 * @param computeRegion - Region name.
 * @param productId - Id of the product.
 * @param productDisplayName - Display name of the product.
 * @param productCategory - Category of the product.
 * @throws IOException - on I/O errors.
 */
public static void createProduct(String projectId, String computeRegion, String productId, String productDisplayName, String productCategory) throws IOException {
    try (ProductSearchClient client = ProductSearchClient.create()) {
        // A resource that represents Google Cloud Platform location.
        String formattedParent = ProductSearchClient.formatLocationName(projectId, computeRegion);
        // Create a product with the product specification in the region.
        // Multiple labels are also supported.
        Product myProduct = Product.newBuilder().setName(productId).setDisplayName(productDisplayName).setProductCategory(productCategory).build();
        Product product = client.createProduct(formattedParent, myProduct, productId);
        // Display the product information
        System.out.println(String.format("Product name: %s", product.getName()));
    }
}
Also used : ProductSearchClient(com.google.cloud.vision.v1.ProductSearchClient) Product(com.google.cloud.vision.v1.Product)

Example 2 with ProductSearchClient

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

the class ProductManagement method updateProductLabels.

// [END vision_product_search_get_product]
// [START vision_product_search_update_product_labels]
/**
 * Update the product labels.
 *
 * @param projectId - Id of the project.
 * @param computeRegion - Region name.
 * @param productId -Id of the product.
 * @param productLabels - Labels of the product.
 * @throws IOException - on I/O errors.
 */
public static void updateProductLabels(String projectId, String computeRegion, String productId, String productLabels) throws IOException {
    try (ProductSearchClient client = ProductSearchClient.create()) {
        // Get the full path of the product.
        String formattedName = ProductSearchClient.formatProductName(projectId, computeRegion, productId);
        // Set product name, product labels and product display name.
        // Multiple labels are also supported.
        Product product = Product.newBuilder().setName(formattedName).addProductLabels(KeyValue.newBuilder().setKey(productLabels.split(",")[0].split("=")[0]).setValue(productLabels.split(",")[0].split("=")[1]).build()).build();
        // Set product update field name.
        FieldMask updateMask = FieldMask.newBuilder().addPaths("product_labels").build();
        // Update the product.
        Product updatedProduct = client.updateProduct(product, updateMask);
        // Display the product information
        System.out.println(String.format("Product name: %s", updatedProduct.getName()));
        System.out.println(String.format("Updated product labels: "));
        for (Product.KeyValue element : updatedProduct.getProductLabelsList()) {
            System.out.println(String.format("%s: %s", element.getKey(), element.getValue()));
        }
    }
}
Also used : ProductSearchClient(com.google.cloud.vision.v1.ProductSearchClient) Product(com.google.cloud.vision.v1.Product) KeyValue(com.google.cloud.vision.v1.Product.KeyValue) FieldMask(com.google.protobuf.FieldMask)

Example 3 with ProductSearchClient

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

the class ProductManagement method getProduct.

// [END vision_product_search_list_products]
// [START vision_product_search_get_product]
/**
 * Get information about 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 getProduct(String projectId, String computeRegion, String productId) throws IOException {
    try (ProductSearchClient client = ProductSearchClient.create()) {
        // Get the full path of the product.
        String formattedName = ProductSearchClient.formatProductName(projectId, computeRegion, productId);
        // Get complete detail of the product.
        Product product = client.getProduct(formattedName);
        // Display the product information
        System.out.println(String.format("Product name: %s", product.getName()));
        System.out.println(String.format("Product id: %s", product.getName().substring(product.getName().lastIndexOf('/') + 1)));
        System.out.println(String.format("Product display name: %s", product.getDisplayName()));
        System.out.println(String.format("Product description: %s", product.getDescription()));
        System.out.println(String.format("Product category: %s", product.getProductCategory()));
        System.out.println(String.format("Product labels: "));
        for (Product.KeyValue element : product.getProductLabelsList()) {
            System.out.println(String.format("%s: %s", element.getKey(), element.getValue()));
        }
    }
}
Also used : ProductSearchClient(com.google.cloud.vision.v1.ProductSearchClient) Product(com.google.cloud.vision.v1.Product) KeyValue(com.google.cloud.vision.v1.Product.KeyValue)

Example 4 with ProductSearchClient

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

the class ProductManagement method listProducts.

// [END vision_product_search_create_product]
// [START vision_product_search_list_products]
/**
 * List all products.
 *
 * @param projectId - Id of the project.
 * @param computeRegion - Region name.
 * @throws IOException - on I/O errors.
 */
public static void listProducts(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 products available in the region.
        for (Product product : client.listProducts(formattedParent).iterateAll()) {
            // Display the product information
            System.out.println(String.format("\nProduct name: %s", product.getName()));
            System.out.println(String.format("Product id: %s", product.getName().substring(product.getName().lastIndexOf('/') + 1)));
            System.out.println(String.format("Product display name: %s", product.getDisplayName()));
            System.out.println(String.format("Product category: %s", product.getProductCategory()));
            System.out.println("Product labels:");
            System.out.println(String.format("Product labels: %s", product.getProductLabelsList().toString()));
        }
    }
}
Also used : ProductSearchClient(com.google.cloud.vision.v1.ProductSearchClient) Product(com.google.cloud.vision.v1.Product)

Example 5 with ProductSearchClient

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

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