Search in sources :

Example 1 with PutItemsRequest

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

ArrayList (java.util.ArrayList)1 Item (software.amazon.awssdk.services.personalizeevents.model.Item)1 PersonalizeEventsException (software.amazon.awssdk.services.personalizeevents.model.PersonalizeEventsException)1 PutItemsRequest (software.amazon.awssdk.services.personalizeevents.model.PutItemsRequest)1