Search in sources :

Example 16 with BaseDataType

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

the class HessianDecoder method decodeResponseByRequestType.

/**
 * Parses the hashtables retrieved from the hessian payload that came from the server and
 * returns a type for it.
 *
 * @param clist The list that will be populated with the data types.
 * @param hash The hash table that contains the parsed date returned by the backend.
 * @param type The type of the request that was sent, e.g. get contacts changes.
 *
 * @return The type of the response that was parsed (to be found in DecodedResponse.ResponseType).
 */
private int decodeResponseByRequestType(List<BaseDataType> clist, Hashtable<String, Object> hash, Request.Type type) {
    int responseType = DecodedResponse.ResponseType.UNKNOWN.ordinal();
    switch(type) {
        case CONTACT_CHANGES_OR_UPDATES:
            responseType = DecodedResponse.ResponseType.GET_CONTACTCHANGES_RESPONSE.ordinal();
            // create ContactChanges
            ContactChanges contChanges = new ContactChanges();
            contChanges = contChanges.createFromHashtable(hash);
            clist.add(contChanges);
            break;
        case ADD_CONTACT:
            clist.add(Contact.createFromHashtable(hash));
            responseType = DecodedResponse.ResponseType.ADD_CONTACT_RESPONSE.ordinal();
            break;
        case SIGN_UP:
            clist.add(Contact.createFromHashtable(hash));
            responseType = DecodedResponse.ResponseType.SIGNUP_RESPONSE.ordinal();
            break;
        case RETRIEVE_PUBLIC_KEY:
            // AA define new object type
            clist.add(PublicKeyDetails.createFromHashtable(hash));
            responseType = DecodedResponse.ResponseType.RETRIEVE_PUBLIC_KEY_RESPONSE.ordinal();
            break;
        case CONTACT_DELETE:
            ContactListResponse cresp = new ContactListResponse();
            cresp.createFromHashTable(hash);
            // add ids
            @SuppressWarnings("unchecked") Vector<Long> contactIds = (Vector<Long>) hash.get(KEY_CONTACT_ID_LIST);
            if (contactIds != null) {
                for (Long cid : contactIds) {
                    cresp.mContactIdList.add((cid).intValue());
                }
            }
            clist.add(cresp);
            responseType = DecodedResponse.ResponseType.DELETE_CONTACT_RESPONSE.ordinal();
            break;
        case CONTACT_DETAIL_DELETE:
            ContactDetailDeletion cdel = new ContactDetailDeletion();
            clist.add(cdel.createFromHashtable(hash));
            responseType = DecodedResponse.ResponseType.DELETE_CONTACT_DETAIL_RESPONSE.ordinal();
            break;
        case CONTACT_GROUP_RELATION_LIST:
            ItemList groupRelationList = new ItemList(ItemList.Type.contact_group_relation);
            groupRelationList.populateFromHashtable(hash);
            clist.add(groupRelationList);
            responseType = DecodedResponse.ResponseType.GET_CONTACT_GROUP_RELATIONS_RESPONSE.ordinal();
            break;
        case CONTACT_GROUP_RELATIONS:
            ItemList groupRelationsList = new ItemList(ItemList.Type.contact_group_relations);
            groupRelationsList.populateFromHashtable(hash);
            clist.add(groupRelationsList);
            responseType = DecodedResponse.ResponseType.GET_CONTACT_GROUP_RELATIONS_RESPONSE.ordinal();
            break;
        case DELETE_CONTACT_GROUP_RELATIONS:
            // The hessian data sent by the backend is of the form
            // r{1}{0}Mt{0}{0}zz. The MicroHessianInput always skips the 2 bytes
            // after the type. This doesn't seem to be handling the case where
            // the type is of length zero. Due to this, after decoding, the hash
            // doesn't contain any elements/keys. Due to this, we are hardcoding
            // the status to true here.
            StatusMsg statusMsg = new StatusMsg();
            statusMsg.mStatus = true;
            clist.add(statusMsg);
            responseType = DecodedResponse.ResponseType.UNKNOWN.ordinal();
            break;
        case GROUP_LIST:
            ItemList zyblist = new ItemList(ItemList.Type.group_privacy);
            zyblist.populateFromHashtable(hash);
            clist.add(zyblist);
            responseType = DecodedResponse.ResponseType.GET_GROUPS_RESPONSE.ordinal();
            break;
        case ITEM_LIST_OF_LONGS:
            ItemList listOfLongs = new ItemList(ItemList.Type.long_value);
            listOfLongs.populateFromHashtable(hash);
            clist.add(listOfLongs);
            // TODO
            responseType = DecodedResponse.ResponseType.UNKNOWN.ordinal();
            break;
        case // TODO status and status list are used by many requests as a type. each request should have its own type however!
        STATUS_LIST:
            ItemList zybstatlist = new ItemList(ItemList.Type.status_msg);
            zybstatlist.populateFromHashtable(hash);
            clist.add(zybstatlist);
            // TODO
            responseType = DecodedResponse.ResponseType.UNKNOWN.ordinal();
            break;
        case STATUS:
            StatusMsg s = new StatusMsg();
            s.mStatus = true;
            clist.add(s);
            // TODO
            responseType = DecodedResponse.ResponseType.UNKNOWN.ordinal();
            break;
        case TEXT_RESPONSE_ONLY:
            Object val = hash.get("result");
            if (val != null && val instanceof String) {
                SimpleText txt = new SimpleText();
                txt.addText((String) val);
                clist.add(txt);
            }
            // TODO
            responseType = DecodedResponse.ResponseType.UNKNOWN.ordinal();
            break;
        case EXPECTING_STATUS_ONLY:
            StatusMsg statMsg = new StatusMsg();
            clist.add(statMsg.createFromHashtable(hash));
            // TODO
            responseType = DecodedResponse.ResponseType.UNKNOWN.ordinal();
            break;
        case PRESENCE_LIST:
            PresenceList mPresenceList = new PresenceList();
            mPresenceList.createFromHashtable(hash);
            clist.add(mPresenceList);
            responseType = DecodedResponse.ResponseType.GET_PRESENCE_RESPONSE.ordinal();
            break;
        case PUSH_MSG:
            // parse content of RPG Push msg
            parsePushMessage(clist, hash);
            responseType = DecodedResponse.ResponseType.PUSH_MESSAGE.ordinal();
            break;
        case CREATE_CONVERSATION:
            Conversation mConversation = new Conversation();
            mConversation.createFromHashtable(hash);
            clist.add(mConversation);
            responseType = DecodedResponse.ResponseType.CREATE_CONVERSATION_RESPONSE.ordinal();
            break;
        case DELETE_IDENTITY:
            IdentityDeletion mIdenitityDeletion = new IdentityDeletion();
            clist.add(mIdenitityDeletion.createFromHashtable(hash));
            responseType = DecodedResponse.ResponseType.DELETE_IDENTITY_RESPONSE.ordinal();
            break;
        default:
            LogUtils.logE("HessianDecoder.decodeResponseByRequestType() Unhandled type[" + type.name() + "]");
    }
    return responseType;
}
Also used : StatusMsg(com.vodafone360.people.datatypes.StatusMsg) SimpleText(com.vodafone360.people.datatypes.SimpleText) PresenceList(com.vodafone360.people.datatypes.PresenceList) Conversation(com.vodafone360.people.datatypes.Conversation) ContactChanges(com.vodafone360.people.datatypes.ContactChanges) ContactListResponse(com.vodafone360.people.datatypes.ContactListResponse) IdentityDeletion(com.vodafone360.people.datatypes.IdentityDeletion) ContactDetailDeletion(com.vodafone360.people.datatypes.ContactDetailDeletion) ItemList(com.vodafone360.people.datatypes.ItemList) ExternalResponseObject(com.vodafone360.people.datatypes.ExternalResponseObject) Vector(java.util.Vector)

