Search in sources :

Example 31 with Contact

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

the class Contacts method deleteContacts.

/**
 * Implementation of contacts/deletecontacts API. Parameters are; [auth],
 * List<Long> contactidlist
 *
 * @param engine Handle to ContactSync engine
 * @param contactidlist List of contact ids to be deleted.
 * @return request id generated for this request.
 */
public static int deleteContacts(BaseEngine engine, List<Long> contactidlist) {
    if (LoginEngine.getSession() == null) {
        LogUtils.logE("Contacts.deleteContacts() Invalid session, return -1");
        return -1;
    }
    if (contactidlist == null) {
        LogUtils.logE("Contacts.deleteContacts() contactidlist cannot be NULL");
        return -1;
    }
    Request request = new Request(FUNCTION_DELETE_CONTACTS, Request.Type.CONTACT_DELETE, engine.engineId(), false, Settings.API_REQUESTS_TIMEOUT_CONTACTS);
    request.addData("contactidlist", new Vector<Object>(contactidlist));
    QueueManager queue = QueueManager.getInstance();
    int requestId = queue.addRequest(request);
    queue.fireQueueStateChanged();
    return requestId;
}
Also used : Request(com.vodafone360.people.service.io.Request) QueueManager(com.vodafone360.people.service.io.QueueManager)

Example 32 with Contact

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

the class Contacts method getContactsChanges.

/**
 * Implementation of contacts/getcontactschanges API. Parameters are;
 * [auth], Integer pagenumber, Integer maxpagesize, Long fromrevision, Long
 * torevision
 *
 * @param engine Handle to ContactSync engine
 * @param pagenumber Page number to request contact changes for.
 * @param maxpagesize Maximum number of contacts retrieved per page.
 * @param fromrevision Starting revision number.
 * @param torevision Final revision number.
 * @param batchRequest If true, this API call will not send the request
 *            until the connection thread is kicked. This allows batching of
 *            requests.
 * @return request id generated for this request.
 */
public static int getContactsChanges(BaseEngine engine, Integer pagenumber, Integer maxpagesize, Long fromrevision, Long torevision, boolean batchRequest) {
    if (LoginEngine.getSession() == null) {
        LogUtils.logE("Contacts.getContactsChanges() Invalid session, return -1");
        return -1;
    }
    if (pagenumber == null) {
        LogUtils.logE("Contacts.getContactsChanges() pagenumber cannot be NULL");
        return -1;
    }
    if (maxpagesize == null) {
        LogUtils.logE("Contacts.getContactsChanges() maxpagesize cannot be NULL");
        return -1;
    }
    if (fromrevision == null) {
        LogUtils.logE("Contacts.getContactsChanges() fromrevision cannot be NULL");
        return -1;
    }
    if (torevision == null) {
        LogUtils.logE("Contacts.getContactsChanges() torevision cannot be NULL");
        return -1;
    }
    Request request = new Request(FUNCTION_GET_CONTACT_CHANGES, Request.Type.CONTACT_CHANGES_OR_UPDATES, engine.engineId(), false, Settings.API_REQUESTS_TIMEOUT_CONTACTS);
    request.addData("pagenumber", pagenumber);
    request.addData("maxpagesize", maxpagesize);
    request.addData("fromrevision", fromrevision);
    request.addData("torevision", torevision);
    // XXX check if this has any implications
    // request.setKickConnectionThread(!batchRequest);
    QueueManager queue = QueueManager.getInstance();
    int requestId = queue.addRequest(request);
    queue.fireQueueStateChanged();
    return requestId;
}
Also used : Request(com.vodafone360.people.service.io.Request) QueueManager(com.vodafone360.people.service.io.QueueManager)

Example 33 with Contact

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

the class Contacts method bulkUpdateContacts.

/**
 * Implementation of contacts/bulkupdatecontacts API. Parameters are;
 * [auth], List<Contact> contactlist
 *
 * @param engine Handle to ContactSync engine
 * @param contactlist List containing the contacts to be updated on server.
 * @return request id generated for this request.
 */
public static int bulkUpdateContacts(BaseEngine engine, List<Contact> contactlist) {
    if (LoginEngine.getSession() == null) {
        LogUtils.logE("Contacts.bulkUpdateContacts() Invalid session, return -1");
        return -1;
    }
    if (contactlist == null) {
        LogUtils.logE("Contacts.bulkUpdateContacts() contactidlist cannot be NULL");
        return -1;
    }
    Request request = new Request(FUNCTION_BULK_UPDATE_CONTACTS, Request.Type.CONTACT_CHANGES_OR_UPDATES, engine.engineId(), false, Settings.API_REQUESTS_TIMEOUT_CONTACTS);
    request.addData("contactlist", ApiUtils.createVectorOfContact(contactlist));
    QueueManager queue = QueueManager.getInstance();
    int requestId = queue.addRequest(request);
    queue.fireQueueStateChanged();
    return requestId;
}
Also used : Request(com.vodafone360.people.service.io.Request) QueueManager(com.vodafone360.people.service.io.QueueManager)

