Search in sources :

Example 31 with DecodedResponse

use of com.vodafone360.people.service.io.ResponseQueue.DecodedResponse in project 360-Engine-for-Android by 360.

the class SyncMeEngine method processPushEvent.

/**
     * This method process the "pc" push event.
     * @param resp Response - server response normally containing a "pc"
     *            PushEvent data type
     * @return boolean - TRUE if a push event was found in the response
     */
private boolean processPushEvent(final DecodedResponse resp) {
    if (resp.mDataTypes == null || resp.mDataTypes.size() == 0) {
        return false;
    }
    BaseDataType dataType = resp.mDataTypes.get(0);
    if ((dataType == null) || dataType.getType() != BaseDataType.PUSH_EVENT_DATA_TYPE) {
        return false;
    }
    PushEvent pushEvent = (PushEvent) dataType;
    LogUtils.logV("SyncMeEngine processPushMessage():" + pushEvent.mMessageType);
    switch(pushEvent.mMessageType) {
        case PROFILE_CHANGE:
            addGetMeProfileContactRequest();
            break;
        default:
            break;
    }
    return true;
}
Also used : PushEvent(com.vodafone360.people.datatypes.PushEvent) BaseDataType(com.vodafone360.people.datatypes.BaseDataType)

Example 32 with DecodedResponse

use of com.vodafone360.people.service.io.ResponseQueue.DecodedResponse in project 360-Engine-for-Android by 360.

the class SyncMeEngine method processMeProfileThumbnailResponse.

/**
     * This method stores the thumbnail picture for the me profile
     * @param resp Response - normally contains ExternalResponseObject for the
     *            picture
     */
private void processMeProfileThumbnailResponse(final DecodedResponse resp) {
    if (resp.mDataTypes.size() == 0) {
        LogUtils.logE("SyncMeProfile processMeProfileThumbnailResponse():" + SystemNotification.SysNotificationCode.EXTERNAL_HTTP_ERROR);
        completeUiRequest(ServiceStatus.ERROR_COMMS_BAD_RESPONSE);
        return;
    }
    Contact currentMeProfile = new Contact();
    ServiceStatus status = SyncMeDbUtils.fetchMeProfile(mDbHelper, currentMeProfile);
    if (status == ServiceStatus.SUCCESS) {
        if (resp.mReqId == null || resp.mReqId == 0) {
            if (resp.mDataTypes.get(0).getType() == BaseDataType.SYSTEM_NOTIFICATION_DATA_TYPE && ((SystemNotification) resp.mDataTypes.get(0)).getSysCode() == SystemNotification.SysNotificationCode.EXTERNAL_HTTP_ERROR) {
                LogUtils.logE("SyncMeProfile processMeProfileThumbnailResponse():" + SystemNotification.SysNotificationCode.EXTERNAL_HTTP_ERROR);
            }
            completeUiRequest(status);
            return;
        } else if (resp.mDataTypes.get(0).getType() == BaseDataType.SYSTEM_NOTIFICATION_DATA_TYPE) {
            if (((SystemNotification) resp.mDataTypes.get(0)).getSysCode() == SystemNotification.SysNotificationCode.EXTERNAL_HTTP_ERROR) {
                LogUtils.logE("SyncMeProfile processMeProfileThumbnailResponse():" + SystemNotification.SysNotificationCode.EXTERNAL_HTTP_ERROR);
            }
            completeUiRequest(status);
            return;
        }
        status = BaseEngine.getResponseStatus(BaseDataType.EXTERNAL_RESPONSE_OBJECT_DATA_TYPE, resp.mDataTypes);
        if (status != ServiceStatus.SUCCESS) {
            completeUiRequest(ServiceStatus.ERROR_COMMS_BAD_RESPONSE);
            LogUtils.logE("SyncMeProfile processMeProfileThumbnailResponse() - Can't read response");
            return;
        }
        if (resp.mDataTypes == null || resp.mDataTypes.isEmpty()) {
            LogUtils.logE("SyncMeProfile processMeProfileThumbnailResponse() - Datatypes are null");
            completeUiRequest(ServiceStatus.ERROR_COMMS_BAD_RESPONSE);
            return;
        }
        // finally save the thumbnails
        ExternalResponseObject ext = (ExternalResponseObject) resp.mDataTypes.get(0);
        if (ext.mBody == null) {
            LogUtils.logE("SyncMeProfile processMeProfileThumbnailResponse() - no body");
            completeUiRequest(ServiceStatus.ERROR_COMMS_BAD_RESPONSE);
            return;
        }
        try {
            ThumbnailUtils.saveExternalResponseObjectToFile(currentMeProfile.localContactID, ext);
            ContactSummaryTable.modifyPictureLoadedFlag(currentMeProfile.localContactID, true, mDbHelper.getWritableDatabase());
            mDbHelper.markMeProfileAvatarChanged();
        } catch (IOException e) {
            LogUtils.logE("SyncMeProfile processMeProfileThumbnailResponse()", e);
            completeUiRequest(ServiceStatus.ERROR_COMMS_BAD_RESPONSE);
        }
    }
    completeUiRequest(status);
}
Also used : SystemNotification(com.vodafone360.people.datatypes.SystemNotification) ExternalResponseObject(com.vodafone360.people.datatypes.ExternalResponseObject) ServiceStatus(com.vodafone360.people.service.ServiceStatus) IOException(java.io.IOException) Contact(com.vodafone360.people.datatypes.Contact)

