Search in sources :

Example 11 with ContactChangeInfo

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

the class UploadServerContacts method sendNextDelGroupRelationsPage.

/**
 * Sends next delete contact/group relation request to the server.
 */
private void sendNextDelGroupRelationsPage() {
    ContactChangeInfo info = null;
    mActiveGroupId = null;
    mContactChangeInfoList.clear();
    List<ContactChangeInfo> groupInfoList = new ArrayList<ContactChangeInfo>();
    long startTime = System.nanoTime();
    if (!ContactChangeLogTable.fetchContactChangeLog(groupInfoList, ContactChangeType.DELETE_GROUP_REL, 0, MAX_UP_PAGE_SIZE, mDb.getReadableDatabase())) {
        LogUtils.logE("UploadServerContacts." + "sendNextDelGroupRelationsPage() Unable to fetch delete " + "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 (mActiveGroupId.equals(info.mGroupOrRelId)) {
                mContactIdList.add(info.mServerContactId);
                mContactChangeInfoList.add(info);
            }
            continue;
        }
        LogUtils.logE("UploadServerContact.sendNextDelGroupRelationsPage() " + "Invalid delete group change: SID = " + info.mServerContactId + ", gid=" + info.mGroupOrRelId);
        deleteInfoList.add(info);
    }
    mDb.deleteContactChanges(deleteInfoList);
    if (mActiveGroupId == null) {
        moveToNextState();
        return;
    }
    if (NetworkAgent.getAgentState() != NetworkAgent.AgentState.CONNECTED) {
        complete(NetworkAgent.getServiceStatusfromDisconnectReason());
        return;
    }
    mNoOfItemsSent = mContactIdList.size();
    setReqId(GroupPrivacy.deleteContactGroupRelationsExt(getEngine(), mActiveGroupId, mContactIdList));
}
Also used : ContactChangeInfo(com.vodafone360.people.database.tables.ContactChangeLogTable.ContactChangeInfo) ArrayList(java.util.ArrayList)

Example 12 with ContactChangeInfo

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

the class UploadServerContacts method processDeletedContactsResp.

/**
 * Called when a server response is received during a deleted contact sync.
 * The server change log is updated. Possibly server errors are also
 * handled.
 *
 * @param resp Response from server.
 */
private void processDeletedContactsResp(final DecodedResponse resp) {
    ServiceStatus status = BaseEngine.getResponseStatus(BaseDataType.CONTACT_LIST_RESPONSE_DATA_TYPE, resp.mDataTypes);
    if (status == ServiceStatus.SUCCESS) {
        ContactListResponse result = (ContactListResponse) resp.mDataTypes.get(0);
        ListIterator<ContactChangeInfo> infoIt = mContactChangeInfoList.listIterator();
        for (Integer contactID : result.mContactIdList) {
            if (!infoIt.hasNext()) {
                complete(ServiceStatus.ERROR_COMMS_BAD_RESPONSE);
                return;
            }
            ContactChangeInfo info = infoIt.next();
            if (contactID == null || contactID.intValue() == -1) {
                LogUtils.logE("UploadServerContacts." + "processDeletedContactsResp() The server failed " + "to delete the following contact: LocalId = " + info.mLocalContactId + ", ServerId = " + info.mServerContactId);
                mFailureList += "Failed to delete contact: " + info.mLocalContactId + "\n";
            }
        }
        long startTime = System.nanoTime();
        mDb.deleteContactChanges(mContactChangeInfoList);
        mDbSyncTime += (System.nanoTime() - startTime);
        mContactChangeInfoList.clear();
        updateProgress();
        sendNextDeleteContactsPage();
        return;
    }
    LogUtils.logE("UploadServerContacts.processModifiedDetailsResp() " + "Error requesting contact changes, error = " + status);
    complete(status);
}
Also used : ContactChangeInfo(com.vodafone360.people.database.tables.ContactChangeLogTable.ContactChangeInfo) ServiceStatus(com.vodafone360.people.service.ServiceStatus) ContactListResponse(com.vodafone360.people.datatypes.ContactListResponse)

Example 13 with ContactChangeInfo

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

