use of org.activityinfo.model.resource.ResourceId in project activityinfo by bedatadriven.
the class ForeignKeyTest method emptyValues.
@Test
public void emptyValues() {
// Build the unfiltered foreign key map
// That maps row indexes to foreign keys
ResourceId formId = ResourceId.valueOf("a00001");
ForeignKeyBuilder builder = new ForeignKeyBuilder(formId, new PendingSlot<ForeignKey>());
builder.onNext(null);
builder.onNext(new ReferenceValue(new RecordRef(formId, ResourceId.valueOf("s0272548382"))));
builder.onNext(null);
builder.onNext(null);
ForeignKey fkMap = builder.build();
assertThat(fkMap.numRows(), equalTo(4));
}
use of org.activityinfo.model.resource.ResourceId 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.resource.ResourceId 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.resource.ResourceId 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;
}
use of org.activityinfo.model.resource.ResourceId in project activityinfo by bedatadriven.
the class SubFormPatch method fromRecordId.
public static CursorObserver<ResourceId> fromRecordId(FormClass formClass, final CursorObserver<FieldValue> observer) {
final ResourceId formId = formClass.getId();
final PeriodType periodType = formClass.getSubFormKind().getPeriodType();
return new CursorObserver<ResourceId>() {
@Override
public void onNext(ResourceId value) {
observer.onNext(periodType.fromSubFormKey(new RecordRef(formId, value)));
}
@Override
public void done() {
observer.done();
}
};
}
Aggregations