Search in sources :

Example 21 with FormClass

use of org.activityinfo.model.form.FormClass 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 22 with FormClass

use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.

the class FormEvalContextTest method circularRefs.

@Test
public void circularRefs() {
    FormField a = new FormField(ResourceId.generateId());
    a.setCode("A");
    a.setType(new CalculatedFieldType("B+1"));
    a.setLabel("A");
    FormField b = new FormField(ResourceId.generateId());
    b.setCode("B");
    b.setType(new CalculatedFieldType("A/50"));
    b.setLabel("B");
    FormClass formClass = new FormClass(ResourceId.generateId());
    formClass.addElement(a);
    formClass.addElement(b);
    FormEvalContext context = new FormEvalContext(formClass);
    context.setInstance(new FormInstance(ResourceId.generateSubmissionId(formClass), formClass.getId()));
    assertThat(context.getFieldValue(a.getId()), instanceOf(ErrorValue.class));
}
Also used : CalculatedFieldType(org.activityinfo.model.type.expr.CalculatedFieldType) FormClass(org.activityinfo.model.form.FormClass) ErrorValue(org.activityinfo.model.type.ErrorValue) FormInstance(org.activityinfo.model.form.FormInstance) FormField(org.activityinfo.model.form.FormField) FormEvalContext(org.activityinfo.model.form.FormEvalContext) Test(org.junit.Test)

Example 23 with FormClass

use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.

the class GeoPointType method getFormClass.

@Override
public FormClass getFormClass() {
    FormClass formClass = new FormClass(ResourceId.valueOf("geoPoint"));
    formClass.setLabel(I18N.CONSTANTS.geographicCoordinatesFieldLabel());
    formClass.addField(ResourceId.valueOf(LATITUDE)).setCode(LATITUDE).setLabel(I18N.CONSTANTS.latitude()).setType(new QuantityType("degrees")).setRequired(true);
    formClass.addField(ResourceId.valueOf(LONGITUDE)).setCode(LONGITUDE).setLabel(I18N.CONSTANTS.longitude()).setType(new QuantityType("degrees")).setRequired(true);
    return formClass;
}
Also used : QuantityType(org.activityinfo.model.type.number.QuantityType) FormClass(org.activityinfo.model.form.FormClass)

Example 24 with FormClass

use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.

the class XFormResources method form.

@GET
@Path("{id}/xform")
@Produces(MediaType.TEXT_XML)
public Response form(@PathParam("id") int id) {
    AuthenticatedUser user = authProvider.get();
    LOGGER.finer("ODK activity form " + id + " requested by " + user.getEmail() + " (" + user.getId() + ")");
    FormClass formClass = fetchFormClass(id);
    String authenticationToken = authenticationTokenService.createAuthenticationToken(user.getId(), formClass.getId());
    XForm xForm = new XFormBuilder(factory).setUserId(authenticationToken).build(formClass);
    return Response.ok(xForm).build();
}
Also used : XForm(org.activityinfo.io.xform.form.XForm) FormClass(org.activityinfo.model.form.FormClass) XFormBuilder(org.activityinfo.server.endpoint.odk.build.XFormBuilder) AuthenticatedUser(org.activityinfo.legacy.shared.AuthenticatedUser)

Example 25 with FormClass

use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.

the class ItemSetBuilder method findRanges.

private Set<ResourceId> findRanges(ResourceId formClassId) {
    FormClass formClass = locator.getFormClass(formClassId);
    Set<ResourceId> rangeClassIds = Sets.newHashSet();
    for (FormField field : formClass.getFields()) {
        if (field.getType() instanceof ReferenceType) {
            rangeClassIds.addAll(((ReferenceType) field.getType()).getRange());
        }
    }
    return rangeClassIds;
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) FormClass(org.activityinfo.model.form.FormClass) FormField(org.activityinfo.model.form.FormField) ReferenceType(org.activityinfo.model.type.ReferenceType)

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