use of com.vodafone360.people.engine.contactsync.ContactChange in project 360-Engine-for-Android by 360.
the class PeopleContactsApi method updateNativeContact.
/**
* Updates a native contact in the people database.
*
* Note: it assumes that the changes come from native as it sets flags
* to prevent syncing back to native
*
* @param contact the contact changes to apply to the contact
*/
public void updateNativeContact(ContactChange[] contact) {
mAddedDetails.clear();
mDeletedDetails.clear();
mUpdatedDetails.clear();
for (int i = 0; i < contact.length; i++) {
final ContactChange change = contact[i];
// convert the ContactChange into a ContactDetail
final ContactDetail detail = mDbh.convertContactChange(change);
final int type = change.getType();
switch(type) {
case ContactChange.TYPE_ADD_DETAIL:
mAddedDetails.add(detail);
break;
case ContactChange.TYPE_DELETE_DETAIL:
mDeletedDetails.add(detail);
break;
case ContactChange.TYPE_UPDATE_DETAIL:
mUpdatedDetails.add(detail);
break;
}
}
if (mAddedDetails.size() > 0) {
mDbh.syncAddContactDetailList(mAddedDetails, true, false);
}
if (mDeletedDetails.size() > 0) {
mDbh.syncDeleteContactDetailList(mDeletedDetails, true, false);
}
if (mUpdatedDetails.size() > 0) {
mDbh.syncModifyContactDetailList(mUpdatedDetails, true, false);
}
// TODO: Throttle the event
mDbh.fireDatabaseChangedEvent(DatabaseChangeType.CONTACTS, true);
}
use of com.vodafone360.people.engine.contactsync.ContactChange in project 360-Engine-for-Android by 360.
the class PeopleContactsApiTest method testUpdateGetNativeContactWithDelete.
/**
* Tests the updateNativeContact() method when a detail is deleted outside.
*/
public void testUpdateGetNativeContactWithDelete() {
final long NATIVE_ID = 15;
PeopleContactsApi pca = new PeopleContactsApi(mDatabaseHelper);
// the database is empty, it shall not return any ids
assertNull(pca.getNativeContactsIds());
// let's add a contact
ContactChange[] contact = filterContactChanges(ContactChangeHelper.randomContact(ContactChange.INVALID_ID, ContactChange.INVALID_ID, NATIVE_ID));
assertTrue(pca.addNativeContact(contact));
// check that it exists
long[] ids = pca.getNativeContactsIds();
assertEquals(1, ids.length);
assertEquals(NATIVE_ID, ids[0]);
// get the contact back
ContactChange[] savedContact = pca.getContact(NATIVE_ID);
assertNotNull(savedContact);
// let's add a detail
ContactChange addedDetail = new ContactChange(ContactChange.KEY_VCARD_PHONE, "+3300000", ContactChange.FLAG_HOME);
addedDetail.setNabContactId(NATIVE_ID);
addedDetail.setType(ContactChange.TYPE_ADD_DETAIL);
addedDetail.setInternalContactId(savedContact[0].getInternalContactId());
ContactChange[] updates = { addedDetail };
pca.updateNativeContact(updates);
// get the contact back
savedContact = pca.getContact(NATIVE_ID);
assertNotNull(savedContact);
assertEquals(contact.length + 1, savedContact.length);
// find the localId of the detail to delete
int index = findContactChangeIndex(savedContact, addedDetail);
assertTrue(index != -1);
addedDetail.setInternalDetailId(savedContact[index].getInternalDetailId());
// remove the detail as if coming from user or server (i.e. not yet synced to native)
ArrayList<ContactDetail> detailList = new ArrayList<ContactDetail>(1);
detailList.add(mDatabaseHelper.convertContactChange(addedDetail));
mDatabaseHelper.syncDeleteContactDetailList(detailList, false, true);
// get the contact back
savedContact = pca.getContact(NATIVE_ID);
assertNotNull(savedContact);
// the deleted detail shall be given
assertEquals(contact.length + 1, savedContact.length);
// check that one contact has the deleted flag
int deletedIndex = -1;
int deletedCount = 0;
for (int i = 0; i < savedContact.length; i++) {
if (savedContact[i].getType() == ContactChange.TYPE_DELETE_DETAIL) {
deletedIndex = i;
deletedCount++;
}
}
// there shall be only one deleted detail
assertEquals(1, deletedCount);
assertEquals(addedDetail.getInternalDetailId(), savedContact[deletedIndex].getInternalDetailId());
}
use of com.vodafone360.people.engine.contactsync.ContactChange in project 360-Engine-for-Android by 360.
the class PeopleContactsApiTest method testAddGetNativeContact.
/**
* Tests the methods sequence addNativeContact() then getNativeContact().
*/
@Suppress
public void testAddGetNativeContact() {
final long NATIVE_ID = 15;
PeopleContactsApi pca = new PeopleContactsApi(mDatabaseHelper);
// the database is empty, it shall not return any ids
assertNull(pca.getNativeContactsIds());
// let's add a contact
ContactChange[] contact = filterContactChanges(ContactChangeHelper.randomContact(ContactChange.INVALID_ID, ContactChange.INVALID_ID, NATIVE_ID));
assertTrue(pca.addNativeContact(contact));
// check that it exists
long[] ids = pca.getNativeContactsIds();
assertEquals(1, ids.length);
assertEquals(NATIVE_ID, ids[0]);
// get the contact back
final ContactChange[] savedContact = pca.getContact(NATIVE_ID);
assertNotNull(savedContact);
// compare with the original one
assertTrue(ContactChangeHelper.areChangeListsEqual(contact, savedContact, false));
}
use of com.vodafone360.people.engine.contactsync.ContactChange in project 360-Engine-for-Android by 360.
the class PeopleContactsApiTest method testUpdateGetNativeContact.
/**
* Tests the updateNativeContact() and getContact() methods.
*/
@Suppress
public void testUpdateGetNativeContact() {
final long NATIVE_ID = 15;
PeopleContactsApi pca = new PeopleContactsApi(mDatabaseHelper);
// the database is empty, it shall not return any ids
assertNull(pca.getNativeContactsIds());
// let's add a contact
ContactChange[] contact = filterContactChanges(ContactChangeHelper.randomContact(ContactChange.INVALID_ID, ContactChange.INVALID_ID, NATIVE_ID));
assertTrue(pca.addNativeContact(contact));
// check that it exists
long[] ids = pca.getNativeContactsIds();
assertEquals(1, ids.length);
assertEquals(NATIVE_ID, ids[0]);
// perform some updates to the contact
final ContactChange[] updatedDetails = ContactChangeHelper.randomContactUpdate(contact);
pca.updateNativeContact(updatedDetails);
// get the contact back
final ContactChange[] savedContact = pca.getContact(NATIVE_ID);
assertNotNull(savedContact);
// check that the needed updates have been performed
checkContactUpdates(contact, updatedDetails, savedContact);
}
use of com.vodafone360.people.engine.contactsync.ContactChange in project 360-Engine-for-Android by 360.
the class UpdateNativeContactsTest method testExportingContactAllDetails.
/**
* Tests the export of a new syncable contact with all the possible details combinations.
*/
public void testExportingContactAllDetails() {
UpdateNativeContacts processor = new UpdateNativeContacts(mContactSyncCallback, mDatabaseHelper);
// check that there are no contacts to sync
long[] syncableIds = mDatabaseHelper.getNativeSyncableContactsLocalIds();
assertEquals(null, syncableIds);
// put a contact that need to be synchronized to native side and that contains
// all the possible details that can be synchronized
final Contact contact = feedOneSyncableContact();
// check the count of the contacts to sync
syncableIds = mDatabaseHelper.getNativeSyncableContactsLocalIds();
assertEquals(1, syncableIds.length);
// run the UpdateNativeContacts processor until it finishes or it times out
runUpdateNativeContactsProcessor(processor);
// check that the contact on native side is equivalent
final NativeContactsApi nca = NativeContactsApi.getInstance();
long[] ids = null;
if (VersionUtils.is2XPlatform()) {
ids = nca.getContactIds(PEOPLE_ACCOUNT);
} else {
ids = nca.getContactIds(null);
}
assertEquals(1, ids.length);
// check that no more contact is syncable as the export is done
syncableIds = mDatabaseHelper.getNativeSyncableContactsLocalIds();
assertEquals(null, syncableIds);
final ContactChange[] contactChanges = nca.getContact(ids[0]);
assertTrue(compareContactWithContactChange(contact, contactChanges));
}
Aggregations