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());
}
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());
}
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;
}
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);
}
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);
}
Aggregations