Example 17 with BaseDataType

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

the class UploadServerContactsTest method reportDeleteGroupListSuccess.

private void reportDeleteGroupListSuccess(int reqId, List<BaseDataType> data) {
    Log.d(LOG_TAG, "reportDeleteGroupListSuccess");
    mProcessor.verifyGroupDelsState();
    final List<Long> contactIdList = new ArrayList<Long>();
    Long activeGroupId = mProcessor.testFetchDeleteGroupList(contactIdList);
    if (mItemCount == 1) {
        assertEquals(Long.valueOf(TEST_GROUP_2), activeGroupId);
    } else if (mItemCount == 2) {
        assertEquals(Long.valueOf(TEST_GROUP_1), activeGroupId);
    } else {
        fail("Unexpected number of groups in delete group list");
    }
    StatusMsg statusMsg = new StatusMsg();
    statusMsg.mStatus = true;
    data.add(statusMsg);
    mItemCount--;
    assertTrue(mItemCount >= 0);
    if (mItemCount == 0) {
        nextState(State.IDLE);
    }
}
Also used : StatusMsg(com.vodafone360.people.datatypes.StatusMsg) ArrayList(java.util.ArrayList)

Example 18 with BaseDataType

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

the class UploadServerContactsTest method reportBackAddGroupSuccess.

