Search in sources :

Example 6 with ContactChangeInfo

use of com.vodafone360.people.database.tables.NativeChangeLogTable.ContactChangeInfo in project 360-Engine-for-Android by 360.

the class NowPlusChangeLogTest method testServerDeleteContact.

/*
	@MediumTest
    public void testServerAddContact() {
		final String fnName = "testServerAddContact";
		mTestStep = 1;

		Log.i(LOG_TAG, "***** EXECUTING " + fnName + "*****");
		Log.i(LOG_TAG, "Adds a contact to the change log, validating all the way");
		
		startSubTest(fnName, "Creating table");
		createTable();

		startSubTest(fnName, "Check change log is empty");
		long noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 0);
		
		startSubTest(fnName, "Add new contact with null local ID to change log (error expected)");
		assertFalse(ContactChangeLogTable.addNewContactChange(null, mTestDatabase.getWritableDatabase()));

		startSubTest(fnName, "Add new contact to change log");
		final Long localContactId = mTestModule.GenerateRandomLong();
		assertTrue(ContactChangeLogTable.addNewContactChange(localContactId, mTestDatabase.getWritableDatabase()));

		startSubTest(fnName, "Checking change log now has 1 entry");
		noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 1);

		startSubTest(fnName, "Fetching new contact change log");
		final List<ContactChangeInfo> contactChangeList = new ArrayList<ContactChangeInfo>();
		assertTrue(ContactChangeLogTable.fetchContactChangeLog(contactChangeList, ContactChangeLogTable.ContactChangeType.NEW_CONTACT, 0, 1000, mTestDatabase.getReadableDatabase()));
		assertTrue(contactChangeList.size() == 1);

		startSubTest(fnName, "Checking new contact log data");
		ContactChangeInfo info = contactChangeList.get(0);
		assertTrue(info.mContactChangeId != null);
		assertTrue(info.mGroupOrRelId == null);
		assertEquals(info.mLocalContactId, localContactId);
		assertTrue(info.mLocalDetailId == null);
		assertTrue(info.mServerContactId == null);
		assertTrue(info.mServerDetailId == null);
		assertTrue(info.mServerDetailKey == null);
		assertEquals(info.mType, ContactChangeLogTable.ContactChangeType.NEW_CONTACT);

		startSubTest(fnName, "Clear new contact from change log");
		assertTrue(ContactChangeLogTable.deleteContactChanges(contactChangeList, mTestDatabase.getWritableDatabase()));
			
		startSubTest(fnName, "Verfy change log is now empty");
		noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 0);
		
		Log.i(LOG_TAG, "***********************************************");
		Log.i(LOG_TAG, fnName + " has completed successfully");
		Log.i(LOG_TAG, "***********************************************");
		Log.i(LOG_TAG, "");
	}
*/
@MediumTest
public void testServerDeleteContact() {
    final String fnName = "testServerDeleteContact";
    mTestStep = 1;
    Log.i(LOG_TAG, "***** EXECUTING " + fnName + "*****");
    Log.i(LOG_TAG, "Deletes a contact to the change log, validating all the way");
    startSubTest(fnName, "Creating table");
    createTable();
    startSubTest(fnName, "Check change log is empty");
    long noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
    assertTrue(noOfChanges == 0);
    startSubTest(fnName, "Add contact deletion with null local ID to change log (error expected) - part 1");
    assertFalse(ContactChangeLogTable.addDeletedContactChange(null, null, false, mTestDatabase.getWritableDatabase()));
    startSubTest(fnName, "Add contact deletion with null local ID to change log (error expected) - part 2");
    assertFalse(ContactChangeLogTable.addDeletedContactChange(null, null, true, mTestDatabase.getWritableDatabase()));
    startSubTest(fnName, "Contact deletion without adding to change log - null server ID (when new contact is not in list)");
    final Long localContactId = TestModule.generateRandomLong();
    assertTrue(ContactChangeLogTable.addDeletedContactChange(localContactId, null, false, mTestDatabase.getWritableDatabase()));
    startSubTest(fnName, "Verify change log is unchanged");
    noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
    assertTrue(noOfChanges == 0);
    startSubTest(fnName, "Add contact deletion to change log with null server ID (when new contact is not in list) (should do nothing)");
    assertTrue(ContactChangeLogTable.addDeletedContactChange(localContactId, null, true, mTestDatabase.getWritableDatabase()));
    startSubTest(fnName, "Verify change log is unchanged");
    noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
    assertTrue(noOfChanges == 0);
    startSubTest(fnName, "Delete contact when not adding to change log (empty change log)");
    final Long serverContactId = TestModule.generateRandomLong();
    assertTrue(ContactChangeLogTable.addDeletedContactChange(localContactId, serverContactId, false, mTestDatabase.getWritableDatabase()));
    startSubTest(fnName, "Verify change log is unchanged");
    noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
    assertTrue(noOfChanges == 0);
    startSubTest(fnName, "Delete contact when adding to change log (empty change log)");
    assertTrue(ContactChangeLogTable.addDeletedContactChange(localContactId, serverContactId, true, mTestDatabase.getWritableDatabase()));
    startSubTest(fnName, "Verify change log has 1 entry");
    noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
    assertTrue(noOfChanges == 1);
    startSubTest(fnName, "Delete contact when adding to change log with server ID (empty change log)");
    assertTrue(ContactChangeLogTable.addDeletedContactChange(localContactId, serverContactId, true, mTestDatabase.getWritableDatabase()));
    startSubTest(fnName, "Verify change log still has 1 entry");
    noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
    assertTrue(noOfChanges == 1);
    startSubTest(fnName, "Fetching change log");
    final List<ContactChangeInfo> contactChangeList = new ArrayList<ContactChangeInfo>();
    assertTrue(ContactChangeLogTable.fetchContactChangeLog(contactChangeList, ContactChangeLogTable.ContactChangeType.DELETE_CONTACT, 0, 1000, mTestDatabase.getReadableDatabase()));
    assertTrue(contactChangeList.size() == 1);
    startSubTest(fnName, "Checking deleted contact log data");
    ContactChangeInfo info = contactChangeList.get(0);
    assertTrue(info.mContactChangeId != null);
    assertTrue(info.mGroupOrRelId == null);
    assertEquals(info.mLocalContactId, localContactId);
    assertTrue(info.mLocalDetailId == null);
    assertEquals(info.mServerContactId, serverContactId);
    assertTrue(info.mServerDetailId == null);
    assertTrue(info.mServerDetailKey == null);
    assertEquals(info.mType, ContactChangeLogTable.ContactChangeType.DELETE_CONTACT);
    startSubTest(fnName, "Clear change log");
    assertTrue(ContactChangeLogTable.deleteContactChanges(contactChangeList, mTestDatabase.getWritableDatabase()));
    startSubTest(fnName, "Verfy change log is now empty");
    noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
    assertTrue(noOfChanges == 0);
    startSubTest(fnName, "Add contact deleted log...");
    assertTrue(ContactChangeLogTable.addDeletedContactChange(localContactId, serverContactId, true, mTestDatabase.getWritableDatabase()));
    startSubTest(fnName, "Followed by contact deleted again");
    assertTrue(ContactChangeLogTable.addDeletedContactChange(localContactId, serverContactId, true, mTestDatabase.getWritableDatabase()));
    startSubTest(fnName, "Check change log has now 1 entry");
    noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
    assertTrue(noOfChanges == 1);
    startSubTest(fnName, "Fetching change log");
    assertTrue(ContactChangeLogTable.fetchContactChangeLog(contactChangeList, ContactChangeLogTable.ContactChangeType.DELETE_CONTACT, 0, 1000, mTestDatabase.getReadableDatabase()));
    assertTrue(contactChangeList.size() == 1);
    startSubTest(fnName, "Clear delete contact from change log");
    assertTrue(ContactChangeLogTable.deleteContactChanges(contactChangeList, mTestDatabase.getWritableDatabase()));
    startSubTest(fnName, "Verify change log is now empty");
    noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
    assertTrue(noOfChanges == 0);
    Log.i(LOG_TAG, "*************************************************************************");
    Log.i(LOG_TAG, fnName + " has completed successfully");
    Log.i(LOG_TAG, "*************************************************************************");
    Log.i(LOG_TAG, "");
}
Also used : ContactChangeInfo(com.vodafone360.people.database.tables.ContactChangeLogTable.ContactChangeInfo) ArrayList(java.util.ArrayList) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 7 with ContactChangeInfo

