Search in sources :

Example 11 with FormTree

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();
}
Also used : FormTree(org.activityinfo.model.formTree.FormTree) HttpStore(org.activityinfo.ui.client.store.http.HttpStore) Test(org.junit.Test)

Example 12 with FormTree

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();
}
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 13 with FormTree

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());
}
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 14 with FormTree

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));
}
Also used : FormTree(org.activityinfo.model.formTree.FormTree) ResourceId(org.activityinfo.model.resource.ResourceId) ObservableTree(org.activityinfo.observable.ObservableTree) FormTreeLoader(org.activityinfo.ui.client.store.FormTreeLoader)

Example 15 with FormTree

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));
    });
}
Also used : HashSet(java.util.HashSet) FormSyncSet(org.activityinfo.model.form.FormSyncSet) Set(java.util.Set) ArrayList(java.util.ArrayList) Observable(org.activityinfo.observable.Observable) FormMetadata(org.activityinfo.model.form.FormMetadata) FormTree(org.activityinfo.model.formTree.FormTree) ResourceId(org.activityinfo.model.resource.ResourceId) List(java.util.List) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Aggregations

FormTree (org.activityinfo.model.formTree.FormTree)55 Test (org.junit.Test)35 ResourceId (org.activityinfo.model.resource.ResourceId)12 FormTreeBuilder (org.activityinfo.model.formTree.FormTreeBuilder)10 FormClass (org.activityinfo.model.form.FormClass)9 ColumnSet (org.activityinfo.model.query.ColumnSet)9 QueryModel (org.activityinfo.model.query.QueryModel)8 ImportModel (org.activityinfo.ui.client.component.importDialog.model.ImportModel)8 PastedTable (org.activityinfo.ui.client.component.importDialog.model.source.PastedTable)8 FormField (org.activityinfo.model.form.FormField)7 RecordRef (org.activityinfo.model.type.RecordRef)7 LookupKeySet (org.activityinfo.model.formTree.LookupKeySet)6 FormulaNode (org.activityinfo.model.formula.FormulaNode)6 ReferenceType (org.activityinfo.model.type.ReferenceType)6 LookupKey (org.activityinfo.model.formTree.LookupKey)5 ValidatedRowTable (org.activityinfo.ui.client.component.importDialog.model.validation.ValidatedRowTable)5 Optional (com.google.common.base.Optional)4 ColumnView (org.activityinfo.model.query.ColumnView)4 Nullable (javax.annotation.Nullable)3 DimensionCategory (org.activityinfo.legacy.shared.reports.content.DimensionCategory)3