private void reportBackAddGroupSuccess(int reqId, List<BaseDataType> data) {
    Log.d(LOG_TAG, "reportBackAddGroupSuccess");
    mProcessor.verifyGroupAddsState();
    final List<Long> contactIdList = new ArrayList<Long>();
    final List<GroupItem> groupList = new ArrayList<GroupItem>();
    mProcessor.testFetchAddGroupLists(contactIdList, groupList);
    assertEquals(1, groupList.size());
    Long activeGroupId = groupList.get(0).mId;
    assertTrue(activeGroupId != null);
    ItemList itemList = new ItemList(ItemList.Type.contact_group_relations);
    data.add(itemList);
    for (Long contactServerId : contactIdList) {
        Contact expectedContact = new Contact();
        ServiceStatus status = mDb.fetchContactByServerId(contactServerId, expectedContact);
        assertEquals(ServiceStatus.SUCCESS, status);
        boolean found = false;
        for (Long groupId : expectedContact.groupList) {
            if (groupId.equals(activeGroupId)) {
                found = true;
                break;
            }
        }
        assertTrue("Contact " + contactServerId + " has been added to group " + activeGroupId + " which is not in the database", found);
        mItemCount--;
    }
    Log.i(LOG_TAG, "Groups/contacts remaining = " + mItemCount);
    assertTrue(mItemCount >= 0);
    if (mItemCount == 0) {
        nextState(State.IDLE);
    }
}
Also used : ServiceStatus(com.vodafone360.people.service.ServiceStatus) ItemList(com.vodafone360.people.datatypes.ItemList) ArrayList(java.util.ArrayList) GroupItem(com.vodafone360.people.datatypes.GroupItem) Contact(com.vodafone360.people.datatypes.Contact)

Example 19 with BaseDataType

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

the class HessianDecoderTest method testErrorResponse.

@MediumTest
public void testErrorResponse() {
    // boolean testPassed = true;
    List<BaseDataType> clist = new ArrayList<BaseDataType>();
    HessianDecoder hess = new HessianDecoder();
    try {
        DecodedResponse resp = hess.decodeHessianByteArray(6, testErrorResponse, Type.COMMON, false, EngineId.UNDEFINED);
        clist = resp.mDataTypes;
    } catch (IOException e) {
        e.printStackTrace();
        assertTrue("IOException thrown", false);
    }
    int size = clist.size();
    assertTrue(size == 1);
    assertTrue(clist.get(0) instanceof ServerError);
}
Also used : DecodedResponse(com.vodafone360.people.service.io.ResponseQueue.DecodedResponse) ServerError(com.vodafone360.people.datatypes.ServerError) ArrayList(java.util.ArrayList) HessianDecoder(com.vodafone360.people.service.utils.hessian.HessianDecoder) BaseDataType(com.vodafone360.people.datatypes.BaseDataType) IOException(java.io.IOException) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 20 with BaseDataType

use of com.vodafone360.people.datatypes.BaseDataType 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)

Aggregations

BaseDataType (com.vodafone360.people.datatypes.BaseDataType)29 ArrayList (java.util.ArrayList)25 DecodedResponse (com.vodafone360.people.service.io.ResponseQueue.DecodedResponse)21 ServiceStatus (com.vodafone360.people.service.ServiceStatus)15 ServerError (com.vodafone360.people.datatypes.ServerError)12 MediumTest (android.test.suitebuilder.annotation.MediumTest)9 Contact (com.vodafone360.people.datatypes.Contact)9 IOException (java.io.IOException)9 ContactChanges (com.vodafone360.people.datatypes.ContactChanges)8 Identity (com.vodafone360.people.datatypes.Identity)7 ResponseQueue (com.vodafone360.people.service.io.ResponseQueue)7 HessianDecoder (com.vodafone360.people.service.utils.hessian.HessianDecoder)7 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)6 ExternalResponseObject (com.vodafone360.people.datatypes.ExternalResponseObject)5 PushEvent (com.vodafone360.people.datatypes.PushEvent)5 StatusMsg (com.vodafone360.people.datatypes.StatusMsg)5 Bundle (android.os.Bundle)3 Suppress (android.test.suitebuilder.annotation.Suppress)3 ActivityItem (com.vodafone360.people.datatypes.ActivityItem)3 AuthSessionHolder (com.vodafone360.people.datatypes.AuthSessionHolder)3