com.vodafone360.people.engine.identities
Class IdentityEngine

java.lang.Object
  extended by com.vodafone360.people.engine.BaseEngine
      extended by com.vodafone360.people.engine.identities.IdentityEngine

public class IdentityEngine
extends BaseEngine

Engine responsible for handling retrieval and validation of Identities (e.g. 3rd party/web accounts). The Identities engine can fetch a list of available accounts, and set required capabilities and validate credentials for specified accounts.


Nested Class Summary
private static class IdentityEngine.IdentityStatusRequest
          Container class for Identity Capability Status request.
private static class IdentityEngine.IdentityValidateCredentialsRequest
          Container class encapsulating an Identity validation request containing: dry-run flag, network, user-name, password, set of required capabilities.
private static class IdentityEngine.State
          States for IdentitiesEngine.
 
Nested classes/interfaces inherited from class com.vodafone360.people.engine.BaseEngine
BaseEngine.IEngineEventCallback
 
Field Summary
static java.lang.String KEY_DATA
           
private static java.lang.String KEY_DATA_CHATABLE_IDENTITIES
           
private static java.lang.String LOG_STATUS_MSG
           
private  java.util.ArrayList<Identity> mIdentityList
          List array of Identities retrieved from Server.
private  java.lang.Object mMutex
          Mutex for thread synchronisation
private  java.util.ArrayList<java.lang.String> mMyChatableIdentityList
          List array of Identities supporting chat retrieved from Server.
private  IdentityEngine.State mState
           
private  java.util.ArrayList<StatusMsg> mStatusList
           
private static java.lang.String TYPE_IDENTITY
          Definitions for expected data-types returned from Server.
private static java.lang.String TYPE_STATUS_MSG
           
 
Fields inherited from class com.vodafone360.people.engine.BaseEngine
mActiveUiRequest, mCurrentTimeout, mEngineId, mEventCallback
 
Constructor Summary
IdentityEngine(BaseEngine.IEngineEventCallback eventCallback)
          Constructor
 
Method Summary
 void addUiFetchIdentities(Bundle filter)
          Add request to fetch available identities.
 void addUiGetMyIdentities(Bundle filter)
          Add request to fetch the current user's identities.
 void addUiSetIdentityStatus(java.lang.String network, java.lang.String identityId, boolean identityStatus)
          Add request to set the capabilities we wish to support for the specified identity (such as support sync of contacts, receipt of status updates, chat etc.)
 void addUiValidateIdentityCredentials(boolean dryRun, java.lang.String network, java.lang.String username, java.lang.String password, Bundle identityCapabilityStatus)
          Add request to validate user credentials for a specified identity.
private  boolean checkConnectivity()
          Get Connectivity status from NetworkAgent.
 void getMyChatableIdentities()
          Add request to fetch the current user's 'chat-able' identities.
 long getNextRunTime()
          Return the next run-time for the IdentitiesEngine.
private  void handleServerGetAvailableIdentitiesResponse(java.util.List<BaseDataType> data)
          Handle Server response to request for available Identities.
private  void handleSetIdentityCapabilityStatus(java.util.List<BaseDataType> data)
          Handle Server response to set capability status request.
private  void handleValidateIdentityCredentials(java.util.List<BaseDataType> data)
          Handle Server response to set validate credentials request.
private  void makeChatableIdentitiesCache(java.util.List<Identity> list)
          Create cache of 'chat-able' identities.
private  void newState(IdentityEngine.State newState)
          Change current IdentityEngine state.
 void onCreate()
          This will be called immediately after creation.
 void onDestroy()
          This will be called just before the engine is shutdown.
protected  void onRequestComplete()
          This function must be implemented in the derived engine implementation.
protected  void onTimeoutEvent()
          The derived engine implementation must call the processTimeout() function (normally from within the run() implementation), otherwise this will not be called.
private static java.util.Map<java.lang.String,java.lang.Object> prepareBoolFilter(Bundle filter)
          Generate Map containing boolean capability filters for supplied Bundle.
private static java.util.Map<java.lang.String,java.util.List<java.lang.String>> prepareStringFilter(Bundle filter)
          Generate Map containing String capability filters for m supplied Bundle.
protected  void processCommsResponse(ResponseQueue.Response resp)
          Process a response received from Server.
protected  void processUiRequest(ServiceUiRequest requestType, java.lang.Object data)
          Issue any outstanding UI request.
 void run()
          Run function called via EngineManager.
