Search in sources :

Example 81 with ServiceStatus

use of com.vodafone360.people.service.ServiceStatus in project 360-Engine-for-Android by 360.

the class DatabaseHelper method syncDeleteContactDetailList.

/**
 * Function used by the contact sync engine to delete a list of contact
 * details from the database.
 *
 * @param contactDetailList The list of details which has been deleted on
 *            the server
 * @param serverIdList A list of server IDs if known, or null
 * @param syncToServer true if the details need to be sent to the server
 * @param syncToNative true if the contacts need to be added to the native
 *            phonebook
 * @param meProfile - TRUE if the added contact is Me profile.
 * @return SUCCESS or a suitable error code
 * @see #deleteContactDetail(long)
 */
public ServiceStatus syncDeleteContactDetailList(List<ContactDetail> contactDetailList, boolean syncToServer, boolean syncToNative) {
    if (Settings.ENABLED_DATABASE_TRACE)
        trace(false, "DatabaseHelper.syncDeleteContactDetailList() syncToServer[" + syncToServer + "] syncToNative[" + syncToNative + "]");
    if (!Settings.ENABLE_SERVER_CONTACT_SYNC) {
        syncToServer = false;
    }
    if (!Settings.ENABLE_UPDATE_NATIVE_CONTACTS) {
        syncToNative = false;
    }
    SQLiteDatabase db = getWritableDatabase();
    boolean needFireDbUpdate = false;
    for (ContactDetail contactDetail : contactDetailList) {
        if ((contactDetail.serverContactId == null) || (contactDetail.serverContactId == -1)) {
            ContactsTable.ContactIdInfo contactIdInfo = ContactsTable.validateContactId(contactDetail.localContactID, db);
            if (contactIdInfo == null) {
                return ServiceStatus.ERROR_NOT_FOUND;
            }
            contactDetail.nativeContactId = contactIdInfo.nativeId;
            contactDetail.serverContactId = contactIdInfo.serverId;
        }
        try {
            db.beginTransaction();
            if (syncToNative) {
                if (!NativeChangeLogTable.addDeletedContactDetailChange(contactDetail, db)) {
                    return ServiceStatus.ERROR_DATABASE_CORRUPT;
                }
            }
            if (syncToServer) {
                if (!ContactChangeLogTable.addDeletedContactDetailChange(contactDetail, syncToServer, db)) {
                    return ServiceStatus.ERROR_DATABASE_CORRUPT;
                }
            }
            if (!ContactDetailsTable.deleteDetailByDetailId(contactDetail.localDetailID, db)) {
                return ServiceStatus.ERROR_DATABASE_CORRUPT;
            }
            // in order not to override the new picture before it is uploaded.
            if (contactDetail.key == ContactDetail.DetailKeys.PHOTO && TextUtils.isEmpty(contactDetail.photo_url)) {
                ContactSummaryTable.modifyPictureLoadedFlag(contactDetail.localContactID, false, db);
                deleteThumbnail(contactDetail.localContactID);
            }
            String displayName = updateContactNameInSummary(db, contactDetail.localContactID, SyncMeDbUtils.isMeProfile(this, contactDetail.localContactID));
            if (displayName == null) {
                return ServiceStatus.ERROR_DATABASE_CORRUPT;
            }
            if (updateTimelineNames(contactDetail, displayName, contactDetail.localContactID, db)) {
                needFireDbUpdate = true;
            }
            db.setTransactionSuccessful();
        } finally {
            db.endTransaction();
        }
    }
    if (needFireDbUpdate) {
        fireDatabaseChangedEvent(DatabaseChangeType.ACTIVITIES, false);
    }
    return ServiceStatus.SUCCESS;
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) ContactsTable(com.vodafone360.people.database.tables.ContactsTable)

Example 82 with ServiceStatus

use of com.vodafone360.people.service.ServiceStatus in project 360-Engine-for-Android by 360.

the class DatabaseHelper method syncModifyContactDetailList.

/**
 * Function used by the contact sync engine to modify a list of contact
 * details in the database.
 *
 * @param contactDetailList The list of details received from the server
 * @param serverIdList A list of server IDs if known, or null
 * @param syncToServer true if the details need to be sent to the server
 * @param syncToNative true if the contacts need to be added to the native
 *            phonebook
 * @return SUCCESS or a suitable error code
 * @see #modifyContactDetail(ContactDetail)
 */
