Search in sources :

Example 26 with FormField

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

the class GetSitesHandler method buildLocationQuery.

private QueryModel buildLocationQuery(QueryModel query, FormTree formTree, FormClass form) {
    Optional<FormField> potentialLocationField = form.getFieldIfPresent(CuidAdapter.field(form.getId(), CuidAdapter.LOCATION_FIELD));
    if (potentialLocationField.isPresent()) {
        FormField locationField = potentialLocationField.get();
        // Location binding will take care of the details wrt geo fields/admin field
        addBinding(new LocationFieldBinding(locationField), query, formTree);
    } else {
        // country form, get country instance from ActivityLoader
        CountryInstance country = getCountryInstance(form.getId());
        if (country != null) {
            addBinding(new CountryFieldBinding(country), query, formTree);
        }
    }
    return query;
}
Also used : CountryInstance(org.activityinfo.store.mysql.metadata.CountryInstance) FormField(org.activityinfo.model.form.FormField)

Example 27 with FormField

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

the class LocationFieldBinding method buildAdminBindings.

private void buildAdminBindings(FormClass locationForm, FormTree formTree, int adminFieldIndex) {
    Optional<FormField> potentialAdminField = locationForm.getFieldIfPresent(CuidAdapter.field(locationForm.getId(), adminFieldIndex));
    if (potentialAdminField.isPresent()) {
        FormField adminField = potentialAdminField.get();
        Iterator<ResourceId> adminLevelRange = getRange(adminField);
        while (adminLevelRange.hasNext()) {
            ResourceId adminLevelId = adminLevelRange.next();
            buildLocationBindings(formTree.getFormClass(adminLevelId), formTree);
        }
    }
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) FormField(org.activityinfo.model.form.FormField)

Example 28 with FormField

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

the class XFormBuilder method gps.

private OdkField gps(FormField original) {
    FormField formField = new FormField(gpsFieldId);
    formField.setType(GeoPointType.INSTANCE);
    formField.setLabel("GPS coordinates (" + original.getLabel() + ")");
    return new OdkField(formField, factory.get(formField.getType()));
}
Also used : OdkField(org.activityinfo.server.endpoint.odk.OdkField) FormField(org.activityinfo.model.form.FormField)

Example 29 with FormField

use of org.activityinfo.model.form.FormField 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)

Example 30 with FormField

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

the class GcsBlobFieldStorageServiceTest method addAttachmentField.

private FormClass addAttachmentField(int activityId, ResourceId attachmentFieldId) {
    FormClass formClass = assertResolves(locator.getFormClass(CuidAdapter.activityFormClass(activityId)));
    formClass.addElement(new FormField(attachmentFieldId).setLabel("Attachment").setType(AttachmentType.TYPE_CLASS.createType()).setVisible(true));
    assertResolves(locator.persist(formClass));
    // re-fetch
    return assertResolves(locator.getFormClass(formClass.getId()));
}
Also used : FormClass(org.activityinfo.model.form.FormClass) FormField(org.activityinfo.model.form.FormField)

Aggregations

FormField (org.activityinfo.model.form.FormField)119 FormClass (org.activityinfo.model.form.FormClass)48 ResourceId (org.activityinfo.model.resource.ResourceId)32 Test (org.junit.Test)30 QuantityType (org.activityinfo.model.type.number.QuantityType)18 SubFormReferenceType (org.activityinfo.model.type.subform.SubFormReferenceType)17 ReferenceType (org.activityinfo.model.type.ReferenceType)16 EnumType (org.activityinfo.model.type.enumerated.EnumType)14 FieldValue (org.activityinfo.model.type.FieldValue)12 EnumItem (org.activityinfo.model.type.enumerated.EnumItem)11 JsonValue (org.activityinfo.json.JsonValue)9 FormTree (org.activityinfo.model.formTree.FormTree)9 FormInstance (org.activityinfo.model.form.FormInstance)8 CalculatedFieldType (org.activityinfo.model.type.expr.CalculatedFieldType)8 ColumnSet (org.activityinfo.model.query.ColumnSet)6 QueryModel (org.activityinfo.model.query.QueryModel)6 KeyGenerator (org.activityinfo.model.legacy.KeyGenerator)5 Quantity (org.activityinfo.model.type.number.Quantity)5 TypedRecordUpdate (org.activityinfo.store.spi.TypedRecordUpdate)5 ArrayList (java.util.ArrayList)4