Search in sources :

Example 1 with NativeImporter

use of com.vodafone360.people.engine.contactsync.NativeImporter in project 360-Engine-for-Android by 360.

the class NativeImporterTest method performNativeImport.

/**
     * Performs a native import and checks that the needed ticks are as expected.
     * 
     * @param ncam the NativeContactsApiMockup instance
     * @param pcam the PeopleContactsApiMockup instance
     * @param contactsCount the number of native contacts to setup and import
     */
private void performNativeImport(NativeContactsApiMockup ncam, PeopleContactsApiMockup pcam, float contactsCount) {
    final NativeImporter nativeImporter = new NativeImporter(pcam, ncam, false);
    final float requiredTicks = 1 + (contactsCount / NATIVE_IMPORTER_MAX_OPERATION_COUNT) + (contactsCount % NATIVE_IMPORTER_MAX_OPERATION_COUNT > 0 ? 1 : 0);
    // feed the native side
    feedNativeContactsApi(ncam, contactsCount, null);
    final long[] nativeIds = ncam.getContactIds(null);
    assertEquals(contactsCount, nativeIds.length);
    // setup the people client side
    long[] peopleIds = pcam.getNativeContactsIds();
    assertNull(peopleIds);
    for (int i = 0; i < requiredTicks; i++) {
        // check the importer state
        assertEquals(NativeImporter.RESULT_UNDEFINED, nativeImporter.getResult());
        assertTrue(!nativeImporter.isDone());
        // perform an import tick
        nativeImporter.tick();
    }
    // check the importer state, it shall have finished the import
    assertEquals(NativeImporter.RESULT_OK, nativeImporter.getResult());
    assertTrue(nativeImporter.isDone());
    // check that all the native contacts are on the people client side
    peopleIds = pcam.getNativeContactsIds();
    assertEquals(contactsCount, peopleIds.length);
    for (int i = 0; i < peopleIds.length; i++) {
        final ContactChange[] peopleContact = pcam.getContact(peopleIds[i]);
        final ContactChange[] nativeContact = pcam.getContact(nativeIds[i]);
        assertTrue(ContactChangeHelper.areChangeListsEqual(peopleContact, nativeContact, false));
    }
}
Also used : NativeImporter(com.vodafone360.people.engine.contactsync.NativeImporter) ContactChange(com.vodafone360.people.engine.contactsync.ContactChange)

Example 2 with NativeImporter

use of com.vodafone360.people.engine.contactsync.NativeImporter in project 360-Engine-for-Android by 360.

the class FetchNativeContacts method onTimeoutEvent.

@Override
public void onTimeoutEvent() {
    LogUtils.logD("FetchNativeContacts.onTimeoutEvent()");
    // call the tick method of the NativeImporter
    final boolean isDone = mNativeImporter.tick();
    // get the index of the last processed id
    final int position = mNativeImporter.getPosition();
    // get the total count of ids to process
    final int total = mNativeImporter.getCount();
    // get the percentage out of position and total count
    final int percentage = (total != 0) ? ((position * 100) / total) : 100;
    LogUtils.logD("FetchNativeContacts.onTimeoutEvent() - pos=" + position + ", total=" + total + ", percentage=" + percentage);
    // check the NativeImporter progress
    if (!isDone) {
        // report the current progress
        // pass an empty name as currently the last processed contact name by the NativeImporter can't be known
        setProgress("", percentage, position, total);
        // yield some time to the other engines and request to be called back immediately
        setTimeout(0);
    } else {
        final ServiceStatus status = mNativeImporter.getResult() == NativeImporter.RESULT_OK ? ServiceStatus.SUCCESS : ServiceStatus.ERROR_UNKNOWN;
        LogUtils.logD("FetchNativeContacts.onTimeoutEvent() - complete(" + status + ")");
        setProgress("", percentage, position, total);
        complete(status);
    }
}
Also used : ServiceStatus(com.vodafone360.people.service.ServiceStatus)

Aggregations

ContactChange (com.vodafone360.people.engine.contactsync.ContactChange)1 NativeImporter (com.vodafone360.people.engine.contactsync.NativeImporter)1 ServiceStatus (com.vodafone360.people.service.ServiceStatus)1