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