Search in sources :

Example 71 with ResourceId

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));
}
Also used : ForeignKeyBuilder(org.activityinfo.store.query.server.join.ForeignKeyBuilder) ResourceId(org.activityinfo.model.resource.ResourceId) ReferenceValue(org.activityinfo.model.type.ReferenceValue) RecordRef(org.activityinfo.model.type.RecordRef) ForeignKey(org.activityinfo.store.query.shared.columns.ForeignKey) Test(org.junit.Test)

Example 72 with ResourceId

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());
}
Also used : FormClassProvider(org.activityinfo.model.formTree.FormClassProvider) ResourceId(org.activityinfo.model.resource.ResourceId) FormClass(org.activityinfo.model.form.FormClass) FormTreeBuilder(org.activityinfo.model.formTree.FormTreeBuilder)

Example 73 with ResourceId

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;
}
Also used : SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType) ReferenceType(org.activityinfo.model.type.ReferenceType) FormTreeBuilder(org.activityinfo.model.formTree.FormTreeBuilder) SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType) FormClassProvider(org.activityinfo.model.formTree.FormClassProvider) FormTree(org.activityinfo.model.formTree.FormTree) ResourceId(org.activityinfo.model.resource.ResourceId) FormClass(org.activityinfo.model.form.FormClass) FormField(org.activityinfo.model.form.FormField)

Example 74 with ResourceId

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;
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) FormClass(org.activityinfo.model.form.FormClass) SymbolNode(org.activityinfo.model.formula.SymbolNode)

Example 75 with ResourceId

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();
        }
    };
}
Also used : PeriodType(org.activityinfo.model.type.time.PeriodType) ResourceId(org.activityinfo.model.resource.ResourceId) RecordRef(org.activityinfo.model.type.RecordRef)

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