Search in sources :

Example 1 with Identity

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

the class PresenceDbUtils method processMeProfile.

/**
 * This method alters the User wrapper of me profile,
 *  and returns true if me profile information contains the ignored TPC networks information.
 * Based on the result this information may be deleted.
 * @param removePCPresence - if TRUE the PC network will be removed from the network list.
 * @param user - the me profile wrapper.
 * @param ignoredNetworks - the list if ignored integer network ids.
 * @return
 */
private static boolean processMeProfile(boolean removePCPresence, User user, ArrayList<Integer> ignoredNetworks) {
    if (removePCPresence) {
        int max = OnlineStatus.OFFLINE.ordinal();
        // calculate the new aggregated presence status
        for (NetworkPresence presence : user.getPayload()) {
            if (presence.getOnlineStatusId() > max) {
                max = presence.getOnlineStatusId();
            }
        }
        user.setOverallOnline(max);
    }
    // the list of chat network ids in this User wrapper
    ArrayList<Integer> userNetworks = new ArrayList<Integer>();
    ArrayList<NetworkPresence> payload = user.getPayload();
    for (NetworkPresence presence : payload) {
        int networkId = presence.getNetworkId();
        userNetworks.add(networkId);
        // 1. ignore offline TPC networks
        if (presence.getOnlineStatusId() == OnlineStatus.OFFLINE.ordinal()) {
            ignoredNetworks.add(networkId);
        }
    }
    // 2. ignore the TPC networks presence state for which is unknown
    ArrayList<Identity> identities = EngineManager.getInstance().getIdentityEngine().getMyChattableIdentities();
    SocialNetwork network = null;
    for (Identity identity : identities) {
        network = SocialNetwork.getValue(identity.mNetwork);
        if (network != null) {
            if (!userNetworks.contains(network.ordinal())) {
                ignoredNetworks.add(network.ordinal());
            }
        }
    }
    return !ignoredNetworks.isEmpty();
}
Also used : ArrayList(java.util.ArrayList) SocialNetwork(com.vodafone360.people.engine.presence.NetworkPresence.SocialNetwork) Identity(com.vodafone360.people.datatypes.Identity)

Example 2 with Identity

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

the class Identities method setIdentityStatus.

/**
 * @param engine
 * @param network
 * @param identityid
 * @param identityStatus
 * @return
 */
