Search in sources :

Example 1 with HttpStore

use of org.activityinfo.ui.client.store.http.HttpStore in project activityinfo by bedatadriven.

the class FormStoreTest method relatedFormsAreAlsoCached.

@Test
public void relatedFormsAreAlsoCached() {
    AsyncClientStub client = new AsyncClientStub();
    IntakeForm intakeForm = client.getStorageProvider().getIntakeForm();
    HttpStore httpStore = new HttpStore(client, scheduler);
    OfflineStore offlineStore = new OfflineStore(httpStore, new IDBFactoryStub());
    FormStoreImpl formStore = new FormStoreImpl(httpStore, offlineStore, scheduler);
    // Start online, and enable offline mode for incidents
    formStore.setFormOffline(IncidentForm.FORM_ID, true);
    // Now synchronize...
    RecordSynchronizer synchronizer = new RecordSynchronizer(httpStore, offlineStore);
    runScheduled();
    // Ensure that related forms and subforms are also synchronized
    SnapshotStatus snapshot = connect(offlineStore.getCurrentSnapshot()).assertLoaded();
    assertTrue("incident form is cached", snapshot.isFormCached(IncidentForm.FORM_ID));
    assertTrue("sub form is cached", snapshot.isFormCached(ReferralSubForm.FORM_ID));
    assertTrue("related form is cached", snapshot.isFormCached(intakeForm.getFormId()));
}
Also used : IDBFactoryStub(org.activityinfo.indexedb.IDBFactoryStub) HttpStore(org.activityinfo.ui.client.store.http.HttpStore) Test(org.junit.Test)

Example 2 with HttpStore

use of org.activityinfo.ui.client.store.http.HttpStore in project activityinfo by bedatadriven.

the class FormStoreTest method httpBus.

@Test
public void httpBus() {
    AsyncClientStub client = new AsyncClientStub();
    Survey survey = client.getStorageProvider().getSurvey();
    HttpStore httpStore = new HttpStore(client, scheduler);
    Connection<FormTree> view = connect(httpStore.getFormTree(survey.getFormId()));
    runScheduled();
    view.assertLoaded();
}
Also used : FormTree(org.activityinfo.model.formTree.FormTree) HttpStore(org.activityinfo.ui.client.store.http.HttpStore) Test(org.junit.Test)

Example 3 with HttpStore

use of org.activityinfo.ui.client.store.http.HttpStore in project activityinfo by bedatadriven.

the class FormStoreTest method formSchemaFetchesAreRetried.

/**
 * If at first the remote fetch does not succeed because
 * of network problems, we should keep retrying.
 */
@Test
public void formSchemaFetchesAreRetried() {
    AsyncClientStub client = new AsyncClientStub();
    HttpStore httpStore = new HttpStore(client, scheduler);
    OfflineStore offlineStore = new OfflineStore(httpStore, new IDBFactoryStub());
    Survey survey = client.getStorageProvider().getSurvey();
    // We start offline
    client.setConnected(false);
    // Now the view connects and should remain in loading state...
    FormStoreImpl formStore = new FormStoreImpl(httpStore, offlineStore, scheduler);
    Connection<FormTree> view = connect(formStore.getFormTree(survey.getFormId()));
    view.assertLoading();
    // Start retries, but we're still offline
    scheduler.executeCommands();
    view.assertLoading();
    // Now connect and retry
    client.setConnected(true);
    scheduler.executeCommands();
    // View should be loaded
    view.assertLoaded();
}
Also used : IDBFactoryStub(org.activityinfo.indexedb.IDBFactoryStub) FormTree(org.activityinfo.model.formTree.FormTree) HttpStore(org.activityinfo.ui.client.store.http.HttpStore) Test(org.junit.Test)

Example 4 with HttpStore

use of org.activityinfo.ui.client.store.http.HttpStore in project activityinfo by bedatadriven.

the class FormStoreTest method offlineRecordFetching.

@Test
public void offlineRecordFetching() {
    AsyncClientStub client = new AsyncClientStub();
    HttpStore httpStore = new HttpStore(client, scheduler);
    OfflineStore offlineStore = new OfflineStore(httpStore, new IDBFactoryStub());
    FormStoreImpl formStore = new FormStoreImpl(httpStore, offlineStore, scheduler);
    Survey survey = client.getStorageProvider().getSurvey();
    // Start online
    Connection<FormOfflineStatus> offlineStatusView = connect(formStore.getOfflineStatus(survey.getFormId()));
    // Initially form should not be loaded
    assertFalse(offlineStatusView.assertLoaded().isEnabled());
    // and mark the survey form for offline usage
    offlineStore.enableOffline(survey.getFormId(), true);
    assertTrue(offlineStatusView.assertLoaded().isEnabled());
    assertFalse(offlineStatusView.assertLoaded().isCached());
    // Now synchronize...
    RecordSynchronizer synchronizer = new RecordSynchronizer(httpStore, offlineStore);
    runScheduled();
    // We go offline...
    client.setConnected(false);
    // Should be able to view the form class and a record
    Connection<FormTree> schemaView = connect(formStore.getFormTree(survey.getFormId()));
    Connection<Maybe<FormRecord>> recordView = connect(formStore.getRecord(survey.getRecordRef(0)));
    runScheduled();
    schemaView.assertLoaded();
    recordView.assertLoaded();
    assertTrue(offlineStatusView.assertLoaded().isEnabled());
    assertTrue(offlineStatusView.assertLoaded().isCached());
}
Also used : Maybe(org.activityinfo.promise.Maybe) IDBFactoryStub(org.activityinfo.indexedb.IDBFactoryStub) FormTree(org.activityinfo.model.formTree.FormTree) HttpStore(org.activityinfo.ui.client.store.http.HttpStore) Test(org.junit.Test)

