Search in sources :

Example 1 with RecordFieldType

use of org.activityinfo.model.type.RecordFieldType in project activityinfo by bedatadriven.

the class FormTreeBuilder method queryTree.

public FormTree queryTree(ResourceId rootFormId) {
    FormTree tree = new FormTree(rootFormId);
    FormMetadata root = metadataProvider.getFormMetadata(rootFormId);
    if (root.isDeleted()) {
        tree.setRootState(FormTree.State.DELETED);
        return tree;
    }
    if (!root.isVisible()) {
        tree.setRootState(FormTree.State.FORBIDDEN);
        return tree;
    }
    FormClass rootSchema = root.getSchema();
    List<ResourceId> stack = Lists.newArrayList(rootFormId);
    Optional<FormField> parentField = rootSchema.getParentField();
    if (parentField.isPresent()) {
        if (!stack.contains(parentField.get().getId())) {
            tree.addFormMetadata(root);
            FormTree.Node node = tree.addRootField(root, parentField.get());
            fetchChildren(stack, tree, node, rootSchema.getParentFormId().asSet());
        }
    }
    // Add fields defined by this FormClass
    for (FormField field : rootSchema.getFields()) {
        tree.addFormMetadata(root);
        FormTree.Node node = tree.addRootField(root, field);
        if (node.isReference()) {
            fetchChildren(stack, tree, node, node.getRange());
        } else if (field.getType() instanceof RecordFieldType) {
            addChildren(stack, tree, node, embeddedForm(node));
        }
    }
    return tree;
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) FormClass(org.activityinfo.model.form.FormClass) FormField(org.activityinfo.model.form.FormField) RecordFieldType(org.activityinfo.model.type.RecordFieldType) FormMetadata(org.activityinfo.model.form.FormMetadata)

Example 2 with RecordFieldType

use of org.activityinfo.model.type.RecordFieldType in project activityinfo by bedatadriven.

the class FormTreeBuilder method embeddedForm.

private FormMetadata embeddedForm(FormTree.Node childNode) {
    FormClass embeddedFormSchema = ((RecordFieldType) childNode.getType()).getFormClass();
    long formVersion = 1L;
    return FormMetadata.of(formVersion, embeddedFormSchema, FormPermissions.readonly());
}
Also used : FormClass(org.activityinfo.model.form.FormClass) RecordFieldType(org.activityinfo.model.type.RecordFieldType)

Aggregations

FormClass (org.activityinfo.model.form.FormClass)2 RecordFieldType (org.activityinfo.model.type.RecordFieldType)2 FormField (org.activityinfo.model.form.FormField)1 FormMetadata (org.activityinfo.model.form.FormMetadata)1 ResourceId (org.activityinfo.model.resource.ResourceId)1