Search in sources :

Example 16 with FormClass

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

the class CurlExamplesGenerator method getFormSchema.

public static Example getFormSchema() {
    FormClass exampleForm = new FormClass(ResourceId.generateId()).setDatabaseId(54).setLabel("NFI Distribution").setDescription("Form for collecting results of NFI distributions in North Kivu");
    exampleForm.addField(ResourceId.generateId()).setLabel("Date of Distribution").setType(LocalDateType.INSTANCE).setRequired(true);
    exampleForm.addField(CuidAdapter.partnerField(33)).setLabel("Partner").setType(ReferenceType.single(CuidAdapter.partnerFormId(54))).setRequired(true).setDescription("The implementing partner who conducted the distribution");
    exampleForm.addField(ResourceId.generateId()).setLabel("Donor").setType(new EnumType(Cardinality.SINGLE, new EnumItem(ResourceId.generateId(), "USAID"), new EnumItem(ResourceId.generateId(), "DFID"), new EnumItem(ResourceId.generateId(), "ECHO"))).setRequired(true);
    exampleForm.addField(ResourceId.generateId()).setLabel("Number of households receiving a kit").setType(new QuantityType("households")).setRequired(true);
    return new Example("curl https://www.activityinfo.org/form/" + exampleForm.getId() + "/schema", exampleForm.toJson());
}
Also used : QuantityType(org.activityinfo.model.type.number.QuantityType) FormClass(org.activityinfo.model.form.FormClass) EnumType(org.activityinfo.model.type.enumerated.EnumType) EnumItem(org.activityinfo.model.type.enumerated.EnumItem)

Example 17 with FormClass

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

the class XlsFormBuilder method build.

public void build(ResourceId formClassId) {
    FormClass formClass = formClassProvider.getFormClass(formClassId);
    symbolHandler = new XlsSymbolHandler(formClass.getFields());
    xPathBuilder = new XPathBuilder(symbolHandler);
    writeFields(formClass);
}
Also used : FormClass(org.activityinfo.model.form.FormClass) XPathBuilder(org.activityinfo.io.xform.xpath.XPathBuilder)

Example 18 with FormClass

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

the class ActivityInfoClient method getFormSchema.

public FormClass getFormSchema(ResourceId formId) {
    String json = client.resource(root).path("resources").path("form").path(formId.asString()).path("schema").accept(MediaType.APPLICATION_JSON_TYPE).get(String.class);
    JsonValue jsonObject = parse(json);
    FormClass formClass = FormClass.fromJson(jsonObject);
    return formClass;
}
Also used : FormClass(org.activityinfo.model.form.FormClass) JsonValue(org.activityinfo.json.JsonValue)

Example 19 with FormClass

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

the class LookupKeySet method addLevels.

private LookupKey addLevels(FormClass formClass) {
    ResourceId formId = formClass.getId();
    if (formMap.containsKey(formId)) {
        return formMap.get(formId);
    }
    // if serial number is present, we use that exclusively.
    Optional<FormField> serialNumberField = findSerialNumberField(formClass);
    if (serialNumberField.isPresent()) {
        LookupKey lookupKey = serialNumberLevel(formClass, serialNumberField.get());
        lookupKeys.add(lookupKey);
        return lookupKey;
    }
    LookupKey parentKey = null;
    String parentFieldId = null;
    // If there is a reference key, then we climb the reference tree recursively.
    Optional<FormField> referenceKey = findReferenceKey(formClass);
    if (referenceKey.isPresent()) {
        ReferenceType referenceType = (ReferenceType) referenceKey.get().getType();
        ResourceId referencedFormId = Iterables.getOnlyElement(referenceType.getRange());
        FormClass referencedFormClass = formTree.getFormClass(referencedFormId);
        parentMap.put(formId, referencedFormId);
        parentKey = addLevels(referencedFormClass);
        parentFieldId = referenceKey.get().getId().asString();
    }
    // Now check for text key fields
    for (FormField formField : formClass.getFields()) {
        if (isTextLikeKey(formField)) {
            LookupKey lookupKey = textKeyLevel(formClass, parentKey, parentFieldId, formField);
            lookupKeys.add(lookupKey);
            parentKey = lookupKey;
            parentFieldId = null;
        }
    }
    // If there is really no other key fields, then use the autogenerated id as a key
    if (parentKey == null) {
        parentKey = idLevel(formClass);
        lookupKeys.add(parentKey);
    }
    formMap.put(formId, parentKey);
    return parentKey;
}
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 20 with FormClass

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

the class FormTree method parentTree.

public FormTree parentTree() {
    FormClass rootFormClass = getRootFormClass();
    assert rootFormClass.isSubForm();
    ResourceId parentFormId = rootFormClass.getParentFormId().get();
    return subTree(parentFormId);
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) FormClass(org.activityinfo.model.form.FormClass)

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