private  void startFetchIdentities(java.lang.Object data)
          Issue request to retrieve available Identities.
private  void startGetMyChatableIdentities()
          Issue request to retrieve 'My chat-able' Identities.
private  void startGetMyIdentities(java.lang.Object data)
          Issue request to retrieve 'My' Identities.
private  void startSetIdentityStatus(java.lang.Object data)
          Issue request to set capabilities for a given Identity.
private  void startValidateIdentityCredentials(java.lang.Object data)
          Issue request to validate the user credentials for an Identity.
 
Methods inherited from class com.vodafone360.people.engine.BaseEngine
addUiRequestToQueue, clearTimeout, completeUiRequest, completeUiRequest, deactivateEngine, emptyUiRequestQueue, engineId, genericHandleResponseType, getCurrentTimeout, isCommsResponseOutstanding, isDeactivated, isUiRequestOutstanding, onCommsInMessage, onReset, processCommsInQueue, processTimeout, processUiQueue, setReqId, setTimeout
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mMutex

private final java.lang.Object mMutex
Mutex for thread synchronisation


mState

private IdentityEngine.State mState

mIdentityList

private final java.util.ArrayList<Identity> mIdentityList
List array of Identities retrieved from Server.


mMyChatableIdentityList

private java.util.ArrayList<java.lang.String> mMyChatableIdentityList
List array of Identities supporting chat retrieved from Server.


mStatusList

private final java.util.ArrayList<StatusMsg> mStatusList

TYPE_IDENTITY

private static final java.lang.String TYPE_IDENTITY
Definitions for expected data-types returned from Server.

See Also:
Constant Field Values

TYPE_STATUS_MSG

private static final java.lang.String TYPE_STATUS_MSG
See Also:
Constant Field Values

KEY_DATA

public static final java.lang.String KEY_DATA
See Also:
Constant Field Values

KEY_DATA_CHATABLE_IDENTITIES

private static final java.lang.String KEY_DATA_CHATABLE_IDENTITIES
See Also:
Constant Field Values

LOG_STATUS_MSG

private static final java.lang.String LOG_STATUS_MSG
See Also:
Constant Field Values
Constructor Detail

IdentityEngine

public IdentityEngine(BaseEngine.IEngineEventCallback eventCallback)
Constructor

Parameters:
eventCallback - IEngineEventCallback allowing engine to report back.
Method Detail

prepareBoolFilter

private static java.util.Map<java.lang.String,java.lang.Object> prepareBoolFilter(Bundle filter)
Generate Map containing boolean capability filters for supplied Bundle.

Parameters:
filter - Bundle containing filter.
Returns:
Map containing set of capabilities.

prepareStringFilter

private static java.util.Map<java.lang.String,java.util.List<java.lang.String>> prepareStringFilter(Bundle filter)
Generate Map containing String capability filters for m supplied Bundle.

Parameters:
filter - Bundle containing filter.
Returns:
Map containing set of capabilities.

getNextRunTime

public long getNextRunTime()
Return the next run-time for the IdentitiesEngine. Will run as soon as possible if we need to issue a request, or we have a resonse waiting.

Specified by:
getNextRunTime in class BaseEngine
Returns:
next run-time.

onCreate

public void onCreate()
This will be called immediately after creation.

Specified by:
onCreate in class BaseEngine

onDestroy

public void onDestroy()
This will be called just before the engine is shutdown.

Specified by:
onDestroy in class BaseEngine

onRequestComplete

protected void onRequestComplete()
This function must be implemented in the derived engine implementation. It can do any post-request complete cleanup.

Specified by:
onRequestComplete in class BaseEngine

onTimeoutEvent

protected void onTimeoutEvent()
The derived engine implementation must call the processTimeout() function (normally from within the run() implementation), otherwise this will not be called. This function will be called when a timeout occurs (started by setTimeout and cancelled by clearTimeout). If this function takes longer than 1 second to complete it should be broken up.

Specified by:
onTimeoutEvent in class BaseEngine

processCommsResponse

protected void processCommsResponse(ResponseQueue.Response resp)
Process a response received from Server. The response is handled according to the current IdentityEngine state.

Specified by:
processCommsResponse in class BaseEngine
Parameters:
resp - The decoded response.

processUiRequest

protected void processUiRequest(ServiceUiRequest requestType,
                                java.lang.Object data)
Issue any outstanding UI request.

Specified by:
processUiRequest in class BaseEngine
Parameters:
requestType - Request to be issued.
dara - Data associated with the request.

run