Example 34 with Contact

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

the class HessianDecoder method decodeResponse.

/**
 * @param is
 * @param requestId
 * @param type
 * @param isZipped
 * @param engineId
 *
 * @return
 *
 * @throws IOException
 */
@SuppressWarnings("unchecked")
private DecodedResponse decodeResponse(InputStream is, int requestId, Request.Type type, boolean isZipped, EngineId engineId) throws IOException {
    boolean usesReplyTag = false;
    int responseType = DecodedResponse.ResponseType.UNKNOWN.ordinal();
    List<BaseDataType> resultList = new ArrayList<BaseDataType>();
    mMicroHessianInput.init(is);
    // skip start
    // initial map tag or fail
    int tag = is.read();
    if (tag == 'r') {
        // reply / response
        // read major and minor
        is.read();
        is.read();
        // read next tag
        tag = is.read();
        usesReplyTag = true;
    }
    if (tag == -1) {
        return null;
    }
    // read reason string and throw exception
    if (tag == 'f') {
        ServerError zybErr = new ServerError(mMicroHessianInput.readFault().errString());
        resultList.add(zybErr);
        DecodedResponse decodedResponse = new DecodedResponse(requestId, resultList, engineId, DecodedResponse.ResponseType.SERVER_ERROR.ordinal());
        return decodedResponse;
    }
    // this is not wrapped up in a hashtable
    if (type == Request.Type.EXTERNAL_RPG_RESPONSE) {
        LogUtils.logV("HessianDecoder.decodeResponse() EXTERNAL_RPG_RESPONSE");
        if (tag != 'I') {
            LogUtils.logE("HessianDecoder.decodeResponse() " + "tag!='I' Unexpected Hessian type:" + tag);
        }
        parseExternalResponse(resultList, is, tag);
        DecodedResponse decodedResponse = new DecodedResponse(requestId, resultList, engineId, DecodedResponse.ResponseType.SERVER_ERROR.ordinal());
        return decodedResponse;
    }
    // internal response: should contain a Map type - i.e. Hashtable
    if (tag != 'M') {
        LogUtils.logE("HessianDecoder.decodeResponse() tag!='M' Unexpected Hessian type:" + tag);
        throw new IOException("Unexpected Hessian type");
    } else if (// if we have a common request or sign in request
    (type == Request.Type.COMMON) || (type == Request.Type.SIGN_IN) || (type == Request.Type.GET_MY_IDENTITIES) || (type == Request.Type.GET_AVAILABLE_IDENTITIES)) {
        Hashtable<String, Object> map = (Hashtable<String, Object>) mMicroHessianInput.readHashMap(tag);
        if (null == map) {
            return null;
        }
        if (map.containsKey(KEY_SESSION)) {
            AuthSessionHolder auth = new AuthSessionHolder();
            Hashtable<String, Object> authHash = (Hashtable<String, Object>) map.get(KEY_SESSION);
            resultList.add(auth.createFromHashtable(authHash));
            responseType = DecodedResponse.ResponseType.LOGIN_RESPONSE.ordinal();
        } else if (map.containsKey(KEY_CONTACT_LIST)) {
            // contact list
            getContacts(resultList, ((Vector<?>) map.get(KEY_CONTACT_LIST)));
            responseType = DecodedResponse.ResponseType.GET_CONTACTCHANGES_RESPONSE.ordinal();
        } else if (map.containsKey(KEY_USER_PROFILE_LIST)) {
            Vector<Hashtable<String, Object>> upVect = (Vector<Hashtable<String, Object>>) map.get(KEY_USER_PROFILE_LIST);
            for (Hashtable<String, Object> obj : upVect) {
                resultList.add(UserProfile.createFromHashtable(obj));
            }
            responseType = DecodedResponse.ResponseType.GETME_RESPONSE.ordinal();
        } else if (map.containsKey(KEY_USER_PROFILE)) {
            Hashtable<String, Object> userProfileHash = (Hashtable<String, Object>) map.get(KEY_USER_PROFILE);
            resultList.add(UserProfile.createFromHashtable(userProfileHash));
            responseType = DecodedResponse.ResponseType.GETME_RESPONSE.ordinal();
        } else if (// we have identity items in the map which we can parse
        (map.containsKey(KEY_IDENTITY_LIST)) || (map.containsKey(KEY_AVAILABLE_IDENTITY_LIST))) {
            int identityType = 0;
            Vector<Hashtable<String, Object>> idcap = null;
            if (map.containsKey(KEY_IDENTITY_LIST)) {
                idcap = (Vector<Hashtable<String, Object>>) map.get(KEY_IDENTITY_LIST);
                identityType = BaseDataType.MY_IDENTITY_DATA_TYPE;
                responseType = DecodedResponse.ResponseType.GET_MY_IDENTITIES_RESPONSE.ordinal();
            } else {
                idcap = (Vector<Hashtable<String, Object>>) map.get(KEY_AVAILABLE_IDENTITY_LIST);
                identityType = BaseDataType.AVAILABLE_IDENTITY_DATA_TYPE;
                responseType = DecodedResponse.ResponseType.GET_AVAILABLE_IDENTITIES_RESPONSE.ordinal();
            }
            for (Hashtable<String, Object> obj : idcap) {
                Identity id = new Identity(identityType);
                resultList.add(id.createFromHashtable(obj));
            }
        } else if (type == Request.Type.GET_AVAILABLE_IDENTITIES) {
            // we have an available identities response, but it is empty
            responseType = DecodedResponse.ResponseType.GET_AVAILABLE_IDENTITIES_RESPONSE.ordinal();
        } else if (type == Request.Type.GET_MY_IDENTITIES) {
            // we have a my identities response, but it is empty
            responseType = DecodedResponse.ResponseType.GET_MY_IDENTITIES_RESPONSE.ordinal();
        } else if (map.containsKey(KEY_ACTIVITY_LIST)) {
            Vector<Hashtable<String, Object>> activityList = (Vector<Hashtable<String, Object>>) map.get(KEY_ACTIVITY_LIST);
            for (Hashtable<String, Object> obj : activityList) {
                resultList.add(ActivityItem.createFromHashtable(obj));
            }
            responseType = DecodedResponse.ResponseType.GET_ACTIVITY_RESPONSE.ordinal();
        }
    } else if ((type != Request.Type.COMMON) && (type != Request.Type.SIGN_IN)) {
        // get initial hash table
        // TODO: we cast every response to a Map, losing e.g. push event
        // "c0" which only contains a string - to fix
        Hashtable<String, Object> hash = (Hashtable<String, Object>) mMicroHessianInput.decodeType(tag);
        responseType = decodeResponseByRequestType(resultList, hash, type);
    }
    if (usesReplyTag) {
        // read the last 'z'
        is.read();
    }
    DecodedResponse decodedResponse = new DecodedResponse(requestId, resultList, engineId, responseType);
    return decodedResponse;
}
Also used : DecodedResponse(com.vodafone360.people.service.io.ResponseQueue.DecodedResponse) ServerError(com.vodafone360.people.datatypes.ServerError) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) IOException(java.io.IOException) AuthSessionHolder(com.vodafone360.people.datatypes.AuthSessionHolder) BaseDataType(com.vodafone360.people.datatypes.BaseDataType) ExternalResponseObject(com.vodafone360.people.datatypes.ExternalResponseObject) Identity(com.vodafone360.people.datatypes.Identity) Vector(java.util.Vector)

