Search in sources :

Example 1 with ActivityContact

use of com.vodafone360.people.datatypes.ActivityContact in project 360-Engine-for-Android by 360.

the class ActivitiesTable method fillUpdateData.

/***
     * Provides a ContentValues object that can be used to update the table.
     *
     * @param item The source activity item
     * @param contactIdx The index of the contact to use for the update, or null
     *            to exclude contact specific information.
     * @return ContentValues for use in an SQL update or insert.
     * @note Items that are NULL will be not modified in the database.
     */
private static ContentValues fillUpdateData(final ActivityItem item, final Integer contactIdx) {
    DatabaseHelper.trace(false, "DatabaseHelper.fillUpdateData()");
    ContentValues activityItemValues = new ContentValues();
    ActivityContact ac = null;
    if (contactIdx != null) {
        ac = item.contactList.get(contactIdx);
    }
    activityItemValues.put(Field.ACTIVITY_ID.toString(), item.activityId);
    activityItemValues.put(Field.TIMESTAMP.toString(), item.time);
    if (item.type != null) {
        activityItemValues.put(Field.TYPE.toString(), item.type.getTypeCode());
    }
    if (item.uri != null) {
        activityItemValues.put(Field.URI.toString(), item.uri);
    }
    /** TODO: Not sure if we need this. **/
    // activityItemValues.put(Field.INCOMING.toString(), false);
    activityItemValues.put(Field.TITLE.toString(), item.title);
    activityItemValues.put(Field.DESCRIPTION.toString(), item.description);
    if (item.previewUrl != null) {
        activityItemValues.put(Field.PREVIEW_URL.toString(), item.previewUrl);
    }
    if (item.store != null) {
        activityItemValues.put(Field.STORE.toString(), item.store);
    }
    if (item.activityFlags != null) {
        activityItemValues.put(Field.FLAG.toString(), item.activityFlags);
    }
    if (item.parentActivity != null) {
        activityItemValues.put(Field.PARENT_ACTIVITY.toString(), item.parentActivity);
    }
    if (item.hasChildren != null) {
        activityItemValues.put(Field.HAS_CHILDREN.toString(), item.hasChildren);
    }
    if (item.visibilityFlags != null) {
        activityItemValues.put(Field.VISIBILITY.toString(), item.visibilityFlags);
    }
    if (ac != null) {
        activityItemValues.put(Field.CONTACT_ID.toString(), ac.mContactId);
        activityItemValues.put(Field.USER_ID.toString(), ac.mUserId);
        activityItemValues.put(Field.CONTACT_NAME.toString(), ac.mName);
        activityItemValues.put(Field.LOCAL_CONTACT_ID.toString(), ac.mLocalContactId);
        if (ac.mNetwork != null) {
            activityItemValues.put(Field.CONTACT_NETWORK.toString(), ac.mNetwork);
        }
        if (ac.mAddress != null) {
            activityItemValues.put(Field.CONTACT_ADDRESS.toString(), ac.mAddress);
        }
        if (ac.mAvatarUrl != null) {
            activityItemValues.put(Field.CONTACT_AVATAR_URL.toString(), ac.mAvatarUrl);
        }
    }
    return activityItemValues;
}
Also used : ContentValues(android.content.ContentValues) ActivityContact(com.vodafone360.people.datatypes.ActivityContact)

Example 2 with ActivityContact

use of com.vodafone360.people.datatypes.ActivityContact in project 360-Engine-for-Android by 360.

the class ActivitiesEngineTest method reportBackToEngine.