Example 33 with DecodedResponse

use of com.vodafone360.people.service.io.ResponseQueue.DecodedResponse in project 360-Engine-for-Android by 360.

the class UploadServerContacts method processDeletedContactsResp.

/**
     * Called when a server response is received during a deleted contact sync.
     * The server change log is updated. Possibly server errors are also
     * handled.
     * 
     * @param resp Response from server.
     */
private void processDeletedContactsResp(final DecodedResponse resp) {
    ServiceStatus status = BaseEngine.getResponseStatus(BaseDataType.CONTACT_LIST_RESPONSE_DATA_TYPE, resp.mDataTypes);
    if (status == ServiceStatus.SUCCESS) {
        ContactListResponse result = (ContactListResponse) resp.mDataTypes.get(0);
        ListIterator<ContactChangeInfo> infoIt = mContactChangeInfoList.listIterator();
        for (Integer contactID : result.mContactIdList) {
            if (!infoIt.hasNext()) {
                complete(ServiceStatus.ERROR_COMMS_BAD_RESPONSE);
                return;
            }
            ContactChangeInfo info = infoIt.next();
            if (contactID == null || contactID.intValue() == -1) {
                LogUtils.logE("UploadServerContacts." + "processDeletedContactsResp() The server failed " + "to delete the following contact: LocalId = " + info.mLocalContactId + ", ServerId = " + info.mServerContactId);
                mFailureList += "Failed to delete contact: " + info.mLocalContactId + "\n";
            }
        }
        long startTime = System.nanoTime();
        mDb.deleteContactChanges(mContactChangeInfoList);
        mDbSyncTime += (System.nanoTime() - startTime);
        mContactChangeInfoList.clear();
        updateProgress();
        sendNextDeleteContactsPage();
        return;
    }
    LogUtils.logE("UploadServerContacts.processModifiedDetailsResp() " + "Error requesting contact changes, error = " + status);
    complete(status);
}
Also used : ContactChangeInfo(com.vodafone360.people.database.tables.ContactChangeLogTable.ContactChangeInfo) ServiceStatus(com.vodafone360.people.service.ServiceStatus) ContactListResponse(com.vodafone360.people.datatypes.ContactListResponse)

Example 34 with DecodedResponse

use of com.vodafone360.people.service.io.ResponseQueue.DecodedResponse in project 360-Engine-for-Android by 360.

the class UploadServerContacts method processGroupDeletionsResp.

/**
     * Called when a server response is received during a group/contact delete
     * relation sync. The server change log is updated. Possibly server errors
     * are also handled.
     * 
     * @param resp Response from server.
     */
