use of com.vodafone360.people.service.io.Request.Type in project 360-Engine-for-Android by 360.
the class IdentityEngine method handleValidateIdentityCredentials.
/**
* 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).
*
* @param data List of BaseDataTypes generated from Server response.
*/
private void handleValidateIdentityCredentials(List<BaseDataType> data) {
Bundle bu = null;
ServiceStatus errorStatus = getResponseStatus(BaseDataType.STATUS_MSG_DATA_TYPE, data);
if (errorStatus == ServiceStatus.SUCCESS) {
mStatusList.clear();
for (BaseDataType item : data) {
if (item.getType() == BaseDataType.STATUS_MSG_DATA_TYPE) {
mStatusList.add((StatusMsg) item);
} else {
completeUiRequest(ServiceStatus.ERROR_UNEXPECTED_RESPONSE);
return;
}
}
bu = new Bundle();
if (mStatusList.size() == 1) {
bu.putBoolean("status", mStatusList.get(0).mStatus);
} else {
LogUtils.logW("Status list sould have one item. It has " + mStatusList.size());
bu.putParcelableArrayList(KEY_DATA, mStatusList);
}
}
completeUiRequest(errorStatus, bu);
newState(State.IDLE);
if (errorStatus == ServiceStatus.SUCCESS) {
addUiRequestToQueue(ServiceUiRequest.GET_MY_IDENTITIES, null);
} else if (errorStatus == ServiceStatus.ERROR_COMMS_TIMEOUT) {
// if we timeout we need to clear our pending identities
clearPendingIdentities();
}
}
use of com.vodafone360.people.service.io.Request.Type 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.");
}
use of com.vodafone360.people.service.io.Request.Type in project 360-Engine-for-Android by 360.
the class IdentityEngine method handleSetIdentityStatus.
/**
* 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).
*
* @param data List of BaseDataTypes generated from Server response.
*/
private void handleSetIdentityStatus(List<BaseDataType> data) {
Bundle bu = null;
ServiceStatus errorStatus = getResponseStatus(BaseDataType.STATUS_MSG_DATA_TYPE, data);
if (errorStatus == ServiceStatus.SUCCESS) {
mStatusList.clear();
for (BaseDataType item : data) {
if (item.getType() == BaseDataType.STATUS_MSG_DATA_TYPE) {
mStatusList.add((StatusMsg) item);
} else {
completeUiRequest(ServiceStatus.ERROR_UNEXPECTED_RESPONSE);
return;
}
}
bu = new Bundle();
bu.putParcelableArrayList(KEY_DATA, mStatusList);
}
completeUiRequest(errorStatus, bu);
newState(State.IDLE);
}
use of com.vodafone360.people.service.io.Request.Type in project 360-Engine-for-Android by 360.
the class IdentityEngine method pushIdentitiesToUi.
/**
*
* Pushes the identities retrieved by get my identities or by get available identities
* to the ui.
*
* @param request The request type: either get my identities, or get available identities.
*/
private void pushIdentitiesToUi(ServiceUiRequest request) {
String requestKey = null;
ArrayList<Identity> idBundle = null;
if (request == ServiceUiRequest.GET_AVAILABLE_IDENTITIES) {
requestKey = KEY_AVAILABLE_IDS;
synchronized (mAvailableIdentityList) {
// provide a shallow copy
idBundle = new ArrayList<Identity>(mAvailableIdentityList);
}
} else {
requestKey = KEY_MY_IDS;
synchronized (mMyIdentityList) {
// provide a shallow copy
idBundle = new ArrayList<Identity>(mMyIdentityList);
}
}
// send update to 3rd party identities ui if it is up
Bundle b = new Bundle();
b.putParcelableArrayList(requestKey, idBundle);
UiAgent uiAgent = mEventCallback.getUiAgent();
if (uiAgent != null && uiAgent.isSubscribed()) {
uiAgent.sendUnsolicitedUiEvent(request, b);
}
// end: send update to 3rd party identities ui if it is up
}
use of com.vodafone360.people.service.io.Request.Type 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!
}
Aggregations