Search in sources :

Example 1 with IdentityCapability

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

the class MyIdentitiesCacheTable method getContentValues.

/**
 * Populates the provided ContentValues object with the Identity data.
 *
 * Note: the ContentValues object is first cleared before being filled.
 *
 * @param values the ContentValues object to populate
 * @param identity the identity to extract the data from
 * @return the provided ContentValues object
 */
private static ContentValues getContentValues(ContentValues values, Identity identity) {
    int capabilities = FLAG_CAPABILITY_NONE;
    values.clear();
    values.put(Fields.NAME.toString(), identity.mName);
    values.put(Fields.USER_NAME.toString(), identity.mUserName);
    values.put(Fields.NETWORK_ID.toString(), identity.mNetwork);
    if (identity.mCapabilities != null) {
        for (IdentityCapability cap : identity.mCapabilities) {
            if (cap.mCapability != null) {
                switch(cap.mCapability) {
                    case chat:
                        if (cap.mValue)
                            capabilities |= FLAG_CAPABILITY_CHAT;
                        break;
                    case mail:
                        if (cap.mValue)
                            capabilities |= FLAG_CAPABILITY_MAIL;
                        break;
                }
            }
        }
    }
    values.put(Fields.CAPABILITIES.toString(), capabilities);
    return values;
}
Also used : IdentityCapability(com.vodafone360.people.datatypes.IdentityCapability)

Example 2 with IdentityCapability

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

the class MyIdentitiesCacheTable method getCapabilities.

/**
 * Gets an array of IdentityCapability from capability flags.
 *
 * @param capabilities the capability flags
 * @return an array of IdentityCapability
 */
private static ArrayList<IdentityCapability> getCapabilities(int capabilities) {
    ArrayList<IdentityCapability> capabilitiesList = null;
    if (capabilities != FLAG_CAPABILITY_NONE) {
        IdentityCapability cap;
        capabilitiesList = new ArrayList<IdentityCapability>();
        if ((capabilities & FLAG_CAPABILITY_CHAT) == FLAG_CAPABILITY_CHAT) {
            cap = new IdentityCapability();
            cap.mCapability = CapabilityID.chat;
            cap.mValue = true;
            capabilitiesList.add(cap);
        }
        if ((capabilities & FLAG_CAPABILITY_MAIL) == FLAG_CAPABILITY_MAIL) {
            cap = new IdentityCapability();
            cap.mCapability = CapabilityID.chat;
            cap.mValue = true;
            capabilitiesList.add(cap);
        }
    }
    return capabilitiesList;
}
Also used : IdentityCapability(com.vodafone360.people.datatypes.IdentityCapability)

Example 3 with IdentityCapability

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

the class NowPlusDatatypesTests method testIdentityCapability.

public void testIdentityCapability() {
    IdentityCapability input = new IdentityCapability();
    input.mCapability = CapabilityID.share_media;
    input.mDescription = "des";
    input.mName = "name";
    input.mValue = true;
    Hashtable<String, Object> hash = new Hashtable<String, Object>();
    hash.put("capabilityid", input.mCapability.name());
    hash.put("description", input.mDescription);
    hash.put("name", input.mName);
    hash.put("value", input.mValue);
    IdentityCapability helper = new IdentityCapability();
    IdentityCapability output = helper.createFromHashtable(hash);
    assertEquals(input.getType(), output.getType());
    assertEquals(input.toString(), output.toString());
    assertEquals(input.describeContents(), output.describeContents());
    assertEquals(input.mCapability, output.mCapability);
    assertEquals(input.mDescription, output.mDescription);
    assertEquals(input.mName, output.mName);
    assertEquals(input.mValue, output.mValue);
}
Also used : Hashtable(java.util.Hashtable) IdentityCapability(com.vodafone360.people.datatypes.IdentityCapability)

Example 4 with IdentityCapability

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

