use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.
the class FormScanBatch method computeParentFilter.
private Slot<TableFilter> computeParentFilter(FilterLevel filterLevel, ResourceId formId) {
if (parentFilterMap.containsKey(formId)) {
return parentFilterMap.get(formId);
}
FormClass formClass = formClassProvider.getFormClass(formId);
if (!formClass.isSubForm()) {
return new PendingSlot<>(TableFilter.ALL_SELECTED);
}
Slot<PrimaryKeyMap> parentPrimaryKeySlot = addPrimaryKey(filterLevel, formClass.getParentFormId().get());
Slot<ColumnView> parentId = addParentColumn(FilterLevel.NONE, formId);
ParentMask filter = new ParentMask(parentPrimaryKeySlot, parentId);
parentFilterMap.put(formId, filter);
return filter;
}
use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.
the class UpdaterTest method missingValue.
@Test
public void missingValue() throws JsonMappingException {
ResourceId fieldId = ResourceId.valueOf("Q1");
FormClass formClass = new FormClass(ResourceId.valueOf("XYZ123"));
formClass.addElement(new FormField(fieldId).setType(new QuantityType("meters")));
JsonValue fields = createObject();
fields.put("Q1", Json.createNull());
JsonValue change = createObject();
change.put("recordId", "A");
change.put("formId", "XYZ123");
change.put("fields", fields);
TypedRecordUpdate update = Updater.parseChange(formClass, change, userId);
assertTrue(update.getChangedFieldValues().containsKey(fieldId));
}
use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.
the class NodeMatcherTest method tree.
private FormTree tree() {
if (rootFormClass == null) {
throw new IllegalStateException("Root FormClass is unset");
}
FormClassProvider provider = new FormClassProvider() {
@Override
public FormClass getFormClass(ResourceId formId) {
if (rootFormClass.getId().equals(formId)) {
return rootFormClass;
}
FormClass formClass = formClasses.get(formId);
if (formClass == null) {
throw new IllegalArgumentException(formId.toString());
}
return formClass;
}
};
FormTreeBuilder builder = new FormTreeBuilder(provider);
return builder.queryTree(rootFormClass.getId());
}
use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.
the class BatchingFormTreeBuilder method queryTrees.
public Map<ResourceId, FormTree> queryTrees(Collection<ResourceId> rootFormIds) {
// Fetch Required FormClasses in batches
Set<ResourceId> toFetch = Sets.newHashSet();
toFetch.addAll(rootFormIds);
while (!toFetch.isEmpty()) {
// First round: fetch root form classes
List<FormClass> fetched = fetchFormClasses(toFetch);
toFetch.clear();
// Find newly referenced forms
for (FormClass formClass : fetched) {
if (formClass.isSubForm()) {
if (!formCache.containsKey(formClass.getParentFormId().get())) {
toFetch.add(formClass.getParentFormId().get());
}
}
for (FormField formField : formClass.getFields()) {
if (formField.getType() instanceof ReferenceType) {
ReferenceType refType = (ReferenceType) formField.getType();
for (ResourceId refFormId : refType.getRange()) {
if (!formCache.containsKey(refFormId)) {
toFetch.add(refFormId);
}
}
} else if (formField.getType() instanceof SubFormReferenceType) {
SubFormReferenceType subFormType = (SubFormReferenceType) formField.getType();
if (!formCache.containsKey(subFormType.getClassId())) {
toFetch.add(subFormType.getClassId());
}
}
}
}
}
// Now assemble trees
Map<ResourceId, FormTree> treeMap = new HashMap<>();
FormTreeBuilder builder = new FormTreeBuilder(new FormClassProvider() {
@Override
public FormClass getFormClass(ResourceId formId) {
return formCache.get(formId);
}
});
for (ResourceId rootFormId : rootFormIds) {
treeMap.put(rootFormId, builder.queryTree(rootFormId));
}
return treeMap;
}
use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.
the class NodeMatcher method unionMatches.
private Collection<NodeMatch> unionMatches(QueryPath path, FormTree.Node parentField) {
List<NodeMatch> results = Lists.newArrayList();
for (ResourceId formClassId : parentField.getRange()) {
FormClass childForm = tree.getFormClass(formClassId);
Iterable<FormTree.Node> childFields = parentField.getChildren(formClassId);
if (path.matches(childForm) && path.peek().equals(ColumnModel.ID_SYMBOL)) {
results.add(NodeMatch.forId(parentField, childForm));
} else if (path.matches(childForm) || path.matches(parentField)) {
results.addAll(matchNodes(path.next(), childFields));
} else {
// Descend the next level
results.addAll(matchNodes(path, childFields));
}
}
return results;
}
Aggregations