@Override
public void reportBackToEngine(int reqId, EngineId engine) {
    Log.d("TAG", "IdentityEngineTest.reportBackToEngine");
    ResponseQueue respQueue = ResponseQueue.getInstance();
    List<BaseDataType> data = new ArrayList<BaseDataType>();
    switch(mState) {
        case IDLE:
            break;
        case ON_CREATE:
        case ON_DESTROY:
            break;
        case GET_ACTIVITIES_SUCCESS:
            ActivityItem item = new ActivityItem();
            data.add(item);
            respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.GET_ACTIVITY_RESPONSE.ordinal()));
            mEng.onCommsInMessage();
            break;
        case GET_TIMELINE_EVENT_FROM_SERVER:
            ActivityItem item2 = new ActivityItem();
            ActivityContact act = new ActivityContact();
            act.mName = "Bill Fleege";
            act.mLocalContactId = new Long(8);
            List<ActivityContact> clist = new ArrayList<ActivityContact>();
            clist.add(act);
            item2.contactList = clist;
            item2.activityFlags = 2;
            item2.type = ActivityItem.Type.CONTACT_JOINED;
            item2.time = System.currentTimeMillis();
            data.add(item2);
            respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.GET_ACTIVITY_RESPONSE.ordinal()));
            mEng.onCommsInMessage();
            break;
        case GET_POPULATED_ACTIVITIES:
            ActivityItem item3 = new ActivityItem();
            ActivityContact act2 = new ActivityContact();
            act2.mName = "Bill Fleege";
            act2.mLocalContactId = new Long(8);
            List<ActivityContact> clist2 = new ArrayList<ActivityContact>();
            clist2.add(act2);
            item3.contactList = clist2;
            item3.activityFlags = 2;
            item3.type = ActivityItem.Type.CONTACT_JOINED;
            item3.time = System.currentTimeMillis();
            item3.title = "bills new status";
            item3.description = "a description";
            data.add(item3);
            ActivityItem item4 = new ActivityItem();
            item4.contactList = clist2;
            item4.activityFlags = 5;
            item4.type = ActivityItem.Type.CONTACT_JOINED;
            item4.time = System.currentTimeMillis();
            item4.title = "bills new status";
            item4.description = "a description";
            item4.activityId = new Long(23);
            item4.hasChildren = false;
            item4.uri = "uri";
            item4.parentActivity = new Long(0);
            item4.preview = ByteBuffer.allocate(46);
            item4.preview.position(0);
            item4.preview.rewind();
            for (int i = 0; i < 23; i++) {
                item4.preview.putChar((char) i);
            }
            item4.previewMime = "jepg";
            item4.previewUrl = "storeurl";
            item4.store = "google";
            item4.visibilityFlags = 0;
            data.add(item4);
            respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.GET_ACTIVITY_RESPONSE.ordinal()));
            mEng.onCommsInMessage();
            break;
        case GET_ACTIVITIES_SERVER_ERR:
            ServerError err = new ServerError("Catastrophe");
            err.errorDescription = "Fail";
            data.add(err);
            respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.SERVER_ERROR.ordinal()));
            mEng.onCommsInMessage();
            break;
        case GET_ACTIVITIES_UNEXPECTED_RESPONSE:
            StatusMsg msg = new StatusMsg();
            msg.mCode = "ok";
            msg.mDryRun = false;
            msg.mStatus = true;
            data.add(msg);
            respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.LOGIN_RESPONSE.ordinal()));
            mEng.onCommsInMessage();
            break;
        case SET_STATUS:
            Identity id3 = new Identity();
            data.add(id3);
            respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.GET_AVAILABLE_IDENTITIES_RESPONSE.ordinal()));
            mEng.onCommsInMessage();
            break;
        case ON_SYNC_COMPLETE:
            ServerError err2 = new ServerError("Catastrophe");
            err2.errorDescription = "Fail";
            data.add(err2);
            respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.SERVER_ERROR.ordinal()));
            mEng.onCommsInMessage();
            break;
        case GET_NEXT_RUNTIME:
            break;
        default:
    }
}
Also used : DecodedResponse(com.vodafone360.people.service.io.ResponseQueue.DecodedResponse) StatusMsg(com.vodafone360.people.datatypes.StatusMsg) ServerError(com.vodafone360.people.datatypes.ServerError) ArrayList(java.util.ArrayList) ActivityContact(com.vodafone360.people.datatypes.ActivityContact) BaseDataType(com.vodafone360.people.datatypes.BaseDataType) ResponseQueue(com.vodafone360.people.service.io.ResponseQueue) Identity(com.vodafone360.people.datatypes.Identity) ActivityItem(com.vodafone360.people.datatypes.ActivityItem)

Example 3 with ActivityContact

use of com.vodafone360.people.datatypes.ActivityContact in project 360-Engine-for-Android by 360.

the class NowPlusActivitiesTableTest method testFetchStatusEventList.

/**
	 * This method checks that status events are present in the table
	 */
