Search in sources :

Example 1 with EventsBatch

use of com.amazonaws.services.pinpoint.model.EventsBatch in project aws-sdk-android by aws-amplify.

the class EventRecorder method createRecordEventsRequest.

/**
 * @param events array of events
 * @param endpointProfile endpoint profile for the device endpoint
 *
 * @return the request to put event
 */
private PutEventsRequest createRecordEventsRequest(final JSONArray events, final EndpointProfile endpointProfile) {
    final PutEventsRequest putRequest = new PutEventsRequest().withApplicationId(endpointProfile.getApplicationId());
    final String endpointId = endpointProfile.getEndpointId();
    final Map<String, EventsBatch> eventsBatchMap = new HashMap<String, EventsBatch>();
    final EventsBatch eventsBatch = new EventsBatch();
    final PublicEndpoint endpoint = new PublicEndpoint();
    final Map<String, Event> eventsMap = new HashMap<String, Event>();
    // build endpoint payload
    buildEndpointPayload(endpointProfile, endpoint);
    for (int i = 0; i < events.length(); i++) {
        JSONObject eventJSON = null;
        AnalyticsEvent internalEvent = null;
        try {
            eventJSON = events.getJSONObject(i);
            internalEvent = AnalyticsEvent.translateToEvent(eventJSON);
        } catch (final JSONException jsonException) {
            // Do not log JSONException due to potentially sensitive information
            log.error("Stored event was invalid JSON.", jsonException);
            continue;
        }
        // build event payload
        final Event event = new Event();
        buildEventPayload(internalEvent, event);
        eventsMap.put(internalEvent.getEventId(), event);
    }
    // build request payload, could also build with only endpoint payload
    buildRequestPayload(putRequest, endpointId, eventsBatchMap, eventsBatch, endpoint, eventsMap);
    return putRequest;
}
Also used : AnalyticsEvent(com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsEvent) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) AnalyticsEvent(com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsEvent) Event(com.amazonaws.services.pinpoint.model.Event) JSONException(org.json.JSONException) PublicEndpoint(com.amazonaws.services.pinpoint.model.PublicEndpoint) PutEventsRequest(com.amazonaws.services.pinpoint.model.PutEventsRequest) EventsBatch(com.amazonaws.services.pinpoint.model.EventsBatch) PublicEndpoint(com.amazonaws.services.pinpoint.model.PublicEndpoint)

Aggregations

AnalyticsEvent (com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsEvent)1 Event (com.amazonaws.services.pinpoint.model.Event)1 EventsBatch (com.amazonaws.services.pinpoint.model.EventsBatch)1 PublicEndpoint (com.amazonaws.services.pinpoint.model.PublicEndpoint)1 PutEventsRequest (com.amazonaws.services.pinpoint.model.PutEventsRequest)1 HashMap (java.util.HashMap)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1