use of com.vodafone360.people.database.tables.NativeChangeLogTable.ContactChangeInfo in project 360-Engine-for-Android by 360.

the class NowPlusChangeLogTest method testServerDeleteContactDetail.

/*
	@MediumTest
    public void testServerAddContactDetail() {
		final String fnName = "testServerAddContactDetail";
		mTestStep = 1;

		Log.i(LOG_TAG, "***** EXECUTING " + fnName + "*****");
		Log.i(LOG_TAG, "Add new contact details to the change log, validating all the way");
		
		startSubTest(fnName, "Creating table");
		createTable();

		startSubTest(fnName, "Check change log is empty");
		long noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 0);
		
		startSubTest(fnName, "Add contact detail with null local contact ID to change log (error expected)");
		final Long serverContactId = mTestModule.GenerateRandomLong();
		ContactDetail testDetail = mTestModule.createDummyDetailsName();
		ContactDetail testDetail2 = new ContactDetail();
		testDetail.localDetailID = mTestModule.GenerateRandomLong();
		testDetail2.localDetailID = testDetail.localDetailID;
		testDetail2.key = testDetail.key;
		assertFalse(ContactChangeLogTable.addNewContactDetailChange(testDetail2, serverContactId, mTestDatabase.getWritableDatabase()));

		startSubTest(fnName, "Add contact detail with null local detail ID to change log (error expected)");
		testDetail.localContactID = mTestModule.GenerateRandomLong();
		testDetail2.localDetailID = null;
		assertFalse(ContactChangeLogTable.addNewContactDetailChange(testDetail2, serverContactId, mTestDatabase.getWritableDatabase()));

		startSubTest(fnName, "Add contact detail with null key to change log (error expected)");
		testDetail2.localDetailID = testDetail.localDetailID;
		testDetail2.key = null;
		assertFalse(ContactChangeLogTable.addNewContactDetailChange(testDetail2, serverContactId, mTestDatabase.getWritableDatabase()));

		startSubTest(fnName, "Check change log is still empty");
		noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 0);

		startSubTest(fnName, "Add valid contact detail to change log");
		assertTrue(ContactChangeLogTable.addNewContactDetailChange(testDetail, serverContactId, mTestDatabase.getWritableDatabase()));

		startSubTest(fnName, "Check change log has now 1 entry");
		noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 1);

		startSubTest(fnName, "Fetching new detail change log");
		final List<ContactChangeInfo> contactChangeList = new ArrayList<ContactChangeInfo>();
		assertTrue(ContactChangeLogTable.fetchContactChangeLog(contactChangeList, ContactChangeLogTable.ContactChangeType.NEW_DETAIL, 0, 1000, mTestDatabase.getReadableDatabase()));
		assertTrue(contactChangeList.size() == 1);

		startSubTest(fnName, "Checking change log data");
		ContactChangeInfo info = contactChangeList.get(0);
		assertTrue(info.mContactChangeId != null);
		assertTrue(info.mGroupOrRelId == null);
		assertEquals(info.mLocalContactId, testDetail.localContactID);
		assertEquals(info.mLocalDetailId, testDetail.localDetailID);
		assertEquals(info.mServerContactId, serverContactId);
		assertTrue(info.mServerDetailId == null);
		assertEquals(info.mServerDetailKey, testDetail.key);
		assertEquals(info.mType, ContactChangeLogTable.ContactChangeType.NEW_DETAIL);

		startSubTest(fnName, "Clear new contact from change log");
		assertTrue(ContactChangeLogTable.deleteContactChanges(contactChangeList, mTestDatabase.getWritableDatabase()));
			
		startSubTest(fnName, "Verfy change log is now empty");
		noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 0);
		
		startSubTest(fnName, "Add contact detail with null server contact ID to change log when add contact is not in list (should add a new contact change)");
		assertTrue(ContactChangeLogTable.addNewContactDetailChange(testDetail, null, mTestDatabase.getWritableDatabase()));

		startSubTest(fnName, "Check change log has now 1 entry");
		noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 1);

		startSubTest(fnName, "Fetching new detail change log");
		assertTrue(ContactChangeLogTable.fetchContactChangeLog(contactChangeList, ContactChangeLogTable.ContactChangeType.NEW_CONTACT, 0, 1000, mTestDatabase.getReadableDatabase()));
		assertTrue(contactChangeList.size() == 1);
		assertEquals(contactChangeList.get(0).mLocalContactId, testDetail.localContactID);
		
		startSubTest(fnName, "Clear new contact from change log");
		assertTrue(ContactChangeLogTable.deleteContactChanges(contactChangeList, mTestDatabase.getWritableDatabase()));
			
		startSubTest(fnName, "Verfy change log is now empty");
		noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 0);

		startSubTest(fnName, "Add new contact log...");
		assertTrue(ContactChangeLogTable.addNewContactChange(testDetail.localContactID, mTestDatabase.getWritableDatabase()));
		
		startSubTest(fnName, "Followed by new detail log with no server ID");
		assertTrue(ContactChangeLogTable.addNewContactDetailChange(testDetail, null, mTestDatabase.getWritableDatabase()));

		startSubTest(fnName, "Check change log has now 2 entries");
		noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 2);

		startSubTest(fnName, "Fetching new detail change log");
		assertTrue(ContactChangeLogTable.fetchContactChangeLog(contactChangeList, ContactChangeLogTable.ContactChangeType.NEW_DETAIL, 0, 1000, mTestDatabase.getReadableDatabase()));
		assertTrue(contactChangeList.size() == 1);

		startSubTest(fnName, "Checking change log data");
		info = contactChangeList.get(0);
		assertTrue(info.mContactChangeId != null);
		assertTrue(info.mGroupOrRelId == null);
		assertEquals(info.mLocalContactId, testDetail.localContactID);
		assertEquals(info.mLocalDetailId, testDetail.localDetailID);
		assertTrue(info.mServerContactId == null);
		assertEquals(info.mServerDetailId, testDetail.unique_id);
		assertEquals(info.mServerDetailKey, testDetail.key);
		assertEquals(info.mType, ContactChangeLogTable.ContactChangeType.NEW_DETAIL);

		startSubTest(fnName, "Clear new detail from change log");
		assertTrue(ContactChangeLogTable.deleteContactChanges(contactChangeList, mTestDatabase.getWritableDatabase()));
			
		startSubTest(fnName, "Fetching new contact change log");
		assertTrue(ContactChangeLogTable.fetchContactChangeLog(contactChangeList, ContactChangeLogTable.ContactChangeType.NEW_CONTACT, 0, 1000, mTestDatabase.getReadableDatabase()));
		assertTrue(contactChangeList.size() == 1);

		startSubTest(fnName, "Clear new contact from change log");
		assertTrue(ContactChangeLogTable.deleteContactChanges(contactChangeList, mTestDatabase.getWritableDatabase()));

		startSubTest(fnName, "Verfy change log is now empty");
		noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 0);

		startSubTest(fnName, "Add contact deleted log...");
		assertTrue(ContactChangeLogTable.addDeletedContactChange(testDetail.localContactID, serverContactId, true, mTestDatabase.getWritableDatabase()));
		
		startSubTest(fnName, "Followed by new detail log (error expected)");
		assertFalse(ContactChangeLogTable.addNewContactDetailChange(testDetail, serverContactId, mTestDatabase.getWritableDatabase()));

		startSubTest(fnName, "Check change log has now 1 entry");
		noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 1);

		startSubTest(fnName, "Fetching change log");
		assertTrue(ContactChangeLogTable.fetchContactChangeLog(contactChangeList, ContactChangeLogTable.ContactChangeType.DELETE_CONTACT, 0, 1000, mTestDatabase.getReadableDatabase()));
		assertTrue(contactChangeList.size() == 1);

		startSubTest(fnName, "Clear delete contact from change log");
		assertTrue(ContactChangeLogTable.deleteContactChanges(contactChangeList, mTestDatabase.getWritableDatabase()));

		startSubTest(fnName, "Verfy change log is now empty");
		noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 0);

		Log.i(LOG_TAG, "*************************************************************************");
		Log.i(LOG_TAG, fnName + " has completed successfully");
		Log.i(LOG_TAG, "*************************************************************************");
		Log.i(LOG_TAG, "");
    }

	@MediumTest
    public void testServerModifyContactDetail() {
		final String fnName = "testServerModifyContactDetail";
		mTestStep = 1;

		Log.i(LOG_TAG, "***** EXECUTING " + fnName + "*****");
		Log.i(LOG_TAG, "Add contact details modifications to the change log, validating all the way");
		
		startSubTest(fnName, "Creating table");
		createTable();

		startSubTest(fnName, "Check change log is empty");
		long noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 0);
		
		startSubTest(fnName, "Add contact detail with null local contact ID to change log (error expected)");
		final Long serverContactId = mTestModule.GenerateRandomLong();
		ContactDetail testDetail = mTestModule.createDummyDetailsName();
		ContactDetail testDetail2 = new ContactDetail();
		testDetail.localDetailID = mTestModule.GenerateRandomLong();
		testDetail2.localDetailID = testDetail.localDetailID;
		testDetail2.key = testDetail.key;
		assertFalse(ContactChangeLogTable.addModifiedContactDetailChange(testDetail, serverContactId, false, mTestDatabase.getWritableDatabase()));
		assertFalse(ContactChangeLogTable.addModifiedContactDetailChange(testDetail, serverContactId, true, mTestDatabase.getWritableDatabase()));

		startSubTest(fnName, "Add contact detail with null local detail ID to change log (error expected)");
		testDetail.localContactID = mTestModule.GenerateRandomLong();
		testDetail2.localDetailID = null;
		assertFalse(ContactChangeLogTable.addModifiedContactDetailChange(testDetail2, serverContactId, false, mTestDatabase.getWritableDatabase()));
		assertFalse(ContactChangeLogTable.addModifiedContactDetailChange(testDetail2, serverContactId, true, mTestDatabase.getWritableDatabase()));

		startSubTest(fnName, "Add contact detail with null key to change log (error expected)");
		testDetail2.localDetailID = testDetail.localDetailID;
		testDetail2.key = null;
		assertFalse(ContactChangeLogTable.addModifiedContactDetailChange(testDetail2, serverContactId, false, mTestDatabase.getWritableDatabase()));
		assertFalse(ContactChangeLogTable.addModifiedContactDetailChange(testDetail2, serverContactId, true, mTestDatabase.getWritableDatabase()));

		startSubTest(fnName, "Check change log is still empty");
		noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 0);

		startSubTest(fnName, "Add modified contact detail change to change log with no unique ID");
		assertTrue(ContactChangeLogTable.addModifiedContactDetailChange(testDetail, serverContactId, false, mTestDatabase.getWritableDatabase()));
		assertTrue(ContactChangeLogTable.addModifiedContactDetailChange(testDetail, serverContactId, true, mTestDatabase.getWritableDatabase()));

		startSubTest(fnName, "Check change log has now 1 entry");
		noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 1);

		startSubTest(fnName, "Fetching new detail change log");
		final List<ContactChangeInfo> contactChangeList = new ArrayList<ContactChangeInfo>();
		assertTrue(ContactChangeLogTable.fetchContactChangeLog(contactChangeList, ContactChangeLogTable.ContactChangeType.MODIFY_DETAIL, 0, 1000, mTestDatabase.getReadableDatabase()));
		assertTrue(contactChangeList.size() == 1);

		startSubTest(fnName, "Checking change log data");
		ContactChangeInfo info = contactChangeList.get(0);
		assertTrue(info.mContactChangeId != null);
		assertTrue(info.mGroupOrRelId == null);
		assertEquals(info.mLocalContactId, testDetail.localContactID);
		assertEquals(info.mLocalDetailId, testDetail.localDetailID);
		assertEquals(info.mServerContactId, serverContactId);
		assertTrue(info.mServerDetailId == null);
		assertEquals(info.mServerDetailKey, testDetail.key);
		assertEquals(info.mType, ContactChangeLogTable.ContactChangeType.MODIFY_DETAIL);

		startSubTest(fnName, "Clear change log");
		assertTrue(ContactChangeLogTable.deleteContactChanges(contactChangeList, mTestDatabase.getWritableDatabase()));
			
		startSubTest(fnName, "Verify change log is now empty");
		noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 0);
		
		startSubTest(fnName, "Add modified contact detail change to change log with unique ID");
		testDetail.unique_id = mTestModule.GenerateRandomLong();
		assertTrue(ContactChangeLogTable.addModifiedContactDetailChange(testDetail, serverContactId, false, mTestDatabase.getWritableDatabase()));
		assertTrue(ContactChangeLogTable.addModifiedContactDetailChange(testDetail, serverContactId, true, mTestDatabase.getWritableDatabase()));

		startSubTest(fnName, "Check change log has now 1 entry");
		noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 1);

		startSubTest(fnName, "Fetching new detail change log");
		assertTrue(ContactChangeLogTable.fetchContactChangeLog(contactChangeList, ContactChangeLogTable.ContactChangeType.MODIFY_DETAIL, 0, 1000, mTestDatabase.getReadableDatabase()));
		assertTrue(contactChangeList.size() == 1);

		startSubTest(fnName, "Checking change log data");
		info = contactChangeList.get(0);
		assertTrue(info.mContactChangeId != null);
		assertTrue(info.mGroupOrRelId == null);
		assertEquals(info.mLocalContactId, testDetail.localContactID);
		assertEquals(info.mLocalDetailId, testDetail.localDetailID);
		assertEquals(info.mServerContactId, serverContactId);
		assertEquals(info.mServerDetailId, testDetail.unique_id);
		assertEquals(info.mServerDetailKey, testDetail.key);
		assertEquals(info.mType, ContactChangeLogTable.ContactChangeType.MODIFY_DETAIL);

		startSubTest(fnName, "Clear change log");
		assertTrue(ContactChangeLogTable.deleteContactChanges(contactChangeList, mTestDatabase.getWritableDatabase()));

		startSubTest(fnName, "Verfy change log is now empty");
		noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 0);

		startSubTest(fnName, "Add contact detail with null server contact ID to change log when add contact is not in list (should add a new contact change)");
		assertTrue(ContactChangeLogTable.addNewContactDetailChange(testDetail, null, mTestDatabase.getWritableDatabase()));

		startSubTest(fnName, "Check change log has now 1 entry");
		noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 1);

		startSubTest(fnName, "Fetching new detail change log");
		assertTrue(ContactChangeLogTable.fetchContactChangeLog(contactChangeList, ContactChangeLogTable.ContactChangeType.NEW_CONTACT, 0, 1000, mTestDatabase.getReadableDatabase()));
		assertTrue(contactChangeList.size() == 1);
		assertEquals(contactChangeList.get(0).mLocalContactId, testDetail.localContactID);
		
		startSubTest(fnName, "Clear new contact from change log");
		assertTrue(ContactChangeLogTable.deleteContactChanges(contactChangeList, mTestDatabase.getWritableDatabase()));
			
		startSubTest(fnName, "Verify change log is now empty");
		noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 0);

		startSubTest(fnName, "Add new contact log...");
		assertTrue(ContactChangeLogTable.addNewContactChange(testDetail.localContactID, mTestDatabase.getWritableDatabase()));
		
		startSubTest(fnName, "Followed by modified detail log with no server ID");
		assertTrue(ContactChangeLogTable.addModifiedContactDetailChange(testDetail, null, true, mTestDatabase.getWritableDatabase()));

		startSubTest(fnName, "Check change log has now 2 entries");
		noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 2);

		startSubTest(fnName, "Fetching change log");
		assertTrue(ContactChangeLogTable.fetchContactChangeLog(contactChangeList, ContactChangeLogTable.ContactChangeType.MODIFY_DETAIL, 0, 1000, mTestDatabase.getReadableDatabase()));
		assertTrue(contactChangeList.size() == 1);

		startSubTest(fnName, "Checking change log data");
		info = contactChangeList.get(0);
		assertTrue(info.mContactChangeId != null);
		assertTrue(info.mGroupOrRelId == null);
		assertEquals(info.mLocalContactId, testDetail.localContactID);
		assertEquals(info.mLocalDetailId, testDetail.localDetailID);
		assertTrue(info.mServerContactId == null);
		assertEquals(info.mServerDetailId, testDetail.unique_id);
		assertEquals(info.mServerDetailKey, testDetail.key);
		assertEquals(info.mType, ContactChangeLogTable.ContactChangeType.MODIFY_DETAIL);

		startSubTest(fnName, "Clear modify detail from change log");
		assertTrue(ContactChangeLogTable.deleteContactChanges(contactChangeList, mTestDatabase.getWritableDatabase()));
			
		startSubTest(fnName, "Fetching new contact change log");
		assertTrue(ContactChangeLogTable.fetchContactChangeLog(contactChangeList, ContactChangeLogTable.ContactChangeType.NEW_CONTACT, 0, 1000, mTestDatabase.getReadableDatabase()));
		assertTrue(contactChangeList.size() == 1);

		startSubTest(fnName, "Clear new contact from change log");
		assertTrue(ContactChangeLogTable.deleteContactChanges(contactChangeList, mTestDatabase.getWritableDatabase()));

		startSubTest(fnName, "Verfy change log is now empty");
		noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 0);

		startSubTest(fnName, "Add contact deleted log...");
		assertTrue(ContactChangeLogTable.addDeletedContactChange(testDetail.localContactID, serverContactId, true, mTestDatabase.getWritableDatabase()));
		
		startSubTest(fnName, "Followed by modify detail log");
		assertFalse(ContactChangeLogTable.addModifiedContactDetailChange(testDetail, serverContactId, true, mTestDatabase.getWritableDatabase()));

		startSubTest(fnName, "Check change log has now 1 entry");
		noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 1);

		startSubTest(fnName, "Fetching change log");
		assertTrue(ContactChangeLogTable.fetchContactChangeLog(contactChangeList, ContactChangeLogTable.ContactChangeType.DELETE_CONTACT, 0, 1000, mTestDatabase.getReadableDatabase()));
		assertTrue(contactChangeList.size() == 1);

		startSubTest(fnName, "Clear delete contact from change log");
		assertTrue(ContactChangeLogTable.deleteContactChanges(contactChangeList, mTestDatabase.getWritableDatabase()));

		startSubTest(fnName, "Verify change log is now empty");
		noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 0);
		
		startSubTest(fnName, "Add contact detail deleted log...");
		assertTrue(ContactChangeLogTable.addDeletedContactDetailChange(testDetail, serverContactId, true, mTestDatabase.getWritableDatabase()));
		
		startSubTest(fnName, "Followed by modify detail log (error expected)");
		assertFalse(ContactChangeLogTable.addModifiedContactDetailChange(testDetail, serverContactId, true, mTestDatabase.getWritableDatabase()));

		startSubTest(fnName, "Check change log has now 1 entry");
		noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 1);

		startSubTest(fnName, "Fetching change log");
		assertTrue(ContactChangeLogTable.fetchContactChangeLog(contactChangeList, ContactChangeLogTable.ContactChangeType.DELETE_DETAIL, 0, 1000, mTestDatabase.getReadableDatabase()));
		assertTrue(contactChangeList.size() == 1);

		startSubTest(fnName, "Clear delete contact detail from change log");
		assertTrue(ContactChangeLogTable.deleteContactChanges(contactChangeList, mTestDatabase.getWritableDatabase()));

		startSubTest(fnName, "Verify change log is now empty");
		noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 0);

		Log.i(LOG_TAG, "*************************************************************************");
		Log.i(LOG_TAG, fnName + " has completed successfully");
		Log.i(LOG_TAG, "*************************************************************************");
		Log.i(LOG_TAG, "");
    }
*/
@MediumTest
public void testServerDeleteContactDetail() {
    final String fnName = "testServerDeleteContactDetail";
    mTestStep = 1;
    Log.i(LOG_TAG, "***** EXECUTING " + fnName + "*****");
    Log.i(LOG_TAG, "Add contact details deletions to the change log, validating all the way");
    startSubTest(fnName, "Creating table");
    createTable();
    startSubTest(fnName, "Check change log is empty");
    long noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
    assertTrue(noOfChanges == 0);
    startSubTest(fnName, "Add contact detail deletion with null local contact ID to change log (error expected)");
    final Long serverContactId = TestModule.generateRandomLong();
    ContactDetail testDetail = mTestModule.createDummyDetailsName();
    ContactDetail testDetail2 = new ContactDetail();
    testDetail.localDetailID = TestModule.generateRandomLong();
    testDetail2.localDetailID = testDetail.localDetailID;
    testDetail2.key = testDetail.key;
    testDetail2.serverContactId = serverContactId;
    testDetail.serverContactId = serverContactId;
    assertFalse(ContactChangeLogTable.addDeletedContactDetailChange(testDetail2, false, mTestDatabase.getWritableDatabase()));
    assertFalse(ContactChangeLogTable.addDeletedContactDetailChange(testDetail2, true, mTestDatabase.getWritableDatabase()));
    startSubTest(fnName, "Add contact detail deletion with null local detail ID to change log (error expected)");
    testDetail.localContactID = TestModule.generateRandomLong();
    testDetail2.localContactID = testDetail.localContactID;
    testDetail2.localDetailID = null;
    assertFalse(ContactChangeLogTable.addDeletedContactDetailChange(testDetail2, false, mTestDatabase.getWritableDatabase()));
    assertFalse(ContactChangeLogTable.addDeletedContactDetailChange(testDetail2, true, mTestDatabase.getWritableDatabase()));
    startSubTest(fnName, "Add contact detail deletion with null key to change log (error expected)");
    testDetail2.localDetailID = testDetail.localDetailID;
    testDetail2.key = null;
    assertFalse(ContactChangeLogTable.addDeletedContactDetailChange(testDetail2, false, mTestDatabase.getWritableDatabase()));
    assertFalse(ContactChangeLogTable.addDeletedContactDetailChange(testDetail2, true, mTestDatabase.getWritableDatabase()));
    startSubTest(fnName, "Check change log is still empty");
    noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
    assertTrue(noOfChanges == 0);
    startSubTest(fnName, "Add deleted contact detail change to change log with no unique ID");
    assertTrue(ContactChangeLogTable.addDeletedContactDetailChange(testDetail, false, mTestDatabase.getWritableDatabase()));
    assertTrue(ContactChangeLogTable.addDeletedContactDetailChange(testDetail, true, mTestDatabase.getWritableDatabase()));
    startSubTest(fnName, "Check change log has now 1 entry");
    noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
    assertTrue(noOfChanges == 1);
    startSubTest(fnName, "Fetching change log");
    final List<ContactChangeInfo> contactChangeList = new ArrayList<ContactChangeInfo>();
    assertTrue(ContactChangeLogTable.fetchContactChangeLog(contactChangeList, ContactChangeLogTable.ContactChangeType.DELETE_DETAIL, 0, 1000, mTestDatabase.getReadableDatabase()));
    assertTrue(contactChangeList.size() == 1);
    startSubTest(fnName, "Checking change log data");
    ContactChangeInfo info = contactChangeList.get(0);
    assertTrue(info.mContactChangeId != null);
    assertTrue(info.mGroupOrRelId == null);
    assertEquals(info.mLocalContactId, testDetail.localContactID);
    assertEquals(info.mLocalDetailId, testDetail.localDetailID);
    assertEquals(info.mServerContactId, serverContactId);
    assertTrue(info.mServerDetailId == null);
    assertEquals(info.mServerDetailKey, testDetail.key);
    assertEquals(info.mType, ContactChangeLogTable.ContactChangeType.DELETE_DETAIL);
    startSubTest(fnName, "Clear change log");
    assertTrue(ContactChangeLogTable.deleteContactChanges(contactChangeList, mTestDatabase.getWritableDatabase()));
    startSubTest(fnName, "Verify change log is now empty");
    noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
    assertTrue(noOfChanges == 0);
    startSubTest(fnName, "Add deleted contact detail change to change log with unique ID");
    testDetail.unique_id = TestModule.generateRandomLong();
    assertTrue(ContactChangeLogTable.addDeletedContactDetailChange(testDetail, false, mTestDatabase.getWritableDatabase()));
    assertTrue(ContactChangeLogTable.addDeletedContactDetailChange(testDetail, true, mTestDatabase.getWritableDatabase()));
    startSubTest(fnName, "Check change log has now 1 entry");
    noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
    assertTrue(noOfChanges == 1);
    startSubTest(fnName, "Fetching new detail change log");
    assertTrue(ContactChangeLogTable.fetchContactChangeLog(contactChangeList, ContactChangeLogTable.ContactChangeType.DELETE_DETAIL, 0, 1000, mTestDatabase.getReadableDatabase()));
    assertTrue(contactChangeList.size() == 1);
    startSubTest(fnName, "Checking change log data");
    info = contactChangeList.get(0);
    assertTrue(info.mContactChangeId != null);
    assertTrue(info.mGroupOrRelId == null);
    assertEquals(info.mLocalContactId, testDetail.localContactID);
    assertEquals(info.mLocalDetailId, testDetail.localDetailID);
    assertEquals(info.mServerContactId, serverContactId);
    assertEquals(info.mServerDetailId, testDetail.unique_id);
    assertEquals(info.mServerDetailKey, testDetail.key);
    assertEquals(info.mType, ContactChangeLogTable.ContactChangeType.DELETE_DETAIL);
    startSubTest(fnName, "Clear change log");
    assertTrue(ContactChangeLogTable.deleteContactChanges(contactChangeList, mTestDatabase.getWritableDatabase()));
    startSubTest(fnName, "Verfy change log is now empty");
    noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
    assertTrue(noOfChanges == 0);
    startSubTest(fnName, "Add contact deleted log...");
    assertTrue(ContactChangeLogTable.addDeletedContactChange(testDetail.localContactID, serverContactId, true, mTestDatabase.getWritableDatabase()));
    startSubTest(fnName, "Followed by delete detail log (error expected)");
    assertFalse(ContactChangeLogTable.addDeletedContactDetailChange(testDetail, true, mTestDatabase.getWritableDatabase()));
    startSubTest(fnName, "Check change log has now 1 entry");
    noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
    assertTrue(noOfChanges == 1);
    startSubTest(fnName, "Fetching change log");
    assertTrue(ContactChangeLogTable.fetchContactChangeLog(contactChangeList, ContactChangeLogTable.ContactChangeType.DELETE_CONTACT, 0, 1000, mTestDatabase.getReadableDatabase()));
    assertTrue(contactChangeList.size() == 1);
    startSubTest(fnName, "Clear delete contact from change log");
    assertTrue(ContactChangeLogTable.deleteContactChanges(contactChangeList, mTestDatabase.getWritableDatabase()));
    startSubTest(fnName, "Verfy change log is now empty");
    noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
    assertTrue(noOfChanges == 0);
    startSubTest(fnName, "Add contact detail deleted log...");
    assertTrue(ContactChangeLogTable.addDeletedContactDetailChange(testDetail, true, mTestDatabase.getWritableDatabase()));
    startSubTest(fnName, "Followed by detail deleted log again");
    assertFalse(ContactChangeLogTable.addDeletedContactDetailChange(testDetail, true, mTestDatabase.getWritableDatabase()));
    startSubTest(fnName, "Check change log has now 1 entry");
    noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
    assertTrue(noOfChanges == 1);
    startSubTest(fnName, "Fetching change log");
    assertTrue(ContactChangeLogTable.fetchContactChangeLog(contactChangeList, ContactChangeLogTable.ContactChangeType.DELETE_DETAIL, 0, 1000, mTestDatabase.getReadableDatabase()));
    assertTrue(contactChangeList.size() == 1);
    startSubTest(fnName, "Clear delete contact detail from change log");
    assertTrue(ContactChangeLogTable.deleteContactChanges(contactChangeList, mTestDatabase.getWritableDatabase()));
    startSubTest(fnName, "Verfy change log is now empty");
    noOfChanges = ContactChangeLogTable.fetchNoOfContactDetailChanges(null, mTestDatabase.getReadableDatabase());
    assertTrue(noOfChanges == 0);
    Log.i(LOG_TAG, "*************************************************************************");
    Log.i(LOG_TAG, fnName + " has completed successfully");
    Log.i(LOG_TAG, "*************************************************************************");
    Log.i(LOG_TAG, "");
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) ContactChangeInfo(com.vodafone360.people.database.tables.ContactChangeLogTable.ContactChangeInfo) ArrayList(java.util.ArrayList) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 8 with ContactChangeInfo

