Search in sources :

Example 51 with Contact

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

the class PeopleContactsApi method updateNativeContact.

/**
 * Updates a native contact in the people database.
 *
 * Note: it assumes that the changes come from native as it sets flags
 *       to prevent syncing back to native
 *
 * @param contact the contact changes to apply to the contact
 */
public void updateNativeContact(ContactChange[] contact) {
    mAddedDetails.clear();
    mDeletedDetails.clear();
    mUpdatedDetails.clear();
    for (int i = 0; i < contact.length; i++) {
        final ContactChange change = contact[i];
        // convert the ContactChange into a ContactDetail
        final ContactDetail detail = mDbh.convertContactChange(change);
        final int type = change.getType();
        switch(type) {
            case ContactChange.TYPE_ADD_DETAIL:
                mAddedDetails.add(detail);
                break;
            case ContactChange.TYPE_DELETE_DETAIL:
                mDeletedDetails.add(detail);
                break;
            case ContactChange.TYPE_UPDATE_DETAIL:
                mUpdatedDetails.add(detail);
                break;
        }
    }
    if (mAddedDetails.size() > 0) {
        mDbh.syncAddContactDetailList(mAddedDetails, true, false);
    }
    if (mDeletedDetails.size() > 0) {
        mDbh.syncDeleteContactDetailList(mDeletedDetails, true, false);
    }
    if (mUpdatedDetails.size() > 0) {
        mDbh.syncModifyContactDetailList(mUpdatedDetails, true, false);
    }
    // TODO: Throttle the event
    mDbh.fireDatabaseChangedEvent(DatabaseChangeType.CONTACTS, true);
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail)

Example 52 with Contact

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

the class UploadServerContacts method processModifiedDetailsResp.

/**
 * Called when a server response is received during a modified contact sync.
 * The server ID, user ID and contact detail unique IDs are extracted from
 * the response and the NowPlus database updated if necessary. Possibly
 * server errors are also handled.
 *
 * @param resp Response from server.
 */
private void processModifiedDetailsResp(final DecodedResponse resp) {
    ServiceStatus status = BaseEngine.getResponseStatus(BaseDataType.CONTACT_CHANGES_DATA_TYPE, resp.mDataTypes);
    if (status == ServiceStatus.SUCCESS) {
        ContactChanges contactChanges = (ContactChanges) resp.mDataTypes.get(0);
        ListIterator<Contact> itContactSrc = contactChanges.mContacts.listIterator();
        ListIterator<Contact> itContactDest = mContactChangeList.listIterator();
        List<ServerIdInfo> detailServerIdList = new ArrayList<ServerIdInfo>();
        while (itContactSrc.hasNext()) {
            if (!itContactDest.hasNext()) {
                /*
                     * The response should contain the same number of contacts
                     * as was supplied but must handle the error.
                     */
                status = ServiceStatus.ERROR_COMMS_BAD_RESPONSE;
                break;
            }
            status = handleUploadDetailChanges(itContactSrc.next(), itContactDest.next(), detailServerIdList);
        }
        if (status != ServiceStatus.SUCCESS) {
            /**
             * Something is going wrong - cancel the update. *
             */
            complete(status);
            return;
        }
        long startTime = System.nanoTime();
        status = ContactDetailsTable.syncSetServerIds(detailServerIdList, mDb.getWritableDatabase());
        if (status != ServiceStatus.SUCCESS) {
            complete(status);
            return;
        }
        mDb.deleteContactChanges(mContactChangeInfoList);
        mDbSyncTime += (System.nanoTime() - startTime);
        mContactChangeInfoList.clear();
        updateProgress();
        sendNextDetailChangesPage();
        return;
    }
    LogUtils.logE("UploadServerContacts.processModifiedDetailsResp() " + "Error requesting contact changes, error = " + status);
    complete(status);
}
Also used : ServiceStatus(com.vodafone360.people.service.ServiceStatus) ArrayList(java.util.ArrayList) ServerIdInfo(com.vodafone360.people.database.DatabaseHelper.ServerIdInfo) ContactChanges(com.vodafone360.people.datatypes.ContactChanges) Contact(com.vodafone360.people.datatypes.Contact)

Example 53 with Contact

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

the class UploadServerContacts method processDeletedDetailsResp.

/**
 * Called when a server response is received during a deleted contact detail
 * sync. The server change log is updated. Possibly server errors are also
 * handled.
 *
 * @param resp Response from server.
 */
