Search in sources :

Example 11 with ActivityItem

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

the class NowPlusDBHelperActivitiesTest method testAddActivity.

@MediumTest
public void testAddActivity() {
    mDatabase.removeUserData();
    ServiceStatus status = mTestUtility.waitForEvent(WAIT_EVENT_TIMEOUT_MS, DbTestUtility.CONTACTS_INT_EVENT_MASK);
    assertEquals(ServiceStatus.SUCCESS, status);
    Log.i(LOG_TAG, "***** EXECUTING testAddActivity *****");
    List<ActivityItem> activityList = mTestModule.createFakeActivitiesList();
    //		ServiceStatus status = mDatabase.addActivities(activityList);
    status = null;
    status = mDatabase.addActivities(activityList);
    assertEquals(ServiceStatus.SUCCESS, status);
    Log.i(LOG_TAG, "********************************");
    Log.i(LOG_TAG, "testAddActivity has completed successfully");
    Log.i(LOG_TAG, "********************************");
    Log.i(LOG_TAG, "");
}
Also used : ServiceStatus(com.vodafone360.people.service.ServiceStatus) ActivityItem(com.vodafone360.people.datatypes.ActivityItem) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 12 with ActivityItem

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

the class NowPlusDBHelperActivitiesTest method testFetchActivityIds.

@MediumTest
public void testFetchActivityIds() {
    mDatabase.removeUserData();
    ServiceStatus status = mTestUtility.waitForEvent(WAIT_EVENT_TIMEOUT_MS, DbTestUtility.CONTACTS_INT_EVENT_MASK);
    assertEquals(ServiceStatus.SUCCESS, status);
    Log.i(LOG_TAG, "***** EXECUTING testFetchActivityIds *****");
    List<ActivityItem> activityList = mTestModule.createFakeActivitiesList();
    status = null;
    status = mDatabase.addActivities(activityList);
    assertEquals(ServiceStatus.SUCCESS, status);
    List<Long> idsList = new ArrayList<Long>();
    for (ActivityItem activity : activityList) {
        idsList.add(activity.activityId);
    }
    status = null;
    List<Long> dbIdsList = new ArrayList<Long>();
    status = mDatabase.fetchActivitiesIds(dbIdsList, YESTERDAY_TIME_MILLIS);
    assertEquals(ServiceStatus.SUCCESS, status);
    compareActivityIds(idsList, dbIdsList);
    status = mDatabase.fetchActivitiesIds(dbIdsList, YESTERDAY_TIME_MILLIS);
    assertEquals(ServiceStatus.SUCCESS, status);
    status = mDatabase.deleteActivities(null);
    assertEquals(ServiceStatus.SUCCESS, status);
    List<Long> fetchedDBIdsList = new ArrayList<Long>();
    status = mDatabase.fetchActivitiesIds(fetchedDBIdsList, YESTERDAY_TIME_MILLIS);
    assertEquals(ServiceStatus.SUCCESS, status);
    assertEquals(0, fetchedDBIdsList.size());
    Log.i(LOG_TAG, "********************************");
    Log.i(LOG_TAG, "testFetchActivityIds has completed successfully");
    Log.i(LOG_TAG, "********************************");
    Log.i(LOG_TAG, "");
}
Also used : ServiceStatus(com.vodafone360.people.service.ServiceStatus) ArrayList(java.util.ArrayList) ActivityItem(com.vodafone360.people.datatypes.ActivityItem) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 13 with ActivityItem

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

the class ActivitiesEngine method handleGetActivitiesResponse.

/**
     * Handle GetActivities response message received from Server
     * 
     * @param reqId Request ID contained in response. This should match an ID of
     *            a request we have issued to the Server.
     * @param data List array of ActivityItem items returned from Server.
     */
private void handleGetActivitiesResponse(List<BaseDataType> data) {
    /** Array of Activities retrieved from Server. */
    ArrayList<ActivityItem> activityList = new ArrayList<ActivityItem>();
    ServiceStatus errorStatus = getResponseStatus(BaseDataType.ACTIVITY_ITEM_DATA_TYPE, data);
    LogUtils.logE("ActivityEngine.handleGetActivitiesResponse status from generic = " + errorStatus);
    if (ServiceStatus.SUCCESS == errorStatus) {
        for (BaseDataType item : data) {
            if (item.getType() == BaseDataType.ACTIVITY_ITEM_DATA_TYPE) {
                activityList.add((ActivityItem) item);
            } else {
                LogUtils.logE("ActivityEngine.handleGetActivitiesResponse will not handle strange type = " + item.getType());
            }
        }
        errorStatus = updateDatabase(activityList);
    // we set timeout for the next execution
    }
    // this method will then call completeUiRequest(status, null);
    onSyncHelperComplete(errorStatus);
}
Also used : ServiceStatus(com.vodafone360.people.service.ServiceStatus) ArrayList(java.util.ArrayList) BaseDataType(com.vodafone360.people.datatypes.BaseDataType) ActivityItem(com.vodafone360.people.datatypes.ActivityItem)

Example 14 with ActivityItem

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

the class ActivitiesEngine method updateDatabase.

private ServiceStatus updateDatabase(ArrayList<ActivityItem> activityList) {
    ServiceStatus errorStatus = ServiceStatus.SUCCESS;
    // add retrieved items to Activities table in db
    removeDuplicates(activityList);
    // update the newest activity
    Long temp = findLastStatusUpdateTime(activityList);
    if (temp != Long.MIN_VALUE) {
        mLastStatusUpdated = temp;
    }
    if (activityList.size() > 0) {
        LogUtils.logD("ActivityEngine Added ActivityItems = " + activityList.size());
        // update database
        errorStatus = mDb.addActivities(activityList);
        if (errorStatus == ServiceStatus.SUCCESS) {
            updateLatestStatusUpdateTime();
            updateOldestStatusUpdateTime();
        }
    }
    return errorStatus;
}
Also used : ServiceStatus(com.vodafone360.people.service.ServiceStatus)

Example 15 with ActivityItem

use of com.vodafone360.people.datatypes.ActivityItem 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)

Aggregations

ActivityItem (com.vodafone360.people.datatypes.ActivityItem)13 ArrayList (java.util.ArrayList)10 ServiceStatus (com.vodafone360.people.service.ServiceStatus)7 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)5 ActivityContact (com.vodafone360.people.datatypes.ActivityContact)5 Cursor (android.database.Cursor)3 MediumTest (android.test.suitebuilder.annotation.MediumTest)3 BaseDataType (com.vodafone360.people.datatypes.BaseDataType)3 ContentValues (android.content.ContentValues)2 Flag (com.vodafone360.people.datatypes.ActivityItem.Flag)2 Visibility (com.vodafone360.people.datatypes.ActivityItem.Visibility)2 DecodedResponse (com.vodafone360.people.service.io.ResponseQueue.DecodedResponse)2 SQLException (android.database.SQLException)1 SQLiteStatement (android.database.sqlite.SQLiteStatement)1 Suppress (android.test.suitebuilder.annotation.Suppress)1 TimelineSummaryItem (com.vodafone360.people.database.tables.ActivitiesTable.TimelineSummaryItem)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