use of com.vodafone360.people.database.tables.NativeChangeLogTable.ContactChangeInfo in project 360-Engine-for-Android by 360.

the class UploadServerContacts method sendNextAddGroupRelationsPage.

/**
 * Sends next add contact/group relation request to the server. Many
 * contacts can be added by a single request.
 */
private void sendNextAddGroupRelationsPage() {
    ContactChangeInfo info = null;
    mActiveGroupId = null;
    mContactIdList.clear();
    mContactChangeInfoList.clear();
    List<ContactChangeInfo> groupInfoList = new ArrayList<ContactChangeInfo>();
    long startTime = System.nanoTime();
    if (!ContactChangeLogTable.fetchContactChangeLog(groupInfoList, ContactChangeType.ADD_GROUP_REL, 0, MAX_UP_PAGE_SIZE, mDb.getReadableDatabase())) {
        LogUtils.logE("UploadServerContacts." + "sendNextAddGroupRelationsPage() Unable to fetch add " + "group relations from database");
        complete(ServiceStatus.ERROR_DATABASE_CORRUPT);
        return;
    }
    mDbSyncTime += (System.nanoTime() - startTime);
    if (groupInfoList.size() == 0) {
        moveToNextState();
        return;
    }
    mContactChangeInfoList.clear();
    List<ContactChangeInfo> deleteInfoList = new ArrayList<ContactChangeInfo>();
    for (int i = 0; i < groupInfoList.size(); i++) {
        info = groupInfoList.get(i);
        if (info.mServerContactId == null) {
            info.mServerContactId = mDb.fetchServerId(info.mLocalContactId);
        }
        if (info.mServerContactId != null && info.mGroupOrRelId != null) {
            if (mActiveGroupId == null) {
                mActiveGroupId = info.mGroupOrRelId;
            }
            if (info.mGroupOrRelId.equals(mActiveGroupId)) {
                mContactIdList.add(info.mServerContactId);
                mContactChangeInfoList.add(info);
            }
            continue;
        }
        LogUtils.logE("UploadServerContact.sendNextAddGroupRelationsPage() " + "Invalid add group change: SID = " + info.mServerContactId + ", gid=" + info.mGroupOrRelId);
        deleteInfoList.add(info);
    }
    mDb.deleteContactChanges(deleteInfoList);
    if (mActiveGroupId == null) {
        moveToNextState();
        return;
    }
    mGroupList.clear();
    GroupItem group = new GroupItem();
    group.mId = mActiveGroupId;
    mGroupList.add(group);
    if (NetworkAgent.getAgentState() != NetworkAgent.AgentState.CONNECTED) {
        complete(NetworkAgent.getServiceStatusfromDisconnectReason());
        return;
    }
    mNoOfItemsSent = mGroupList.size();
    setReqId(GroupPrivacy.addContactGroupRelations(getEngine(), mContactIdList, mGroupList));
}
Also used : ContactChangeInfo(com.vodafone360.people.database.tables.ContactChangeLogTable.ContactChangeInfo) ArrayList(java.util.ArrayList) GroupItem(com.vodafone360.people.datatypes.GroupItem)

