Search in sources :

Example 6 with Product

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

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

the class ProductInProductSetManagement method listProductsInProductSet.

// [END vision_product_search_add_product_to_product_set]
// [START vision_product_search_list_products_in_product_set]
/**
 * List all products in a 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 listProductsInProductSet(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);
        // List all the products available in the product set.
        for (Product product : client.listProductsInProductSet(formattedName).iterateAll()) {
            // 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("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)

Example 8 with Product

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

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

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

Aggregations

Product (com.google.cloud.retail.v2.Product)20 ProductSearchClient (com.google.cloud.vision.v1.ProductSearchClient)19 Product (com.google.cloud.vision.v1.Product)10 Test (org.junit.Test)9 SetupCleanup.deleteProduct (setup.SetupCleanup.deleteProduct)9 ProductServiceClient (com.google.cloud.retail.v2.ProductServiceClient)8 SetupCleanup.createProduct (setup.SetupCleanup.createProduct)6 AbstractMessage (com.google.protobuf.AbstractMessage)5 ProductSet (com.google.cloud.vision.v1.ProductSet)4 ReferenceImage (com.google.cloud.vision.v1.ReferenceImage)4 Product (com.haulmont.cuba.testmodel.sales_1.Product)4 Test (org.junit.jupiter.api.Test)4 NotFoundException (com.google.api.gax.rpc.NotFoundException)3 CreateProductRequest (com.google.cloud.retail.v2.CreateProductRequest)3 GetProductRequest (com.google.cloud.retail.v2.GetProductRequest)3 QueryRunner (com.haulmont.bali.db.QueryRunner)3 Id (com.haulmont.cuba.core.entity.contracts.Id)3 com.haulmont.cuba.core.global (com.haulmont.cuba.core.global)3 TestContainer (com.haulmont.cuba.testsupport.TestContainer)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3