public ServiceStatus syncModifyContactDetailList(List<ContactDetail> contactDetailList, boolean syncToServer, boolean syncToNative) {
    if (Settings.ENABLED_DATABASE_TRACE)
        trace(false, "DatabaseHelper.syncModifyContactDetailList() syncToServer[" + syncToServer + "] syncToNative[" + syncToNative + "]");
    if (!Settings.ENABLE_SERVER_CONTACT_SYNC) {
        syncToServer = false;
    }
    if (!Settings.ENABLE_UPDATE_NATIVE_CONTACTS) {
        syncToNative = false;
    }
    boolean needFireDbUpdate = false;
    SQLiteDatabase db = getWritableDatabase();
    for (ContactDetail contactDetail : contactDetailList) {
        ContactsTable.ContactIdInfo contactIdInfo = ContactsTable.validateContactId(contactDetail.localContactID, db);
        if (contactIdInfo == null) {
            return ServiceStatus.ERROR_NOT_FOUND;
        }
        contactDetail.serverContactId = contactIdInfo.serverId;
        if (contactIdInfo.syncToPhone) {
            contactDetail.syncNativeContactId = contactIdInfo.nativeId;
        } else {
            contactDetail.syncNativeContactId = -1;
        }
        try {
            db.beginTransaction();
            if (contactDetail.order != null && contactDetail.order.equals(ContactDetail.ORDER_PREFERRED)) {
                ContactDetailsTable.removePreferred(contactDetail.localContactID, contactDetail.key, db);
            }
            ServiceStatus status = ContactDetailsTable.modifyDetail(contactDetail, syncToServer, syncToNative, db);
            if (ServiceStatus.SUCCESS != status) {
                return status;
            }
            // in order not to override the new picture before it is uploaded.
            if (ContactDetail.DetailKeys.PHOTO == contactDetail.key && TextUtils.isEmpty(contactDetail.photo_url)) {
                ContactSummaryTable.modifyPictureLoadedFlag(contactDetail.localContactID, false, db);
            }
            String displayName = updateContactNameInSummary(db, contactDetail.localContactID, SyncMeDbUtils.isMeProfile(this, contactDetail.localContactID));
            if (null == displayName) {
                return ServiceStatus.ERROR_DATABASE_CORRUPT;
            }
            if (updateTimelineNames(contactDetail, displayName, null, db)) {
                needFireDbUpdate = true;
            }
            db.setTransactionSuccessful();
        } finally {
            db.endTransaction();
        }
    }
    if (needFireDbUpdate) {
        fireDatabaseChangedEvent(DatabaseChangeType.ACTIVITIES, false);
    }
    return ServiceStatus.SUCCESS;
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) ContactsTable(com.vodafone360.people.database.tables.ContactsTable) ServiceStatus(com.vodafone360.people.service.ServiceStatus)

Example 83 with ServiceStatus

use of com.vodafone360.people.service.ServiceStatus in project 360-Engine-for-Android by 360.

the class DatabaseHelper method deleteActivities.

/**
 * Removes all the status or timeline activities from the database. Note:
 * Only called from tests.
 *
 * @param flag The type of activity to delete or null to delete all
 * @return SUCCESS or a suitable error code
 * @see #addActivities(List)
 * @see #fetchActivitiesIds(List, Long)
 */
public ServiceStatus deleteActivities(Integer flag) {
    if (Settings.ENABLED_DATABASE_TRACE)
        trace(false, "DatabaseHelper.deleteActivities() flag[" + flag + "]");
    ServiceStatus status = ActivitiesTable.deleteActivities(flag, getWritableDatabase());
    if (ServiceStatus.SUCCESS == status) {
        if (flag == null || flag.intValue() == ActivityItem.TIMELINE_ITEM) {
            StateTable.modifyLatestPhoneCallTime(System.currentTimeMillis(), getWritableDatabase());
        }
    }
    fireDatabaseChangedEvent(DatabaseChangeType.ACTIVITIES, true);
    return status;
}
Also used : ServiceStatus(com.vodafone360.people.service.ServiceStatus)

Example 84 with ServiceStatus

use of com.vodafone360.people.service.ServiceStatus in project 360-Engine-for-Android by 360.

the class DatabaseHelper method modifyContactDetail.

/**
 * Modifies an existing contact detail in the database. Also fires an
 * internal database change event.
 *
 * @param detail A {@link ContactDetail} object which contains the detail to add
 *
 * @return SUCCESS or a suitable error code
 * @see #addContactDetail(ContactDetail)
 * @see #deleteContactDetail(long)
 * @see #addContact(Contact)
 * @see #deleteContact(long)
 * @see #addContactToGroup(long, long)
 * @see #deleteContactFromGroup(long, long)
 */
public ServiceStatus modifyContactDetail(ContactDetail detail) {
    if (Settings.ENABLED_DATABASE_TRACE) {
        trace(false, "DatabaseHelper.modifyContactDetail() name[" + detail.getName() + "]");
    }
    boolean isMeProfile = SyncMeDbUtils.isMeProfile(this, detail.localContactID);
    List<ContactDetail> detailList = new ArrayList<ContactDetail>();
    detailList.add(detail);
    ServiceStatus status = syncModifyContactDetailList(detailList, !isMeProfile, !isMeProfile);
    if (ServiceStatus.SUCCESS == status) {
        fireDatabaseChangedEvent(DatabaseChangeType.CONTACTS, false);
        if (isMeProfile) {
            WidgetUtils.kickWidgetUpdateNow(mContext);
        }
    }
    return status;
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) ServiceStatus(com.vodafone360.people.service.ServiceStatus) ArrayList(java.util.ArrayList)