Example 9 with ContactChangeInfo

use of com.vodafone360.people.database.tables.NativeChangeLogTable.ContactChangeInfo in project 360-Engine-for-Android by 360.

the class UploadServerContacts method sendNextDeleteContactsPage.

/**
 * Sends the next page of deleted contacts to the server.
 */
private void sendNextDeleteContactsPage() {
    mContactChangeInfoList.clear();
    long startTime = System.nanoTime();
    if (!ContactChangeLogTable.fetchContactChangeLog(mContactChangeInfoList, ContactChangeType.DELETE_CONTACT, 0, MAX_UP_PAGE_SIZE, mDb.getReadableDatabase())) {
        LogUtils.logE("UploadServerContacts.sendNextDeleteContactsPage() " + "Unable to fetch contact changes from database");
        complete(ServiceStatus.ERROR_DATABASE_CORRUPT);
        return;
    }
    mDbSyncTime += (System.nanoTime() - startTime);
    if (mContactChangeInfoList.size() == 0) {
        moveToNextState();
        return;
    }
    mContactIdList.clear();
    for (ContactChangeInfo info : mContactChangeInfoList) {
        if (info.mServerContactId != null) {
            mContactIdList.add(info.mServerContactId);
        }
    }
    if (mContactIdList.size() == 0) {
        startTime = System.nanoTime();
        mDb.deleteContactChanges(mContactChangeInfoList);
        mDbSyncTime += (System.nanoTime() - startTime);
        moveToNextState();
        return;
    }
    /**
     * Debug output. *
     */
    if (Settings.ENABLED_CONTACTS_SYNC_TRACE) {
        LogUtils.logI("UploadServerContacts.sendNextDeleteContactsPage() " + "Contacts deleted:");
        for (Long id : mContactIdList) {
            LogUtils.logI("UploadServerContacts." + "sendNextDeleteContactsPage() Contact Id: " + id);
        }
    }
    if (NetworkAgent.getAgentState() != NetworkAgent.AgentState.CONNECTED) {
        complete(NetworkAgent.getServiceStatusfromDisconnectReason());
        return;
    }
    mNoOfItemsSent = mContactIdList.size();
    setReqId(Contacts.deleteContacts(getEngine(), mContactIdList));
}
Also used : ContactChangeInfo(com.vodafone360.people.database.tables.ContactChangeLogTable.ContactChangeInfo)

