use of org.activityinfo.observable.Observable in project activityinfo by bedatadriven.
the class LookupViewModel method select.
public void select(LookupKey lookupKey, String keyChoice) {
Map<LookupKey, String> newSelectedKeys = new HashMap<>();
for (Map.Entry<LookupKey, Observable<Optional<String>>> entry : selectedKeys.entrySet()) {
Optional<String> selectedKey = entry.getValue().get();
if (selectedKey.isPresent()) {
newSelectedKeys.put(entry.getKey(), selectedKey.get());
}
}
newSelectedKeys.put(lookupKey, keyChoice);
// Clear the child choices
clearChildChoices(lookupKey, newSelectedKeys);
model.updateIfNotEqual(new LookupModel(newSelectedKeys));
}
use of org.activityinfo.observable.Observable 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.observable.Observable 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.observable.Observable in project activityinfo by bedatadriven.
the class TableViewModel method getEffectiveSubTable.
public Observable<EffectiveTableModel> getEffectiveSubTable(final ResourceId subFormId) {
Observable<EffectiveTableModel> effectiveSubTable = effectiveSubTables.get(subFormId);
if (effectiveSubTable == null) {
final TableModel subModel = ImmutableTableModel.builder().formId(subFormId).build();
effectiveSubTable = formTree.transform(tree -> tree.subTree(subFormId)).transform(subTree -> new EffectiveTableModel(formStore, subTree, subModel, Optional.of(getSelectedRecordRef())));
effectiveSubTables.put(subFormId, effectiveSubTable);
}
return effectiveSubTable;
}
Aggregations