Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

samples: migrate code from googleapis/java-retail #7403

Merged
merged 115 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
d8f3f96
chore(samples): Code samples for Retail Tutorials. Search service sam…
sborisenkox Mar 8, 2022
2e01c63
chore(samples): Retail Tutorials. CRUD products (#301)
sborisenkox Mar 8, 2022
eb0b661
deps: update dependency com.google.cloud:google-cloud-bigquery to v2.…
renovate-bot Mar 8, 2022
2496fd5
deps: update dependency com.google.cloud:google-cloud-storage to v2.4…
renovate-bot Mar 8, 2022
3409105
build(deps): update dependency org.codehaus.mojo:exec-maven-plugin to…
renovate-bot Mar 8, 2022
114ac40
build(deps): update dependency org.codehaus.mojo:exec-maven-plugin to…
renovate-bot Mar 8, 2022
a37556e
deps: update dependency com.google.code.gson:gson to v2.9.0 (#324)
renovate-bot Mar 8, 2022
bcde8fd
chore(samples): Retail Tutorials. Product Setup/Cleanup test resource…
sborisenkox Mar 8, 2022
792a74c
chore(samples): Retail Tutorials. Import products (#297)
sborisenkox Mar 8, 2022
171282a
chore(samples): Code samples for Retail Tutorials. Search service sam…
sborisenkox Mar 9, 2022
ae2c481
deps: update dependency com.google.cloud:google-cloud-bigquery to v2.…
renovate-bot Mar 9, 2022
ea360e8
deps: update dependency com.google.cloud:google-cloud-storage to v2.4…
renovate-bot Mar 9, 2022
719c4a4
chore(deps): update dependency com.google.cloud:google-cloud-retail t…
renovate-bot Mar 10, 2022
2065b6e
chore(deps): update dependency com.google.cloud:google-cloud-retail t…
renovate-bot Mar 10, 2022
4a421b0
chore(samples): Retail Tutorials. Events (write, rejoin, purge) (#303)
sborisenkox Mar 16, 2022
dbdefc8
deps: update dependency com.google.cloud:google-cloud-bigquery to v2.…
renovate-bot Mar 16, 2022
c2668bf
chore(deps): update dependency com.google.cloud:libraries-bom to v24.…
renovate-bot Mar 16, 2022
9bdf4d1
chore(deps): update dependency com.google.cloud:libraries-bom to v25 …
renovate-bot Mar 16, 2022
2cfb804
chore(samples): Retail Tutorials. Events import (#302)
sborisenkox Mar 17, 2022
ef49f70
chore(deps): update dependency com.google.cloud:google-cloud-retail t…
renovate-bot Mar 17, 2022
a7f7d78
deps: update dependency com.google.cloud:google-cloud-bigquery to v2.…
renovate-bot Mar 21, 2022
1c46668
chore(deps): update dependency com.google.cloud:google-cloud-retail t…
renovate-bot Mar 22, 2022
091c27b
deps: update dependency com.google.cloud:google-cloud-bigquery to v2.…
renovate-bot Mar 25, 2022
63f3a75
chore(samples): Major update according review comments. (#369)
sborisenkox Mar 29, 2022
ffc5873
deps: update dependency com.google.cloud:google-cloud-storage to v2.5…
renovate-bot Mar 29, 2022
98b1610
deps: update dependency com.google.cloud:google-cloud-bigquery to v2.…
renovate-bot Mar 29, 2022
6424cce
deps: update dependency com.google.cloud:google-cloud-storage to v2.5…
renovate-bot Mar 29, 2022
bd2a605
chore(deps): update dependency com.google.cloud:google-cloud-retail t…
renovate-bot Mar 29, 2022
610a265
chore(main): release 2.0.17 (#381)
release-please[bot] Mar 30, 2022
4b79c07
chore(deps): update dependency com.google.cloud:google-cloud-retail t…
renovate-bot Apr 1, 2022
ffb9fe8
chore(deps): update dependency com.google.cloud:libraries-bom to v25.…
renovate-bot Apr 1, 2022
8168fc7
deps: update dependency com.google.cloud:google-cloud-bigquery to v2.…
renovate-bot Apr 1, 2022
a7d0c40
deps: update dependency com.google.cloud:google-cloud-storage to v2.6…
renovate-bot Apr 1, 2022
03e3bfa
chore(deps): update dependency com.google.cloud:google-cloud-retail t…
renovate-bot Apr 4, 2022
2f480e8
docs(samples): the bash scripts for environment setup are added (#392)
t-karasova Apr 7, 2022
95a1b6f
deps: update dependency com.google.cloud:google-cloud-bigquery to v2.…
renovate-bot Apr 11, 2022
8821073
deps: update dependency com.google.cloud:google-cloud-bigquery to v2.…
renovate-bot Apr 15, 2022
28b042b
deps: update dependency com.google.cloud:google-cloud-bigquery to v2.…
renovate-bot Apr 18, 2022
40e2c58
deps: update dependency com.google.cloud:google-cloud-storage to v2.6…
renovate-bot Apr 18, 2022
cec45b7
deps: update dependency com.google.cloud:google-cloud-bigquery to v2.…
renovate-bot Apr 19, 2022
56ed2bf
chore(deps): update dependency com.google.cloud:google-cloud-retail t…
renovate-bot Apr 21, 2022
58a5881
chore(deps): update dependency com.google.cloud:libraries-bom to v25.…
renovate-bot Apr 27, 2022
8703828
docs(samples): Retail. Prediction samples (#412)
sborisenkox Apr 27, 2022
2bd75fc
Revert "docs(samples): Retail. Prediction samples (#412)" (#430)
Neenu1995 May 6, 2022
bd04d36
deps: update dependency com.google.cloud:google-cloud-bigquery to v2.…
renovate-bot May 12, 2022
52a273c
chore(deps): update dependency com.google.cloud:libraries-bom to v25.…
renovate-bot May 16, 2022
7bae40d
deps: update dependency com.google.cloud:google-cloud-bigquery to v2.…
renovate-bot May 17, 2022
8b7d4d5
deps: update dependency com.google.cloud:google-cloud-bigquery to v2.…
renovate-bot May 19, 2022
6ceb94f
deps: update dependency com.google.cloud:google-cloud-storage to v2.7…
renovate-bot May 25, 2022
89ac6e5
chore(deps): update dependency com.google.cloud:google-cloud-retail t…
renovate-bot May 25, 2022
51fb49d
deps: update dependency com.google.cloud:google-cloud-bigquery to v2.…
renovate-bot May 25, 2022
e3a6b4d
deps: update dependency com.google.cloud:google-cloud-storage to v2.7…
renovate-bot May 27, 2022
8ce2d85
chore(deps): update dependency com.google.cloud:libraries-bom to v25.…
renovate-bot Jun 6, 2022
d645738
deps: update dependency com.google.cloud:google-cloud-bigquery to v2.…
renovate-bot Jun 6, 2022
471d446
chore(deps): update dependency com.google.cloud:google-cloud-retail t…
renovate-bot Jun 13, 2022
4615462
deps: update dependency com.google.cloud:google-cloud-storage to v2.8…
renovate-bot Jun 13, 2022
cccea7a
deps: update dependency com.google.cloud:google-cloud-bigquery to v2.…
renovate-bot Jun 13, 2022
9c16450
chore(deps): update dependency com.google.cloud:google-cloud-retail t…
renovate-bot Jun 15, 2022
15b2a00
deps: update dependency com.google.cloud:google-cloud-bigquery to v2.…
renovate-bot Jun 21, 2022
c333481
deps: update dependency com.google.cloud:google-cloud-bigquery to v2.…
renovate-bot Jun 22, 2022
01cd2a0
chore(deps): update dependency com.google.cloud:libraries-bom to v26 …
renovate-bot Jul 11, 2022
ff46b25
docs(samples): Refactoring search package (#415)
sborisenkox Jul 11, 2022
8ab9282
docs(samples): Refactoring product package (CRUD) (#417)
sborisenkox Jul 13, 2022
2047689
build(deps): update dependency org.codehaus.mojo:exec-maven-plugin to…
renovate-bot Jul 15, 2022
85b1f77
chore(deps): update dependency com.google.cloud:google-cloud-retail t…
renovate-bot Aug 2, 2022
36ee037
deps: update dependency com.google.cloud:google-cloud-storage to v2.1…
renovate-bot Aug 2, 2022
361469a
deps: update dependency com.google.code.gson:gson to v2.9.1 (#500)
renovate-bot Aug 2, 2022
b487eb7
deps: update dependency com.google.cloud:google-cloud-storage to v2.1…
renovate-bot Aug 3, 2022
36b5e75
deps: update dependency com.google.cloud:google-cloud-storage to v2.1…
renovate-bot Aug 4, 2022
a59cedf
deps: update dependency com.google.cloud:google-cloud-storage to v2.1…
renovate-bot Aug 5, 2022
7b4192b
chore (samples) Added a place for updateMask insertion from tutorials…
dfirova Aug 8, 2022
f56f818
chore (samples) Warn user about fails on user_import_data_to_catalog.…
dfirova Aug 9, 2022
4662b6c
chore (samples) Warn user about fails on user_environment_setup.sh. (…
dfirova Aug 9, 2022
15aa9cc
chore (samples) Refactored error handling check for import product fr…
dfirova Aug 10, 2022
03a61d5
fix(samples) Add fulfillment places code sample: didn't work (#488)
dfirova Aug 11, 2022
e3c5ee4
fix (samples) Import user events BQ, missing UpdateUserEventsJson.jav…
dfirova Aug 11, 2022
30e42c8
deps: update dependency com.google.cloud:google-cloud-bigquery to v2.…
renovate-bot Aug 16, 2022
fc5d1fd
chore(deps): update dependency com.google.cloud:google-cloud-retail t…
renovate-bot Aug 16, 2022
8c59735
chore(deps): update dependency com.google.cloud:libraries-bom to v26.…
renovate-bot Aug 16, 2022
373f4ca
chore (samples) Refactoring: added invalid catalog name in import pro…
dfirova Aug 17, 2022
842ac8b
fix (samples) Warning about wrong relativePath for parent (#508)
dfirova Aug 17, 2022
0136088
deps: update dependency com.google.cloud:google-cloud-storage to v2.1…
renovate-bot Aug 17, 2022
56279dd
deps: update dependency com.google.cloud:google-cloud-bigquery to v2.…
renovate-bot Aug 18, 2022
ae78650
deps: update dependency com.google.cloud:google-cloud-bigquery to v2.…
renovate-bot Aug 24, 2022
e9f1aa7
deps: update dependency com.google.cloud:google-cloud-bigquery to v2.…
renovate-bot Aug 29, 2022
1756ed2
chore(deps): update dependency com.google.cloud:libraries-bom to v26.…
renovate-bot Aug 31, 2022
a24d44d
fix(samples): removed region tags (#531)
dfirova Sep 12, 2022
cb79689
fix(samples): removed add time from lro. (#530)
dfirova Sep 12, 2022
a02d40c
docs(samples): Refactoring events package (#481)
dfirova Sep 13, 2022
2aee8f5
docs(samples): Refactoring product package (#480)
dfirova Sep 13, 2022
d5084c5
deps: update dependency com.google.cloud:google-cloud-bigquery to v2.…
renovate-bot Sep 13, 2022
627cdab
fix(samples): removed env variables and buckets from creating bq. (#526)
dfirova Sep 16, 2022
a286ce4
fix(samples): updating both json files. (#540)
dfirova Sep 19, 2022
dfbbb45
chore(deps): update dependency com.google.cloud:google-cloud-retail t…
renovate-bot Sep 20, 2022
58844a7
deps: update dependency com.google.cloud:google-cloud-bigquery to v2.…
renovate-bot Sep 20, 2022
2370352
deps: update dependency com.google.cloud:google-cloud-storage to v2.1…
renovate-bot Sep 20, 2022
9104b3e
chore(deps): update dependency com.google.cloud:libraries-bom to v26.…
renovate-bot Sep 20, 2022
24a1278
fix(samples): replaced your-project-id with default. (#541)
dfirova Sep 20, 2022
e56e6cd
fix (samples) user environment setup script. (#534)
dfirova Sep 20, 2022
881695e
fix(samples): lro added out-of-order step. (#539)
dfirova Sep 21, 2022
5628077
chore(samples): improved message if no result returned in search tuto…
dfirova Sep 21, 2022
660036e
fix(samples): bug fix for setup script (#549)
dfirova Sep 23, 2022
1780330
fix(samples): bug fix for removing buckets from bq. (#548)
dfirova Sep 26, 2022
76ed2d0
fix(samples): Removed delays on LRO (#527)
dfirova Sep 26, 2022
31b46eb
chore(samples): refactoring comments. (#528)
dfirova Sep 29, 2022
82b0de5
samples(fix): bug fix, wrong projectId. (#575)
dfirova Oct 5, 2022
86a0f74
chore(deps): update dependency com.google.cloud:google-cloud-retail t…
renovate-bot Oct 6, 2022
b6edd6a
deps: update dependency com.google.cloud:google-cloud-bigquery to v2.…
renovate-bot Oct 6, 2022
1cae68c
deps: update dependency com.google.cloud:google-cloud-storage to v2.1…
renovate-bot Oct 6, 2022
c5bb921
chore(deps): update dependency com.google.cloud:google-cloud-retail t…
renovate-bot Oct 6, 2022
3e9a99b
chore(deps): update dependency com.google.cloud:libraries-bom to v26.…
renovate-bot Oct 10, 2022
4869569
Merge remote-tracking branch 'migration/main' into java-retail-migration
Shabirmean Nov 10, 2022
8bf47af
chore: post migration updates - groupId, artifact url, repo references
Shabirmean Nov 10, 2022
7564437
cleanup: fix lint errors
Shabirmean Nov 10, 2022
f0f3eda
cleanup: fix lint errors
Shabirmean Nov 10, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
211 changes: 211 additions & 0 deletions retail/interactive-tutorials/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
# Retail Search Interactive Tutorials

## Run tutorials in Cloud Shell

To advance with the interactive tutorials, use Retail Search step-by-step manuals on the right side of the Cloud Shell IDE:
![Interactive tutorials](images/tutorial1.png)

The interactive tutorial should open by default. If it didn’t, click on the Tutorial symbol in the menu bar to open the step-by-step manual:
![Toggle tutorial](images/tutorials2.png)

For more details about the Cloud Shell environment, refer to the [Cloud Shell documentation](https://cloud.google.com/shell/docs).

## Interactive tutorial flow

Interactive guides are intended to help you understand the features provided by Google Cloud Retail Search and test the Retail API in action.

To proceed with the tutorial, choose a language you’ll be deploying your project in:
![Select a programming language](images/tutorials3.png)


To begin with the tutorial workflow, click the Start button:
![Begin with the tutorial](images/tutorials4.png)

Then, you can use Next and Previous buttons to navigate the tutorial pages.

## Java code samples

The code here demonstrates how to consume Google Retail Search API in Java

## Get started with the Google Cloud Retail API

The Retail API provides you with the following possibilities to:
- Create and maintaining the catalog data.
- Fine-tune the search configuration.
- Import and maintain the user events data.

You can find the information about the Retail services in the [documentation](https://cloud.google.com/retail/docs)

If you would like to have a closer look at the Retail API features and try them yourself,
the best option is to use the [Interactive Tutorials](https://cloud.google.com/retail/docs/overview). In the documentation chapters find the "Guide me" button, the tutorials will be launched in the CloudShell environment, and you will be able to request the Retail services and check the response with minimum time and effort.

The code samples in the directory **java-docs-samples/retail/interactive-tutorials** are explicitly created for use with the Retail Interactive Tutorials.

If, for some reason, you have decided to proceed with these code samples without the tutorial, please go through the following steps and set up the required preconditions.

## Prepare your work environment

To prepare the work environment you should perform the following steps:
- Create a service account.
- Create a service account key and set it to authorize your calls to the Retail API.
- Install Google Cloud Retail library.

### There are two ways to set up your work environment:

- If you want to **speed up the process** of setting up the working environment, run the script java-docs-samples/retail/interactive-tutorials/src/main/java/user_environment_setup.sh and skip the next **set up the work environment step-by-step** tutorial step:

```bash
bash java-docs-samples/retail/interactive-tutorials/user_environment_setup.sh
```

- If you want to perform the environment set up step by step along with getting the explanation you should proceed with the next tutorial step.

## Set up the work environment step-by-step

### Create service account

To access the Retail API, you must create a service account. Check that you are an owner of your Google Cloud project on the [IAM page](https://console.cloud.google.com/iam-admin/iam).

1. To create a service account, perform the following command:

```bash
gcloud iam service-accounts create <YOUR_SERVICE_ACCOUNT_ID>
```

1. Assign the needed roles to your service account:

```bash
for role in {retail.admin,editor,bigquery.admin}
do gcloud projects add-iam-policy-binding <YOUR_PROJECT_ID> --member="serviceAccount:<YOUR_SERVICE_ACCOUNT_ID>@<YOUR_PROJECT_ID>.iam.gserviceaccount.com" --role="roles/${role}"
done
```

1. Use the following command to show the service account email:

```bash
gcloud iam service-accounts list|grep <YOUR_SERVICE_ACCOUNT_ID>
```

Copy the service account email.


1. Upload your service account key JSON file and use it to activate the service
account:

```bash
gcloud iam service-accounts keys create ~/key.json --iam-account <YOUR_SERVICE_ACCOUNT_EMAIL>
```

```bash
gcloud auth activate-service-account --key-file ~/key.json
```

1. Set the key as the GOOGLE_APPLICATION_CREDENTIALS environment variable to
use it for sending requests to the Retail API.

```bash
export GOOGLE_APPLICATION_CREDENTIALS=~/key.json
```

### Google Cloud Retail libraries

Learn more about the [Java Google Cloud Retail library](https://googleapis.dev/java/google-cloud-retail/latest/index.html).

## Congrats! You have configured your work environment

1. Check that you are in the directory with code samples.

The code samples for each of the Retail services are stored in different directories.

Go to the code samples directory, your starting point to run more commands.

```bash
cd java-docs-samples/retail/interactive-tutorials/
```

## Import catalog data

<i>This step is required if this is the first Retail API tutorial that you run.
Otherwise, you can skip it.</i>

There is a java-docs-samples/retail/interactive-tutorials/src/main/resources/products.json file with valid products prepared in the `resources` directory.

The other file, java-docs-samples/retail/interactive-tutorials/src/main/resources/products_some_invalid.json, contains both valid and invalid products. You will use it to check the error handling.

- If you want to **speed up the process**, run the following script in the Terminal directory to import all products to catalog and skip the next **Prepare the catalog data step-by-step** tutorial step:

```bash
bash java-docs-samples/retail/interactive-tutorials/user_import_data_to_catalog.sh
```

- If you want to upload products to the catalog step by step along with getting the explanation, you should proceed with the next tutorial step.

## Prepare the catalog data step-by-step

### Upload catalog data to Cloud Storage

In your own project you need to create a Cloud Storage bucket and put the JSON file there.
The bucket name must be unique. For convenience, you can name it `<YOUR_PROJECT_ID>_<TIMESTAMP>`.

1. The code samples for each of the Retail services are stored in different directories.

Go to the code samples directory, your starting point to run more commands.

```bash
cd java-docs-samples/retail/interactive-tutorials
```

1. To create the bucket and upload the JSON file, open java-docs-samples/retail/interactive-tutorials/src/main/java/product/setup/ProductsCreateGcsBucket.java file

1. Go to the **product** directory and run the following command in the Terminal:

```bash
mvn compile exec:java
-Dexec.mainClass=product.setup.ProductsCreateGcsBucket
```

Now you can see the bucket is created in the [Cloud Storage](https://console.cloud.google.com/storage/browser), and the files are uploaded.

1. The name of the created Cloud Storage bucket is shown in the Terminal.

```
The gcs bucket <YOUR_PROJECT_ID>_<TIMESTAMP> was created
```

Copy the name and set it as the environment variable `BUCKET_NAME`:

```bash
export BUCKET_NAME=<YOUR_BUCKET_NAME>
```

### Import products to the Retail Catalog

To import the prepared products to a catalog, open java-docs-samples/retail/interactive-tutorials/src/main/java/product/ImportProductsGcs.java file and run the following command in the Terminal:

```bash
mvn compile exec:java -Dexec.mainClass=product.ImportProductsGcs
```

## Your Retail catalog is ready to use!

### Running code samples

Use maven command to run specific code sample:

```
mvn compile exec:java -Dexec.mainClass="package.CodeSampleClass"
```

### Running unit tests

Use maven command to run specific unit test class:

```
mvn test -Dtest=TestClassName
```

Use maven command to run all unit tests:

```
mvn test
```
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
88 changes: 88 additions & 0 deletions retail/interactive-tutorials/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.retail</groupId>
<artifactId>retail-interactive-tutorials</artifactId>
<packaging>jar</packaging>
<name>Google Cloud Retail Interactive Tutorials</name>
<url>https://github.com/GoogleCloudPlatform/java-docs-samples/tree/main/retail</url>

<!--
The parent pom defines common style checks and testing strategies for our samples.
Removing or replacing it should not affect the execution of the samples in anyway.
-->
<parent>
<groupId>com.google.cloud.samples</groupId>
<artifactId>shared-configuration</artifactId>
<version>1.2.0</version>
<relativePath/>
</parent>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>libraries-bom</artifactId>
<version>26.1.3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-retail</artifactId>
<version>2.5.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-bigquery</artifactId>
<version>2.17.0</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-storage</artifactId>
<version>2.13.0</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.9.1</version>
</dependency>
<dependency>
<groupId>com.google.truth</groupId>
<artifactId>truth</artifactId>
<version>1.1.3</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<cleanupDaemonThreads>true</cleanupDaemonThreads>
</configuration>
</plugin>
</plugins>
</build>
</project>
Loading