Search in sources :

Example 1 with ContactSyncEngine

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

the class EngineManager method createContactSyncEngine.

private synchronized void createContactSyncEngine() {
    final MainApplication app = (MainApplication) mService.getApplication();
    mContactSyncEngine = new ContactSyncEngine(mService, mUiEventCallback, app.getDatabase(), null);
    addEngine(mContactSyncEngine);
}
Also used : ContactSyncEngine(com.vodafone360.people.engine.contactsync.ContactSyncEngine) MainApplication(com.vodafone360.people.MainApplication)

Example 2 with ContactSyncEngine

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

the class ContactSyncEngineTest method setUpContactSyncEngineTestFramework.

/**
 * Sets up the test framework.
 *
 * @param factory the factory used by the ContactSyncEngine
 * @param observer the test framework observer
 */
private void setUpContactSyncEngineTestFramework(IEngineTestFrameworkObserver observer, ProcessorFactory factory) {
    mEngineTester = new EngineTestFramework(observer);
    mContactSyncEngine = new ContactSyncEngine(mApplication.getApplicationContext(), mEngineTester, mApplication.getDatabase(), factory);
    mContactSyncEngine.onCreate();
    mEngineTester.setEngine(mContactSyncEngine);
}
Also used : EngineTestFramework(com.vodafone360.people.tests.engine.EngineTestFramework) ContactSyncEngine(com.vodafone360.people.engine.contactsync.ContactSyncEngine)

Example 3 with ContactSyncEngine

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

the class GroupPrivacy method addContactGroupRelations.

/**
 * Implementation of groupprivacy/addcontactgrouprelations API. Parameters
 * are; [auth], List<Long> contactidlist, List<Group> grouplist
 *
 * @param engine handle to ContactSyncEngine
 * @param contactidlist List of contacts ids associated with this request.
 * @param grouplist List of groups associated with this request.
 * @return request id generated for this request
 */
public static int addContactGroupRelations(BaseEngine engine, List<Long> contactidlist, List<GroupItem> grouplist) {
    if (LoginEngine.getSession() == null) {
        LogUtils.logE("GroupPrivacy.addContactGroupRelations() Invalid session, return -1");
        return -1;
    }
    if (contactidlist == null) {
        LogUtils.logE("GroupPrivacy.addContactGroupRelations() contactidlist cannot be NULL");
        return -1;
    }
    if (grouplist == null) {
        LogUtils.logE("GroupPrivacy.addContactGroupRelations() grouplist cannot be NULL");
        return -1;
    }
    Request request = new Request(FUNCTION_ADD_CONTACT_GROUP_RELATIONS, Request.Type.CONTACT_GROUP_RELATIONS, engine.engineId(), false, Settings.API_REQUESTS_TIMEOUT_GROUP_PRIVACY);
    request.addData("contactidlist", new Vector<Object>(contactidlist));
    request.addData("grouplist", ApiUtils.createVectorOfGroup(grouplist));
    QueueManager queue = QueueManager.getInstance();
    int requestId = queue.addRequest(request);
    queue.fireQueueStateChanged();
    return requestId;
}
Also used : Request(com.vodafone360.people.service.io.Request) QueueManager(com.vodafone360.people.service.io.QueueManager)

Example 4 with ContactSyncEngine

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

the class ContactSyncEngineTest method testNativeSync_newEngineInstantiation.

/**
 * Tests that the native sync is scheduled and performed after a first time
 * sync then a re-instantiation of the ContactSyncEngine.
 */
