Search in sources :

Example 11 with ResourceId

use of org.activityinfo.model.resource.ResourceId in project activityinfo by bedatadriven.

the class KeyValueStore method getOfflineForms.

public final Promise<Set<ResourceId>> getOfflineForms() {
    return impl.get(OFFLINE_FORMS).then(json -> {
        if (json == null) {
            return Collections.emptySet();
        } else {
            Set<ResourceId> forms = new HashSet<>();
            JsonValue array = json;
            for (int i = 0; i < array.length(); i++) {
                forms.add(ResourceId.valueOf(array.getString(i)));
            }
            return forms;
        }
    });
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) JsonValue(org.activityinfo.json.JsonValue) HashSet(java.util.HashSet)

Example 12 with ResourceId

use of org.activityinfo.model.resource.ResourceId in project activityinfo by bedatadriven.

the class OfflineStore method getCachedMetadata.

/**
 * Try to load a cached FormSchema from the offline store.
 */
public Observable<FormMetadata> getCachedMetadata(ResourceId formId) {
    Observable<FormClass> schema = new ObservableTask<>(new SchemaQuery(database, formId), new FormChangeWatcher(eventBus, change -> change.isFormChanged(formId)));
    Observable<FormMetadataObject> metadata = new ObservableTask<>(new MetadataQuery(database, formId), new FormChangeWatcher(eventBus, change -> change.isFormChanged(formId)));
    return Observable.transform(schema, metadata, (s, m) -> FormMetadata.of(m.getVersion(), s, m.getPermissions()));
}
Also used : ObservableTask(org.activityinfo.ui.client.store.tasks.ObservableTask) FormTreeLoader(org.activityinfo.ui.client.store.FormTreeLoader) java.util(java.util) Json(org.activityinfo.json.Json) ObservableTree(org.activityinfo.observable.ObservableTree) Function2(org.activityinfo.promise.Function2) IDBTransaction(org.activityinfo.indexedb.IDBTransaction) Promise(org.activityinfo.promise.Promise) org.activityinfo.model.form(org.activityinfo.model.form) FormChange(org.activityinfo.ui.client.store.FormChange) Level(java.util.logging.Level) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) HttpStore(org.activityinfo.ui.client.store.http.HttpStore) OfflineDatabase(org.activityinfo.indexedb.OfflineDatabase) ResourceId(org.activityinfo.model.resource.ResourceId) RecordRef(org.activityinfo.model.type.RecordRef) JsonValue(org.activityinfo.json.JsonValue) RecordUpdate(org.activityinfo.model.resource.RecordUpdate) FormChangeWatcher(org.activityinfo.ui.client.store.http.FormChangeWatcher) Function(com.google.common.base.Function) ImmutableSet(com.google.common.collect.ImmutableSet) FormChangeEvent(org.activityinfo.ui.client.store.FormChangeEvent) EventBus(com.google.gwt.event.shared.EventBus) IDBFactory(org.activityinfo.indexedb.IDBFactory) StatefulValue(org.activityinfo.observable.StatefulValue) Logger(java.util.logging.Logger) ObservableTask(org.activityinfo.ui.client.store.tasks.ObservableTask) ColumnSet(org.activityinfo.model.query.ColumnSet) QueryModel(org.activityinfo.model.query.QueryModel) SimpleEventBus(com.google.gwt.event.shared.SimpleEventBus) RecordTransaction(org.activityinfo.model.resource.RecordTransaction) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Observable(org.activityinfo.observable.Observable) Maybe(org.activityinfo.promise.Maybe) FormTree(org.activityinfo.model.formTree.FormTree) FormChangeWatcher(org.activityinfo.ui.client.store.http.FormChangeWatcher)

Example 13 with ResourceId

use of org.activityinfo.model.resource.ResourceId 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 14 with ResourceId

use of org.activityinfo.model.resource.ResourceId 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)

Example 15 with ResourceId

use of org.activityinfo.model.resource.ResourceId in project activityinfo by bedatadriven.

the class FormDesignerModel method removeSubform.

public void removeSubform(FormClass subForm) {
    ResourceId formFieldId = formFieldToSubFormClass.inverse().get(subForm);
    formFieldToSubFormClass.remove(formFieldId);
    rootFormClass.removeField(formFieldId);
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId)

Aggregations

ResourceId (org.activityinfo.model.resource.ResourceId)198 Test (org.junit.Test)42 FormClass (org.activityinfo.model.form.FormClass)41 FormField (org.activityinfo.model.form.FormField)34 RecordRef (org.activityinfo.model.type.RecordRef)30 JsonValue (org.activityinfo.json.JsonValue)21 FormTree (org.activityinfo.model.formTree.FormTree)18 ReferenceValue (org.activityinfo.model.type.ReferenceValue)17 FieldValue (org.activityinfo.model.type.FieldValue)16 FormInstance (org.activityinfo.model.form.FormInstance)15 HashMap (java.util.HashMap)14 QuantityType (org.activityinfo.model.type.number.QuantityType)13 ColumnSet (org.activityinfo.model.query.ColumnSet)12 QueryModel (org.activityinfo.model.query.QueryModel)12 EnumValue (org.activityinfo.model.type.enumerated.EnumValue)11 SubFormReferenceType (org.activityinfo.model.type.subform.SubFormReferenceType)11 ReferenceType (org.activityinfo.model.type.ReferenceType)10 EnumItem (org.activityinfo.model.type.enumerated.EnumItem)10 FormStorage (org.activityinfo.store.spi.FormStorage)10 ArrayList (java.util.ArrayList)9