Search in sources :

Example 6 with ContactChanges

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

the class SyncMeDbUtils method updateMeProfileDbDetailIds.

/**
 * The utility method to save Contacts/setMe() response to the database...
 * @param dbHelper Database - database
 * @param uploadedMeProfile Contact - me profile which has been uploaded in
 *            Contacts/setMe() call
 * @param result ContactChanges - the contents of response Contacts/setMe().
 *            The contact details in response need to be in the same order
 *            as they were in setMe() request
 */
public static void updateMeProfileDbDetailIds(final DatabaseHelper dbHelper, final ArrayList<ContactDetail> uploadedDetails, final ContactChanges result) {
    Contact uploadedMeProfile = new Contact();
    SyncMeDbUtils.fetchMeProfile(dbHelper, uploadedMeProfile);
    boolean changed = false;
    if (result.mUserProfile.userID != null && !result.mUserProfile.userID.equals(uploadedMeProfile.userID)) {
        uploadedMeProfile.userID = result.mUserProfile.userID;
        changed = true;
    }
    if (result.mUserProfile.contactID != null && !result.mUserProfile.contactID.equals(uploadedMeProfile.contactID)) {
        uploadedMeProfile.contactID = result.mUserProfile.contactID;
        changed = true;
    }
    if (changed) {
        dbHelper.modifyContactServerId(uploadedMeProfile.localContactID, uploadedMeProfile.contactID, uploadedMeProfile.userID);
    }
    ListIterator<ContactDetail> destIt = uploadedDetails.listIterator();
    for (ContactDetail srcDetail : result.mUserProfile.details) {
        if (!destIt.hasNext()) {
            LogUtils.logE("SyncMeDbUtils updateProfileDbDetailsId() - # of details in response > # in request");
            return;
        }
        final ContactDetail destDetail = destIt.next();
        if (srcDetail.key == null || !srcDetail.key.equals(destDetail.key)) {
            LogUtils.logE("SyncMeDbUtils updateProfileDbDetailsId() - details order is wrong");
            break;
        }
        destDetail.unique_id = srcDetail.unique_id;
        dbHelper.syncContactDetail(destDetail.localDetailID, destDetail.unique_id);
    }
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) Contact(com.vodafone360.people.datatypes.Contact)

Example 7 with ContactChanges

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

the class SyncMeEngine method processSetMeResponse.

/**
 * Processes the response from a SetMe request. If successful, the server
 * IDs will be stored in the local database if they have changed. Otherwise
 * the processor will complete with a suitable error.
 * @param resp Response from server.
 */
private void processSetMeResponse(final DecodedResponse resp) {
    LogUtils.logD("SyncMeProfile.processMeProfileUpdateResponse()");
    ServiceStatus status = BaseEngine.getResponseStatus(BaseDataType.CONTACT_CHANGES_DATA_TYPE, resp.mDataTypes);
    if (status == ServiceStatus.SUCCESS) {
        ContactChanges result = (ContactChanges) resp.mDataTypes.get(0);
        SyncMeDbUtils.updateMeProfileDbDetailIds(mDbHelper, mUploadedMeDetails, result);
        if (updateRevisionPostUpdate(result.mServerRevisionBefore, result.mServerRevisionAfter, mFromRevision, mDbHelper)) {
            mFromRevision = result.mServerRevisionAfter;
        }
    }
    completeUiRequest(status);
}
Also used : ServiceStatus(com.vodafone360.people.service.ServiceStatus) ContactChanges(com.vodafone360.people.datatypes.ContactChanges)

Example 8 with ContactChanges

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

the class SyncMeEngine method processUpdateStatusResponse.

/**
 * This method processes the response to status update by setMe() method
 * @param resp Response - the expected response datatype is ContactChanges
 */
private void processUpdateStatusResponse(final DecodedResponse resp) {
    LogUtils.logD("SyncMeDbUtils processUpdateStatusResponse()");
    ServiceStatus status = BaseEngine.getResponseStatus(BaseDataType.CONTACT_CHANGES_DATA_TYPE, resp.mDataTypes);
    if (status == ServiceStatus.SUCCESS) {
        ContactChanges result = (ContactChanges) resp.mDataTypes.get(0);
        LogUtils.logI("SyncMeProfile.processUpdateStatusResponse() - Me profile userId = " + result.mUserProfile.userID);
        SyncMeDbUtils.savePresenceStatusResponse(mDbHelper, result);
    }
    completeUiRequest(status);
}
Also used : ServiceStatus(com.vodafone360.people.service.ServiceStatus) ContactChanges(com.vodafone360.people.datatypes.ContactChanges)

