use of com.vodafone360.people.engine.presence.NetworkPresence in project 360-Engine-for-Android by 360.
the class MePresenceCacheTableTest method testGetUpdateCache.
public void testGetUpdateCache() {
final String userId = "1234";
assertTrue(createTable());
final ArrayList<NetworkPresence> presenceList = new ArrayList<NetworkPresence>();
int onlineStatus = OnlineStatus.ONLINE.ordinal();
for (int i = SocialNetwork.FACEBOOK_COM.ordinal(); i < SocialNetwork.MICROSOFT.ordinal(); i++) {
NetworkPresence networkPresence = new NetworkPresence(userId, i, onlineStatus);
presenceList.add(networkPresence);
MePresenceCacheTable.updateCache(networkPresence, mTestDatabase.getWritableDatabase());
assertTrue(checkCacheEquals(presenceList));
}
onlineStatus = OnlineStatus.OFFLINE.ordinal();
for (int i = SocialNetwork.FACEBOOK_COM.ordinal(); i < SocialNetwork.MICROSOFT.ordinal(); i++) {
NetworkPresence networkPresence = new NetworkPresence(userId, i, onlineStatus);
presenceList.set(i, networkPresence);
MePresenceCacheTable.updateCache(networkPresence, mTestDatabase.getWritableDatabase());
assertTrue(checkCacheEquals(presenceList));
}
}
use of com.vodafone360.people.engine.presence.NetworkPresence in project 360-Engine-for-Android by 360.
the class MePresenceCacheTableTest method checkCacheEquals.
private boolean checkCacheEquals(ArrayList<NetworkPresence> presenceList) {
final ArrayList<NetworkPresence> cache = MePresenceCacheTable.getCache(mTestDatabase.getReadableDatabase());
if (presenceList == null && cache == null) {
return true;
} else if (presenceList == null || cache == null) {
return false;
}
final int cacheSize = cache.size();
if (presenceList.size() != cacheSize) {
return false;
}
for (int i = 0; i < cacheSize; i++) {
NetworkPresence cacheValue = cache.get(i);
NetworkPresence listValue = presenceList.get(i);
if (cacheValue.getNetworkId() != listValue.getNetworkId()) {
return false;
}
if (!(cacheValue.getUserId().equals(listValue.getUserId()))) {
return false;
}
if (cacheValue.getOnlineStatusId() != listValue.getOnlineStatusId()) {
return false;
}
}
return true;
}
use of com.vodafone360.people.engine.presence.NetworkPresence in project 360-Engine-for-Android by 360.
the class User method createPayload.
/**
* @param payload
* @return
*/
private ArrayList<NetworkPresence> createPayload(String userId, Hashtable<String, String> payload) {
ArrayList<NetworkPresence> presenceList = new ArrayList<NetworkPresence>(payload.size());
String parsedUserId = parseUserName(userId);
String key = null;
SocialNetwork network = null;
String value = null;
OnlineStatus status = null;
for (Enumeration<String> en = payload.keys(); en.hasMoreElements(); ) {
key = en.nextElement();
network = SocialNetwork.getValue(key);
if (network != null) {
int keyIdx = network.ordinal();
value = payload.get(key);
if (value != null) {
status = OnlineStatus.getValue(value);
if (status != null) {
int valueIdx = status.ordinal();
presenceList.add(new NetworkPresence(parsedUserId, keyIdx, valueIdx));
}
}
}
}
return presenceList;
}
use of com.vodafone360.people.engine.presence.NetworkPresence in project 360-Engine-for-Android by 360.
the class PresenceDbUtils method processMeProfile.
/**
* This method alters the User wrapper of me profile,
* and returns true if me profile information contains the ignored TPC networks information.
* Based on the result this information may be deleted.
* @param removePCPresence - if TRUE the PC network will be removed from the network list.
* @param user - the me profile wrapper.
* @param ignoredNetworks - the list if ignored integer network ids.
* @return
*/
private static boolean processMeProfile(boolean removePCPresence, User user, ArrayList<Integer> ignoredNetworks) {
if (removePCPresence) {
int max = OnlineStatus.OFFLINE.ordinal();
// calculate the new aggregated presence status
for (NetworkPresence presence : user.getPayload()) {
if (presence.getOnlineStatusId() > max) {
max = presence.getOnlineStatusId();
}
}
user.setOverallOnline(max);
}
// the list of chat network ids in this User wrapper
ArrayList<Integer> userNetworks = new ArrayList<Integer>();
ArrayList<NetworkPresence> payload = user.getPayload();
for (NetworkPresence presence : payload) {
int networkId = presence.getNetworkId();
userNetworks.add(networkId);
// 1. ignore offline TPC networks
if (presence.getOnlineStatusId() == OnlineStatus.OFFLINE.ordinal()) {
ignoredNetworks.add(networkId);
}
}
// 2. ignore the TPC networks presence state for which is unknown
ArrayList<Identity> identities = EngineManager.getInstance().getIdentityEngine().getMyChattableIdentities();
SocialNetwork network = null;
for (Identity identity : identities) {
network = SocialNetwork.getValue(identity.mNetwork);
if (network != null) {
if (!userNetworks.contains(network.ordinal())) {
ignoredNetworks.add(network.ordinal());
}
}
}
return !ignoredNetworks.isEmpty();
}
use of com.vodafone360.people.engine.presence.NetworkPresence in project 360-Engine-for-Android by 360.
the class PresenceTable method updateUser.
/**
* This method updates the user with the information from the User wrapper.
*
* @param user2Update - User info to update
* @param ignoredNetworkIds - ArrayList of integer network ids presence state for which must be ignored.
* @param writableDatabase - writable database
* @return USER_ADDED if no user with user id like the one in user2Update
* payload "status.getUserId()" ever existed in this table,
* USER_UPDATED if the user already existed in the table and has
* been successfully added, USER_NOT_ADDED - if user was not added.
* @throws SQLException if the database layer throws this exception.
* @throws NullPointerException if the passed in database instance is null.
*/
public static int updateUser(User user2Update, ArrayList<Integer> ignoredNetworkIds, SQLiteDatabase writableDatabase) throws SQLException, NullPointerException {
int ret = USER_NOTADDED;
if (writableDatabase == null) {
throw new NullPointerException(DEFAULT_ERROR_MESSAGE);
}
if (user2Update != null) {
ArrayList<NetworkPresence> statusesOnNetworks = user2Update.getPayload();
if (!statusesOnNetworks.isEmpty()) {
ContentValues values = new ContentValues();
StringBuffer where = null;
Iterator<NetworkPresence> itr = statusesOnNetworks.iterator();
NetworkPresence status = null;
long localContactId = user2Update.getLocalContactId();
int networkId = 0;
while (itr.hasNext()) {
status = itr.next();
networkId = status.getNetworkId();
if (ignoredNetworkIds == null || !ignoredNetworkIds.contains(networkId)) {
values.put(Field.LOCAL_CONTACT_ID.toString(), localContactId);
values.put(Field.USER_ID.toString(), status.getUserId());
values.put(Field.NETWORK_ID.toString(), networkId);
values.put(Field.NETWORK_STATUS.toString(), status.getOnlineStatusId());
where = StringBufferPool.getStringBuffer(Field.LOCAL_CONTACT_ID.toString());
where.append(SQLKeys.EQUALS).append(localContactId).append(SQLKeys.AND).append(Field.NETWORK_ID).append(SQLKeys.EQUALS).append(networkId);
int numberOfAffectedRows = writableDatabase.update(TABLE_NAME, values, StringBufferPool.toStringThenRelease(where), null);
if (numberOfAffectedRows == 0) {
if (writableDatabase.insert(TABLE_NAME, null, values) != -1) {
ret = USER_ADDED;
} else {
LogUtils.logE("PresenceTable updateUser(): could not add new user!");
}
} else if (ret == USER_NOTADDED) {
ret = USER_UPDATED;
}
values.clear();
} else if (ignoredNetworkIds != null) {
// presence information from this network needs to be ignored
itr.remove();
}
}
}
}
return ret;
}
Aggregations