use of org.activityinfo.model.formTree.FormTree 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.model.formTree.FormTree 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.model.formTree.FormTree 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.model.formTree.FormTree in project activityinfo by bedatadriven.
the class OfflineStore method query.
public Observable<ColumnSet> query(QueryModel queryModel) {
ResourceId rootFormId = queryModel.getRowSources().get(0).getRootFormId();
Observable<FormTree> tree = new ObservableTree<>(new FormTreeLoader(rootFormId, this::getCachedMetadata), com.google.gwt.core.client.Scheduler.get());
return tree.join(formTree1 -> query(formTree1, queryModel));
}
use of org.activityinfo.model.formTree.FormTree in project activityinfo by bedatadriven.
the class Snapshot method compute.
public static Observable<Snapshot> compute(Observable<Set<ResourceId>> offlineForms, HttpStore httpStore) {
// We start with the "offlineForm" set which contains the set
// of forms the user has explicitly asked to cache.
// In order to find the related forms, we need the complete form trees of each of the
// selected forms.
Observable<List<FormTree>> formTrees = flatMap(offlineForms, httpStore::getFormTree);
// Together, all the related forms constitute the set of forms we need for
// a complete offline snapshot
Observable<Set<ResourceId>> completeSet = formTrees.transform(trees -> {
Set<ResourceId> set = new HashSet<>();
for (FormTree tree : trees) {
for (FormMetadata form : tree.getForms()) {
if (!isBuiltinForm(form.getId())) {
set.add(form.getId());
}
}
}
return set;
});
// Now need fetch the latest version numbers of each of these forms
Observable<List<FormMetadata>> metadata = flatMap(completeSet, httpStore::getFormMetadata);
// And finally fetch any difference between our current snapshot and the latest version of the new snapshot
return metadata.join(forms -> {
List<Observable<FormSyncSet>> recordSets = new ArrayList<>();
for (FormMetadata form : forms) {
recordSets.add(httpStore.getVersionRange(form.getId(), 0, form.getVersion()));
}
return Observable.flatten(recordSets).transform(x -> new Snapshot(forms, x));
});
}
Aggregations