Search in sources :

Example 11 with DecodedResponse

use of com.vodafone360.people.service.io.ResponseQueue.DecodedResponse 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 12 with DecodedResponse

use of com.vodafone360.people.service.io.ResponseQueue.DecodedResponse 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 13 with DecodedResponse

use of com.vodafone360.people.service.io.ResponseQueue.DecodedResponse 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 14 with DecodedResponse

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

the class ContentEngine method processCommsResponse.

/**
     * Processes the response Finds the matching contentobject for the repsonse
     * using the id of the response and sets its status to done. At last the
     * TransferComplete method of the ContentObject is called.
     * 
     * @param resp Response object that has been processed
     */
@Override
protected final void processCommsResponse(final DecodedResponse resp) {
    ContentObject co = requestContentObjectMatchTable.remove(resp.mReqId);
    if (co == null) {
        // check if we have an invalid response
        return;
    }
    List<BaseDataType> mDataTypes = resp.mDataTypes;
    // Sometimes it is null or empty
    if (mDataTypes == null || mDataTypes.size() == 0) {
        co.setTransferStatus(ContentObject.TransferStatus.ERROR);
        RuntimeException exc = new RuntimeException("Empty response returned");
        co.getTransferListener().transferError(co, exc);
        return;
    }
    Object data = mDataTypes.get(0);
    if (mDataTypes.get(0).getType() == BaseDataType.SERVER_ERROR_DATA_TYPE || mDataTypes.get(0).getType() == BaseDataType.SYSTEM_NOTIFICATION_DATA_TYPE) {
        co.setTransferStatus(ContentObject.TransferStatus.ERROR);
        RuntimeException exc = new RuntimeException(data.toString());
        co.getTransferListener().transferError(co, exc);
    } else {
        co.setTransferStatus(ContentObject.TransferStatus.DONE);
        co.setExtResponse((ExternalResponseObject) data);
        co.getTransferListener().transferComplete(co);
    }
}
Also used : BaseDataType(com.vodafone360.people.datatypes.BaseDataType) ExternalResponseObject(com.vodafone360.people.datatypes.ExternalResponseObject)

Example 15 with DecodedResponse

use of com.vodafone360.people.service.io.ResponseQueue.DecodedResponse 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)

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