use of com.vodafone360.people.service.io.Request.Type in project 360-Engine-for-Android by 360.
the class NativeContactsApiTest method testAccountDataType.
/**
* Tests the plain Account inner class
*/
@SmallTest
public void testAccountDataType() {
// Account with null name and type
Account emptyAccount = new Account(null, null);
assertNotNull(emptyAccount);
assertNull(emptyAccount.getName());
assertNull(emptyAccount.getType());
emptyAccount = null;
// Array of accounts
final int NUM_OBJS_TO_CREATE = 4;
final String baseName = "AccountBaseName";
final String baseType = "AccountBaseType";
for (int i = 0; i < NUM_OBJS_TO_CREATE; i++) {
Account account = new Account(baseName + i, baseType + i);
assertNotNull(account);
assertNotNull(account.getName());
assertNotNull(account.getType());
assertNotNull(account.toString());
assertEquals("Account: name=" + baseName + i + ", type=" + baseType + i, account.toString());
assertEquals(baseName + i, account.getName());
assertEquals(baseType + i, account.getType());
assertFalse(account.isPeopleAccount());
}
}
use of com.vodafone360.people.service.io.Request.Type in project 360-Engine-for-Android by 360.
the class TcpConnectionThread method run.
public void run() {
QueueManager queueManager = QueueManager.getInstance();
setFailedRetrying(false);
setIsRetrying(false);
try {
// start the initial connection
reconnectSocket();
HeartbeatSenderThread hbSender = new HeartbeatSenderThread(this, mService, mSocket);
hbSender.setOutputStream(mOs);
hbSender.sendHeartbeat();
hbSender = null;
// TODO run this when BE supports it but keep HB in front!
/*
* ConnectionTester connTester = new ConnectionTester(mIs, mOs); if
* (connTester.runTest()) { } else {}
*/
startHelperThreads();
ConnectionManager.getInstance().onConnectionStateChanged(ITcpConnectionListener.STATE_CONNECTED);
} catch (IOException e) {
haltAndRetryConnection(FIRST_ATTEMPT);
} catch (Exception e) {
haltAndRetryConnection(FIRST_ATTEMPT);
}
while (mConnectionShouldBeRunning) {
try {
if ((null != mOs) && (!getFailedRetrying())) {
List<Request> reqs = QueueManager.getInstance().getRpgRequests();
int reqNum = reqs.size();
List<Integer> reqIdList = null;
if (Settings.sEnableProtocolTrace || Settings.sEnableSuperExpensiveResponseFileLogging) {
reqIdList = new ArrayList<Integer>();
}
if (reqNum > 0) {
mBaos.reset();
// batch payloads
for (int i = 0; i < reqNum; i++) {
Request req = reqs.get(i);
if ((null == req) || (req.getAuthenticationType() == Request.USE_API)) {
HttpConnectionThread.logV("TcpConnectionThread.run()", "Ignoring non-RPG method");
continue;
}
HttpConnectionThread.logD("TcpConnectionThread.run()", "Preparing [" + req.getRequestId() + "] for sending via RPG...");
req.setActive(true);
req.writeToOutputStream(mBaos, true);
// so we should not remove it from the queue otherwise there will be no timeout triggered.
if (req.isFireAndForget() && (req.mType != Request.Type.AVAILABILITY)) {
// f-a-f, no response,
// remove from queue
HttpConnectionThread.logD("TcpConnectionThread.run()", "Removed F&F-Request: " + req.getRequestId());
queueManager.removeRequest(req.getRequestId());
}
if (Settings.sEnableProtocolTrace) {
reqIdList.add(req.getRequestId());
HttpConnectionThread.logD("HttpConnectionThread.run()", "Req ID: " + req.getRequestId() + " <-> Auth: " + req.getAuth());
}
}
mBaos.flush();
byte[] payload = mBaos.toByteArray();
if (null != payload) {
// log file containing response to SD card
if (Settings.sEnableSuperExpensiveResponseFileLogging) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < reqIdList.size(); i++) {
sb.append(reqIdList.get(i));
sb.append("_");
}
LogUtils.logE("XXXXXXYYYXXXXXX Do not Remove this!");
LogUtils.logToFile(payload, "people_" + (reqIdList.size() > 0 ? reqIdList.get(0) : 0) + "_" + System.currentTimeMillis() + "_req_" + // message
((int) payload[2]) + // type
".txt");
}
if (Settings.sEnableProtocolTrace) {
Long userID = null;
AuthSessionHolder auth = LoginEngine.getSession();
if (auth != null) {
userID = auth.userID;
}
HttpConnectionThread.logI("TcpConnectionThread.run()", "\n > Sending request(s) " + reqIdList.toString() + ", for user ID " + userID + " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" + HessianUtils.getInHessian(new ByteArrayInputStream(payload), true) + "\n ");
}
try {
synchronized (mOs) {
mOs.write(payload);
mOs.flush();
}
} catch (IOException ioe) {
HttpConnectionThread.logE("TcpConnectionThread.run()", "Could not send request", ioe);
notifyOfNetworkProblems();
}
payload = null;
}
}
}
if (!getFailedRetrying()) {
synchronized (requestLock) {
requestLock.wait();
}
} else {
while (getFailedRetrying()) {
// loop until a retry
// succeeds
HttpConnectionThread.logI("TcpConnectionThread.run()", "Wait() for next connection retry has started.");
synchronized (errorLock) {
errorLock.wait(Settings.TCP_RETRY_BROKEN_CONNECTION_INTERVAL);
}
if (mConnectionShouldBeRunning) {
haltAndRetryConnection(FIRST_ATTEMPT);
}
}
}
} catch (Throwable t) {
HttpConnectionThread.logE("TcpConnectionThread.run()", "Unknown Error: ", t);
}
}
stopConnection();
ConnectionManager.getInstance().onConnectionStateChanged(ITcpConnectionListener.STATE_DISCONNECTED);
}
use of com.vodafone360.people.service.io.Request.Type in project 360-Engine-for-Android by 360.
the class TimeOutWatcher method sendTimeoutEvent.
/**
* Sends a timeout event for all the expired requests.
*
* @param currentTime the current time until when a timeout event needs to
* be sent
*/
private void sendTimeoutEvent(long currentTime) {
LogUtils.logV("TimeOutWatcher.sendTimeoutEvent(" + currentTime + ")");
while (mRequests.size() > 0) {
final Request request = mRequests.get(0);
if (request.getExpiryDate() <= currentTime) {
LogUtils.logW("TimeOutWatcher.sendTimeoutEvent(): " + "Expired request found with reqId=[" + request.getRequestId() + "], type=[" + request.mType + "] and timeout=" + request.getTimeout() + " milliseconds");
fireRequestExpired(request);
// no need to remove the request, this happened during previous
// method call... (removeRequest is called when adding a
// response)
} else {
// of it
break;
}
}
}
use of com.vodafone360.people.service.io.Request.Type in project 360-Engine-for-Android by 360.
the class HessianDecoder method decodeResponseByRequestType.
/**
*
* Parses the hashtables retrieved from the hessian payload that came from the server and
* returns a type for it.
*
* @param clist The list that will be populated with the data types.
* @param hash The hash table that contains the parsed date returned by the backend.
* @param type The type of the request that was sent, e.g. get contacts changes.
*
* @return The type of the response that was parsed (to be found in DecodedResponse.ResponseType).
*
*/
private int decodeResponseByRequestType(List<BaseDataType> clist, Hashtable<String, Object> hash, Request.Type type) {
int responseType = DecodedResponse.ResponseType.UNKNOWN.ordinal();
switch(type) {
case CONTACT_CHANGES_OR_UPDATES:
responseType = DecodedResponse.ResponseType.GET_CONTACTCHANGES_RESPONSE.ordinal();
// create ContactChanges
ContactChanges contChanges = new ContactChanges();
contChanges = contChanges.createFromHashtable(hash);
clist.add(contChanges);
break;
case ADD_CONTACT:
clist.add(Contact.createFromHashtable(hash));
responseType = DecodedResponse.ResponseType.ADD_CONTACT_RESPONSE.ordinal();
break;
case SIGN_UP:
clist.add(Contact.createFromHashtable(hash));
responseType = DecodedResponse.ResponseType.SIGNUP_RESPONSE.ordinal();
break;
case RETRIEVE_PUBLIC_KEY:
// AA define new object type
clist.add(PublicKeyDetails.createFromHashtable(hash));
responseType = DecodedResponse.ResponseType.RETRIEVE_PUBLIC_KEY_RESPONSE.ordinal();
break;
case CONTACT_DELETE:
ContactListResponse cresp = new ContactListResponse();
cresp.createFromHashTable(hash);
// add ids
@SuppressWarnings("unchecked") Vector<Long> contactIds = (Vector<Long>) hash.get(KEY_CONTACT_ID_LIST);
if (contactIds != null) {
for (Long cid : contactIds) {
cresp.mContactIdList.add((cid).intValue());
}
}
clist.add(cresp);
responseType = DecodedResponse.ResponseType.DELETE_CONTACT_RESPONSE.ordinal();
break;
case CONTACT_DETAIL_DELETE:
ContactDetailDeletion cdel = new ContactDetailDeletion();
clist.add(cdel.createFromHashtable(hash));
responseType = DecodedResponse.ResponseType.DELETE_CONTACT_DETAIL_RESPONSE.ordinal();
break;
case CONTACT_GROUP_RELATION_LIST:
ItemList groupRelationList = new ItemList(ItemList.Type.contact_group_relation);
groupRelationList.populateFromHashtable(hash);
clist.add(groupRelationList);
responseType = DecodedResponse.ResponseType.GET_CONTACT_GROUP_RELATIONS_RESPONSE.ordinal();
break;
case CONTACT_GROUP_RELATIONS:
ItemList groupRelationsList = new ItemList(ItemList.Type.contact_group_relations);
groupRelationsList.populateFromHashtable(hash);
clist.add(groupRelationsList);
responseType = DecodedResponse.ResponseType.GET_CONTACT_GROUP_RELATIONS_RESPONSE.ordinal();
break;
case DELETE_CONTACT_GROUP_RELATIONS:
// The hessian data sent by the backend is of the form
// r{1}{0}Mt{0}{0}zz. The MicroHessianInput always skips the 2 bytes
// after the type. This doesn't seem to be handling the case where
// the type is of length zero. Due to this, after decoding, the hash
// doesn't contain any elements/keys. Due to this, we are hardcoding
// the status to true here.
StatusMsg statusMsg = new StatusMsg();
statusMsg.mStatus = true;
clist.add(statusMsg);
responseType = DecodedResponse.ResponseType.UNKNOWN.ordinal();
break;
case GROUP_LIST:
ItemList zyblist = new ItemList(ItemList.Type.group_privacy);
zyblist.populateFromHashtable(hash);
clist.add(zyblist);
responseType = DecodedResponse.ResponseType.GET_GROUPS_RESPONSE.ordinal();
break;
case ITEM_LIST_OF_LONGS:
ItemList listOfLongs = new ItemList(ItemList.Type.long_value);
listOfLongs.populateFromHashtable(hash);
clist.add(listOfLongs);
// TODO
responseType = DecodedResponse.ResponseType.UNKNOWN.ordinal();
break;
case // TODO status and status list are used by many requests as a type. each request should have its own type however!
STATUS_LIST:
ItemList zybstatlist = new ItemList(ItemList.Type.status_msg);
zybstatlist.populateFromHashtable(hash);
clist.add(zybstatlist);
// TODO
responseType = DecodedResponse.ResponseType.UNKNOWN.ordinal();
break;
case STATUS:
StatusMsg s = new StatusMsg();
s.mStatus = true;
clist.add(s);
// TODO
responseType = DecodedResponse.ResponseType.UNKNOWN.ordinal();
break;
case TEXT_RESPONSE_ONLY:
Object val = hash.get("result");
if (val != null && val instanceof String) {
SimpleText txt = new SimpleText();
txt.addText((String) val);
clist.add(txt);
}
// TODO
responseType = DecodedResponse.ResponseType.UNKNOWN.ordinal();
break;
case EXPECTING_STATUS_ONLY:
StatusMsg statMsg = new StatusMsg();
clist.add(statMsg.createFromHashtable(hash));
// TODO
responseType = DecodedResponse.ResponseType.UNKNOWN.ordinal();
break;
case PRESENCE_LIST:
PresenceList mPresenceList = new PresenceList();
mPresenceList.createFromHashtable(hash);
clist.add(mPresenceList);
responseType = DecodedResponse.ResponseType.GET_PRESENCE_RESPONSE.ordinal();
break;
case PUSH_MSG:
// parse content of RPG Push msg
parsePushMessage(clist, hash);
responseType = DecodedResponse.ResponseType.PUSH_MESSAGE.ordinal();
break;
case CREATE_CONVERSATION:
Conversation mConversation = new Conversation();
mConversation.createFromHashtable(hash);
clist.add(mConversation);
responseType = DecodedResponse.ResponseType.CREATE_CONVERSATION_RESPONSE.ordinal();
break;
case DELETE_IDENTITY:
IdentityDeletion mIdenitityDeletion = new IdentityDeletion();
clist.add(mIdenitityDeletion.createFromHashtable(hash));
responseType = DecodedResponse.ResponseType.DELETE_IDENTITY_RESPONSE.ordinal();
break;
default:
LogUtils.logE("HessianDecoder.decodeResponseByRequestType() Unhandled type[" + type.name() + "]");
}
return responseType;
}
use of com.vodafone360.people.service.io.Request.Type in project 360-Engine-for-Android by 360.
the class TestModule method createFakeActivitiesList.
/**
* TODO: fill in the method properly
* @return
*/
public List<ActivityItem> createFakeActivitiesList() {
List<ActivityItem> activityList = new ArrayList<ActivityItem>();
for (int i = 0; i < TABLE_SIZE; i++) {
ActivityItem activityItem = new ActivityItem();
/** Unique identifier for the activity. This can be empty when setting
* a new activity (the id is generated on the server side) */
activityItem.activityId = System.currentTimeMillis();
/** Timestamp representing the time of the activity.
* This may not be related to creation/updated time. */
activityItem.time = System.currentTimeMillis();
/** local id for db */
// activityItem.mLocalId; set by DB insertion
// activityItem.mMoreInfo; //new Hashtable<ActivityItem, String>
/** The parent activity for 'grouped' or aggregated activities. This must be empty
* for normal activities that can be retrieved normally. Normally, a GetActivities
* without filter will not yield any 'grouped' or 'child' activities.
* To get activities that have a mParentActivity set, the 'children' filter must
* be used with a value of the parent Activity's id.*/
// activityItem.mParentActivity; // null
/** Indicates wether this activity 'groups' several child activities. When set,
* there must be child activities set that refer the main activity. Normally,
* a GetActivities without filter will not yield any 'grouped' or 'child' activities.
* To get activities that have a parentactivity set, the 'children' filter
* must be used with a value of the parent Activity's id.*/
// activityItem.mHasChildren = false;
/** Defines a binary preview for the activity. The preview can be a small thumbnail
* of the activity. The type of the binary data is defined into the previewmime field.*/
// keep null
// activityItem.mPreview = ByteBuffer.allocate(bytes.length);
// activityItem.mPreviewMime;
/** Defines an http url that the client can use to retrieve preview binary data.
* Can be used to embed the url into an IMG HTML tag.*/
// activityItem.mPreviewUrl
/** Name of the store type for this message. This field contains information about the
* originator network (local or external community activity).
* By default, should be set to local*/
activityItem.store = "local";
activityItem.title = generateRandomString();
activityItem.description = activityItem.description + activityItem.store;
/** Defines the type of the activity. */
activityItem.type = Type.CONTACT_FRIEND_INVITATION_SENT;
/** Defines an internal reference (if any) to the source of the activity.
* The format for the uri is "module:identifier".Some examples of valid uri are:
* contact:2737b322c9f6476ca152aa6cf3e5ac12 The activity is linked to some
* changes on a contact identified by id=2737b322c9f6476ca152aa6cf3e5ac12.
* file:virtual/flickr/2590004126 The activity is linked to some actions
* on a file identified by id=virtual/flickr/2590004126.
* message:9efd255359074dd9bd04cc1c8c4743e5 The activity is linked to a message
* identified by id=9efd255359074dd9bd04cc1c8c4743e5 */
activityItem.uri = "virtual/flickr/2590004126";
//can be 0 activityItem.mActivityFlags;
/** Miscellaneous flags.*/
activityItem.flagList = new ArrayList<Flag>();
activityItem.flagList.add(Flag.ALREADY_READ);
/** Defines the contact information of the counter-parties in the activity.
* This field is not mandatory, because some activity types
* are not related to contacts, but required if known.. */
//keep it simple - empty activityItem.mContactList = ;
activityItem.visibility = new ArrayList<Visibility>();
activityItem.visibility.add(Visibility.ORIGINATOR);
//keep it 0 activityItem.mVisibilityFlags = 0;
activityList.add(activityItem);
}
return activityList;
}
Aggregations