use of com.vodafone360.people.engine.presence.User in project 360-Engine-for-Android by 360.
the class NowPlusContactsTest method testFetchContactInfo.
@SmallTest
public void testFetchContactInfo() {
Log.i(LOG_TAG, "***** EXECUTING testFetchContactInfo *****");
Log.i(LOG_TAG, "Test contact add sync contact detail list");
Log.i(LOG_TAG, "Test 1a: Initialise test environment and load database");
assertTrue(initialise());
Log.i(LOG_TAG, "Test 1b: Remove user data");
mDatabaseHelper.removeUserData();
ServiceStatus status = mTestUtility.waitForEvent(WAIT_EVENT_TIMEOUT_MS, DbTestUtility.CONTACTS_INT_EVENT_MASK);
// add contacts and check if added contacts are the same as fetched
Contact addedContact = new Contact();
status = mDatabaseHelper.addContact(addedContact);
assertEquals(ServiceStatus.SUCCESS, status);
// create and add phoneDetail
ContactDetail phoneDetail = new ContactDetail();
phoneDetail.localContactID = addedContact.localContactID;
phoneDetail.key = ContactDetail.DetailKeys.VCARD_PHONE;
String number = "07967 123456";
phoneDetail.setTel(number, ContactDetail.DetailKeyTypes.CELL);
status = mDatabaseHelper.addContactDetail(phoneDetail);
assertEquals(ServiceStatus.SUCCESS, status);
Contact c = new Contact();
ContactDetail fetchedPhoneDetail = new ContactDetail();
status = mDatabaseHelper.fetchContactInfo(number, c, fetchedPhoneDetail);
assertEquals(ServiceStatus.SUCCESS, status);
assertTrue(DatabaseHelper.doDetailsMatch(phoneDetail, fetchedPhoneDetail));
shutdown();
}
use of com.vodafone360.people.engine.presence.User in project 360-Engine-for-Android by 360.
the class UploadServerContacts method processNewContactsResp.
/**
* Called when a server response is received during a new contact sync. The
* server ID, user ID and contact detail unique IDs are extracted from the
* response and the NowPlus database updated. Possibly server errors are
* also handled.
*
* @param resp Response from server.
*/
private void processNewContactsResp(final DecodedResponse resp) {
ServiceStatus status = BaseEngine.getResponseStatus(BaseDataType.CONTACT_CHANGES_DATA_TYPE, resp.mDataTypes);
if (status == ServiceStatus.SUCCESS) {
ContactChanges contactChanges = (ContactChanges) resp.mDataTypes.get(0);
ListIterator<Contact> itContactSrc = contactChanges.mContacts.listIterator();
ListIterator<Contact> itContactDest = mContactChangeList.listIterator();
List<ServerIdInfo> contactServerIdList = new ArrayList<ServerIdInfo>();
List<ServerIdInfo> detailServerIdList = new ArrayList<ServerIdInfo>();
while (itContactSrc.hasNext()) {
if (!itContactDest.hasNext()) {
/**
* The response should contain the same number of contacts
* as was supplied but must handle the error.
*/
status = ServiceStatus.ERROR_COMMS_BAD_RESPONSE;
break;
}
Contact contactSrc = itContactSrc.next();
Contact contactDest = itContactDest.next();
if (Settings.ENABLED_CONTACTS_SYNC_TRACE) {
String name = null;
String sns = null;
for (ContactDetail detail : contactDest.details) {
if (detail.key == ContactDetail.DetailKeys.VCARD_NAME) {
if (detail.value != null) {
VCardHelper.Name nameObj = detail.getName();
if (nameObj != null) {
name = nameObj.toString();
}
}
}
if (detail.key == ContactDetail.DetailKeys.VCARD_INTERNET_ADDRESS) {
sns = detail.alt;
}
}
LogUtils.logV("UploadServerContacts." + "processNewContactsResp() Contact uploaded: SID" + " = " + contactSrc.contactID + ", name = " + name + ", sns = " + sns + ", no of details = " + contactDest.details.size() + ", deleted=" + contactSrc.deleted);
}
if (contactSrc.contactID != null && contactSrc.contactID.longValue() != -1L) {
if (contactDest.contactID == null || !contactDest.contactID.equals(contactSrc.contactID)) {
ServerIdInfo info = new ServerIdInfo();
info.localId = contactDest.localContactID;
info.serverId = contactSrc.contactID;
info.userId = contactSrc.userID;
contactServerIdList.add(info);
}
} else {
LogUtils.logE("UploadServerContacts." + "processNewContactsResp() The server failed to " + "add the following contact: " + contactDest.localContactID + ", server ID = " + contactDest.contactID);
mFailureList += "Failed to add contact: " + contactDest.localContactID + "\n";
for (ContactDetail d : contactDest.details) {
LogUtils.logV("Failed Contact Info: " + contactDest.localContactID + ", Detail: " + d.key + ", " + d.keyType + " = " + d.value);
}
}
status = handleUploadDetailChanges(contactSrc, contactDest, detailServerIdList);
}
if (status != ServiceStatus.SUCCESS) {
/**
* Something is going wrong - cancel the update *
*/
complete(status);
return;
}
long startTime = System.nanoTime();
List<ContactIdInfo> dupList = new ArrayList<ContactIdInfo>();
status = ContactsTable.syncSetServerIds(contactServerIdList, dupList, mDb.getWritableDatabase());
if (status != ServiceStatus.SUCCESS) {
complete(status);
return;
}
status = ContactDetailsTable.syncSetServerIds(detailServerIdList, mDb.getWritableDatabase());
if (status != ServiceStatus.SUCCESS) {
complete(status);
return;
}
if (dupList.size() > 0) {
LogUtils.logV("UploadServerContacts.processNewContactsResp() Found " + dupList.size() + " duplicate contacts. Trying to remove them...");
if (VersionUtils.is2XPlatform()) {
// This is a very important distinction for 2.X devices!
// the NAB IDs from the contacts we first import are stripped away
// So we won't have the correct ID if syncMergeContactList() is executed
// This is critical because a chain reaction will cause a Contact Delete in the end
// Instead we can syncDeleteContactList() which should be safe on 2.X!
status = mDb.syncDeleteContactList(dupList, false, true);
} else {
status = mDb.syncMergeContactList(dupList);
}
if (status != ServiceStatus.SUCCESS) {
complete(status);
return;
}
markDbChanged();
}
mDbSyncTime += (System.nanoTime() - startTime);
while (itContactDest.hasNext()) {
Contact contactDest = itContactDest.next();
LogUtils.logE("UploadServerContacts.processNewContactsResp() " + "The server failed to add the following contact (not " + "included in returned list): " + contactDest.localContactID);
mFailureList += "Failed to add contact (missing from return " + "list): " + contactDest.localContactID + "\n";
}
updateProgress();
sendNextContactAdditionsPage();
return;
}
complete(status);
}
use of com.vodafone360.people.engine.presence.User in project 360-Engine-for-Android by 360.
the class IdentityEngine method getMyChattableIdentities.
/**
* Takes all third party identities that have a chat capability set to true.
*
* @return A list of chattable 3rd party identities the user is signed in to. If the retrieval identities failed the returned list will be empty.
*/
public ArrayList<Identity> getMyChattableIdentities() {
final ArrayList<Identity> chattableIdentities = new ArrayList<Identity>();
final ArrayList<Identity> myIdentityList;
final int identityListSize;
synchronized (mMyIdentityList) {
// make a shallow copy
myIdentityList = new ArrayList<Identity>(mMyIdentityList);
}
identityListSize = myIdentityList.size();
// list if it does
for (int i = 0; i < identityListSize; i++) {
Identity identity = myIdentityList.get(i);
List<IdentityCapability> capabilities = identity.mCapabilities;
if (null == capabilities) {
// if the capabilties are null skip to next identity
continue;
}
// run through capabilties and check for chat
for (int j = 0; j < capabilities.size(); j++) {
IdentityCapability capability = capabilities.get(j);
if (null == capability) {
// skip null capabilities
continue;
}
if ((capability.mCapability == IdentityCapability.CapabilityID.chat) && (capability.mValue)) {
chattableIdentities.add(identity);
break;
}
}
}
return chattableIdentities;
}
use of com.vodafone360.people.engine.presence.User in project 360-Engine-for-Android by 360.
the class LoginEngine method onReset.
/**
* Called by the framework before a remove user data operation takes place.
* Initiates a suitable UI request which will kick the worker thread.
*/
@Override
public void onReset() {
// reset the engine as if it was just created
super.onReset();
setRegistrationComplete(false);
mState = State.NOT_REGISTERED;
mRegistrationDetails = new RegistrationDetails();
mActivationCode = null;
onLoginStateChanged(false);
}
use of com.vodafone360.people.engine.presence.User in project 360-Engine-for-Android by 360.
the class SyncMeEngine method setFirstTimeMeSyncComplete.
/**
* Helper function to update the database when the state of the
* {@link #mFirstTimeMeSyncComplete} flag changes.
* @param value New value to the flag. True indicates that first time sync
* has been completed. The flag is never set to false again by
* the engine, it will be only set to false when a remove user
* data is done (and the database is deleted).
* @return SUCCESS or a suitable error code if the database could not be
* updated.
*/
private ServiceStatus setFirstTimeMeSyncComplete(final boolean value) {
if (mFirstTimeMeSyncComplete == value) {
return ServiceStatus.SUCCESS;
}
PersistSettings setting = new PersistSettings();
setting.putFirstTimeMeSyncComplete(value);
ServiceStatus status = mDbHelper.setOption(setting);
if (ServiceStatus.SUCCESS == status) {
synchronized (this) {
mFirstTimeMeSyncComplete = value;
}
}
return status;
}
Aggregations