Search in sources :

Example 6 with EnumItem

use of org.activityinfo.model.type.enumerated.EnumItem 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 7 with EnumItem

use of org.activityinfo.model.type.enumerated.EnumItem in project activityinfo by bedatadriven.

the class AttributeGroupDTO method asFormField.

@Override
public FormField asFormField() {
    Cardinality cardinality = isMultipleAllowed() ? Cardinality.MULTIPLE : Cardinality.SINGLE;
    List<EnumItem> values = Lists.newArrayList();
    for (AttributeDTO attribute : getAttributes()) {
        values.add(new EnumItem(CuidAdapter.attributeId(attribute.getId()), attribute.getName()));
    }
    return new FormField(CuidAdapter.attributeGroupField(getId())).setLabel(getName()).setType(new EnumType(cardinality, values)).setRequired(isMandatory());
}
Also used : Cardinality(org.activityinfo.model.type.Cardinality) EnumType(org.activityinfo.model.type.enumerated.EnumType) EnumItem(org.activityinfo.model.type.enumerated.EnumItem) FormField(org.activityinfo.model.form.FormField)

Example 8 with EnumItem

use of org.activityinfo.model.type.enumerated.EnumItem in project activityinfo by bedatadriven.

the class AttributeDimBinding method findAttributeOrder.

private Map<String, Integer> findAttributeOrder(Optional<FormField> field) {
    Map<String, Integer> map = new HashMap<>();
    if (field.isPresent() && field.get().getType() instanceof EnumType) {
        EnumType type = (EnumType) field.get().getType();
        List<EnumItem> items = type.getValues();
        for (int i = 0; i < items.size(); i++) {
            map.put(items.get(i).getLabel(), i);
        }
    }
    return map;
}
Also used : EnumType(org.activityinfo.model.type.enumerated.EnumType) EnumItem(org.activityinfo.model.type.enumerated.EnumItem)

Example 9 with EnumItem

use of org.activityinfo.model.type.enumerated.EnumItem in project activityinfo by bedatadriven.

the class OdkFormFieldBuilderFactory method enumOptions.

private SelectOptions enumOptions(EnumType enumType) {
    Cardinality cardinality = enumType.getCardinality();
    List<Item> items = Lists.newArrayListWithCapacity(enumType.getValues().size());
    for (EnumItem enumItem : enumType.getValues()) {
        Item item = new Item();
        item.setLabel(enumItem.getLabel());
        item.setValue(enumItem.getId().asString());
        items.add(item);
    }
    return new SelectOptions(cardinality, items);
}
Also used : Item(org.activityinfo.io.xform.form.Item) EnumItem(org.activityinfo.model.type.enumerated.EnumItem) EnumItem(org.activityinfo.model.type.enumerated.EnumItem)

Example 10 with EnumItem

use of org.activityinfo.model.type.enumerated.EnumItem in project activityinfo by bedatadriven.

the class ActivityTest method orderIndicatorsActivities.

@Test
public void orderIndicatorsActivities() {
    SchemaDTO schema = execute(new GetSchema());
    UserDatabaseDTO db = schema.getDatabaseById(1);
    LocationTypeDTO locType = schema.getCountryById(1).getLocationTypes().get(0);
    ActivityFormDTO act = new ActivityFormDTO();
    act.setName("Household Survey");
    act.setLocationType(locType);
    act.setReportingFrequency(ActivityFormDTO.REPORT_ONCE);
    CreateResult createResult = execute(CreateEntity.Activity(db, act));
    ResourceId classId = activityFormClass(createResult.getNewId());
    FormClass formClass = assertResolves(locator.getFormClass(classId));
    // create three new fields with an order that mixes "attributes" and "indicators"
    FormField newField = new FormField(ResourceId.generateFieldId(QuantityType.TYPE_CLASS));
    newField.setLabel("How old are you?");
    newField.setType(new QuantityType().setUnits("years"));
    formClass.addElement(newField);
    FormField newGenderField = new FormField(ResourceId.generateFieldId(EnumType.TYPE_CLASS));
    newGenderField.setLabel("Gender");
    EnumItem male = new EnumItem(EnumItem.generateId(), "Male");
    EnumItem female = new EnumItem(EnumItem.generateId(), "Female");
    newGenderField.setType(new EnumType(Cardinality.SINGLE, Arrays.asList(male, female)));
    formClass.addElement(newGenderField);
    FormField newTextField = new FormField(ResourceId.generateFieldId(TextType.TYPE_CLASS));
    newTextField.setLabel("What is your name?");
    newTextField.setType(TextType.SIMPLE);
    formClass.addElement(newTextField);
    assertResolves(locator.persist(formClass));
    TFormClass reform = new TFormClass(assertResolves(locator.getFormClass(formClass.getId())));
    System.out.println(Joiner.on("\n").join(reform.getFormClass().getFields()));
    int a = reform.indexOfField("How old are you?");
    int b = reform.indexOfField("Gender");
    int c = reform.indexOfField("What is your name?");
    assertTrue(a < b && b < c);
}
Also used : CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) ResourceId(org.activityinfo.model.resource.ResourceId) QuantityType(org.activityinfo.model.type.number.QuantityType) CuidAdapter.activityFormClass(org.activityinfo.model.legacy.CuidAdapter.activityFormClass) EnumType(org.activityinfo.model.type.enumerated.EnumType) EnumItem(org.activityinfo.model.type.enumerated.EnumItem) Test(org.junit.Test)

Aggregations

EnumItem (org.activityinfo.model.type.enumerated.EnumItem)44 EnumType (org.activityinfo.model.type.enumerated.EnumType)30 FormField (org.activityinfo.model.form.FormField)11 FormClass (org.activityinfo.model.form.FormClass)9 ResourceId (org.activityinfo.model.resource.ResourceId)9 Test (org.junit.Test)7 QuantityType (org.activityinfo.model.type.number.QuantityType)6 EnumValue (org.activityinfo.model.type.enumerated.EnumValue)5 CuidAdapter.activityFormClass (org.activityinfo.model.legacy.CuidAdapter.activityFormClass)4 CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)3 CompoundExpr (org.activityinfo.model.formula.CompoundExpr)2 SymbolNode (org.activityinfo.model.formula.SymbolNode)2 ColumnModel (org.activityinfo.model.query.ColumnModel)2 ColumnView (org.activityinfo.model.query.ColumnView)2 Cardinality (org.activityinfo.model.type.Cardinality)2 FieldValue (org.activityinfo.model.type.FieldValue)2 CalculatedFieldType (org.activityinfo.model.type.expr.CalculatedFieldType)2 SubFormReferenceType (org.activityinfo.model.type.subform.SubFormReferenceType)2 ActivityField (org.activityinfo.store.mysql.metadata.ActivityField)2 Optional (com.google.common.base.Optional)1