Example 35 with Contact

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

Aggregations

Contact (com.vodafone360.people.datatypes.Contact)109 ServiceStatus (com.vodafone360.people.service.ServiceStatus)107 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)100 ArrayList (java.util.ArrayList)62 MediumTest (android.test.suitebuilder.annotation.MediumTest)50 Suppress (android.test.suitebuilder.annotation.Suppress)39 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)34 Cursor (android.database.Cursor)31 ContactChange (com.vodafone360.people.engine.contactsync.ContactChange)22 SmallTest (android.test.suitebuilder.annotation.SmallTest)19 ContactSummary (com.vodafone360.people.datatypes.ContactSummary)18 SQLException (android.database.SQLException)15 ContentValues (android.content.ContentValues)14 VCardHelper (com.vodafone360.people.datatypes.VCardHelper)13 Uri (android.net.Uri)11 ContactChangeInfo (com.vodafone360.people.database.tables.ContactChangeLogTable.ContactChangeInfo)11 ContactIdInfo (com.vodafone360.people.database.tables.ContactsTable.ContactIdInfo)11 ContactChanges (com.vodafone360.people.datatypes.ContactChanges)11 SQLiteException (android.database.sqlite.SQLiteException)9 ContactsTable (com.vodafone360.people.database.tables.ContactsTable)9