public void run()
Run function called via EngineManager. Should have a UI, Comms response or timeout event to handle.

Specified by:
run in class BaseEngine

addUiFetchIdentities

public void addUiFetchIdentities(Bundle filter)
Add request to fetch available identities. The request is added to the UI request and processed when the engine is ready.

Parameters:
filter - Bundle containing parameters for fetch identities request. This contains the set of filters applied to GetIdentities API call.

addUiSetIdentityStatus

public void addUiSetIdentityStatus(java.lang.String network,
                                   java.lang.String identityId,
                                   boolean identityStatus)
Add request to set the capabilities we wish to support for the specified identity (such as support sync of contacts, receipt of status updates, chat etc.)

Parameters:
network - Name of the identity,
identityId - Id of identity.
identityStatus - Bundle containing the capability information for this identity.

addUiValidateIdentityCredentials

public void addUiValidateIdentityCredentials(boolean dryRun,
                                             java.lang.String network,
                                             java.lang.String username,
                                             java.lang.String password,
                                             Bundle identityCapabilityStatus)
Add request to validate user credentials for a specified identity.

Parameters:
dryRun - True if this is a dry-run.
network - Name of the network/identity.
username - User-name for login for this identity.
password - Password for login for this identity.
identityCapabilityStatus - Bundle containing capability details for this identity.

addUiGetMyIdentities

public void addUiGetMyIdentities(Bundle filter)
Add request to fetch the current user's identities.

Parameters:
filter - Bundle containing parameters for fetch identities request. This contains the set of filters applied to GetMyIdentities API call.

newState

private void newState(IdentityEngine.State newState)
Change current IdentityEngine state.

Parameters:
newState - new state.

startGetMyIdentities

private void startGetMyIdentities(java.lang.Object data)
Issue request to retrieve 'My' Identities. (Request is not issued if there is currently no connectivity).

Parameters:
data - Bundled request data.

startGetMyChatableIdentities

private void startGetMyChatableIdentities()
Issue request to retrieve 'My chat-able' Identities. The request is filtered to retrieve only identities with the chat capability enabled. (Request is not issued if there is currently no connectivity).


startSetIdentityStatus

private void startSetIdentityStatus(java.lang.Object data)
Issue request to set capabilities for a given Identity. (Request is not issued if there is currently no connectivity).

Parameters:
data - Bundled request data.

startValidateIdentityCredentials

private void startValidateIdentityCredentials(java.lang.Object data)
Issue request to validate the user credentials for an Identity. (Request is not issued if there is currently no connectivity).

Parameters:
data - Bundled request data.

startFetchIdentities

private void startFetchIdentities(java.lang.Object data)
Issue request to retrieve available Identities. (Request is not issued if there is currently no connectivity).

Parameters:
data - Bundled request data.

handleServerGetAvailableIdentitiesResponse

private void handleServerGetAvailableIdentitiesResponse(java.util.List<BaseDataType> data)
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.

Parameters:
data - List of BaseDataTypes generated from Server response.

handleValidateIdentityCredentials

private void handleValidateIdentityCredentials(java.util.List<BaseDataType> data)
Handle Server response to set validate credentials request. The response should be a Status-msg indicating whether the request has succeeded or failed. The request is completed with the status result (or ERROR_UNEXPECTED_RESPONSE if the data-type retrieved is not a Status-msg).

Parameters:
data - List of BaseDataTypes generated from Server response.

handleSetIdentityCapabilityStatus

private void handleSetIdentityCapabilityStatus(java.util.List<BaseDataType> data)
Handle Server response to set capability status request. The response should be a Status-msg indicating whether the request has succeeded or failed. The request is completed with the status result (or ERROR_UNEXPECTED_RESPONSE if the data-type retrieved is not a Status-msg).

Parameters:
data - List of BaseDataTypes generated from Server response.

checkConnectivity

private boolean checkConnectivity()
Get Connectivity status from NetworkAgent.

Returns:
true if NetworkAgent reports we have connectivity, false otherwise (complete outstanding request with ERROR_COMMS).

makeChatableIdentitiesCache

private void makeChatableIdentitiesCache(java.util.List<Identity> list)
Create cache of 'chat-able' identities.

Parameters:
list - List array of retrieved Identities.

getMyChatableIdentities

public void getMyChatableIdentities()
Add request to fetch the current user's 'chat-able' identities. This will automatically apply set of filters applied to GetMyIdentities API call to get Identities with chat capability. Note: Only called from tests.



JavaDoc