Skip to content
This repository has been archived by the owner on Sep 16, 2023. It is now read-only.

Commit

Permalink
chore: fix samples (#1068)
Browse files Browse the repository at this point in the history
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://github.com/googleapis/java-vision/pull/1047
- https://github.com/googleapis/java-vision/pull/1066
  • Loading branch information
Shabirmean authored Nov 18, 2022
1 parent 5e28b50 commit 649bead
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 36 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion google-cloud-vision-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-shared-config</artifactId>
<version>1.5.3</version>
<version>1.5.4</version>
</parent>

<name>Google Cloud Vision BOM</name>
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-shared-config</artifactId>
<version>1.5.3</version>
<version>1.5.4</version>
</parent>

<developers>
Expand Down Expand Up @@ -117,7 +117,7 @@
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-shared-dependencies</artifactId>
<version>3.0.4</version>
<version>3.0.5</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand All @@ -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()));
Expand Down

0 comments on commit 649bead

Please sign in to comment.