the class IdentityEngineTest 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 FETCH_IDENTITIES:
            Log.d("TAG", "IdentityEngineTest.reportBackToEngine FETCH ids");
            Identity id = new Identity();
            data.add(id);
            respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.GET_AVAILABLE_IDENTITIES_RESPONSE.ordinal()));
            Log.d("TAG", "IdentityEngineTest.reportBackToEngine add to Q");
            mEng.onCommsInMessage();
            break;
        case GET_MY_IDENTITIES:
            Log.d("TAG", "IdentityEngineTest.reportBackToEngine Get ids");
            Identity myId = new Identity();
            data.add(myId);
            respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.GET_AVAILABLE_IDENTITIES_RESPONSE.ordinal()));
            Log.d("TAG", "IdentityEngineTest.reportBackToEngine add to Q");
            mEng.onCommsInMessage();
            break;
        case FETCH_IDENTITIES_FAIL:
            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 SET_IDENTITY_CAPABILTY:
            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.SET_IDENTITY_CAPABILITY_RESPONSE.ordinal()));
            mEng.onCommsInMessage();
            break;
        case VALIDATE_ID_CREDENTIALS_SUCCESS:
            StatusMsg msg2 = new StatusMsg();
            msg2.mCode = "ok";
            msg2.mDryRun = false;
            msg2.mStatus = true;
            data.add(msg2);
            respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.VALIDATE_IDENTITY_CREDENTIALS_RESPONSE.ordinal()));
            mEng.onCommsInMessage();
            break;
        case VALIDATE_ID_CREDENTIALS_FAIL:
            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;
        case GET_CHATABLE_IDENTITIES:
        case FETCH_IDENTITIES_POPULATED:
            Identity id2 = new Identity();
            id2.mActive = true;
            id2.mAuthType = "auth";
            List<String> clist = new ArrayList<String>();
            clist.add("uk");
            clist.add("fr");
            id2.mCountryList = clist;
            id2.mCreated = new Long(0);
            id2.mDisplayName = "Facebook";
            // id2.mIcon2Mime = "jpeg";
            id2.mIconMime = "jpeg";
            try {
                id2.mIcon2Url = new URL("url2");
                id2.mIconUrl = new URL("url");
                id2.mNetworkUrl = new URL("network");
            } catch (Exception e) {
            }
            id2.mIdentityId = "fb";
            id2.mIdentityType = "type";
            id2.mName = "Facebook";
            id2.mNetwork = "Facebook";
            id2.mOrder = 0;
            id2.mPluginId = "";
            id2.mUpdated = new Long(0);
            id2.mUserId = 23;
            id2.mUserName = "user";
            data.add(id2);
            List<IdentityCapability> capList = new ArrayList<IdentityCapability>();
            IdentityCapability idcap = new IdentityCapability();
            idcap.mCapability = IdentityCapability.CapabilityID.sync_contacts;
            idcap.mDescription = "sync cont";
            idcap.mName = "sync cont";
            idcap.mValue = true;
            capList.add(idcap);
            id2.mCapabilities = capList;
            data.add(id2);
            respQueue.addToResponseQueue(new DecodedResponse(reqId, data, engine, DecodedResponse.ResponseType.GET_AVAILABLE_IDENTITIES_RESPONSE.ordinal()));
            Log.d("TAG", "IdentityEngineTest.reportBackToEngine add to Q");
            mEng.onCommsInMessage();
            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) URL(java.net.URL) IdentityCapability(com.vodafone360.people.datatypes.IdentityCapability) BaseDataType(com.vodafone360.people.datatypes.BaseDataType) ResponseQueue(com.vodafone360.people.service.io.ResponseQueue) Identity(com.vodafone360.people.datatypes.Identity)

Example 5 with IdentityCapability

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

the class IdentityEngine method getMyChattableIdentities.

/**
 * Takes all third party identities that have a chat capability set to true.
 *
 * @return A list of chattable 3rd party identities the user is signed in to. If the retrieval identities failed the returned list will be empty.
 */
public ArrayList<Identity> getMyChattableIdentities() {
    final ArrayList<Identity> chattableIdentities = new ArrayList<Identity>();
    final ArrayList<Identity> myIdentityList;
    final int identityListSize;
    synchronized (mMyIdentityList) {
        // make a shallow copy
        myIdentityList = new ArrayList<Identity>(mMyIdentityList);
    }
    identityListSize = myIdentityList.size();
    // list if it does
    for (int i = 0; i < identityListSize; i++) {
        Identity identity = myIdentityList.get(i);
        List<IdentityCapability> capabilities = identity.mCapabilities;
        if (null == capabilities) {
            // if the capabilties are null skip to next identity
            continue;
        }
        // run through capabilties and check for chat
        for (int j = 0; j < capabilities.size(); j++) {
            IdentityCapability capability = capabilities.get(j);
            if (null == capability) {
                // skip null capabilities
                continue;
            }
            if ((capability.mCapability == IdentityCapability.CapabilityID.chat) && (capability.mValue)) {
                chattableIdentities.add(identity);
                break;
            }
        }
    }
    return chattableIdentities;
}
Also used : ArrayList(java.util.ArrayList) Identity(com.vodafone360.people.datatypes.Identity) IdentityCapability(com.vodafone360.people.datatypes.IdentityCapability)

Aggregations

IdentityCapability (com.vodafone360.people.datatypes.IdentityCapability)5 Identity (com.vodafone360.people.datatypes.Identity)2 ArrayList (java.util.ArrayList)2 BaseDataType (com.vodafone360.people.datatypes.BaseDataType)1 ServerError (com.vodafone360.people.datatypes.ServerError)1 StatusMsg (com.vodafone360.people.datatypes.StatusMsg)1 ResponseQueue (com.vodafone360.people.service.io.ResponseQueue)1 DecodedResponse (com.vodafone360.people.service.io.ResponseQueue.DecodedResponse)1 URL (java.net.URL)1 Hashtable (java.util.Hashtable)1