public static int setIdentityStatus(BaseEngine engine, String network, String identityid, String identityStatus) {
    if (LoginEngine.getSession() == null) {
        LogUtils.logE("Identities.setIdentityStatus() Invalid session, return -1");
        return -1;
    }
    if (identityid == null) {
        LogUtils.logE("Identities.setIdentityStatus() identityid cannot be NULL");
        return -1;
    }
    if (network == null) {
        LogUtils.logE("Identities.setIdentityStatus() network cannot be NULL");
        return -1;
    }
    if (identityStatus == null) {
        LogUtils.logE("Identities.setIdentityStatus() identity status cannot be NULL");
        return -1;
    }
    Request request = new Request(FUNCTION_SET_IDENTITY_STATUS, Request.Type.EXPECTING_STATUS_ONLY, engine.engineId(), false, Settings.API_REQUESTS_TIMEOUT_IDENTITIES);
    request.addData("network", network);
    request.addData("identityid", identityid);
    request.addData("status", identityStatus);
    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 3 with Identity

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

the class Identities method validateIdentityCredentials.

/**
 * Implementation of identities/validateidentitycredentials API. Parameters
 * are; [auth], Boolean dryrun [opt], String network [opt], String username,
 * String password, String server [opt], String contactdetail [opt], Map
 * identitycapabilitystatus [opt]
 *
 * @param engine handle to IdentitiesEngine
 * @param dryrun Whether this is a dry-run request.
 * @param network Name of network.
 * @param username User-name.
 * @param password Password.
 * @param server
 * @param contactdetail
 * @param identitycapabilitystatus Capabilities for this identity/network.
 * @return request id generated for this request
 */
public static int validateIdentityCredentials(BaseEngine engine, Boolean dryrun, String network, String username, String password, String server, String contactdetail, Map<String, Boolean> identitycapabilitystatus) {
    if (LoginEngine.getSession() == null) {
        LogUtils.logE("Identities.validateIdentityCredentials() Invalid session, return -1");
        return -1;
    }
    if (network == null) {
        LogUtils.logE("Identities.validateIdentityCredentials() network cannot be NULL");
        return -1;
    }
    if (username == null) {
        LogUtils.logE("Identities.validateIdentityCredentials() username cannot be NULL");
        return -1;
    }
    if (password == null) {
        LogUtils.logE("Identities.validateIdentityCredentials() password cannot be NULL");
        return -1;
    }
    Request request = new Request(FUNCTION_VALIDATE_IDENTITY_CREDENTIALS, Request.Type.EXPECTING_STATUS_ONLY, engine.engineId(), false, Settings.API_REQUESTS_TIMEOUT_IDENTITIES);
    if (dryrun != null) {
        request.addData("dryrun", dryrun);
    }
    request.addData("network", network);
    request.addData("username", username);
    request.addData("password", password);
    if (server != null) {
        request.addData("server", server);
    }
    if (contactdetail != null) {
        request.addData("contactdetail", contactdetail);
    }
    if (identitycapabilitystatus != null) {
        request.addData("identitycapabilitystatus", new Hashtable<String, Object>(identitycapabilitystatus));
    }
    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 4 with Identity

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

the class ActivitiesEngineTest method reportBackToEngine.

@Override
public void reportBackToEngine(int reqId, EngineId engine) {
    Log.d("TAG", "IdentityEngineTest.reportBackToEngine");
    ResponseQueue respQueue = ResponseQueue.getInstance();
    List<BaseDataType> data = new ArrayList<BaseDataType>();
    switch(mState) {
        case IDLE:
            break;
        case ON_CREATE:
        case ON_DESTROY:
            break;
        case GET_ACTIVITIES_SUCCESS:
            ActivityItem item = new ActivityItem();
            data.add(item);
            respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.GET_ACTIVITY_RESPONSE.ordinal()));
            mEng.onCommsInMessage();
            break;
        case GET_TIMELINE_EVENT_FROM_SERVER:
            ActivityItem item2 = new ActivityItem();
            ActivityContact act = new ActivityContact();
            act.mName = "Bill Fleege";
            act.mLocalContactId = new Long(8);
            List<ActivityContact> clist = new ArrayList<ActivityContact>();
            clist.add(act);
            item2.contactList = clist;
            item2.activityFlags = 2;
            item2.type = ActivityItem.Type.CONTACT_JOINED;
            item2.time = System.currentTimeMillis();
            data.add(item2);
            respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.GET_ACTIVITY_RESPONSE.ordinal()));
            mEng.onCommsInMessage();
            break;
        case GET_POPULATED_ACTIVITIES:
            ActivityItem item3 = new ActivityItem();
            ActivityContact act2 = new ActivityContact();
            act2.mName = "Bill Fleege";
            act2.mLocalContactId = new Long(8);
            List<ActivityContact> clist2 = new ArrayList<ActivityContact>();
            clist2.add(act2);
            item3.contactList = clist2;
            item3.activityFlags = 2;
            item3.type = ActivityItem.Type.CONTACT_JOINED;
            item3.time = System.currentTimeMillis();
            item3.title = "bills new status";
            item3.description = "a description";
            data.add(item3);
            ActivityItem item4 = new ActivityItem();
            item4.contactList = clist2;
            item4.activityFlags = 5;
            item4.type = ActivityItem.Type.CONTACT_JOINED;
            item4.time = System.currentTimeMillis();
            item4.title = "bills new status";
            item4.description = "a description";
            item4.activityId = new Long(23);
            item4.hasChildren = false;
            item4.uri = "uri";
            item4.parentActivity = new Long(0);
            item4.preview = ByteBuffer.allocate(46);
            item4.preview.position(0);
            item4.preview.rewind();
            for (int i = 0; i < 23; i++) {
                item4.preview.putChar((char) i);
            }
            item4.previewMime = "jepg";
            item4.previewUrl = "storeurl";
            item4.store = "google";
            item4.visibilityFlags = 0;
            data.add(item4);
            respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.GET_ACTIVITY_RESPONSE.ordinal()));
            mEng.onCommsInMessage();
            break;
        case GET_ACTIVITIES_SERVER_ERR:
            ServerError err = new ServerError("Catastrophe");
            err.errorDescription = "Fail";
            data.add(err);
            respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.SERVER_ERROR.ordinal()));
            mEng.onCommsInMessage();
            break;
        case GET_ACTIVITIES_UNEXPECTED_RESPONSE:
            StatusMsg msg = new StatusMsg();
            msg.mCode = "ok";
            msg.mDryRun = false;
            msg.mStatus = true;
            data.add(msg);
            respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.LOGIN_RESPONSE.ordinal()));
            mEng.onCommsInMessage();
            break;
        case SET_STATUS:
            Identity id3 = new Identity();
            data.add(id3);
            respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.GET_AVAILABLE_IDENTITIES_RESPONSE.ordinal()));
            mEng.onCommsInMessage();
            break;
        case ON_SYNC_COMPLETE:
            ServerError err2 = new ServerError("Catastrophe");
            err2.errorDescription = "Fail";
            data.add(err2);
            respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.SERVER_ERROR.ordinal()));
            mEng.onCommsInMessage();
            break;
        case GET_NEXT_RUNTIME:
            break;
        default:
    }
}
Also used : DecodedResponse(com.vodafone360.people.service.io.ResponseQueue.DecodedResponse) StatusMsg(com.vodafone360.people.datatypes.StatusMsg) ServerError(com.vodafone360.people.datatypes.ServerError) ArrayList(java.util.ArrayList) ActivityContact(com.vodafone360.people.datatypes.ActivityContact) BaseDataType(com.vodafone360.people.datatypes.BaseDataType) ResponseQueue(com.vodafone360.people.service.io.ResponseQueue) Identity(com.vodafone360.people.datatypes.Identity) ActivityItem(com.vodafone360.people.datatypes.ActivityItem)

Example 5 with Identity

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

Aggregations

Identity (com.vodafone360.people.datatypes.Identity)17 BaseDataType (com.vodafone360.people.datatypes.BaseDataType)7 ServiceStatus (com.vodafone360.people.service.ServiceStatus)6 ArrayList (java.util.ArrayList)6 Bundle (android.os.Bundle)5 MediumTest (android.test.suitebuilder.annotation.MediumTest)4 DecodedResponse (com.vodafone360.people.service.io.ResponseQueue.DecodedResponse)4 Hashtable (java.util.Hashtable)4 Suppress (android.test.suitebuilder.annotation.Suppress)3 IdentityCapability (com.vodafone360.people.datatypes.IdentityCapability)3 ServerError (com.vodafone360.people.datatypes.ServerError)3 StatusMsg (com.vodafone360.people.datatypes.StatusMsg)3 QueueManager (com.vodafone360.people.service.io.QueueManager)3 Request (com.vodafone360.people.service.io.Request)3 ResponseQueue (com.vodafone360.people.service.io.ResponseQueue)2 IOException (java.io.IOException)2 URL (java.net.URL)2 ContentValues (android.content.ContentValues)1 Cursor (android.database.Cursor)1 ActivityContact (com.vodafone360.people.datatypes.ActivityContact)1