Search in sources :

Example 41 with FormClass

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;
}
Also used : FormClass(org.activityinfo.model.form.FormClass) ColumnView(org.activityinfo.model.query.ColumnView)

Example 42 with FormClass

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));
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) QuantityType(org.activityinfo.model.type.number.QuantityType) FormClass(org.activityinfo.model.form.FormClass) JsonValue(org.activityinfo.json.JsonValue) FormField(org.activityinfo.model.form.FormField) TypedRecordUpdate(org.activityinfo.store.spi.TypedRecordUpdate) Test(org.junit.Test)

Example 43 with FormClass

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());
}
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 44 with FormClass

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;
}
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 45 with FormClass

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

Aggregations

FormClass (org.activityinfo.model.form.FormClass)109 FormField (org.activityinfo.model.form.FormField)49 ResourceId (org.activityinfo.model.resource.ResourceId)41 Test (org.junit.Test)38 QuantityType (org.activityinfo.model.type.number.QuantityType)20 SubFormReferenceType (org.activityinfo.model.type.subform.SubFormReferenceType)19 FormInstance (org.activityinfo.model.form.FormInstance)14 EnumType (org.activityinfo.model.type.enumerated.EnumType)12 JsonValue (org.activityinfo.json.JsonValue)11 FormTree (org.activityinfo.model.formTree.FormTree)10 EnumItem (org.activityinfo.model.type.enumerated.EnumItem)10 ColumnSet (org.activityinfo.model.query.ColumnSet)8 QueryModel (org.activityinfo.model.query.QueryModel)8 CalculatedFieldType (org.activityinfo.model.type.expr.CalculatedFieldType)8 FieldValue (org.activityinfo.model.type.FieldValue)7 Quantity (org.activityinfo.model.type.number.Quantity)7 FormTreeBuilder (org.activityinfo.model.formTree.FormTreeBuilder)6 KeyGenerator (org.activityinfo.model.legacy.KeyGenerator)6 ColumnSetBuilder (org.activityinfo.store.query.server.ColumnSetBuilder)6 ColumnView (org.activityinfo.model.query.ColumnView)5