Search in sources :

Example 1 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 2 with ContactChanges

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

the class DownloadServerContactsTest method reportBackWithModifiedContacts.

private void reportBackWithModifiedContacts(int reqId, List<BaseDataType> data) {
    Log.d(LOG_TAG, "reportBackWithModifiedContacts");
    Integer pageNo = mProcessor.testGetPageFromReqId(reqId);
    int pageSize = mProcessor.getDownloadPageSize();
    assertTrue(pageNo != null);
    assertEquals(Integer.valueOf(mPageCount), 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;
    assertTrue(pageSize > 0);
    if (pageSize > 0) {
        contactChanges.mNumberOfPages = 1 + mPageCount + (mItemCount / pageSize);
    }
    int noOfContacts = Math.min(pageSize, mItemCount);
    for (int i = 0; i < noOfContacts; i++) {
        Contact modifiedContact = new Contact();
        modifiedContact.contactID = FIRST_MODIFIED_CONTACT_ID + mItemCount - 1;
        // Modified details
        ContactDetail detail1 = new ContactDetail();
        detail1.key = ContactDetail.DetailKeys.VCARD_NICKNAME;
        detail1.value = generateModifiedString(MODIFIED_NICKNAME_STRING, mItemCount - 1);
        modifiedContact.details.add(detail1);
        ContactDetail detail2 = new ContactDetail();
        detail2.key = ContactDetail.DetailKeys.VCARD_PHONE;
        detail2.keyType = MODIFIED_PHONE_TYPE;
        detail2.order = MODIFIED_PHONE_ORDER;
        detail2.value = generateModifiedString(MODIFIED_PHONE_STRING, mItemCount - 1);
        detail2.unique_id = OLD_PHONE_DETAIL_ID + mItemCount - 1;
        modifiedContact.details.add(detail2);
        // New details
        ContactDetail detail3 = new ContactDetail();
        detail3.key = ContactDetail.DetailKeys.VCARD_PHONE;
        detail3.keyType = NEW_PHONE_TYPE;
        detail3.order = NEW_PHONE_ORDER;
        detail3.value = generateModifiedString(NEW_PHONE_STRING, mItemCount - 1);
        detail3.unique_id = NEW_PHONE_DETAIL_ID + mItemCount - 1;
        modifiedContact.details.add(detail3);
        ContactDetail detail4 = new ContactDetail();
        detail4.key = ContactDetail.DetailKeys.VCARD_EMAIL;
        detail4.keyType = NEW_EMAIL_TYPE;
        detail4.order = NEW_EMAIL_ORDER;
        detail4.value = generateModifiedString(NEW_EMAIL_STRING, mItemCount - 1);
        detail4.unique_id = NEW_EMAIL_DETAIL_ID + mItemCount - 1;
        modifiedContact.details.add(detail4);
        Log.d(LOG_TAG, "Contact " + modifiedContact.contactID + " has details " + detail1.unique_id + ", " + detail2.unique_id + ", " + detail3.unique_id + ", " + detail4.unique_id);
        contactChanges.mContacts.add(modifiedContact);
        mItemCount--;
    }
    mPageCount++;
    assertTrue(mItemCount >= 0);
    if (mItemCount == 0) {
        nextState(State.IDLE);
    }
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) ContactChanges(com.vodafone360.people.datatypes.ContactChanges) Contact(com.vodafone360.people.datatypes.Contact)

Example 3 with ContactChanges

use of com.vodafone360.people.datatypes.ContactChanges 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 4 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 5 with ContactChanges

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

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