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()));
}
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();
}
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();
}
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());
}
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();
}
Aggregations