private void processDeletedDetailsResp(final DecodedResponse resp) {
    ServiceStatus status = BaseEngine.getResponseStatus(BaseDataType.CONTACT_DETAIL_DELETION_DATA_TYPE, resp.mDataTypes);
    if (status == ServiceStatus.SUCCESS) {
        ContactDetailDeletion result = (ContactDetailDeletion) resp.mDataTypes.get(0);
        if (result.mDetails != null) {
            LogUtils.logV("UploadServerContacts." + "processDeletedDetailsResp() Deleted details " + result.mDetails.size());
        }
        ListIterator<ContactChangeInfo> infoIt = mContactChangeInfoList.listIterator();
        if (result.mContactId == null || result.mContactId == -1) {
            boolean first = true;
            while (infoIt.hasNext()) {
                ContactChangeInfo info = infoIt.next();
                if (first) {
                    first = false;
                    LogUtils.logE("UploadServerContacts." + "processDeletedDetailsResp() The server " + "failed to delete detail from the following " + "contact: LocalId = " + info.mLocalContactId + ", ServerId = " + info.mServerContactId);
                }
                mFailureList += "Failed to delete detail: " + info.mLocalDetailId + "\n";
            }
        } else if (result.mDetails != null) {
            for (ContactDetail d : result.mDetails) {
                if (!infoIt.hasNext()) {
                    complete(ServiceStatus.ERROR_COMMS_BAD_RESPONSE);
                    return;
                }
                ContactChangeInfo info = infoIt.next();
                if (!d.key.equals(info.mServerDetailKey)) {
                    LogUtils.logE("UploadServerContacts." + "processDeletedDetailsResp() The server " + "failed to delete the following detail: " + "LocalId = " + info.mLocalContactId + ", " + "ServerId = " + info.mServerContactId + ", key = " + info.mServerDetailKey + ", detail ID = " + info.mServerDetailId);
                    mFailureList += "Failed to delete detail: " + info.mLocalDetailId + "\n";
                }
            }
        }
        long startTime = System.nanoTime();
        mDb.deleteContactChanges(mContactChangeInfoList);
        mDbSyncTime += (System.nanoTime() - startTime);
        mContactChangeInfoList.clear();
        updateProgress();
        sendNextDeleteDetailsPage();
        return;
    }
    LogUtils.logE("UploadServerContacts.processModifiedDetailsResp() " + "Error requesting contact changes, error = " + status);
    complete(status);
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) ContactChangeInfo(com.vodafone360.people.database.tables.ContactChangeLogTable.ContactChangeInfo) ContactDetailDeletion(com.vodafone360.people.datatypes.ContactDetailDeletion) ServiceStatus(com.vodafone360.people.service.ServiceStatus)

Example 54 with Contact

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

the class UploadServerContacts method processGroupAdditionsResp.

/**
 * Called when a server response is received during a group/contact add
 * relation sync. The server change log is updated. Possibly server errors
 * are also handled.
 *
 * @param resp Response from server.
 */
private void processGroupAdditionsResp(final DecodedResponse resp) {
    ServiceStatus status = BaseEngine.getResponseStatus(BaseDataType.ITEM_LIST_DATA_TYPE, resp.mDataTypes);
    if (status == ServiceStatus.SUCCESS) {
        if (resp.mDataTypes.size() == 0) {
            LogUtils.logE("UploadServerContacts." + "processGroupAdditionsResp() " + "Item list cannot be empty");
            complete(ServiceStatus.ERROR_COMMS_BAD_RESPONSE);
            return;
        }
        ItemList itemList = (ItemList) resp.mDataTypes.get(0);
        if (itemList.mItemList == null) {
            LogUtils.logE("UploadServerContacts." + "processGroupAdditionsResp() " + "Item list cannot be NULL");
            complete(ServiceStatus.ERROR_COMMS_BAD_RESPONSE);
            return;
        }
        // TODO: Check response
        long startTime = System.nanoTime();
        mDb.deleteContactChanges(mContactChangeInfoList);
        mDbSyncTime += (System.nanoTime() - startTime);
        mContactChangeInfoList.clear();
        updateProgress();
        sendNextAddGroupRelationsPage();
        return;
    }
    LogUtils.logE("UploadServerContacts.processGroupAdditionsResp() " + "Error adding group relations, error = " + status);
    complete(status);
}
Also used : ServiceStatus(com.vodafone360.people.service.ServiceStatus) ItemList(com.vodafone360.people.datatypes.ItemList)

