-
Notifications
You must be signed in to change notification settings - Fork 11
chore(samples): Retail Tutorials. Events (write, rejoin, purge) #303
Changes from 3 commits
47390ed
cb2d502
d8e0c24
cb7df0a
a59d185
4f1bd2a
2043308
6af1997
7e494dc
5fb6e9e
ead78b2
7a28d4a
7c76b49
3187000
d47baec
eb92a3b
d795c9e
a44347d
9859fa5
f209ade
ef59642
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| # Format: //devtools/kokoro/config/proto/build.proto | ||
|
|
||
| # Configure the docker image for kokoro-trampoline. | ||
| env_vars: { | ||
| key: "TRAMPOLINE_IMAGE" | ||
| value: "gcr.io/cloud-devrel-kokoro-resources/java8" | ||
| } | ||
|
|
||
| env_vars: { | ||
| key: "JOB_TYPE" | ||
| value: "tutorials-samples" | ||
| } | ||
|
|
||
| # TODO: remove this after we've migrated all tests and scripts | ||
| env_vars: { | ||
| key: "PROJECT_NUMBER" | ||
| value: "779844219229" | ||
| } | ||
|
|
||
| env_vars: { | ||
| key: "PROJECT_ID" | ||
| value: "java-docs-samples-testing" | ||
| } | ||
|
|
||
| env_vars: { | ||
| key: "GOOGLE_APPLICATION_CREDENTIALS" | ||
| value: "secret_manager/java-docs-samples-service-account" | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In general we usually try to avoid putting secrets here and instead put them in secret-manager. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This issue is still open.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is in secret manager. This just configures the env var for ADC |
||
|
|
||
| env_vars: { | ||
| key: "SECRET_MANAGER_KEYS" | ||
| value: "java-docs-samples-service-account" | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| <?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.google.cloud</groupId> | ||
| <artifactId>retail-interactive-tutorials</artifactId> | ||
| <packaging>jar</packaging> | ||
| <name>Google Cloud Retail Interactive Tutorials</name> | ||
| <url>https://github.com/googleapis/java-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> | ||
| </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> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>com.google.cloud</groupId> | ||
| <artifactId>google-cloud-retail</artifactId> | ||
| <version>2.0.6</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.5.1</version> | ||
kurtisvg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.google.cloud</groupId> | ||
| <artifactId>google-cloud-storage</artifactId> | ||
| <version>2.2.2</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.google.code.gson</groupId> | ||
| <artifactId>gson</artifactId> | ||
| <version>2.8.9</version> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.codehaus.mojo</groupId> | ||
| <artifactId>exec-maven-plugin</artifactId> | ||
| <version>1.2.1</version> | ||
| <configuration> | ||
| <cleanupDaemonThreads>false</cleanupDaemonThreads> | ||
kurtisvg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </configuration> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| </project> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| /* | ||
| * Copyright 2022 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| // [START retail_purge_user_event] | ||
|
|
||
| /* | ||
| * Import user events into a catalog from inline source using Retail API | ||
|
||
| */ | ||
|
|
||
| package events; | ||
|
|
||
| import static setup.SetupCleanup.writeUserEvent; | ||
|
|
||
| import com.google.api.gax.longrunning.OperationFuture; | ||
| import com.google.cloud.retail.v2.PurgeMetadata; | ||
| import com.google.cloud.retail.v2.PurgeUserEventsRequest; | ||
| import com.google.cloud.retail.v2.PurgeUserEventsResponse; | ||
| import com.google.cloud.retail.v2.UserEventServiceClient; | ||
| import java.io.IOException; | ||
| import java.util.concurrent.ExecutionException; | ||
|
|
||
| public class PurgeUserEvent { | ||
|
|
||
| private static final String PROJECT_ID = System.getenv("PROJECT_ID"); | ||
| private static final String DEFAULT_CATALOG = | ||
| String.format("projects/%s/locations/global/catalogs/default_catalog", PROJECT_ID); | ||
| private static final String VISITOR_ID = "test_visitor_id"; | ||
|
|
||
| public static void main(String[] args) | ||
| throws IOException, ExecutionException, InterruptedException { | ||
| writeUserEvent(VISITOR_ID); | ||
| callPurgeUserEvents(); | ||
| } | ||
kurtisvg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| public static void callPurgeUserEvents() | ||
| throws IOException, ExecutionException, InterruptedException { | ||
| OperationFuture<PurgeUserEventsResponse, PurgeMetadata> purgeOperation = | ||
| UserEventServiceClient.create().purgeUserEventsAsync(getPurgeUserEventRequest()); | ||
|
||
|
|
||
| System.out.printf("The purge operation was started: %s%n", purgeOperation.getName()); | ||
| } | ||
|
|
||
| private static PurgeUserEventsRequest getPurgeUserEventRequest() { | ||
| PurgeUserEventsRequest purgeUserEventsRequest = | ||
| PurgeUserEventsRequest.newBuilder() | ||
| // TO CHECK ERROR HANDLING SET INVALID FILTER HERE: | ||
| .setFilter(String.format("visitorId=\"%s\"", VISITOR_ID)) | ||
| .setParent(DEFAULT_CATALOG) | ||
| .setForce(true) | ||
| .build(); | ||
|
|
||
| System.out.printf("Purge user events request: %s%n", purgeUserEventsRequest); | ||
|
|
||
| return purgeUserEventsRequest; | ||
|
||
| } | ||
| } | ||
|
|
||
| // [END retail_purge_user_event] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| /* | ||
| * Copyright 2022 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| // [START retail_rejoin_user_event] | ||
|
|
||
| /* | ||
| * Import user events into a catalog from inline source using Retail API | ||
|
||
| */ | ||
|
|
||
| package events; | ||
|
|
||
| import static setup.SetupCleanup.purgeUserEvent; | ||
| import static setup.SetupCleanup.writeUserEvent; | ||
|
|
||
| import com.google.api.gax.longrunning.OperationFuture; | ||
| import com.google.cloud.retail.v2.RejoinUserEventsMetadata; | ||
| import com.google.cloud.retail.v2.RejoinUserEventsRequest; | ||
| import com.google.cloud.retail.v2.RejoinUserEventsRequest.UserEventRejoinScope; | ||
| import com.google.cloud.retail.v2.RejoinUserEventsResponse; | ||
| import com.google.cloud.retail.v2.UserEventServiceClient; | ||
| import java.io.IOException; | ||
| import java.util.concurrent.ExecutionException; | ||
|
|
||
| public class RejoinUserEvent { | ||
|
|
||
| private static final String PROJECT_ID = System.getenv("PROJECT_ID"); | ||
| private static final String DEFAULT_CATALOG = | ||
| String.format("projects/%s/locations/global/catalogs/default_catalog", PROJECT_ID); | ||
| // TO CHECK THE ERROR HANDLING TRY TO PASS INVALID CATALOG: | ||
| // 'invalid_catalog' INSTEAD OF 'default_catalog' | ||
| private static final String VISITOR_ID = "test_visitor_id"; | ||
|
|
||
| public static void main(final String[] args) | ||
| throws IOException, ExecutionException, InterruptedException { | ||
| writeUserEvent(VISITOR_ID); | ||
| callRejoinUserEvents(); | ||
| purgeUserEvent(VISITOR_ID); | ||
| } | ||
|
|
||
| public static void callRejoinUserEvents() | ||
| throws IOException, ExecutionException, InterruptedException { | ||
| OperationFuture<RejoinUserEventsResponse, RejoinUserEventsMetadata> rejoinOperation = | ||
| UserEventServiceClient.create().rejoinUserEventsAsync(getRejoinUserEventRequest()); | ||
|
|
||
| System.out.printf("The rejoin operation was started: %s%n", rejoinOperation.getName()); | ||
| } | ||
|
|
||
| public static RejoinUserEventsRequest getRejoinUserEventRequest() { | ||
| RejoinUserEventsRequest rejoinUserEventsRequest = | ||
| RejoinUserEventsRequest.newBuilder() | ||
| .setParent(DEFAULT_CATALOG) | ||
| .setUserEventRejoinScope(UserEventRejoinScope.UNJOINED_EVENTS) | ||
| .build(); | ||
|
|
||
| System.out.printf("Rejoin user events request: %s%n", rejoinUserEventsRequest); | ||
|
|
||
| return rejoinUserEventsRequest; | ||
| } | ||
| } | ||
|
|
||
| // [END retail_rejoin_user_event] | ||
Uh oh!
There was an error while loading. Please reload this page.