use of com.vodafone360.people.database.DatabaseHelper.ServerIdInfo in project 360-Engine-for-Android by 360.
the class NowPlusContactDetailsTableTest method testsyncSetServerIds.
@MediumTest
public void testsyncSetServerIds() {
final String fnName = "testsyncSetServerIds";
mTestStep = 1;
Log.i(LOG_TAG, "***** EXECUTING " + fnName + "*****");
Log.i(LOG_TAG, "Validates syncSetServerIds details");
SQLiteDatabase writeableDb = mTestDatabase.getWritableDatabase();
SQLiteDatabase readableDb = mTestDatabase.getReadableDatabase();
startSubTest(fnName, "Creating table");
createTable();
List<ServerIdInfo> detailServerIdList = new ArrayList<ServerIdInfo>();
List<ContactDetail> detailsList = new ArrayList<ContactDetail>();
for (int i = 0; i < NUM_OF_CONTACTS; i++) {
ContactDetail detail = new ContactDetail();
detail.localContactID = TestModule.generateRandomLong();
mTestModule.createDummyDetailsData(detail);
ContactDetailsTable.addContactDetail(detail, true, true, writeableDb);
ServerIdInfo serverInfo = new ServerIdInfo();
serverInfo.localId = detail.localDetailID;
serverInfo.serverId = TestModule.generateRandomLong();
detailServerIdList.add(serverInfo);
detailsList.add(detail);
}
ServiceStatus status = ContactDetailsTable.syncSetServerIds(detailServerIdList, writeableDb);
assertEquals(ServiceStatus.SUCCESS, status);
for (int i = 0; i < NUM_OF_CONTACTS; i++) {
ContactDetail fetchedDetail = ContactDetailsTable.fetchDetail(detailsList.get(i).localDetailID, readableDb);
assertNotNull(fetchedDetail);
assertEquals(detailServerIdList.get(i).serverId, fetchedDetail.unique_id);
}
Log.i(LOG_TAG, "***********************************************");
Log.i(LOG_TAG, fnName + " has completed successfully");
Log.i(LOG_TAG, "***********************************************");
}
use of com.vodafone360.people.database.DatabaseHelper.ServerIdInfo in project 360-Engine-for-Android by 360.
the class NowPlusContactsTableTest method testServerSyncMethods.
@MediumTest
public void testServerSyncMethods() {
final String fnName = "testServerSyncMethods";
mTestStep = 1;
Log.i(LOG_TAG, "***** EXECUTING " + fnName + "*****");
Log.i(LOG_TAG, "Validates server sync methods");
SQLiteDatabase writeableDb = mTestDatabase.getWritableDatabase();
SQLiteDatabase readableDb = mTestDatabase.getReadableDatabase();
startSubTest(fnName, "Creating table");
createTable();
// add contacts and populate contactServerIdList
List<ServerIdInfo> contactServerIdList = new ArrayList<ServerIdInfo>();
final long contactIdBase = TestModule.generateRandomLong();
for (int i = 0; i < NUM_OF_CONTACTS; i++) {
Contact c = mTestModule.createDummyContactData();
if (i == 2) {
// Add duplicate server ID in database
c.contactID = contactIdBase;
}
c.userID = TestModule.generateRandomLong();
ServiceStatus status = ContactsTable.addContact(c, writeableDb);
assertEquals(ServiceStatus.SUCCESS, status);
ServerIdInfo serverInfo = new ServerIdInfo();
serverInfo.localId = c.localContactID;
serverInfo.serverId = contactIdBase + i;
serverInfo.userId = c.userID;
contactServerIdList.add(serverInfo);
}
// Add duplicate server ID in list from server
Contact duplicateContact = mTestModule.createDummyContactData();
duplicateContact.userID = TestModule.generateRandomLong();
ServiceStatus status = ContactsTable.addContact(duplicateContact, writeableDb);
assertEquals(ServiceStatus.SUCCESS, status);
ServerIdInfo serverInfo = new ServerIdInfo();
serverInfo.localId = duplicateContact.localContactID;
serverInfo.serverId = contactIdBase + 1;
serverInfo.userId = duplicateContact.userID;
contactServerIdList.add(serverInfo);
List<ContactIdInfo> dupList = new ArrayList<ContactIdInfo>();
status = ContactsTable.syncSetServerIds(contactServerIdList, dupList, writeableDb);
assertEquals(ServiceStatus.SUCCESS, status);
// fetch server ids
HashSet<Long> serverIds = new HashSet<Long>();
status = ContactsTable.fetchContactServerIdList(serverIds, readableDb);
assertEquals(ServiceStatus.SUCCESS, status);
// validate if lists have the same sizes
assertEquals(2, dupList.size());
assertEquals(contactServerIdList.size() - 2, serverIds.size());
assertEquals(Long.valueOf(dupList.get(0).localId), contactServerIdList.get(0).localId);
assertEquals(contactServerIdList.get(0).serverId, dupList.get(0).serverId);
assertEquals(duplicateContact.localContactID, Long.valueOf(dupList.get(1).localId));
assertEquals(Long.valueOf(contactIdBase + 1), dupList.get(1).serverId);
// Need to convert HashSet into an Arraylist, otherwise it's not possible to compare
// HashSet is not sorted!
ArrayList<Long> serverIdsArrayList = new ArrayList<Long>(serverIds);
Collections.sort(serverIdsArrayList);
final Iterator<Long> serverIdsIt = serverIdsArrayList.iterator();
for (int i = 1; i < contactServerIdList.size() - 1; i++) {
Long actServerId = serverIdsIt.next();
assertEquals(contactServerIdList.get(i).serverId, actServerId);
}
Log.i(LOG_TAG, "***********************************************");
Log.i(LOG_TAG, fnName + " has completed successfully");
Log.i(LOG_TAG, "***********************************************");
Log.i(LOG_TAG, "");
}
use of com.vodafone360.people.database.DatabaseHelper.ServerIdInfo in project 360-Engine-for-Android by 360.
the class NowPlusContactsTest method testAddContactDetail.
@SmallTest
@Suppress
public void testAddContactDetail() {
assertTrue(initialise());
mDatabaseHelper.removeUserData();
ServiceStatus status = mTestUtility.waitForEvent(WAIT_EVENT_TIMEOUT_MS, DbTestUtility.CONTACTS_INT_EVENT_MASK);
assertEquals(ServiceStatus.SUCCESS, status);
Contact addedContact = new Contact();
status = mDatabaseHelper.addContact(addedContact);
assertEquals(ServiceStatus.SUCCESS, status);
ContactDetail detail = new ContactDetail();
mTestModule.createDummyDetailsData(detail);
detail.localContactID = addedContact.localContactID;
status = mDatabaseHelper.addContactDetail(detail);
assertEquals(ServiceStatus.SUCCESS, status);
ContactDetail fetchedDetail = new ContactDetail();
status = mDatabaseHelper.fetchContactDetail(detail.localDetailID, fetchedDetail);
assertEquals(ServiceStatus.SUCCESS, status);
assertTrue(DatabaseHelper.doDetailsMatch(detail, fetchedDetail));
assertTrue(!DatabaseHelper.hasDetailChanged(detail, fetchedDetail));
assertEquals(ServiceStatus.SUCCESS, mDatabaseHelper.deleteAllGroups());
List<ServerIdInfo> serverIdList = new ArrayList<ServerIdInfo>();
ServerIdInfo info = new ServerIdInfo();
info.localId = fetchedDetail.localDetailID;
info.serverId = fetchedDetail.localDetailID + 1;
serverIdList.add(info);
status = ContactDetailsTable.syncSetServerIds(serverIdList, mDatabaseHelper.getWritableDatabase());
assertEquals(ServiceStatus.SUCCESS, status);
status = mDatabaseHelper.fetchContactDetail(detail.localDetailID, fetchedDetail);
assertEquals(ServiceStatus.SUCCESS, status);
assertEquals(info.serverId, fetchedDetail.unique_id);
shutdown();
}
use of com.vodafone360.people.database.DatabaseHelper.ServerIdInfo in project 360-Engine-for-Android by 360.
the class UploadServerContacts method processModifiedDetailsResp.
/**
* Called when a server response is received during a modified contact sync.
* The server ID, user ID and contact detail unique IDs are extracted from
* the response and the NowPlus database updated if necessary. Possibly
* server errors are also handled.
*
* @param resp Response from server.
*/
private void processModifiedDetailsResp(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> 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;
}
status = handleUploadDetailChanges(itContactSrc.next(), itContactDest.next(), detailServerIdList);
}
if (status != ServiceStatus.SUCCESS) {
/**
* Something is going wrong - cancel the update. *
*/
complete(status);
return;
}
long startTime = System.nanoTime();
status = ContactDetailsTable.syncSetServerIds(detailServerIdList, mDb.getWritableDatabase());
if (status != ServiceStatus.SUCCESS) {
complete(status);
return;
}
mDb.deleteContactChanges(mContactChangeInfoList);
mDbSyncTime += (System.nanoTime() - startTime);
mContactChangeInfoList.clear();
updateProgress();
sendNextDetailChangesPage();
return;
}
LogUtils.logE("UploadServerContacts.processModifiedDetailsResp() " + "Error requesting contact changes, error = " + status);
complete(status);
}
use of com.vodafone360.people.database.DatabaseHelper.ServerIdInfo in project 360-Engine-for-Android by 360.
the class UploadServerContacts method handleUploadDetailChanges.
/**
* Called when handling the server response from a new contact or modify
* contact sync. Updates the unique IDs for all the details if necessary.
*
* @param contactSrc Contact received from server.
* @param contactDest Contact from database.
* @param detailServerIdList List of contact details with updated unique id.
* @return ServiceStatus object.
*/
private ServiceStatus handleUploadDetailChanges(final Contact contactSrc, final Contact contactDest, final List<ServerIdInfo> detailServerIdList) {
if (contactSrc.contactID == null || contactSrc.contactID.longValue() == -1L) {
LogUtils.logE("UploadServerContacts.handleUploadDetailChanges() " + "The server failed to modify the following contact: " + contactDest.localContactID);
mFailureList += "Failed to add contact: " + contactDest.localContactID + "\n";
return ServiceStatus.SUCCESS;
}
ListIterator<ContactDetail> itContactDetailSrc = contactSrc.details.listIterator();
ListIterator<ContactDetail> itContactDetailDest = contactDest.details.listIterator();
while (itContactDetailSrc.hasNext()) {
if (!itContactDetailDest.hasNext()) {
/*
* The response should contain the same number of details as was
* supplied but must handle the error.
*/
return ServiceStatus.ERROR_COMMS_BAD_RESPONSE;
}
ContactDetail contactDetailSrc = itContactDetailSrc.next();
ContactDetail contactDetailDest = itContactDetailDest.next();
ServerIdInfo info = new ServerIdInfo();
info.localId = contactDetailDest.localDetailID;
if (contactDetailSrc.unique_id != null && contactDetailSrc.unique_id.longValue() == -1L) {
LogUtils.logE("UploadServerContacts." + "handleUploadDetailChanges() The server failed to " + "modify the following contact detail: LocalDetailId " + "= " + contactDetailDest.localDetailID + ", Key = " + contactDetailDest.key + ", value = " + contactDetailDest.value);
mFailureList += "Failed to modify contact detail: " + contactDetailDest.localDetailID + ", for contact " + contactDetailDest.localContactID + "\n";
info.serverId = null;
} else {
info.serverId = contactDetailSrc.unique_id;
}
detailServerIdList.add(info);
}
while (itContactDetailDest.hasNext()) {
ContactDetail contactDetailDest = itContactDetailDest.next();
mFailureList += "Failed to modify contact detail (not in return " + "list):" + contactDetailDest.localDetailID + ", for contact " + contactDetailDest.localContactID + "\n";
LogUtils.logE("UploadServerContacts.handleUploadDetailChanges() " + "The server failed to modify the following contact detail " + "(not found in returned list): LocalDetailId = " + contactDetailDest.localDetailID + ", Key = " + contactDetailDest.key + ", value = " + contactDetailDest.value);
}
return ServiceStatus.SUCCESS;
}
Aggregations