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()));
}
}
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.");
}
}
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()));
}
}
}
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."));
}
}
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."));
}
}
Aggregations