Search in sources :

Example 1 with PersonalizeEventsException

use of software.amazon.awssdk.services.personalizeevents.model.PersonalizeEventsException in project aws-doc-sdk-examples by awsdocs.

the class PutEvents method putEvents.

// snippet-start:[personalize.java2.put_events.main]
public static int putEvents(PersonalizeEventsClient personalizeEventsClient, String trackingId, String userId, String itemId, String sessionId) {
    int responseCode = 0;
    try {
        // Build an event and a putEvents request with only the required information for a minimal schema.
        // Schema columns for this example would be itemId, userId, and timestamp.
        Event event = Event.builder().sentAt(Instant.ofEpochMilli(System.currentTimeMillis() + 10 * 60 * 1000)).itemId(itemId).eventType("typePlaceholder").build();
        PutEventsRequest putEventsRequest = PutEventsRequest.builder().trackingId(trackingId).userId(userId).sessionId(sessionId).eventList(event).build();
        responseCode = personalizeEventsClient.putEvents(putEventsRequest).sdkHttpResponse().statusCode();
        System.out.println("Response code: " + responseCode);
        return responseCode;
    } catch (PersonalizeEventsException e) {
        System.out.println(e.awsErrorDetails().errorMessage());
    }
    return responseCode;
}
Also used : PersonalizeEventsException(software.amazon.awssdk.services.personalizeevents.model.PersonalizeEventsException) Event(software.amazon.awssdk.services.personalizeevents.model.Event) PutEventsRequest(software.amazon.awssdk.services.personalizeevents.model.PutEventsRequest)

Example 2 with PersonalizeEventsException

use of software.amazon.awssdk.services.personalizeevents.model.PersonalizeEventsException in project aws-doc-sdk-examples by awsdocs.

the class PutUsers method putUsers.

// snippet-start:[personalize.java2.put_users.main]
public static int putUsers(PersonalizeEventsClient personalizeEventsClient, String datasetArn, String user1Id, String user1PropertyName, String user1PropertyValue, String user2Id, String user2PropertyName, String user2PropertyValue) {
    int responseCode = 0;
    ArrayList<User> users = new ArrayList<>();
    try {
        User user1 = User.builder().userId(user1Id).properties(String.format("{\"%1$s\": \"%2$s\"}", user1PropertyName, user1PropertyValue)).build();
        users.add(user1);
        User user2 = User.builder().userId(user2Id).properties(String.format("{\"%1$s\": \"%2$s\"}", user2PropertyName, user2PropertyValue)).build();
        users.add(user2);
        PutUsersRequest putUsersRequest = PutUsersRequest.builder().datasetArn(datasetArn).users(users).build();
        responseCode = personalizeEventsClient.putUsers(putUsersRequest).sdkHttpResponse().statusCode();
        System.out.println("Response code: " + responseCode);
        return responseCode;
    } catch (PersonalizeEventsException e) {
        System.out.println(e.awsErrorDetails().errorMessage());
    }
    return responseCode;
}
Also used : PutUsersRequest(software.amazon.awssdk.services.personalizeevents.model.PutUsersRequest) User(software.amazon.awssdk.services.personalizeevents.model.User) PersonalizeEventsException(software.amazon.awssdk.services.personalizeevents.model.PersonalizeEventsException) ArrayList(java.util.ArrayList)

Example 3 with PersonalizeEventsException

use of software.amazon.awssdk.services.personalizeevents.model.PersonalizeEventsException in project aws-doc-sdk-examples by awsdocs.

the class PutItems method putItems.

// snippet-start:[personalize.java2.put_items.main]
public static int putItems(PersonalizeEventsClient personalizeEventsClient, String datasetArn, String item1Id, String item1PropertyName, String item1PropertyValue, String item2Id, String item2PropertyName, String item2PropertyValue) {
    int responseCode = 0;
    ArrayList<Item> items = new ArrayList<>();
    try {
        Item item1 = Item.builder().itemId(item1Id).properties(String.format("{\"%1$s\": \"%2$s\"}", item1PropertyName, item1PropertyValue)).build();
        items.add(item1);
        Item item2 = Item.builder().itemId(item2Id).properties(String.format("{\"%1$s\": \"%2$s\"}", item2PropertyName, item2PropertyValue)).build();
        items.add(item2);
        PutItemsRequest putItemsRequest = PutItemsRequest.builder().datasetArn(datasetArn).items(items).build();
        responseCode = personalizeEventsClient.putItems(putItemsRequest).sdkHttpResponse().statusCode();
        System.out.println("Response code: " + responseCode);
        return responseCode;
    } catch (PersonalizeEventsException e) {
        System.out.println(e.awsErrorDetails().errorMessage());
    }
    return responseCode;
}
Also used : Item(software.amazon.awssdk.services.personalizeevents.model.Item) PersonalizeEventsException(software.amazon.awssdk.services.personalizeevents.model.PersonalizeEventsException) ArrayList(java.util.ArrayList) PutItemsRequest(software.amazon.awssdk.services.personalizeevents.model.PutItemsRequest)

Aggregations

PersonalizeEventsException (software.amazon.awssdk.services.personalizeevents.model.PersonalizeEventsException)3 ArrayList (java.util.ArrayList)2 Event (software.amazon.awssdk.services.personalizeevents.model.Event)1 Item (software.amazon.awssdk.services.personalizeevents.model.Item)1 PutEventsRequest (software.amazon.awssdk.services.personalizeevents.model.PutEventsRequest)1 PutItemsRequest (software.amazon.awssdk.services.personalizeevents.model.PutItemsRequest)1 PutUsersRequest (software.amazon.awssdk.services.personalizeevents.model.PutUsersRequest)1 User (software.amazon.awssdk.services.personalizeevents.model.User)1