Search in sources :

Example 21 with ContactSummary

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

the class DatabaseHelper method updateTimelineAndContactSummaryWithLegacyCode.

/**
 * Updates the Timeline and ContactSummary tables with a new contact. Note:
 * this method assumes that it being called within a transaction
 *
 * @param contact the contact to take info from
 * @param writableDb the db to use to write the updates
 * @return true if successful, false otherwise
 */
private boolean updateTimelineAndContactSummaryWithLegacyCode(Contact contact, SQLiteDatabase writableDb) {
    if (!contact.details.isEmpty()) {
        final ServiceStatus status = ContactSummaryTable.addContact(contact, writableDb);
        if (ServiceStatus.SUCCESS != status) {
            return false;
        }
    }
    // update the summary with the new contact, pass "false" as Me Profile can't be a native contact
    String displayName = updateContactNameInSummary(writableDb, contact.localContactID, false);
    if (displayName == null) {
        return false;
    }
    for (int i = 0; i < contact.details.size(); i++) {
        final ContactDetail detail = contact.details.get(i);
        // updating timeline
        if (detail.key != ContactDetail.DetailKeys.VCARD_NAME) {
            detail.localContactID = contact.localContactID;
            detail.nativeContactId = contact.nativeContactId;
            updateTimelineNames(detail, displayName, contact.contactID, writableDb);
        }
    }
    return true;
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) ServiceStatus(com.vodafone360.people.service.ServiceStatus)

Example 22 with ContactSummary

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

the class DatabaseHelper method addNativeContact.

/**
 * Adds a native contact to the people database and makes sure that the
 * related tables are updated (Contact, ContactDetail, ContactSummary and
 * Activities).
 *
 * @param contact the contact to add
 * @return true if successful, false otherwise
 */
public boolean addNativeContact(ContactChange[] contact) {
    if (contact == null || contact.length <= 0)
        return false;
    final SQLiteDatabase wdb = getWritableDatabase();
    try {
        wdb.beginTransaction();
        // add the contact in the Contacts table
        final ContentValues values = ContactsTable.getNativeContentValues(contact[0]);
        final long internalContactId = ContactsTable.addContact(values, wdb);
        if (internalContactId != -1) {
            // sets the newly created internal contact id to all the
            // ContactChange
            setInternalContactId(contact, internalContactId);
            // details
            if (!ContactDetailsTable.addNativeContactDetails(contact, wdb)) {
                return false;
            }
            // from this point, legacy code will be called...
            final Contact legacyContact = convertNativeContactChanges(contact);
            // ...update timeline and contact summary with legacy code...
            if (!updateTimelineAndContactSummaryWithLegacyCode(legacyContact, wdb)) {
                return false;
            }
        } else {
            return false;
        }
        wdb.setTransactionSuccessful();
        return true;
    } catch (Exception e) {
        LogUtils.logE("addNativeContact() - Error:" + e);
    } finally {
        if (wdb != null) {
            wdb.endTransaction();
        }
    }
    return false;
}
Also used : ContentValues(android.content.ContentValues) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SQLiteException(android.database.sqlite.SQLiteException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) SQLException(android.database.SQLException) Contact(com.vodafone360.people.datatypes.Contact)

Example 23 with ContactSummary

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

ContactSummary (com.vodafone360.people.datatypes.ContactSummary)18 ServiceStatus (com.vodafone360.people.service.ServiceStatus)18 Contact (com.vodafone360.people.datatypes.Contact)15 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)9 Cursor (android.database.Cursor)8 Suppress (android.test.suitebuilder.annotation.Suppress)8 ContentValues (android.content.ContentValues)7 MediumTest (android.test.suitebuilder.annotation.MediumTest)6 Uri (android.net.Uri)5 VCardHelper (com.vodafone360.people.datatypes.VCardHelper)4 SmallTest (android.test.suitebuilder.annotation.SmallTest)3 SQLException (android.database.SQLException)2 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)2 LargeTest (android.test.suitebuilder.annotation.LargeTest)2 User (com.vodafone360.people.engine.presence.User)2 Hashtable (java.util.Hashtable)2 SQLiteException (android.database.sqlite.SQLiteException)1 SQLiteStatement (android.database.sqlite.SQLiteStatement)1 ActivityContact (com.vodafone360.people.datatypes.ActivityContact)1 ActivityItem (com.vodafone360.people.datatypes.ActivityItem)1