Example 55 with Contact

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

the class UploadServerContacts method handleUploadDetailChanges.

/**
 * Called when handling the server response from a new contact or modify
 * contact sync. Updates the unique IDs for all the details if necessary.
 *
 * @param contactSrc Contact received from server.
 * @param contactDest Contact from database.
 * @param detailServerIdList List of contact details with updated unique id.
 * @return ServiceStatus object.
 */
private ServiceStatus handleUploadDetailChanges(final Contact contactSrc, final Contact contactDest, final List<ServerIdInfo> detailServerIdList) {
    if (contactSrc.contactID == null || contactSrc.contactID.longValue() == -1L) {
        LogUtils.logE("UploadServerContacts.handleUploadDetailChanges() " + "The server failed to modify the following contact: " + contactDest.localContactID);
        mFailureList += "Failed to add contact: " + contactDest.localContactID + "\n";
        return ServiceStatus.SUCCESS;
    }
    ListIterator<ContactDetail> itContactDetailSrc = contactSrc.details.listIterator();
    ListIterator<ContactDetail> itContactDetailDest = contactDest.details.listIterator();
    while (itContactDetailSrc.hasNext()) {
        if (!itContactDetailDest.hasNext()) {
            /*
                 * The response should contain the same number of details as was
                 * supplied but must handle the error.
                 */
            return ServiceStatus.ERROR_COMMS_BAD_RESPONSE;
        }
        ContactDetail contactDetailSrc = itContactDetailSrc.next();
        ContactDetail contactDetailDest = itContactDetailDest.next();
        ServerIdInfo info = new ServerIdInfo();
        info.localId = contactDetailDest.localDetailID;
        if (contactDetailSrc.unique_id != null && contactDetailSrc.unique_id.longValue() == -1L) {
            LogUtils.logE("UploadServerContacts." + "handleUploadDetailChanges() The server failed to " + "modify the following contact detail: LocalDetailId " + "= " + contactDetailDest.localDetailID + ", Key = " + contactDetailDest.key + ", value = " + contactDetailDest.value);
            mFailureList += "Failed to modify contact detail: " + contactDetailDest.localDetailID + ", for contact " + contactDetailDest.localContactID + "\n";
            info.serverId = null;
        } else {
            info.serverId = contactDetailSrc.unique_id;
        }
        detailServerIdList.add(info);
    }
    while (itContactDetailDest.hasNext()) {
        ContactDetail contactDetailDest = itContactDetailDest.next();
        mFailureList += "Failed to modify contact detail (not in return " + "list):" + contactDetailDest.localDetailID + ", for contact " + contactDetailDest.localContactID + "\n";
        LogUtils.logE("UploadServerContacts.handleUploadDetailChanges() " + "The server failed to modify the following contact detail " + "(not found in returned list): LocalDetailId = " + contactDetailDest.localDetailID + ", Key = " + contactDetailDest.key + ", value = " + contactDetailDest.value);
    }
    return ServiceStatus.SUCCESS;
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) ServerIdInfo(com.vodafone360.people.database.DatabaseHelper.ServerIdInfo)

Aggregations

Contact (com.vodafone360.people.datatypes.Contact)109 ServiceStatus (com.vodafone360.people.service.ServiceStatus)107 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)100 ArrayList (java.util.ArrayList)62 MediumTest (android.test.suitebuilder.annotation.MediumTest)50 Suppress (android.test.suitebuilder.annotation.Suppress)39 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)34 Cursor (android.database.Cursor)31 ContactChange (com.vodafone360.people.engine.contactsync.ContactChange)22 SmallTest (android.test.suitebuilder.annotation.SmallTest)19 ContactSummary (com.vodafone360.people.datatypes.ContactSummary)18 SQLException (android.database.SQLException)15 ContentValues (android.content.ContentValues)14 VCardHelper (com.vodafone360.people.datatypes.VCardHelper)13 Uri (android.net.Uri)11 ContactChangeInfo (com.vodafone360.people.database.tables.ContactChangeLogTable.ContactChangeInfo)11 ContactIdInfo (com.vodafone360.people.database.tables.ContactsTable.ContactIdInfo)11 ContactChanges (com.vodafone360.people.datatypes.ContactChanges)11 SQLiteException (android.database.sqlite.SQLiteException)9 ContactsTable (com.vodafone360.people.database.tables.ContactsTable)9