public void testFetchStatusEventList() {
    Log.i(LOG_TAG, "***** testFetchStatusEventList: create table *****");
    SQLiteDatabase writableDataBase = mTestDatabase.getWritableDatabase();
    ActivitiesTable.create(writableDataBase);
    List<ActivityItem> activitiesList = mTestModule.createFakeStatusEventList();
    ServiceStatus status = ActivitiesTable.addActivities(activitiesList, writableDataBase, mContext);
    assertEquals("Activities not added to the table", ServiceStatus.SUCCESS, status);
    Log.i(LOG_TAG, "***** testFetchStatusEventList: activities added *****");
    // check if the records are there
    List<Long> activitiesIds = new ArrayList<Long>();
    for (ActivityItem item : activitiesList) {
        activitiesIds.add(item.activityId);
    }
    SQLiteDatabase readableDataBase = mTestDatabase.getReadableDatabase();
    List<Long> actualDBIds = new ArrayList<Long>();
    Cursor c = ActivitiesTable.fetchStatusEventList(YESTERDAY_TIME_MILLIS, readableDataBase);
    while (c.moveToNext()) {
        ActivityItem ai = new ActivityItem();
        ActivityContact ac = new ActivityContact();
        ActivitiesTable.getQueryData(c, ai, ac);
        if (ac.mContactId != null) {
            ai.contactList = new ArrayList<ActivityContact>();
            ai.contactList.add(ac);
        }
        actualDBIds.add(ai.activityId);
    }
    c.close();
    compareActivityIds(activitiesIds, actualDBIds);
    Log.i(LOG_TAG, "***** fetchStatusEventlist SUCCEEDED *****");
}
Also used : ActivityContact(com.vodafone360.people.datatypes.ActivityContact) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) ServiceStatus(com.vodafone360.people.service.ServiceStatus) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) ActivityItem(com.vodafone360.people.datatypes.ActivityItem)

Example 4 with ActivityContact

use of com.vodafone360.people.datatypes.ActivityContact in project 360-Engine-for-Android by 360.

the class ActivitiesTable method addActivities.

/**
     * Adds a list of activities to table. The activities added will be grouped
     * in the database, based on local contact Id, name or contact address (see
     * {@link #removeContactGroup(Long, String, Long, int,
     * TimelineNativeTypes[], SQLiteDatabase)}
     * for more information on how the grouping works.
     *
     * @param actList The list of activities
     * @param writableDb Writable SQLite database
     * @return SUCCESS or a suitable error code
     */
public static ServiceStatus addActivities(final List<ActivityItem> actList, final SQLiteDatabase writableDb, final Context context) {
    DatabaseHelper.trace(true, "DatabaseHelper.addActivities()");
    SQLiteStatement statement = ContactsTable.fetchLocalFromServerIdStatement(writableDb);
    boolean isMeProfileChanged = false;
    Long meProfileId = StateTable.fetchMeProfileId(writableDb);
    for (ActivityItem activity : actList) {
        try {
            writableDb.beginTransaction();
            if (activity.contactList != null) {
                int clistSize = activity.contactList.size();
                for (int i = 0; i < clistSize; i++) {
                    final ActivityContact activityContact = activity.contactList.get(i);
                    activityContact.mLocalContactId = ContactsTable.fetchLocalFromServerId(activityContact.mContactId, statement);
                    // Check if me profile status has been modified.
                    boolean isMeProfile = meProfileId != null && meProfileId.equals(activityContact.mLocalContactId);
                    // ORing to ensure that the value remains true once set
                    isMeProfileChanged |= isMeProfile;
                    if (activityContact.mLocalContactId == null) {
                        // This is the same on the web but we could use the provided name instead.
                        continue;
                    } else {
                        // Find a more up-to-date name as the names in the Activities are the ones
                        // from submit time. If they changed in the meantime, this is not reflected
                        // so we fetch the names from the ContactSummary table.
                        final ContactSummary contactSummary = new ContactSummary();
                        if (ContactSummaryTable.fetchSummaryItem(activityContact.mLocalContactId, contactSummary, writableDb) == ServiceStatus.SUCCESS) {
                            // Me Profile can have empty name
                            if ((isMeProfile && contactSummary.formattedName != null) || !TextUtils.isEmpty(contactSummary.formattedName)) {
                                activityContact.mName = contactSummary.formattedName;
                            }
                        }
                    }
                    int latestStatusVal = removeContactGroup(activityContact.mLocalContactId, activityContact.mName, activity.time, activity.activityFlags, null, writableDb);
                    ContentValues cv = fillUpdateData(activity, i);
                    cv.put(Field.LATEST_CONTACT_STATUS.toString(), latestStatusVal);
                    activity.localActivityId = writableDb.insertOrThrow(TABLE_NAME, null, cv);
                }
            } else {
                activity.localActivityId = writableDb.insertOrThrow(TABLE_NAME, null, fillUpdateData(activity, null));
            }
            if ((activity.localActivityId != null) && (activity.localActivityId < 0)) {
                LogUtils.logE("ActivitiesTable.addActivities() " + "Unable to add activity");
                return ServiceStatus.ERROR_DATABASE_CORRUPT;
            }
            writableDb.setTransactionSuccessful();
        } catch (SQLException e) {
            LogUtils.logE("ActivitiesTable.addActivities() " + "Unable to add activity", e);
            return ServiceStatus.ERROR_DATABASE_CORRUPT;
        } finally {
            writableDb.endTransaction();
        }
    }
    if (statement != null) {
        statement.close();
        statement = null;
    }
    // Update widget if me profile status has been modified.
    if (isMeProfileChanged) {
        WidgetUtils.kickWidgetUpdateNow(context);
    }
    return ServiceStatus.SUCCESS;
}
Also used : ContentValues(android.content.ContentValues) ActivityContact(com.vodafone360.people.datatypes.ActivityContact) ContactSummary(com.vodafone360.people.datatypes.ContactSummary) SQLiteStatement(android.database.sqlite.SQLiteStatement) SQLException(android.database.SQLException) ActivityItem(com.vodafone360.people.datatypes.ActivityItem)

