1616
1717package com .example .vision ;
1818
19- // [START product_search_import]
19+ // [START vision_product_search_create_product]
20+ // [START vision_product_search_delete_product]
21+ // [START vision_product_search_get_product]
22+ // [START vision_product_search_update_product_labels]
2023import com .google .cloud .vision .v1p3beta1 .LocationName ;
2124import com .google .cloud .vision .v1p3beta1 .Product ;
2225import com .google .cloud .vision .v1p3beta1 .Product .KeyValue ;
2730import java .io .IOException ;
2831import java .io .PrintStream ;
2932
33+ // [END vision_product_search_create_product]
34+ // [END vision_product_search_delete_product]
35+ // [END vision_product_search_get_product]
36+ // [END vision_product_search_update_product_labels]
3037import net .sourceforge .argparse4j .ArgumentParsers ;
3138import net .sourceforge .argparse4j .inf .ArgumentParser ;
3239import net .sourceforge .argparse4j .inf .ArgumentParserException ;
3340import net .sourceforge .argparse4j .inf .Namespace ;
3441import net .sourceforge .argparse4j .inf .Subparser ;
3542import net .sourceforge .argparse4j .inf .Subparsers ;
36- // [END product_search_import]
3743
3844/**
3945 * This application demonstrates how to perform basic operations on Products.
4450
4551public class ProductManagement {
4652
47- // [START product_search_create_product ]
53+ // [START vision_product_search_create_product ]
4854 /**
4955 * Create one product.
5056 *
@@ -90,40 +96,9 @@ public static void createProduct(
9096 // Display the product information
9197 System .out .println (String .format ("Product name: %s" , product .getName ()));
9298 }
93- // [END product_search_create_product ]
99+ // [END vision_product_search_create_product ]
94100
95- // [START product_search_list_products]
96- /**
97- * List all products.
98- *
99- * @param projectId - Id of the project.
100- * @param computeRegion - Region name.
101- * @throws IOException - on I/O errors.
102- */
103- public static void listProducts (String projectId , String computeRegion ) throws IOException {
104- ProductSearchClient client = ProductSearchClient .create ();
105-
106- // A resource that represents Google Cloud Platform location.
107- LocationName projectLocation = LocationName .of (projectId , computeRegion );
108-
109- // List all the products available in the region.
110- for (Product product : client .listProducts (projectLocation ).iterateAll ()) {
111- // Display the product information
112- System .out .println (String .format ("\n Product name: %s" , product .getName ()));
113- System .out .println (
114- String .format (
115- "Product id: %s" ,
116- product .getName ().substring (product .getName ().lastIndexOf ('/' ) + 1 )));
117- System .out .println (String .format ("Product display name: %s" , product .getDisplayName ()));
118- System .out .println (String .format ("Product category: %s" , product .getProductCategory ()));
119- System .out .println ("Product labels:" );
120- System .out .println (
121- String .format ("Product labels: %s" , product .getProductLabelsList ().toString ()));
122- }
123- }
124- // [END product_search_list_products]
125-
126- // [START product_search_get_product]
101+ // [START vision_product_search_get_product]
127102 /**
128103 * Get information about a product.
129104 *
@@ -154,9 +129,9 @@ public static void getProduct(String projectId, String computeRegion, String pro
154129 System .out .println (
155130 String .format ("Product labels: %s" , product .getProductLabelsList ().toString ()));
156131 }
157- // [END product_search_get_product ]
132+ // [END vision_product_search_get_product ]
158133
159- // [START product_search_update_product_labels ]
134+ // [START vision_product_search_update_product_labels ]
160135 /**
161136 * Update the product labels.
162137 *
@@ -198,9 +173,9 @@ public static void updateProductLabels(
198173 String .format (
199174 "Updated product labels: %s" , updatedProduct .getProductLabelsList ().toString ()));
200175 }
201- // [END product_search_update_product_labels ]
176+ // [END vision_product_search_update_product_labels ]
202177
203- // [START product_search_delete_product ]
178+ // [START vision_product_search_delete_product ]
204179 /**
205180 * Delete the product and all its reference images.
206181 *
@@ -221,7 +196,7 @@ public static void deleteProduct(String projectId, String computeRegion, String
221196
222197 System .out .println ("Product deleted." );
223198 }
224- // [END product_search_delete_product ]
199+ // [END vision_product_search_delete_product ]
225200
226201 public static void main (String [] args ) throws Exception {
227202 ProductManagement productManagement = new ProductManagement ();
@@ -267,9 +242,6 @@ public void argsHelper(String[] args, PrintStream out) throws Exception {
267242 ns .getString ("productDescription" ),
268243 ns .getString ("productLabels" ));
269244 }
270- if (ns .get ("command" ).equals ("list_products" )) {
271- listProducts (projectId , computeRegion );
272- }
273245 if (ns .get ("command" ).equals ("get_product" )) {
274246 getProduct (projectId , computeRegion , ns .getString ("productId" ));
275247 }
0 commit comments