Example 10 with ContactChangeInfo

use of com.vodafone360.people.database.tables.NativeChangeLogTable.ContactChangeInfo in project 360-Engine-for-Android by 360.

the class UploadServerContacts method sendNextDeleteDetailsPage.

/**
 * Sends the next deleted details to the server. This has to be done one
 * contact at a time.
 */
private void sendNextDeleteDetailsPage() {
    mContactChangeInfoList.clear();
    long startTime = System.nanoTime();
    List<ContactChangeInfo> groupInfoList = new ArrayList<ContactChangeInfo>();
    if (!ContactChangeLogTable.fetchContactChangeLog(groupInfoList, ContactChangeType.DELETE_DETAIL, 0, MAX_UP_PAGE_SIZE, mDb.getReadableDatabase())) {
        LogUtils.logE("UploadServerContacts.sendNextDeleteDetailsPage() " + "Unable to fetch contact changes from database");
        complete(ServiceStatus.ERROR_DATABASE_CORRUPT);
        return;
    }
    mDbSyncTime += (System.nanoTime() - startTime);
    if (groupInfoList.size() == 0) {
        moveToNextState();
        return;
    }
    mDeleteDetailContact = new Contact();
    List<ContactChangeInfo> deleteInfoList = new ArrayList<ContactChangeInfo>();
    int i = 0;
    for (i = 0; i < groupInfoList.size(); i++) {
        ContactChangeInfo info = groupInfoList.get(i);
        if (info.mServerContactId == null) {
            info.mServerContactId = mDb.fetchServerId(info.mLocalContactId);
        }
        if (info.mServerContactId != null) {
            mDeleteDetailContact.localContactID = info.mLocalContactId;
            mDeleteDetailContact.contactID = info.mServerContactId;
            break;
        }
        deleteInfoList.add(info);
        info.mLocalContactId = null;
    }
    mDb.deleteContactChanges(deleteInfoList);
    if (mDeleteDetailContact.contactID == null) {
        moveToNextState();
        return;
    }
    mContactChangeInfoList.clear();
    for (; i < groupInfoList.size(); i++) {
        ContactChangeInfo info = groupInfoList.get(i);
        if (info.mLocalContactId != null && info.mLocalContactId.equals(mDeleteDetailContact.localContactID)) {
            final ContactDetail detail = new ContactDetail();
            detail.localDetailID = info.mLocalDetailId;
            detail.key = info.mServerDetailKey;
            detail.unique_id = info.mServerDetailId;
            mDeleteDetailContact.details.add(detail);
            mContactChangeInfoList.add(info);
        }
    }
    /**
     * Debug output. *
     */
    if (Settings.ENABLED_CONTACTS_SYNC_TRACE) {
        LogUtils.logI("UploadServerContacts.sendNextDeleteDetailsPage() " + "Contact details for deleting:");
        for (ContactDetail detail : mDeleteDetailContact.details) {
            LogUtils.logI("UploadServerContacts." + "sendNextDeleteDetailsPage() Contact ID: " + mDeleteDetailContact.contactID + ", detail = " + detail.key + ", unique_id = " + detail.unique_id);
        }
    }
    if (NetworkAgent.getAgentState() != NetworkAgent.AgentState.CONNECTED) {
        complete(NetworkAgent.getServiceStatusfromDisconnectReason());
        return;
    }
    mNoOfItemsSent = mDeleteDetailContact.details.size();
    setReqId(Contacts.deleteContactDetails(getEngine(), mDeleteDetailContact.contactID, mDeleteDetailContact.details));
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) ContactChangeInfo(com.vodafone360.people.database.tables.ContactChangeLogTable.ContactChangeInfo) ArrayList(java.util.ArrayList) Contact(com.vodafone360.people.datatypes.Contact)

Aggregations

ContactChangeInfo (com.vodafone360.people.database.tables.ContactChangeLogTable.ContactChangeInfo)11 ArrayList (java.util.ArrayList)10 MediumTest (android.test.suitebuilder.annotation.MediumTest)6 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)5 Cursor (android.database.Cursor)2 ContactChangeInfo (com.vodafone360.people.database.tables.NativeChangeLogTable.ContactChangeInfo)2 ServiceStatus (com.vodafone360.people.service.ServiceStatus)2 Contact (com.vodafone360.people.datatypes.Contact)1 ContactDetailDeletion (com.vodafone360.people.datatypes.ContactDetailDeletion)1 ContactListResponse (com.vodafone360.people.datatypes.ContactListResponse)1 GroupItem (com.vodafone360.people.datatypes.GroupItem)1