@Suppress
public // Breaks tests.
void testNativeSync_newEngineInstantiation() {
    Log.i(LOG_TAG, "**** testNativeSync_newEngineInstantiation() begin ****");
    final ArrayList<ProcessorLog> processorLogs = new ArrayList<ProcessorLog>();
    final UiEventCall uiEventCall = new UiEventCall();
    final IEngineEventCallback engineEventCallback = new HelperClasses.EngineCallbackBase() {

        @Override
        public void onUiEvent(ServiceUiRequest event, int request, int status, Object data) {
            Log.i(LOG_TAG, "onUiEvent: " + event + ", " + request + ", " + status + ", " + data);
            uiEventCall.event = event.ordinal();
            uiEventCall.request = request;
            uiEventCall.status = status;
            uiEventCall.data = data;
        }
    };
    final ProcessorFactory factory = new ProcessorFactory() {

        @Override
        public BaseSyncProcessor create(int type, IContactSyncCallback callback, DatabaseHelper dbHelper) {
            Log.i(LOG_TAG, "create(), type=" + type);
            ProcessorLog log = new ProcessorLog();
            log.type = type;
            log.time = System.currentTimeMillis();
            processorLogs.add(log);
            return new DummySyncProcessor(mContactSyncEngine, null);
        }
    };
    minimalEngineSetup(engineEventCallback, factory);
    // set the connection to be fine
    NetworkAgent.setAgentState(NetworkAgent.AgentState.CONNECTED);
    long nextRuntime = mContactSyncEngine.getNextRunTime();
    // should be equal to -1 because first time sync has not been yet
    // started
    assertEquals(-1, mContactSyncEngine.getNextRunTime());
    // force a first time sync
    mContactSyncEngine.addUiStartFullSync();
    nextRuntime = mContactSyncEngine.getNextRunTime();
    // next runtime should be now
    assertEquals(0, nextRuntime);
    // perform the first time sync
    mContactSyncEngine.run();
    // check that first time sync is completed
    assertEquals(ServiceUiRequest.UI_REQUEST_COMPLETE.ordinal(), uiEventCall.event);
    assertEquals(uiEventCall.status, ServiceStatus.SUCCESS.ordinal());
    // destroy the engine
    mContactSyncEngine.onDestroy();
    mContactSyncEngine = null;
    // create a new ContactSyncEngine
    minimalEngineSetup(engineEventCallback, factory);
    processorLogs.clear();
    // check sync is scheduled within 30 seconds
    nextRuntime = mContactSyncEngine.getNextRunTime();
    assertTrue(isValueInsideErrorMargin(30000, nextRuntime - System.currentTimeMillis(), 5));
    final long timeBeforeWait = System.currentTimeMillis();
    // call run() and check that nothing is performed
    mContactSyncEngine.run();
    assertEquals(0, processorLogs.size());
    // wait until we get the nextRuntime to now
    boolean isNextRuntimeNow = false;
    while (!isNextRuntimeNow) {
        try {
            long timeToWait = mContactSyncEngine.getNextRunTime();
            timeToWait = (timeToWait <= 0) ? 0 : timeToWait - System.currentTimeMillis();
            if (timeToWait > 0) {
                synchronized (this) {
                    Log.i(LOG_TAG, "timeToWait=" + timeToWait);
                    wait(timeToWait);
                }
            }
            if (mContactSyncEngine.getNextRunTime() < System.currentTimeMillis()) {
                isNextRuntimeNow = true;
            }
        } catch (Exception e) {
            Log.e(LOG_TAG, "testAllSyncsAfterFirstTimeSync(): error while waiting for the runtime now");
        }
    }
    long timeAfterWait = System.currentTimeMillis();
    // check that we have waited about 30 seconds
    assertTrue(isValueInsideErrorMargin(timeAfterWait - timeBeforeWait, 30000, 5));
    // call run() until the sync is performed
    final long startTime = System.currentTimeMillis();
    while (processorLogs.size() < 3) {
        if (System.currentTimeMillis() - startTime > TEST_TIMEOUT) {
            fail("It seems that the engine is stuck, the processor logs should contain 3 objects by now!");
        }
        mContactSyncEngine.run();
    }
    // check processor calls
    ProcessorLog log;
    assertEquals(3, processorLogs.size());
    log = processorLogs.get(0);
    assertEquals(ProcessorFactory.FETCH_NATIVE_CONTACTS, log.type);
    log = processorLogs.get(1);
    assertEquals(ProcessorFactory.UPLOAD_SERVER_CONTACTS, log.type);
    log = processorLogs.get(2);
    assertEquals(ProcessorFactory.UPDATE_NATIVE_CONTACTS, log.type);
    Log.i(LOG_TAG, "**** testNativeSync_newEngineInstantiation() end ****");
}
Also used : ArrayList(java.util.ArrayList) ServiceUiRequest(com.vodafone360.people.service.ServiceUiRequest) DatabaseHelper(com.vodafone360.people.database.DatabaseHelper) ProcessorFactory(com.vodafone360.people.engine.contactsync.ProcessorFactory) IContactSyncCallback(com.vodafone360.people.engine.contactsync.IContactSyncCallback) IEngineEventCallback(com.vodafone360.people.engine.IEngineEventCallback) Suppress(android.test.suitebuilder.annotation.Suppress)

Example 5 with ContactSyncEngine

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

the class ContactSyncEngineTest method minimalEngineSetup.

/**
 * Sets up the ContactSyncEngine without the test framework.
 *
 * @param eventCallback the engine event callback
 * @param factory the factory used by the ContactSyncEngine
 */
private void minimalEngineSetup(IEngineEventCallback eventCallback, ProcessorFactory factory) {
    mContactSyncEngine = new ContactSyncEngine(mApplication.getApplicationContext(), eventCallback, mApplication.getDatabase(), factory);
    mContactSyncEngine.onCreate();
}
Also used : ContactSyncEngine(com.vodafone360.people.engine.contactsync.ContactSyncEngine)

Aggregations

ContactSyncEngine (com.vodafone360.people.engine.contactsync.ContactSyncEngine)3 Suppress (android.test.suitebuilder.annotation.Suppress)1 MainApplication (com.vodafone360.people.MainApplication)1 DatabaseHelper (com.vodafone360.people.database.DatabaseHelper)1 IEngineEventCallback (com.vodafone360.people.engine.IEngineEventCallback)1 IContactSyncCallback (com.vodafone360.people.engine.contactsync.IContactSyncCallback)1 ProcessorFactory (com.vodafone360.people.engine.contactsync.ProcessorFactory)1 ServiceUiRequest (com.vodafone360.people.service.ServiceUiRequest)1 QueueManager (com.vodafone360.people.service.io.QueueManager)1 Request (com.vodafone360.people.service.io.Request)1 EngineTestFramework (com.vodafone360.people.tests.engine.EngineTestFramework)1 ArrayList (java.util.ArrayList)1