Search in sources :

Example 1 with IdentityEngine

use of com.vodafone360.people.engine.identities.IdentityEngine in project 360-Engine-for-Android by 360.

the class IdentityEngine method handleGetMyIdentitiesResponse.

/**
     * Handle Server response to request for available Identities. The response
     * should be a list of Identity items. The request is completed with
     * ServiceStatus.SUCCESS or ERROR_UNEXPECTED_RESPONSE if the data-type
     * retrieved are not Identity items.
     * 
     * @param data List of BaseDataTypes generated from Server response.
     */
private void handleGetMyIdentitiesResponse(List<BaseDataType> data) {
    LogUtils.logD("IdentityEngine: handleGetMyIdentitiesResponse");
    ServiceStatus errorStatus = getResponseStatus(BaseDataType.MY_IDENTITY_DATA_TYPE, data);
    if (errorStatus == ServiceStatus.SUCCESS) {
        synchronized (mMyIdentityList) {
            mMyIdentityList.clear();
            for (BaseDataType item : data) {
                Identity identity = (Identity) item;
                if (!identity.isIdentityFieldBlankorNull()) {
                    mMyIdentityList.add(identity);
                }
            }
            // cache the identities
            MyIdentitiesCacheTable.setCachedIdentities(mDatabaseHelper.getWritableDatabase(), mMyIdentityList);
            clearPendingIdentities();
        }
    } else if (errorStatus == ServiceStatus.ERROR_COMMS_TIMEOUT) {
        // reset the pending list in case of a timeout
        clearPendingIdentities();
    }
    pushIdentitiesToUi(ServiceUiRequest.GET_MY_IDENTITIES);
    // remove any identites returned from the pending list as they are validated by now! 
    removePendingIdentities(mMyIdentityList);
    LogUtils.logD("IdentityEngine: handleGetMyIdentitiesResponse complete request.");
}
Also used : ServiceStatus(com.vodafone360.people.service.ServiceStatus) BaseDataType(com.vodafone360.people.datatypes.BaseDataType) Identity(com.vodafone360.people.datatypes.Identity)

Example 2 with IdentityEngine

use of com.vodafone360.people.engine.identities.IdentityEngine in project 360-Engine-for-Android by 360.

the class IdentityEngine method processCommsResponse.

/**
     * Process a response received from Server. The response is handled
     * according to the current IdentityEngine state.
     * 
     * @param resp The decoded response.
     */
@Override
protected void processCommsResponse(DecodedResponse resp) {
    LogUtils.logD("IdentityEngine.processCommsResponse() - resp = " + resp);
    if ((null == resp) || (null == resp.mDataTypes)) {
        LogUtils.logE("Response objects or its contents were null. Aborting...");
        return;
    }
    // TODO replace this whole block with the response type in the DecodedResponse class in the future!
    if (resp.mReqId == 0 && resp.mDataTypes.size() > 0) {
        // push msg
        PushEvent evt = (PushEvent) resp.mDataTypes.get(0);
        handlePushResponse(evt.mMessageType);
    } else if (resp.mDataTypes.size() > 0) {
        // regular response
        switch(resp.mDataTypes.get(0).getType()) {
            case BaseDataType.MY_IDENTITY_DATA_TYPE:
                handleGetMyIdentitiesResponse(resp.mDataTypes);
                break;
            case BaseDataType.AVAILABLE_IDENTITY_DATA_TYPE:
                handleGetAvailableIdentitiesResponse(resp.mDataTypes);
                break;
            case BaseDataType.IDENTITY_CAPABILITY_DATA_TYPE:
                handleSetIdentityStatus(resp.mDataTypes);
                break;
            case BaseDataType.STATUS_MSG_DATA_TYPE:
                handleValidateIdentityCredentials(resp.mDataTypes);
                break;
            case BaseDataType.IDENTITY_DELETION_DATA_TYPE:
                handleDeleteIdentity(resp.mDataTypes);
                break;
            default:
                LogUtils.logW("IdentityEngine.processCommsResponse DEFAULT should never happened.");
                break;
        }
    } else {
        // responses data list is 0, that means e.g. no identities in an identities response
        LogUtils.logW("IdentityEngine.processCommsResponse List was empty!");
        if (resp.getResponseType() == DecodedResponse.ResponseType.GET_MY_IDENTITIES_RESPONSE.ordinal()) {
            pushIdentitiesToUi(ServiceUiRequest.GET_MY_IDENTITIES);
        } else if (resp.getResponseType() == DecodedResponse.ResponseType.GET_AVAILABLE_IDENTITIES_RESPONSE.ordinal()) {
            pushIdentitiesToUi(ServiceUiRequest.GET_AVAILABLE_IDENTITIES);
        }
    }
// end: replace this whole block with the response type in the DecodedResponse class in the future!
}
Also used : PushEvent(com.vodafone360.people.datatypes.PushEvent)