the class NowPlusNativeChangeTableTest 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 = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
		assertTrue(noOfChanges == 0);
		
		startSubTest(fnName, "Add new contact with null local ID to change log (error expected)");
		assertFalse(NativeChangeLogTable.addNewContactChange(null, mTestDatabase.getWritableDatabase()));

		startSubTest(fnName, "Add new contact to change log");
		final List<Long> changeIdxList = new ArrayList<Long>();
		Long localContactID = mTestModule.GenerateRandomLong();
		assertTrue(NativeChangeLogTable.addNewContactChange(localContactID, mTestDatabase.getWritableDatabase()));

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

		startSubTest(fnName, "Fetching new contact change log");
		Cursor cursor = NativeChangeLogTable.fetchContactChangeLogCursor(NativeChangeLogTable.ContactChangeType.NEW_CONTACT, mTestDatabase.getReadableDatabase());
		assertTrue(cursor != null);
		assertTrue(cursor.getCount() == 1);
		assertTrue(cursor.moveToFirst());

		startSubTest(fnName, "Checking new contact log data");
		ContactChangeInfo info = NativeChangeLogTable.getQueryData(cursor);
		assertTrue(info.mNativeChangeId != null);
		assertEquals(info.mLocalContactId, localContactID);
		assertTrue(info.mLocalDetailId == null);
		assertTrue(info.mNativeContactId == null);
		assertTrue(info.mNativeDetailId == null);
		assertEquals(info.mType, NativeChangeLogTable.ContactChangeType.NEW_CONTACT);
		changeIdxList.add(info.mNativeChangeId);
		cursor.close();
		
		startSubTest(fnName, "Clear new contact from change log");
		assertTrue(NativeChangeLogTable.syncDeleteNativeChangeLog(changeIdxList, mTestDatabase.getWritableDatabase()));
			
		startSubTest(fnName, "Verfy change log is now empty");
		noOfChanges = NativeChangeLogTable.fetchNoOfChanges(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 = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
    assertTrue(noOfChanges == 0);
    startSubTest(fnName, "Add contact deletion with null local ID to change log (error expected)");
    assertFalse(NativeChangeLogTable.addDeletedContactChange(null, null, mTestDatabase.getWritableDatabase()));
    startSubTest(fnName, "Add contact deletion to change log with null native ID (when new contact is not in list) (should do nothing)");
    final List<Long> changeIdxList = new ArrayList<Long>();
    final Long localContactId = TestModule.generateRandomLong();
    assertTrue(NativeChangeLogTable.addDeletedContactChange(localContactId, null, mTestDatabase.getWritableDatabase()));
    startSubTest(fnName, "Verify change log is unchanged");
    noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
    assertTrue(noOfChanges == 0);
    startSubTest(fnName, "Put delete contact in empty change log with native Id");
    final Integer nativeId = TestModule.generateRandomInt();
    assertTrue(NativeChangeLogTable.addDeletedContactChange(localContactId, nativeId, mTestDatabase.getWritableDatabase()));
    startSubTest(fnName, "Verify change log has 1 entry");
    noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
    assertTrue(noOfChanges == 1);
    startSubTest(fnName, "Put delete contact in change log with native ID again");
    assertTrue(NativeChangeLogTable.addDeletedContactChange(localContactId, nativeId, mTestDatabase.getWritableDatabase()));
    startSubTest(fnName, "Verify change log still has 1 entry");
    noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
    assertTrue(noOfChanges == 1);
    startSubTest(fnName, "Fetching change log");
    Cursor cursor = NativeChangeLogTable.fetchContactChangeLogCursor(NativeChangeLogTable.ContactChangeType.DELETE_CONTACT, mTestDatabase.getReadableDatabase());
    assertTrue(cursor != null);
    assertTrue(cursor.getCount() == 1);
    assertTrue(cursor.moveToFirst());
    startSubTest(fnName, "Checking log data");
    ContactChangeInfo info = NativeChangeLogTable.getQueryData(cursor);
    assertTrue(info.mNativeChangeId != null);
    assertEquals(info.mLocalContactId, localContactId);
    assertTrue(info.mLocalDetailId == null);
    assertEquals(info.mNativeContactId, nativeId);
    assertTrue(info.mNativeDetailId == null);
    assertEquals(info.mType, NativeChangeLogTable.ContactChangeType.DELETE_CONTACT);
    changeIdxList.add(info.mNativeChangeId);
    cursor.close();
    startSubTest(fnName, "Clear change log");
    assertTrue(NativeChangeLogTable.syncDeleteNativeChangeLog(changeIdxList, mTestDatabase.getWritableDatabase()));
    changeIdxList.clear();
    startSubTest(fnName, "Verfy change log is now empty");
    noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
    assertTrue(noOfChanges == 0);
    startSubTest(fnName, "Add contact deleted log...");
    assertTrue(NativeChangeLogTable.addDeletedContactChange(localContactId, nativeId, mTestDatabase.getWritableDatabase()));
    startSubTest(fnName, "Followed by contact deleted again");
    assertTrue(NativeChangeLogTable.addDeletedContactChange(localContactId, nativeId, mTestDatabase.getWritableDatabase()));
    startSubTest(fnName, "Check change log has now 1 entry");
    noOfChanges = NativeChangeLogTable.fetchNoOfChanges(null, mTestDatabase.getReadableDatabase());
    assertTrue(noOfChanges == 1);
    startSubTest(fnName, "Fetching change log");
    cursor = NativeChangeLogTable.fetchContactChangeLogCursor(NativeChangeLogTable.ContactChangeType.DELETE_CONTACT, mTestDatabase.getReadableDatabase());
    assertTrue(cursor != null);
    assertTrue(cursor.getCount() == 1);
    assertTrue(cursor.moveToFirst());
    startSubTest(fnName, "Checking log data");
    info = NativeChangeLogTable.getQueryData(cursor);
    assertTrue(info.mNativeChangeId != null);
    assertEquals(info.mLocalContactId, localContactId);
    assertTrue(info.mLocalDetailId == null);
    assertEquals(info.mNativeContactId, nativeId);
    assertTrue(info.mNativeDetailId == null);
    assertEquals(info.mType, NativeChangeLogTable.ContactChangeType.DELETE_CONTACT);
    changeIdxList.add(info.mNativeChangeId);
    cursor.close();
    startSubTest(fnName, "Clear change log");
    assertTrue(NativeChangeLogTable.syncDeleteNativeChangeLog(changeIdxList, mTestDatabase.getWritableDatabase()));
    changeIdxList.clear();
    startSubTest(fnName, "Verfy change log is now empty");
    noOfChanges = NativeChangeLogTable.fetchNoOfChanges(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.NativeChangeLogTable.ContactChangeInfo) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) MediumTest(android.test.suitebuilder.annotation.MediumTest)

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