Search in sources :

Example 1 with OSInfluenceType

use of com.onesignal.influence.domain.OSInfluenceType in project OneSignal-Android-SDK by OneSignal.

the class OSOutcomeEvent method fromOutcomeEventParamsV2toOutcomeEventV1.

/**
 * Creates an OutcomeEvent from an OSOutcomeEventParams in order to work on V1 from V2
 */
public static OSOutcomeEvent fromOutcomeEventParamsV2toOutcomeEventV1(OSOutcomeEventParams outcomeEventParams) {
    OSInfluenceType influenceType = OSInfluenceType.UNATTRIBUTED;
    JSONArray notificationId = null;
    if (outcomeEventParams.getOutcomeSource() != null) {
        OSOutcomeSource source = outcomeEventParams.getOutcomeSource();
        if (source.getDirectBody() != null && source.getDirectBody().getNotificationIds() != null && source.getDirectBody().getNotificationIds().length() > 0) {
            influenceType = OSInfluenceType.DIRECT;
            notificationId = source.getDirectBody().getNotificationIds();
        } else if (source.getIndirectBody() != null && source.getIndirectBody().getNotificationIds() != null && source.getIndirectBody().getNotificationIds().length() > 0) {
            influenceType = OSInfluenceType.INDIRECT;
            notificationId = source.getIndirectBody().getNotificationIds();
        }
    }
    return new OSOutcomeEvent(influenceType, notificationId, outcomeEventParams.getOutcomeId(), outcomeEventParams.getTimestamp(), outcomeEventParams.getWeight());
}
Also used : OSOutcomeSource(com.onesignal.outcomes.domain.OSOutcomeSource) OSInfluenceType(com.onesignal.influence.domain.OSInfluenceType) JSONArray(org.json.JSONArray)

Example 2 with OSInfluenceType

use of com.onesignal.influence.domain.OSInfluenceType in project OneSignal-Android-SDK by OneSignal.

the class TestHelpers method getAllOutcomesRecords.

static List<OSOutcomeEventDB> getAllOutcomesRecords(OneSignalDb db) {
    Cursor cursor = db.query(MockOSOutcomeEventsTable.TABLE_NAME, null, null, null, // group by
    null, // filter by row groups
    null, // sort order, new to old
    null, // limit
    null);
    List<OSOutcomeEventDB> events = new ArrayList<>();
    if (cursor.moveToFirst()) {
        do {
            String name = cursor.getString(cursor.getColumnIndex(MockOSOutcomeEventsTable.COLUMN_NAME_NAME));
            String iamIds = cursor.getString(cursor.getColumnIndex(MockOSOutcomeEventsTable.COLUMN_NAME_IAM_IDS));
            String iamInfluenceTypeString = cursor.getString(cursor.getColumnIndex(MockOSOutcomeEventsTable.COLUMN_NAME_IAM_INFLUENCE_TYPE));
            String notificationIds = cursor.getString(cursor.getColumnIndex(MockOSOutcomeEventsTable.COLUMN_NAME_NOTIFICATION_IDS));
            String notificationInfluenceTypeString = cursor.getString(cursor.getColumnIndex(MockOSOutcomeEventsTable.COLUMN_NAME_NOTIFICATION_INFLUENCE_TYPE));
            OSInfluenceType iamInfluenceType = OSInfluenceType.fromString(iamInfluenceTypeString);
            OSInfluenceType notificationInfluenceType = OSInfluenceType.fromString(notificationInfluenceTypeString);
            long timestamp = cursor.getLong(cursor.getColumnIndex(MockOSOutcomeEventsTable.COLUMN_NAME_TIMESTAMP));
            float weight = cursor.getFloat(cursor.getColumnIndex(MockOSOutcomeEventsTable.COLUMN_NAME_WEIGHT));
            try {
                OSOutcomeEventDB event = new OSOutcomeEventDB(iamInfluenceType, notificationInfluenceType, new JSONArray(iamIds != null ? iamIds : "[]"), new JSONArray(notificationIds != null ? notificationIds : "[]"), name, timestamp, weight);
                events.add(event);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        } while (cursor.moveToNext());
    }
    cursor.close();
    return events;
}
Also used : OSOutcomeEventDB(com.onesignal.outcomes.OSOutcomeEventDB) OSInfluenceType(com.onesignal.influence.domain.OSInfluenceType) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) Cursor(android.database.Cursor)

Example 3 with OSInfluenceType

use of com.onesignal.influence.domain.OSInfluenceType in project OneSignal-Android-SDK by OneSignal.

the class TestHelpers method getAllOutcomesRecordsDBv5.

static List<OSOutcomeEvent> getAllOutcomesRecordsDBv5(OneSignalDb db) {
    ;
    Cursor cursor = db.query(MockOSOutcomeEventsTable.TABLE_NAME, null, null, null, // group by
    null, // filter by row groups
    null, // sort order, new to old
    null, // limit
    null);
    List<OSOutcomeEvent> events = new ArrayList<>();
    if (cursor.moveToFirst()) {
        do {
            String notificationIds = cursor.getString(cursor.getColumnIndex(MockOSOutcomeEventsTable.COLUMN_NAME_NOTIFICATION_IDS));
            String name = cursor.getString(cursor.getColumnIndex(MockOSOutcomeEventsTable.COLUMN_NAME_NAME));
            String sessionString = cursor.getString(cursor.getColumnIndex(MockOSOutcomeEventsTable.COLUMN_NAME_SESSION));
            OSInfluenceType session = OSInfluenceType.fromString(sessionString);
            long timestamp = cursor.getLong(cursor.getColumnIndex(MockOSOutcomeEventsTable.COLUMN_NAME_TIMESTAMP));
            float weight = cursor.getFloat(cursor.getColumnIndex(MockOSOutcomeEventsTable.COLUMN_NAME_WEIGHT));
            try {
                OSOutcomeEvent event = new OSOutcomeEvent(session, new JSONArray(notificationIds), name, timestamp, weight);
                events.add(event);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        } while (cursor.moveToNext());
    }
    cursor.close();
    return events;
}
Also used : OSOutcomeEvent(com.onesignal.OSOutcomeEvent) OSInfluenceType(com.onesignal.influence.domain.OSInfluenceType) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) Cursor(android.database.Cursor)

Aggregations

OSInfluenceType (com.onesignal.influence.domain.OSInfluenceType)3 JSONArray (org.json.JSONArray)3 Cursor (android.database.Cursor)2 ArrayList (java.util.ArrayList)2 JSONException (org.json.JSONException)2 OSOutcomeEvent (com.onesignal.OSOutcomeEvent)1 OSOutcomeEventDB (com.onesignal.outcomes.OSOutcomeEventDB)1 OSOutcomeSource (com.onesignal.outcomes.domain.OSOutcomeSource)1