Example 3 with IdentityEngine

use of com.vodafone360.people.engine.identities.IdentityEngine in project 360-Engine-for-Android by 360.

the class EngineManager method createIdentityEngine.

/**
     * Create instance of IdentityEngine.
     */
private synchronized void createIdentityEngine() {
    final MainApplication app = (MainApplication) mService.getApplication();
    mIdentityEngine = new IdentityEngine(mUiEventCallback, app.getDatabase());
    ConnectionManager.getInstance().addConnectionListener(mIdentityEngine);
    addEngine(mIdentityEngine);
}
Also used : IdentityEngine(com.vodafone360.people.engine.identities.IdentityEngine) MainApplication(com.vodafone360.people.MainApplication)

Example 4 with IdentityEngine

use of com.vodafone360.people.engine.identities.IdentityEngine in project 360-Engine-for-Android by 360.

the class IdentityEngine method handleGetAvailableIdentitiesResponse.

/**
     * Handle Server response to request for available Identities. The response
     * should be a list of Identity items. The request is completed with
     * ServiceStatus.SUCCESS or ERROR_UNEXPECTED_RESPONSE if the data-type
     * retrieved are not Identity items.
     * 
     * @param data List of BaseDataTypes generated from Server response.
     */
private void handleGetAvailableIdentitiesResponse(List<BaseDataType> data) {
    LogUtils.logD("IdentityEngine: handleServerGetAvailableIdentitiesResponse");
    ServiceStatus errorStatus = getResponseStatus(BaseDataType.AVAILABLE_IDENTITY_DATA_TYPE, data);
    if (errorStatus == ServiceStatus.SUCCESS) {
        synchronized (mAvailableIdentityList) {
            mAvailableIdentityList.clear();
            for (BaseDataType item : data) {
                Identity identity = (Identity) item;
                if (!identity.isIdentityFieldBlankorNull()) {
                    mAvailableIdentityList.add(identity);
                }
            }
        }
    }
    pushIdentitiesToUi(ServiceUiRequest.GET_AVAILABLE_IDENTITIES);
    LogUtils.logD("IdentityEngine: handleGetAvailableIdentitiesResponse complete request.");
}
Also used : ServiceStatus(com.vodafone360.people.service.ServiceStatus) BaseDataType(com.vodafone360.people.datatypes.BaseDataType) Identity(com.vodafone360.people.datatypes.Identity)

Example 5 with IdentityEngine

use of com.vodafone360.people.engine.identities.IdentityEngine in project 360-Engine-for-Android by 360.

the class IdentityEngineTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    mApplication = (MainApplication) Instrumentation.newApplication(MainApplication.class, getInstrumentation().getTargetContext());
    mApplication.onCreate();
    mEngineTester = new EngineTestFramework(this);
    mEng = new IdentityEngine(mEngineTester, mApplication.getDatabase());
    mEngineTester.setEngine(mEng);
    mState = IdentityTestState.IDLE;
}
Also used : IdentityEngine(com.vodafone360.people.engine.identities.IdentityEngine)

Aggregations

BaseDataType (com.vodafone360.people.datatypes.BaseDataType)2 Identity (com.vodafone360.people.datatypes.Identity)2 IdentityEngine (com.vodafone360.people.engine.identities.IdentityEngine)2 ServiceStatus (com.vodafone360.people.service.ServiceStatus)2 MainApplication (com.vodafone360.people.MainApplication)1 PushEvent (com.vodafone360.people.datatypes.PushEvent)1