use of com.vodafone360.people.datatypes.ContactChanges in project 360-Engine-for-Android by 360.
the class SyncMeEngine method processGetMyChangesResponse.
/**
* Processes the response from a GetMyChanges request. The me profile data
* will be merged in the local database if the response is successful.
* Otherwise the processor will complete with a suitable error.
* @param resp Response from server.
*/
private void processGetMyChangesResponse(final DecodedResponse resp) {
LogUtils.logD("SyncMeEngine processGetMyChangesResponse()");
ServiceStatus status = BaseEngine.getResponseStatus(BaseDataType.CONTACT_CHANGES_DATA_TYPE, resp.mDataTypes);
if (status == ServiceStatus.SUCCESS) {
ContactChanges changes = (ContactChanges) resp.mDataTypes.get(0);
Contact currentMeProfile = new Contact();
status = SyncMeDbUtils.fetchMeProfile(mDbHelper, currentMeProfile);
switch(status) {
case SUCCESS:
SyncMeDbUtils.updateMeProfile(mDbHelper, currentMeProfile, changes.mUserProfile);
break;
case // this is the 1st time sync
ERROR_NOT_FOUND:
currentMeProfile.copy(changes.mUserProfile);
status = SyncMeDbUtils.setMeProfile(mDbHelper, currentMeProfile);
setFirstTimeMeSyncComplete(true);
break;
default:
completeUiRequest(status);
return;
}
final String url = fetchThumbnailUrlFromProfile(changes.mUserProfile);
if (url != null) {
downloadMeProfileThumbnail(url, currentMeProfile.localContactID);
} else {
completeUiRequest(status);
}
storeMeProfileRevisionInDb(changes.mCurrentServerVersion);
} else {
completeUiRequest(status);
}
}
use of com.vodafone360.people.datatypes.ContactChanges 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.datatypes.ContactChanges in project 360-Engine-for-Android by 360.
the class SyncMeDbUtils method savePresenceStatusResponse.
/**
* The utility method to save Contacts/setMe() response for the status text
* change to the database...
* @param dbHelper DatabaseHelper - database.
* @param ContactChanges result - status text change.
*/
public static void savePresenceStatusResponse(final DatabaseHelper dbHelper, ContactChanges result) {
Contact currentMeProfile = new Contact();
if (ServiceStatus.SUCCESS == SyncMeDbUtils.fetchMeProfile(dbHelper, currentMeProfile)) {
boolean changed = false;
if (result.mUserProfile.userID != null && (!result.mUserProfile.userID.equals(currentMeProfile.userID))) {
currentMeProfile.userID = result.mUserProfile.userID;
changed = true;
}
if (result.mUserProfile.contactID != null && (!result.mUserProfile.contactID.equals(currentMeProfile.contactID))) {
currentMeProfile.contactID = result.mUserProfile.contactID;
changed = true;
}
if (changed) {
dbHelper.modifyContactServerId(currentMeProfile.localContactID, currentMeProfile.contactID, currentMeProfile.userID);
}
for (ContactDetail oldStatus : currentMeProfile.details) {
if (oldStatus.key == ContactDetail.DetailKeys.PRESENCE_TEXT) {
for (ContactDetail newStatus : result.mUserProfile.details) {
if (newStatus.key == ContactDetail.DetailKeys.PRESENCE_TEXT) {
oldStatus.unique_id = newStatus.unique_id;
dbHelper.syncContactDetail(oldStatus.localDetailID, oldStatus.unique_id);
break;
}
}
}
}
}
}
use of com.vodafone360.people.datatypes.ContactChanges in project 360-Engine-for-Android by 360.
the class UpdateNativeContactsTest method compareContactWithContactChange.
/**
* Compares a Contact details with an array of ContactChange.
*
* @param contact the Contact to compare
* @param contactChange the array of ContactChange to compare
* @return true if the Contact is equivalent to the array of ContactChange, false otherwise
*/
private boolean compareContactWithContactChange(Contact contact, ContactChange[] contactChanges) {
final NativeContactsApi nca = NativeContactsApi.getInstance();
final List<ContactDetail> details = contact.details;
for (int i = 0; i < details.size(); i++) {
final ContactDetail detail = details.get(i);
if (nca.isKeySupported(ContactDetailsTable.mapInternalKeyToContactChangeKey(detail.key.ordinal()))) {
// check if there is a corresponding ContactChange
if (!hasEquivalentContactChange(contactChanges, detail)) {
return false;
}
}
}
return true;
}
use of com.vodafone360.people.datatypes.ContactChanges in project 360-Engine-for-Android by 360.
the class DownloadServerContacts method processCommsResponse.
/**
* Called by framework when a response is received from the server. In case
* of the first page this will only be called if the request ID matches.
* Processes the page and if the page is the last one in the batch, sends a
* new batch of requests to the server.
*
* @param response from server
*/
@Override
public void processCommsResponse(DecodedResponse resp) {
Integer pageNo = 0;
if (mInternalState == InternalState.FETCHING_NEXT_BATCH) {
pageNo = mPageReqIds.remove(resp.mReqId);
if (pageNo == null) {
LogUtils.logD("DownloadServerContacts.processCommsResponse: Req ID not known");
return;
}
}
LogUtils.logD("DownloadServerContacts.processCommsResponse() - Page " + pageNo);
ServiceStatus status = BaseEngine.getResponseStatus(BaseDataType.CONTACT_CHANGES_DATA_TYPE, resp.mDataTypes);
if (status == ServiceStatus.SUCCESS) {
ContactChanges contactChanges = (ContactChanges) resp.mDataTypes.get(0);
LogUtils.logI("DownloadServerContacts.processCommsResponse - No of contacts = " + contactChanges.mContacts.size());
if (contactChanges.mContacts.size() == 0 && pageNo > 0) {
LogUtils.logW("DownloadServerContacts.processCommsResponse - " + "Error a page with 0 contacts was received");
LogUtils.logW("DownloadServerContacts.processCommsResponse - Changes = " + contactChanges);
}
mBatchPageReceivedCount++;
if (mBatchPageReceivedCount == mBatchNoOfPages) {
mLastPageSize = contactChanges.mContacts.size();
// Page batch is now complete
if (mInternalState == InternalState.FETCHING_FIRST_PAGE) {
mTotalNoOfPages = contactChanges.mNumberOfPages;
mToRevision = contactChanges.mVersionAnchor;
mInternalState = InternalState.FETCHING_NEXT_BATCH;
}
mBatchFirstPageNo += mBatchNoOfPages;
if (mTotalNoOfPages == null || mToRevision == null) {
complete(ServiceStatus.ERROR_COMMS_BAD_RESPONSE);
return;
}
if (mBatchFirstPageNo < mTotalNoOfPages.intValue()) {
status = fetchNextBatch();
if (ServiceStatus.SUCCESS != status) {
complete(status);
return;
}
} else {
mIsComplete = true;
}
}
status = syncContactChangesPage(contactChanges);
mNoOfPagesDone++;
LogUtils.logI("DownloadServerContacts.processCommsResponse() - Contact changes page " + mNoOfPagesDone + "/" + mTotalNoOfPages + " received, no of contacts = " + contactChanges.mContacts.size());
if (ServiceStatus.SUCCESS != status) {
LogUtils.logE("DownloadServerContacts.processCommsResponse() - Error syncing page: " + status);
complete(status);
return;
}
if (mIsComplete && mContactsChangedList.size() == 0 && !mSyncDataPending) {
downloadSyncSuccessful();
}
return;
}
complete(status);
}
Aggregations