Example 5 with HttpStore

use of org.activityinfo.ui.client.store.http.HttpStore in project activityinfo by bedatadriven.

the class AppEntryPoint method onModuleLoad.

@Override
public void onModuleLoad() {
    LOGGER.info("user.agent = " + System.getProperty("user.agent"));
    LOGGER.info("gxt.user.agent = " + System.getProperty("gxt.user.agent"));
    LOGGER.info("gxt.device = " + System.getProperty("gxt.device"));
    Icons.INSTANCE.ensureInjected();
    AppCache appCache = new AppCache();
    AppCacheMonitor3 monitor = new AppCacheMonitor3(appCache);
    monitor.start();
    EventBus eventBus = new SimpleEventBus();
    PlaceController placeController = new PlaceController(eventBus);
    ConnectionListener connectionListener = new ConnectionListener();
    connectionListener.start();
    ActivityInfoClientAsync client = new ActivityInfoClientAsyncImpl(findServerUrl());
    HttpStore httpStore = new HttpStore(connectionListener.getOnline(), client, Scheduler.get());
    OfflineStore offlineStore = new OfflineStore(httpStore, IDBFactoryImpl.create());
    FormStore formStore = new FormStoreImpl(httpStore, offlineStore, Scheduler.get());
    LocalStorage storage = LocalStorage.create();
    Viewport viewport = new Viewport();
    AppFrame appFrame = new AppFrame(appCache, httpStore, offlineStore);
    ActivityMapper activityMapper = new AppActivityMapper(formStore, storage);
    ActivityManager activityManager = new ActivityManager(activityMapper, eventBus);
    activityManager.setDisplay(appFrame.getDisplayWidget());
    AppPlaceHistoryMapper historyMapper = new AppPlaceHistoryMapper();
    PlaceHistoryHandler historyHandler = new PlaceHistoryHandler(historyMapper);
    historyHandler.register(placeController, eventBus, DEFAULT_PLACE);
    // Start synchronizer...
    RecordSynchronizer synchronizer = new RecordSynchronizer(httpStore, offlineStore);
    viewport.add(appFrame);
    RootLayoutPanel.get().add(viewport);
    historyHandler.handleCurrentHistory();
}
Also used : FormStoreImpl(org.activityinfo.ui.client.store.FormStoreImpl) OfflineStore(org.activityinfo.ui.client.store.offline.OfflineStore) PlaceController(com.google.gwt.place.shared.PlaceController) Viewport(com.sencha.gxt.widget.core.client.container.Viewport) SimpleEventBus(com.google.web.bindery.event.shared.SimpleEventBus) EventBus(com.google.web.bindery.event.shared.EventBus) ConnectionListener(org.activityinfo.ui.client.store.http.ConnectionListener) ActivityInfoClientAsyncImpl(org.activityinfo.api.client.ActivityInfoClientAsyncImpl) ActivityManager(com.google.gwt.activity.shared.ActivityManager) PlaceHistoryHandler(com.google.gwt.place.shared.PlaceHistoryHandler) RecordSynchronizer(org.activityinfo.ui.client.store.offline.RecordSynchronizer) ActivityMapper(com.google.gwt.activity.shared.ActivityMapper) LocalStorage(org.activityinfo.storage.LocalStorage) SimpleEventBus(com.google.web.bindery.event.shared.SimpleEventBus) HttpStore(org.activityinfo.ui.client.store.http.HttpStore) AppFrame(org.activityinfo.ui.client.chrome.AppFrame) FormStore(org.activityinfo.ui.client.store.FormStore) ActivityInfoClientAsync(org.activityinfo.api.client.ActivityInfoClientAsync)

Aggregations

HttpStore (org.activityinfo.ui.client.store.http.HttpStore)7 Test (org.junit.Test)5 IDBFactoryStub (org.activityinfo.indexedb.IDBFactoryStub)4 FormTree (org.activityinfo.model.formTree.FormTree)3 FormStoreImpl (org.activityinfo.ui.client.store.FormStoreImpl)2 ActivityManager (com.google.gwt.activity.shared.ActivityManager)1 ActivityMapper (com.google.gwt.activity.shared.ActivityMapper)1 PlaceController (com.google.gwt.place.shared.PlaceController)1 PlaceHistoryHandler (com.google.gwt.place.shared.PlaceHistoryHandler)1 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)1 EventBus (com.google.web.bindery.event.shared.EventBus)1 SimpleEventBus (com.google.web.bindery.event.shared.SimpleEventBus)1 Viewport (com.sencha.gxt.widget.core.client.container.Viewport)1 ActivityInfoClientAsync (org.activityinfo.api.client.ActivityInfoClientAsync)1 ActivityInfoClientAsyncImpl (org.activityinfo.api.client.ActivityInfoClientAsyncImpl)1 ColumnSet (org.activityinfo.model.query.ColumnSet)1 QueryModel (org.activityinfo.model.query.QueryModel)1 RecordTransactionBuilder (org.activityinfo.model.resource.RecordTransactionBuilder)1 Maybe (org.activityinfo.promise.Maybe)1 LocalStorage (org.activityinfo.storage.LocalStorage)1