16
16
17
17
package com .example .vision ;
18
18
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]
20
23
import com .google .cloud .vision .v1p3beta1 .LocationName ;
21
24
import com .google .cloud .vision .v1p3beta1 .Product ;
22
25
import com .google .cloud .vision .v1p3beta1 .Product .KeyValue ;
27
30
import java .io .IOException ;
28
31
import java .io .PrintStream ;
29
32
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]
30
37
import net .sourceforge .argparse4j .ArgumentParsers ;
31
38
import net .sourceforge .argparse4j .inf .ArgumentParser ;
32
39
import net .sourceforge .argparse4j .inf .ArgumentParserException ;
33
40
import net .sourceforge .argparse4j .inf .Namespace ;
34
41
import net .sourceforge .argparse4j .inf .Subparser ;
35
42
import net .sourceforge .argparse4j .inf .Subparsers ;
36
- // [END product_search_import]
37
43
38
44
/**
39
45
* This application demonstrates how to perform basic operations on Products.
44
50
45
51
public class ProductManagement {
46
52
47
- // [START product_search_create_product ]
53
+ // [START vision_product_search_create_product ]
48
54
/**
49
55
* Create one product.
50
56
*
@@ -90,40 +96,9 @@ public static void createProduct(
90
96
// Display the product information
91
97
System .out .println (String .format ("Product name: %s" , product .getName ()));
92
98
}
93
- // [END product_search_create_product ]
99
+ // [END vision_product_search_create_product ]
94
100
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]
127
102
/**
128
103
* Get information about a product.
129
104
*
@@ -154,9 +129,9 @@ public static void getProduct(String projectId, String computeRegion, String pro
154
129
System .out .println (
155
130
String .format ("Product labels: %s" , product .getProductLabelsList ().toString ()));
156
131
}
157
- // [END product_search_get_product ]
132
+ // [END vision_product_search_get_product ]
158
133
159
- // [START product_search_update_product_labels ]
134
+ // [START vision_product_search_update_product_labels ]
160
135
/**
161
136
* Update the product labels.
162
137
*
@@ -198,9 +173,9 @@ public static void updateProductLabels(
198
173
String .format (
199
174
"Updated product labels: %s" , updatedProduct .getProductLabelsList ().toString ()));
200
175
}
201
- // [END product_search_update_product_labels ]
176
+ // [END vision_product_search_update_product_labels ]
202
177
203
- // [START product_search_delete_product ]
178
+ // [START vision_product_search_delete_product ]
204
179
/**
205
180
* Delete the product and all its reference images.
206
181
*
@@ -221,7 +196,7 @@ public static void deleteProduct(String projectId, String computeRegion, String
221
196
222
197
System .out .println ("Product deleted." );
223
198
}
224
- // [END product_search_delete_product ]
199
+ // [END vision_product_search_delete_product ]
225
200
226
201
public static void main (String [] args ) throws Exception {
227
202
ProductManagement productManagement = new ProductManagement ();
@@ -267,9 +242,6 @@ public void argsHelper(String[] args, PrintStream out) throws Exception {
267
242
ns .getString ("productDescription" ),
268
243
ns .getString ("productLabels" ));
269
244
}
270
- if (ns .get ("command" ).equals ("list_products" )) {
271
- listProducts (projectId , computeRegion );
272
- }
273
245
if (ns .get ("command" ).equals ("get_product" )) {
274
246
getProduct (projectId , computeRegion , ns .getString ("productId" ));
275
247
}
0 commit comments