Search in sources :

Example 1 with ContactDetailDeletion

use of com.vodafone360.people.datatypes.ContactDetailDeletion 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 2 with ContactDetailDeletion

use of com.vodafone360.people.datatypes.ContactDetailDeletion 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 3 with ContactDetailDeletion

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

the class UploadServerContactsTest method reportDeleteContactDetailSuccess.

private void reportDeleteContactDetailSuccess(int reqId, List<BaseDataType> data) {
    Log.d(LOG_TAG, "reportDeleteContactDetailSuccess");
    mProcessor.verifyDeleteDetailsState();
    Contact contact = new Contact();
    mProcessor.testFetchContactDetailDeleteList(contact);
    assertEquals(2, contact.details.size());
    assertEquals(ContactDetail.DetailKeys.VCARD_NAME, contact.details.get(0).key);
    assertEquals(ContactDetail.DetailKeys.VCARD_PHONE, contact.details.get(1).key);
    ContactDetailDeletion contactDetailDeletion = new ContactDetailDeletion();
    contactDetailDeletion.mServerVersionAfter = 1;
    contactDetailDeletion.mServerVersionBefore = 0;
    data.add(contactDetailDeletion);
    contactDetailDeletion.mContactId = contact.contactID.intValue();
    contactDetailDeletion.mDetails = new ArrayList<ContactDetail>();
    for (ContactDetail detail : contact.details) {
        ContactDetail tempDetail = new ContactDetail();
        tempDetail.key = detail.key;
        tempDetail.unique_id = detail.unique_id;
        contactDetailDeletion.mDetails.add(tempDetail);
    }
    mItemCount--;
    assertTrue(mItemCount >= 0);
    if (mItemCount == 0) {
        nextState(State.IDLE);
    }
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) ContactDetailDeletion(com.vodafone360.people.datatypes.ContactDetailDeletion) Contact(com.vodafone360.people.datatypes.Contact)

Example 4 with ContactDetailDeletion

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

the class NowPlusDatatypesTests method testContactDetailDeletion.

public void testContactDetailDeletion() {
    long serverVersionBefore = 1;
    long serverVersionAfter = 2;
    long contactId = 3;
    ContactDetailDeletion input = new ContactDetailDeletion();
    input.mServerVersionBefore = ((Long) serverVersionBefore).intValue();
    input.mServerVersionAfter = ((Long) serverVersionAfter).intValue();
    input.mContactId = ((Long) contactId).intValue();
    Hashtable<String, Object> hash = new Hashtable<String, Object>();
    hash.put("serverrevisionbefore", serverVersionBefore);
    hash.put("serverrevisionafter", serverVersionAfter);
    hash.put("contactid", contactId);
    ContactDetailDeletion helper = new ContactDetailDeletion();
    ContactDetailDeletion output = helper.createFromHashtable(hash);
    assertEquals(input.getType(), output.getType());
    assertEquals(input.toString(), output.toString());
    assertEquals(input.mServerVersionBefore, output.mServerVersionBefore);
    assertEquals(input.mServerVersionAfter, output.mServerVersionAfter);
    assertEquals(input.mContactId, output.mContactId);
}
Also used : ContactDetailDeletion(com.vodafone360.people.datatypes.ContactDetailDeletion) Hashtable(java.util.Hashtable)

Aggregations

ContactDetailDeletion (com.vodafone360.people.datatypes.ContactDetailDeletion)4 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)2 ContactChangeInfo (com.vodafone360.people.database.tables.ContactChangeLogTable.ContactChangeInfo)1 Contact (com.vodafone360.people.datatypes.Contact)1 ContactChanges (com.vodafone360.people.datatypes.ContactChanges)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 ServiceStatus (com.vodafone360.people.service.ServiceStatus)1 Hashtable (java.util.Hashtable)1 Vector (java.util.Vector)1