private void processGroupDeletionsResp(final DecodedResponse resp) {
    ServiceStatus status = BaseEngine.getResponseStatus(BaseDataType.STATUS_MSG_DATA_TYPE, resp.mDataTypes);
    if (status == ServiceStatus.SUCCESS) {
        if (resp.mDataTypes.size() == 0) {
            LogUtils.logE("UploadServerContacts." + "processGroupDeletionsResp() " + "Response cannot be empty");
            complete(ServiceStatus.ERROR_COMMS_BAD_RESPONSE);
            return;
        }
        StatusMsg result = (StatusMsg) resp.mDataTypes.get(0);
        if (!result.mStatus.booleanValue()) {
            LogUtils.logE("UploadServerContacts." + "processGroupDeletionsResp() Error deleting group " + "relation, error = " + result.mError);
            complete(ServiceStatus.ERROR_COMMS_BAD_RESPONSE);
        }
        LogUtils.logV("UploadServerContacts." + "processGroupDeletionsResp() Deleted relation");
        long startTime = System.nanoTime();
        mDb.deleteContactChanges(mContactChangeInfoList);
        mDbSyncTime += (System.nanoTime() - startTime);
        mContactChangeInfoList.clear();
        updateProgress();
        sendNextDelGroupRelationsPage();
        return;
    }
    LogUtils.logE("UploadServerContacts.processGroupDeletionsResp() " + "Error deleting group relation, error = " + status);
    complete(status);
}
Also used : StatusMsg(com.vodafone360.people.datatypes.StatusMsg) ServiceStatus(com.vodafone360.people.service.ServiceStatus)

Example 35 with DecodedResponse

use of com.vodafone360.people.service.io.ResponseQueue.DecodedResponse in project 360-Engine-for-Android by 360.

the class UploadServerContacts method processNewContactsResp.

/**
     * Called when a server response is received during a new contact sync. The
     * server ID, user ID and contact detail unique IDs are extracted from the
     * response and the NowPlus database updated. Possibly server errors are
     * also handled.
     * 
     * @param resp Response from server.
     */