Example 5 with ActivityContact

use of com.vodafone360.people.datatypes.ActivityContact in project 360-Engine-for-Android by 360.

the class ActivitiesTable method getLatestStatusForContact.

/**
     * Returns the latest status event for a contact with the given local contact id.
     *
     * @param local contact id Server contact ID.
     * @param readableDb Readable SQLite database.
     * @return The ActivityItem representing the latest status event for given local contact id,
     * or null if nothing was found.
     */
public static ActivityItem getLatestStatusForContact(final long localContactId, final SQLiteDatabase readableDb) {
    DatabaseHelper.trace(false, "DatabaseHelper getLatestStatusForContact");
    Cursor cursor = null;
    try {
        StringBuffer query = StringBufferPool.getStringBuffer(SQLKeys.SELECT);
        query.append(getFullQueryList()).append(SQLKeys.FROM).append(TABLE_NAME).append(SQLKeys.WHERE).append(Field.FLAG).append('&').append(ActivityItem.STATUS_ITEM).append(SQLKeys.AND).append(Field.LOCAL_CONTACT_ID).append('=').append(localContactId).append(" ORDER BY ").append(Field.TIMESTAMP).append(" DESC");
        cursor = readableDb.rawQuery(StringBufferPool.toStringThenRelease(query), null);
        if (cursor.moveToFirst()) {
            final ActivityItem activityItem = new ActivityItem();
            final ActivityContact activityContact = new ActivityContact();
            ActivitiesTable.getQueryData(cursor, activityItem, activityContact);
            return activityItem;
        }
    } finally {
        CloseUtils.close(cursor);
        cursor = null;
    }
    return null;
}
Also used : ActivityContact(com.vodafone360.people.datatypes.ActivityContact) Cursor(android.database.Cursor) ActivityItem(com.vodafone360.people.datatypes.ActivityItem)

Aggregations

ActivityContact (com.vodafone360.people.datatypes.ActivityContact)6 ActivityItem (com.vodafone360.people.datatypes.ActivityItem)4 ContentValues (android.content.ContentValues)2 Cursor (android.database.Cursor)2 ArrayList (java.util.ArrayList)2 SQLException (android.database.SQLException)1 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 SQLiteStatement (android.database.sqlite.SQLiteStatement)1 BaseDataType (com.vodafone360.people.datatypes.BaseDataType)1 ContactSummary (com.vodafone360.people.datatypes.ContactSummary)1 Identity (com.vodafone360.people.datatypes.Identity)1 ServerError (com.vodafone360.people.datatypes.ServerError)1 StatusMsg (com.vodafone360.people.datatypes.StatusMsg)1 ServiceStatus (com.vodafone360.people.service.ServiceStatus)1 ResponseQueue (com.vodafone360.people.service.io.ResponseQueue)1 DecodedResponse (com.vodafone360.people.service.io.ResponseQueue.DecodedResponse)1 Hashtable (java.util.Hashtable)1