Example 9 with ContactChanges

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

the class DatabaseHelper method convertNativeContactChanges.

/**
 * Converts an array of ContactChange into a Contact object.
 *
 * @see ContactChange
 * @see Contact
 * @param contactChanges the array of ContactChange to convert
 * @return the equivalent Contact
 */
private Contact convertNativeContactChanges(ContactChange[] contactChanges) {
    if (contactChanges == null || contactChanges.length <= 0)
        return null;
    final Contact contact = new Contact();
    contact.localContactID = contactChanges[0].getInternalContactId();
    // coming from native
    contact.nativeContactId = new Integer((int) contactChanges[0].getNabContactId());
    contact.synctophone = true;
    // fill the contact with all the details
    for (int i = 0; i < contactChanges.length; i++) {
        final ContactDetail detail = convertContactChange(contactChanges[i]);
        // setting it to -1 means that it does not need to be synced back to
        // native
        detail.syncNativeContactId = -1;
        contact.details.add(detail);
    }
    return contact;
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) Contact(com.vodafone360.people.datatypes.Contact)

Example 10 with ContactChanges

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

the class DownloadServerContactsTest method reportBackWithNoChanges.

private void reportBackWithNoChanges(int reqId, List<BaseDataType> data) {
    Log.d(LOG_TAG, "reportBackWithNoChanges");
    Integer pageNo = mProcessor.testGetPageFromReqId(reqId);
    assertTrue(pageNo != null);
    assertEquals(Integer.valueOf(0), pageNo);
    ContactChanges contactChanges = new ContactChanges();
    data.add(contactChanges);
    contactChanges.mCurrentServerVersion = CURRENT_SERVER_VERSION;
    contactChanges.mServerRevisionBefore = CURRENT_SERVER_VERSION;
    contactChanges.mServerRevisionAfter = CURRENT_SERVER_VERSION;
    contactChanges.mVersionAnchor = CURRENT_SERVER_VERSION;
    contactChanges.mNumberOfPages = 1;
    mItemCount--;
    assertTrue(mItemCount >= 0);
    if (mItemCount == 0) {
        nextState(State.IDLE);
    }
}
Also used : ContactChanges(com.vodafone360.people.datatypes.ContactChanges)

Aggregations

Contact (com.vodafone360.people.datatypes.Contact)15 ContactChanges (com.vodafone360.people.datatypes.ContactChanges)15 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)11 ServiceStatus (com.vodafone360.people.service.ServiceStatus)7 ArrayList (java.util.ArrayList)5 ServerIdInfo (com.vodafone360.people.database.DatabaseHelper.ServerIdInfo)2 NativeContactsApi (com.vodafone360.people.engine.contactsync.NativeContactsApi)2 ContactIdInfo (com.vodafone360.people.database.tables.ContactsTable.ContactIdInfo)1 ActivityContact (com.vodafone360.people.datatypes.ActivityContact)1 ContactDetailDeletion (com.vodafone360.people.datatypes.ContactDetailDeletion)1 ContactListResponse (com.vodafone360.people.datatypes.ContactListResponse)1 Conversation (com.vodafone360.people.datatypes.Conversation)1 ExternalResponseObject (com.vodafone360.people.datatypes.ExternalResponseObject)1 IdentityDeletion (com.vodafone360.people.datatypes.IdentityDeletion)1 ItemList (com.vodafone360.people.datatypes.ItemList)1 PresenceList (com.vodafone360.people.datatypes.PresenceList)1 SimpleText (com.vodafone360.people.datatypes.SimpleText)1 StatusMsg (com.vodafone360.people.datatypes.StatusMsg)1 VCardHelper (com.vodafone360.people.datatypes.VCardHelper)1 ContactChange (com.vodafone360.people.engine.contactsync.ContactChange)1