Search in sources :

Example 1 with WriteUserEventRequest

use of com.google.cloud.retail.v2.WriteUserEventRequest in project java-retail by googleapis.

the class SetupCleanup method writeUserEvent.

public static UserEvent writeUserEvent(String visitorId) throws IOException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (UserEventServiceClient userEventServiceClient = UserEventServiceClient.create()) {
        WriteUserEventRequest writeUserEventRequest = WriteUserEventRequest.newBuilder().setUserEvent(getUserEvent(visitorId)).setParent(DEFAULT_CATALOG).build();
        UserEvent userEvent = userEventServiceClient.writeUserEvent(writeUserEventRequest);
        System.out.printf("The user event is written. %n%s%n", userEvent);
        return userEvent;
    }
}
Also used : WriteUserEventRequest(com.google.cloud.retail.v2.WriteUserEventRequest) UserEvent(com.google.cloud.retail.v2.UserEvent) UserEventServiceClient(com.google.cloud.retail.v2.UserEventServiceClient)

Example 2 with WriteUserEventRequest

use of com.google.cloud.retail.v2.WriteUserEventRequest in project java-retail by googleapis.

the class WriteUserEvent method writeUserEvent.

public static void writeUserEvent(String defaultCatalog, String visitorId) throws IOException, ExecutionException, InterruptedException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (UserEventServiceClient userEventServiceClient = UserEventServiceClient.create()) {
        Timestamp timestamp = Timestamp.newBuilder().setSeconds(Instant.now().getEpochSecond()).build();
        UserEvent userEvent = UserEvent.newBuilder().setEventType("home-page-view").setVisitorId(visitorId).setEventTime(timestamp).build();
        System.out.println(userEvent);
        WriteUserEventRequest writeUserEventRequest = WriteUserEventRequest.newBuilder().setUserEvent(userEvent).setParent(defaultCatalog).build();
        System.out.printf("Write user event request: %s%n", writeUserEventRequest);
        userEventServiceClient.writeUserEvent(writeUserEventRequest);
        System.out.printf("Written user event: %s%n", userEvent);
    }
    purgeUserEvent(visitorId);
}
Also used : WriteUserEventRequest(com.google.cloud.retail.v2.WriteUserEventRequest) Timestamp(com.google.protobuf.Timestamp) SetupCleanup.purgeUserEvent(setup.SetupCleanup.purgeUserEvent) UserEvent(com.google.cloud.retail.v2.UserEvent) UserEventServiceClient(com.google.cloud.retail.v2.UserEventServiceClient)

Aggregations

UserEvent (com.google.cloud.retail.v2.UserEvent)2 UserEventServiceClient (com.google.cloud.retail.v2.UserEventServiceClient)2 WriteUserEventRequest (com.google.cloud.retail.v2.WriteUserEventRequest)2 Timestamp (com.google.protobuf.Timestamp)1 SetupCleanup.purgeUserEvent (setup.SetupCleanup.purgeUserEvent)1