From 649bead3df7646a8535d2a1703aa2190225213a2 Mon Sep 17 00:00:00 2001 From: Shabir Mohamed Abdul Samadh <7249208+Shabirmean@users.noreply.github.com> Date: Fri, 18 Nov 2022 18:20:18 -0500 Subject: [PATCH] chore: fix samples (#1068) Fixing samples in this repo in order to get pending PRs merged for the mono-repo migrations The changes from the following PRs were also added to this PR: - https://togithub.com/googleapis/java-vision/pull/1047 - https://togithub.com/googleapis/java-vision/pull/1066 --- README.md | 6 +++--- google-cloud-vision-bom/pom.xml | 2 +- pom.xml | 4 ++-- .../com/example/vision/ImportProductSets.java | 3 ++- .../vision/ProductInProductSetManagement.java | 13 +++++-------- .../com/example/vision/ProductManagement.java | 15 +++++++-------- .../java/com/example/vision/ProductSearch.java | 4 +--- .../com/example/vision/ProductSetManagement.java | 12 ++++++------ .../example/vision/ReferenceImageManagement.java | 7 +++---- 9 files changed, 30 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index c33110964..011670c5b 100644 --- a/README.md +++ b/README.md @@ -57,20 +57,20 @@ If you are using Maven without BOM, add this to your dependencies: If you are using Gradle 5.x or later, add this to your dependencies: ```Groovy -implementation platform('com.google.cloud:libraries-bom:26.1.4') +implementation platform('com.google.cloud:libraries-bom:26.1.5') implementation 'com.google.cloud:google-cloud-vision' ``` If you are using Gradle without BOM, add this to your dependencies: ```Groovy -implementation 'com.google.cloud:google-cloud-vision:3.3.0' +implementation 'com.google.cloud:google-cloud-vision:3.4.0' ``` If you are using SBT, add this to your dependencies: ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-vision" % "3.3.0" +libraryDependencies += "com.google.cloud" % "google-cloud-vision" % "3.4.0" ``` ## Authentication diff --git a/google-cloud-vision-bom/pom.xml b/google-cloud-vision-bom/pom.xml index 432381d1f..e49756c66 100644 --- a/google-cloud-vision-bom/pom.xml +++ b/google-cloud-vision-bom/pom.xml @@ -8,7 +8,7 @@ com.google.cloud google-cloud-shared-config - 1.5.3 + 1.5.4 Google Cloud Vision BOM diff --git a/pom.xml b/pom.xml index 89d79ca41..c26035d38 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ com.google.cloud google-cloud-shared-config - 1.5.3 + 1.5.4 @@ -117,7 +117,7 @@ com.google.cloud google-cloud-shared-dependencies - 3.0.4 + 3.0.5 pom import diff --git a/samples/snippets/src/main/java/com/example/vision/ImportProductSets.java b/samples/snippets/src/main/java/com/example/vision/ImportProductSets.java index 9759fe682..bc8c3a263 100644 --- a/samples/snippets/src/main/java/com/example/vision/ImportProductSets.java +++ b/samples/snippets/src/main/java/com/example/vision/ImportProductSets.java @@ -23,6 +23,7 @@ import com.google.cloud.vision.v1.ImportProductSetsGcsSource.Builder; import com.google.cloud.vision.v1.ImportProductSetsInputConfig; import com.google.cloud.vision.v1.ImportProductSetsResponse; +import com.google.cloud.vision.v1.LocationName; import com.google.cloud.vision.v1.ProductSearchClient; import com.google.cloud.vision.v1.ReferenceImage; import java.io.PrintStream; @@ -57,7 +58,7 @@ public static void importProductSets(String projectId, String computeRegion, Str try (ProductSearchClient client = ProductSearchClient.create()) { // A resource that represents Google Cloud Platform location. - String formattedParent = ProductSearchClient.formatLocationName(projectId, computeRegion); + String formattedParent = LocationName.format(projectId, computeRegion); Builder gcsSource = ImportProductSetsGcsSource.newBuilder().setCsvFileUri(gcsUri); // Set the input configuration along with Google Cloud Storage URI diff --git a/samples/snippets/src/main/java/com/example/vision/ProductInProductSetManagement.java b/samples/snippets/src/main/java/com/example/vision/ProductInProductSetManagement.java index 6173df12e..11d21ebf3 100644 --- a/samples/snippets/src/main/java/com/example/vision/ProductInProductSetManagement.java +++ b/samples/snippets/src/main/java/com/example/vision/ProductInProductSetManagement.java @@ -19,6 +19,7 @@ import com.google.cloud.vision.v1.Product; import com.google.cloud.vision.v1.ProductName; import com.google.cloud.vision.v1.ProductSearchClient; +import com.google.cloud.vision.v1.ProductSetName; import java.io.IOException; import java.io.PrintStream; import net.sourceforge.argparse4j.ArgumentParsers; @@ -52,8 +53,7 @@ public static void addProductToProductSet( try (ProductSearchClient client = ProductSearchClient.create()) { // Get the full path of the product set. - String formattedName = - ProductSearchClient.formatProductSetName(projectId, computeRegion, productSetId); + String formattedName = ProductSetName.format(projectId, computeRegion, productSetId); // Get the full path of the product. String productPath = ProductName.of(projectId, computeRegion, productId).toString(); @@ -80,8 +80,7 @@ public static void listProductsInProductSet( try (ProductSearchClient client = ProductSearchClient.create()) { // Get the full path of the product set. - String formattedName = - ProductSearchClient.formatProductSetName(projectId, computeRegion, productSetId); + String formattedName = ProductSetName.format(projectId, computeRegion, productSetId); // List all the products available in the product set. for (Product product : client.listProductsInProductSet(formattedName).iterateAll()) { // Display the product information @@ -118,12 +117,10 @@ public static void removeProductFromProductSet( try (ProductSearchClient client = ProductSearchClient.create()) { // Get the full path of the product set. - String formattedParent = - ProductSearchClient.formatProductSetName(projectId, computeRegion, productSetId); + String formattedParent = ProductSetName.format(projectId, computeRegion, productSetId); // Get the full path of the product. - String formattedName = - ProductSearchClient.formatProductName(projectId, computeRegion, productId); + String formattedName = ProductName.format(projectId, computeRegion, productId); // Remove the product from the product set. client.removeProductFromProductSet(formattedParent, formattedName); diff --git a/samples/snippets/src/main/java/com/example/vision/ProductManagement.java b/samples/snippets/src/main/java/com/example/vision/ProductManagement.java index 94fb411f4..25217f898 100644 --- a/samples/snippets/src/main/java/com/example/vision/ProductManagement.java +++ b/samples/snippets/src/main/java/com/example/vision/ProductManagement.java @@ -16,8 +16,10 @@ package com.example.vision; +import com.google.cloud.vision.v1.LocationName; import com.google.cloud.vision.v1.Product; import com.google.cloud.vision.v1.Product.KeyValue; +import com.google.cloud.vision.v1.ProductName; import com.google.cloud.vision.v1.ProductSearchClient; import com.google.protobuf.FieldMask; import java.io.IOException; @@ -58,7 +60,7 @@ public static void createProduct( try (ProductSearchClient client = ProductSearchClient.create()) { // A resource that represents Google Cloud Platform location. - String formattedParent = ProductSearchClient.formatLocationName(projectId, computeRegion); + String formattedParent = LocationName.format(projectId, computeRegion); // Create a product with the product specification in the region. // Multiple labels are also supported. Product myProduct = @@ -86,7 +88,7 @@ public static void listProducts(String projectId, String computeRegion) throws I try (ProductSearchClient client = ProductSearchClient.create()) { // A resource that represents Google Cloud Platform location. - String formattedParent = ProductSearchClient.formatLocationName(projectId, computeRegion); + String formattedParent = LocationName.format(projectId, computeRegion); // List all the products available in the region. for (Product product : client.listProducts(formattedParent).iterateAll()) { @@ -120,8 +122,7 @@ public static void getProduct(String projectId, String computeRegion, String pro try (ProductSearchClient client = ProductSearchClient.create()) { // Get the full path of the product. - String formattedName = - ProductSearchClient.formatProductName(projectId, computeRegion, productId); + String formattedName = ProductName.format(projectId, computeRegion, productId); // Get complete detail of the product. Product product = client.getProduct(formattedName); // Display the product information @@ -157,8 +158,7 @@ public static void updateProductLabels( try (ProductSearchClient client = ProductSearchClient.create()) { // Get the full path of the product. - String formattedName = - ProductSearchClient.formatProductName(projectId, computeRegion, productId); + String formattedName = ProductName.format(projectId, computeRegion, productId); // Set product name, product labels and product display name. // Multiple labels are also supported. @@ -201,8 +201,7 @@ public static void deleteProduct(String projectId, String computeRegion, String try (ProductSearchClient client = ProductSearchClient.create()) { // Get the full path of the product. - String formattedName = - ProductSearchClient.formatProductName(projectId, computeRegion, productId); + String formattedName = ProductName.format(projectId, computeRegion, productId); // Delete a product. client.deleteProduct(formattedName); diff --git a/samples/snippets/src/main/java/com/example/vision/ProductSearch.java b/samples/snippets/src/main/java/com/example/vision/ProductSearch.java index 9cd4bca0e..cd201275a 100644 --- a/samples/snippets/src/main/java/com/example/vision/ProductSearch.java +++ b/samples/snippets/src/main/java/com/example/vision/ProductSearch.java @@ -24,7 +24,6 @@ import com.google.cloud.vision.v1.ImageAnnotatorClient; import com.google.cloud.vision.v1.ImageContext; import com.google.cloud.vision.v1.ImageSource; -import com.google.cloud.vision.v1.ProductSearchClient; import com.google.cloud.vision.v1.ProductSearchParams; import com.google.cloud.vision.v1.ProductSearchResults.Result; import com.google.cloud.vision.v1.ProductSetName; @@ -76,8 +75,7 @@ public static void getSimilarProductsFile( try (ImageAnnotatorClient queryImageClient = ImageAnnotatorClient.create()) { // Get the full path of the product set. - String productSetPath = - ProductSearchClient.formatProductSetName(projectId, computeRegion, productSetId); + String productSetPath = ProductSetName.format(projectId, computeRegion, productSetId); // Read the image as a stream of bytes. File imgPath = new File(filePath); diff --git a/samples/snippets/src/main/java/com/example/vision/ProductSetManagement.java b/samples/snippets/src/main/java/com/example/vision/ProductSetManagement.java index a6aa33f0d..61d218e2c 100644 --- a/samples/snippets/src/main/java/com/example/vision/ProductSetManagement.java +++ b/samples/snippets/src/main/java/com/example/vision/ProductSetManagement.java @@ -17,8 +17,10 @@ package com.example.vision; import com.google.cloud.vision.v1.CreateProductSetRequest; +import com.google.cloud.vision.v1.LocationName; import com.google.cloud.vision.v1.ProductSearchClient; import com.google.cloud.vision.v1.ProductSet; +import com.google.cloud.vision.v1.ProductSetName; import java.io.IOException; import java.io.PrintStream; import net.sourceforge.argparse4j.ArgumentParsers; @@ -52,7 +54,7 @@ public static void createProductSet( try (ProductSearchClient client = ProductSearchClient.create()) { // A resource that represents Google Cloud Platform location. - String formattedParent = ProductSearchClient.formatLocationName(projectId, computeRegion); + String formattedParent = LocationName.format(projectId, computeRegion); // Create a product set with the product set specification in the region. ProductSet myProductSet = @@ -81,7 +83,7 @@ public static void createProductSet( 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); + String formattedParent = LocationName.format(projectId, computeRegion); // List all the product sets available in the region. for (ProductSet productSet : client.listProductSets(formattedParent).iterateAll()) { // Display the product set information @@ -114,8 +116,7 @@ public static void getProductSet(String projectId, String computeRegion, String try (ProductSearchClient client = ProductSearchClient.create()) { // Get the full path of the product set. - String formattedName = - ProductSearchClient.formatProductSetName(projectId, computeRegion, productSetId); + String formattedName = ProductSetName.format(projectId, computeRegion, productSetId); // Get complete detail of the product set. ProductSet productSet = client.getProductSet(formattedName); // Display the product set information @@ -147,8 +148,7 @@ public static void deleteProductSet(String projectId, String computeRegion, Stri try (ProductSearchClient client = ProductSearchClient.create()) { // Get the full path of the product set. - String formattedName = - ProductSearchClient.formatProductSetName(projectId, computeRegion, productSetId); + String formattedName = ProductSetName.format(projectId, computeRegion, productSetId); // Delete the product set. client.deleteProductSet(formattedName); System.out.println(String.format("Product set deleted")); diff --git a/samples/snippets/src/main/java/com/example/vision/ReferenceImageManagement.java b/samples/snippets/src/main/java/com/example/vision/ReferenceImageManagement.java index 9260d64ae..50df7dbb8 100644 --- a/samples/snippets/src/main/java/com/example/vision/ReferenceImageManagement.java +++ b/samples/snippets/src/main/java/com/example/vision/ReferenceImageManagement.java @@ -17,6 +17,7 @@ package com.example.vision; import com.google.cloud.vision.v1.ImageName; +import com.google.cloud.vision.v1.ProductName; import com.google.cloud.vision.v1.ProductSearchClient; import com.google.cloud.vision.v1.ReferenceImage; import java.io.IOException; @@ -58,8 +59,7 @@ public static void createReferenceImage( try (ProductSearchClient client = ProductSearchClient.create()) { // Get the full path of the product. - String formattedParent = - ProductSearchClient.formatProductName(projectId, computeRegion, productId); + String formattedParent = ProductName.format(projectId, computeRegion, productId); // Create a reference image. ReferenceImage referenceImage = ReferenceImage.newBuilder().setUri(gcsUri).build(); @@ -86,8 +86,7 @@ public static void listReferenceImagesOfProduct( try (ProductSearchClient client = ProductSearchClient.create()) { // Get the full path of the product. - String formattedParent = - ProductSearchClient.formatProductName(projectId, computeRegion, productId); + String formattedParent = ProductName.format(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()));