Example 85 with ServiceStatus

use of com.vodafone360.people.service.ServiceStatus in project 360-Engine-for-Android by 360.

the class DatabaseHelper method syncMergeContactList.

/**
 * Function used by the contact sync engine to merge contacts which are
 * marked as duplicate by the server. This involves moving native
 * information from one contact to the other, before deleting it.
 *
 * @param contactIdList The list of contact IDs (localId, serverId and
 *            mergedLocalId should be set)
 * @return SUCCESS or a suitable error code
 */
public ServiceStatus syncMergeContactList(List<ContactsTable.ContactIdInfo> contactIdList) {
    if (Settings.ENABLED_DATABASE_TRACE)
        trace(false, "DatabaseHelper.syncMergeContactList()");
    List<ContactDetail> detailInfoList = new ArrayList<ContactDetail>();
    SQLiteDatabase writableDb = getWritableDatabase();
    SQLiteStatement contactStatement = null, contactSummaryStatement = null;
    try {
        contactStatement = ContactsTable.mergeContactStatement(writableDb);
        contactSummaryStatement = ContactSummaryTable.mergeContactStatement(writableDb);
        writableDb.beginTransaction();
        for (int i = 0; i < contactIdList.size(); i++) {
            ContactsTable.ContactIdInfo contactIdInfo = contactIdList.get(i);
            if (contactIdInfo.mergedLocalId != null) {
                contactIdInfo.nativeId = ContactsTable.fetchNativeFromLocalId(writableDb, contactIdInfo.localId);
                LogUtils.logI("DatabaseHelper.syncMergeContactList - Copying native Ids from duplicate to original contact: Dup ID " + contactIdInfo.localId + ", Org ID " + contactIdInfo.mergedLocalId + ", Nat ID " + contactIdInfo.nativeId);
                ServiceStatus status = ContactsTable.mergeContact(contactIdInfo, contactStatement);
                if (status != ServiceStatus.SUCCESS) {
                    return status;
                }
                status = ContactSummaryTable.mergeContact(contactIdInfo, contactSummaryStatement);
                if (status != ServiceStatus.SUCCESS) {
                    return status;
                }
                status = ContactDetailsTable.fetchNativeInfo(contactIdInfo.localId, detailInfoList, writableDb);
                if (status != ServiceStatus.SUCCESS) {
                    return status;
                }
                status = ContactDetailsTable.mergeContactDetails(contactIdInfo, detailInfoList, writableDb);
                if (status != ServiceStatus.SUCCESS) {
                    return status;
                }
            }
        }
        writableDb.setTransactionSuccessful();
    } finally {
        writableDb.endTransaction();
        if (contactStatement != null) {
            contactStatement.close();
            contactStatement = null;
        }
        if (contactSummaryStatement != null) {
            contactSummaryStatement.close();
            contactSummaryStatement = null;
        }
    }
    LogUtils.logI("DatabaseHelper.syncMergeContactList - Deleting duplicate contacts");
    return syncDeleteContactList(contactIdList, false, true);
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SQLiteStatement(android.database.sqlite.SQLiteStatement) ContactsTable(com.vodafone360.people.database.tables.ContactsTable) ServiceStatus(com.vodafone360.people.service.ServiceStatus) ArrayList(java.util.ArrayList)

Aggregations

ServiceStatus (com.vodafone360.people.service.ServiceStatus)190 Contact (com.vodafone360.people.datatypes.Contact)71 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)63 MediumTest (android.test.suitebuilder.annotation.MediumTest)62 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)43 ArrayList (java.util.ArrayList)43 Suppress (android.test.suitebuilder.annotation.Suppress)40 Cursor (android.database.Cursor)17 SmallTest (android.test.suitebuilder.annotation.SmallTest)17 ContactSummary (com.vodafone360.people.datatypes.ContactSummary)16 Bundle (android.os.Bundle)12 ContentValues (android.content.ContentValues)11 VCardHelper (com.vodafone360.people.datatypes.VCardHelper)11 SQLException (android.database.SQLException)9 ServerIdInfo (com.vodafone360.people.database.DatabaseHelper.ServerIdInfo)9 ContactsTable (com.vodafone360.people.database.tables.ContactsTable)9 ContactIdInfo (com.vodafone360.people.database.tables.ContactsTable.ContactIdInfo)9 ActivityItem (com.vodafone360.people.datatypes.ActivityItem)8 LoginDetails (com.vodafone360.people.datatypes.LoginDetails)8 PersistSettings (com.vodafone360.people.service.PersistSettings)8