private void processNewContactsResp(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> contactServerIdList = new ArrayList<ServerIdInfo>();
        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;
            }
            Contact contactSrc = itContactSrc.next();
            Contact contactDest = itContactDest.next();
            if (Settings.ENABLED_CONTACTS_SYNC_TRACE) {
                String name = null;
                String sns = null;
                for (ContactDetail detail : contactDest.details) {
                    if (detail.key == ContactDetail.DetailKeys.VCARD_NAME) {
                        if (detail.value != null) {
                            VCardHelper.Name nameObj = detail.getName();
                            if (nameObj != null) {
                                name = nameObj.toString();
                            }
                        }
                    }
                    if (detail.key == ContactDetail.DetailKeys.VCARD_INTERNET_ADDRESS) {
                        sns = detail.alt;
                    }
                }
                LogUtils.logV("UploadServerContacts." + "processNewContactsResp() Contact uploaded: SID" + " = " + contactSrc.contactID + ", name = " + name + ", sns = " + sns + ", no of details = " + contactDest.details.size() + ", deleted=" + contactSrc.deleted);
            }
            if (contactSrc.contactID != null && contactSrc.contactID.longValue() != -1L) {
                if (contactDest.contactID == null || !contactDest.contactID.equals(contactSrc.contactID)) {
                    ServerIdInfo info = new ServerIdInfo();
                    info.localId = contactDest.localContactID;
                    info.serverId = contactSrc.contactID;
                    info.userId = contactSrc.userID;
                    contactServerIdList.add(info);
                }
            } else {
                LogUtils.logE("UploadServerContacts." + "processNewContactsResp() The server failed to " + "add the following contact: " + contactDest.localContactID + ", server ID = " + contactDest.contactID);
                mFailureList += "Failed to add contact: " + contactDest.localContactID + "\n";
                for (ContactDetail d : contactDest.details) {
                    LogUtils.logV("Failed Contact Info: " + contactDest.localContactID + ", Detail: " + d.key + ", " + d.keyType + " = " + d.value);
                }
            }
            status = handleUploadDetailChanges(contactSrc, contactDest, detailServerIdList);
        }
        if (status != ServiceStatus.SUCCESS) {
            /** Something is going wrong - cancel the update **/
            complete(status);
            return;
        }
        long startTime = System.nanoTime();
        List<ContactIdInfo> dupList = new ArrayList<ContactIdInfo>();
        status = ContactsTable.syncSetServerIds(contactServerIdList, dupList, mDb.getWritableDatabase());
        if (status != ServiceStatus.SUCCESS) {
            complete(status);
            return;
        }
        status = ContactDetailsTable.syncSetServerIds(detailServerIdList, mDb.getWritableDatabase());
        if (status != ServiceStatus.SUCCESS) {
            complete(status);
            return;
        }
        if (dupList.size() > 0) {
            LogUtils.logV("UploadServerContacts.processNewContactsResp() Found " + dupList.size() + " duplicate contacts. Trying to remove them...");
            if (VersionUtils.is2XPlatform()) {
                // This is a very important distinction for 2.X devices!
                // the NAB IDs from the contacts we first import are stripped away
                // So we won't have the correct ID if syncMergeContactList() is executed
                // This is critical because a chain reaction will cause a Contact Delete in the end
                // Instead we can syncDeleteContactList() which should be safe on 2.X!
                status = mDb.syncDeleteContactList(dupList, false, true);
            } else {
                status = mDb.syncMergeContactList(dupList);
            }
            if (status != ServiceStatus.SUCCESS) {
                complete(status);
                return;
            }
            markDbChanged();
        }
        mDbSyncTime += (System.nanoTime() - startTime);
        while (itContactDest.hasNext()) {
            Contact contactDest = itContactDest.next();
            LogUtils.logE("UploadServerContacts.processNewContactsResp() " + "The server failed to add the following contact (not " + "included in returned list): " + contactDest.localContactID);
            mFailureList += "Failed to add contact (missing from return " + "list): " + contactDest.localContactID + "\n";
        }
        updateProgress();
        sendNextContactAdditionsPage();
        return;
    }
    complete(status);
}
Also used : ContactIdInfo(com.vodafone360.people.database.tables.ContactsTable.ContactIdInfo) ArrayList(java.util.ArrayList) ServerIdInfo(com.vodafone360.people.database.DatabaseHelper.ServerIdInfo) ContactChanges(com.vodafone360.people.datatypes.ContactChanges) Contact(com.vodafone360.people.datatypes.Contact) ContactDetail(com.vodafone360.people.datatypes.ContactDetail) ServiceStatus(com.vodafone360.people.service.ServiceStatus) VCardHelper(com.vodafone360.people.datatypes.VCardHelper)

Aggregations

DecodedResponse (com.vodafone360.people.service.io.ResponseQueue.DecodedResponse)26 BaseDataType (com.vodafone360.people.datatypes.BaseDataType)23 ArrayList (java.util.ArrayList)23 ServiceStatus (com.vodafone360.people.service.ServiceStatus)13 ServerError (com.vodafone360.people.datatypes.ServerError)12 IOException (java.io.IOException)10 MediumTest (android.test.suitebuilder.annotation.MediumTest)9 ResponseQueue (com.vodafone360.people.service.io.ResponseQueue)8 PushEvent (com.vodafone360.people.datatypes.PushEvent)7 HessianDecoder (com.vodafone360.people.service.utils.hessian.HessianDecoder)7 ContactChanges (com.vodafone360.people.datatypes.ContactChanges)6 Contact (com.vodafone360.people.datatypes.Contact)5 Suppress (android.test.suitebuilder.annotation.Suppress)4 Identity (com.vodafone360.people.datatypes.Identity)4 StatusMsg (com.vodafone360.people.datatypes.StatusMsg)4 AuthSessionHolder (com.vodafone360.people.datatypes.AuthSessionHolder)3 ExternalResponseObject (com.vodafone360.people.datatypes.ExternalResponseObject)3 Request (com.vodafone360.people.service.io.Request)3 ServerIdInfo (com.vodafone360.people.database.DatabaseHelper.ServerIdInfo)2 ContactChangeInfo (com.vodafone360.people.database.tables.ContactChangeLogTable.ContactChangeInfo)2