Search in sources :

Example 1 with PutUsersRequest

use of software.amazon.awssdk.services.personalizeevents.model.PutUsersRequest 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)

Aggregations

ArrayList (java.util.ArrayList)1 PersonalizeEventsException (software.amazon.awssdk.services.personalizeevents.model.PersonalizeEventsException)1 PutUsersRequest (software.amazon.awssdk.services.personalizeevents.model.PutUsersRequest)1 User (software.amazon.awssdk.services.personalizeevents.model.User)1