use of org.activityinfo.model.type.enumerated.EnumType in project activityinfo by bedatadriven.
the class CloneDatabaseTest method assertFormClass.
private void assertFormClass(FormClass sourceFormClass, FormClass targetFormClass) {
assertNotEquals(sourceFormClass.getId(), targetFormClass.getId());
assertEquals(sourceFormClass.getLabel(), targetFormClass.getLabel());
assertEquals(sourceFormClass.getDescription(), targetFormClass.getDescription());
// fields
for (FormField sourceField : sourceFormClass.getFields()) {
FormField targetField = (FormField) elementByName(targetFormClass.getElements(), sourceField.getLabel());
assertNotEquals(sourceField.getId(), targetField.getId());
assertEquals(sourceField.getDescription(), targetField.getDescription());
assertEquals(sourceField.getCode(), targetField.getCode());
assertEquals(sourceField.getRelevanceConditionExpression(), targetField.getRelevanceConditionExpression());
assertEquals(sourceField.getType().getTypeClass(), targetField.getType().getTypeClass());
// todo
if (sourceField.getType() instanceof ReferenceType) {
// need something more sophisticated to check equality of ReferenceType
} else if (sourceField.getType() instanceof EnumType) {
// need something more sophisticated to check equality of ReferenceType
}
}
// sections
for (FormSection sourceSection : sourceFormClass.getSections()) {
FormSection targetSection = (FormSection) elementByName(targetFormClass.getElements(), sourceSection.getLabel());
assertNotEquals(sourceSection.getId(), targetSection.getId());
assertEquals(sourceSection.getLabel(), targetSection.getLabel());
}
}
use of org.activityinfo.model.type.enumerated.EnumType in project activityinfo by bedatadriven.
the class CompactingEnumColumnBuilderTest method buildCompact.
@Test
public void buildCompact() {
EnumItem a = new EnumItem(ResourceId.valueOf("a"), "Enumerated Item A");
EnumItem b = new EnumItem(ResourceId.valueOf("b"), "Enumerated Item B");
EnumItem c = new EnumItem(ResourceId.valueOf("c"), "Enumerated Item C");
EnumType enumType = new EnumType(Cardinality.SINGLE, a, b, c);
CompactingEnumColumnBuilder builder = new CompactingEnumColumnBuilder(new PendingSlot<ColumnView>(), enumType);
for (int i = 0; i < 13; i++) {
builder.onNext(new EnumValue(a.getId()));
builder.onNext(new EnumValue(b.getId()));
builder.onNext(new EnumValue(c.getId()));
builder.onNext(null);
}
ColumnView column8 = builder.build8();
ColumnView column32 = builder.build32();
for (int i = 0; i < column32.numRows(); i++) {
if (!Objects.equals(column8.getString(i), column32.getString(i))) {
throw new AssertionError("Vectors not equal at index " + i);
}
}
assertThat(builder.build(), instanceOf(DiscreteStringColumnView8.class));
}
use of org.activityinfo.model.type.enumerated.EnumType in project activityinfo by bedatadriven.
the class NodeMatcherTest method multiEnum.
private FormField multiEnum(String id, String label, String... values) {
List<EnumItem> enumValues = Lists.newArrayList();
for (String value : values) {
enumValues.add(new EnumItem(ResourceId.valueOf(value), value));
}
EnumType type = new EnumType(Cardinality.MULTIPLE, enumValues);
FormField field = new FormField(ResourceId.valueOf(id));
field.setLabel(label);
field.setType(type);
return field;
}
use of org.activityinfo.model.type.enumerated.EnumType in project activityinfo by bedatadriven.
the class NodeMatcher method matchEnum.
private Optional<NodeMatch> matchEnum(QueryPath queryPath, FormTree.Node field) {
if (queryPath.matches(field)) {
QueryPath next = queryPath.next();
if (next.isLeaf()) {
EnumType type = (EnumType) field.getType();
List<EnumItem> matchingItems = Lists.newArrayList();
for (EnumItem enumItem : type.getValues()) {
if (next.head().equals(enumItem.getId().asString()) || next.head().equalsIgnoreCase(enumItem.getLabel()) || next.head().equalsIgnoreCase(enumItem.getCode())) {
matchingItems.add(enumItem);
}
}
if (matchingItems.size() == 1) {
return Optional.of(NodeMatch.forEnumItem(field, matchingItems.get(0)));
}
}
}
return Optional.absent();
}
use of org.activityinfo.model.type.enumerated.EnumType in project activityinfo by bedatadriven.
the class SchemaCsvWriterV3Test method setupSurveyForm.
private void setupSurveyForm() {
surveyForm = new FormClass(ResourceId.valueOf("FORM1"));
surveyForm.setLabel("Household Survey");
surveyForm.addElement(new FormField(ResourceId.valueOf("F1")).setCode("NAME").setLabel("What is your name?").setDescription("The head of household's name").setRequired(true).setType(TextType.SIMPLE));
surveyForm.addElement(new FormField(ResourceId.valueOf("F2")).setCode("AGE").setLabel("What is your age?").setType(new QuantityType("years")).setRequired(true));
surveyForm.addElement(new FormField(ResourceId.valueOf("F3")).setCode("GENDER").setLabel("Gender of head of household").setType(new EnumType(Cardinality.SINGLE, new EnumItem(ResourceId.valueOf("GF"), "Female"), new EnumItem(ResourceId.valueOf("GM"), "Male"))).setRequired(true));
surveyForm.addElement(new FormField(ResourceId.valueOf("F4")).setLabel("Are you currently pregnant?").setRelevanceConditionExpression("AGE > 18 && GENDER == 'Female'").setType(new EnumType(Cardinality.SINGLE, new EnumItem(ResourceId.valueOf("PY"), "Yes"), new EnumItem(ResourceId.valueOf("PN"), "No"))).setRequired(true));
surveyForm.addElement(new FormField(ResourceId.valueOf("F5")).setLabel("Remarks").setType(NarrativeType.INSTANCE).setRequired(false));
FormClass subFormClass = new FormClass(ResourceId.valueOf("FORM2"));
subFormClass.setSubFormKind(SubFormKind.REPEATING);
subFormClass.addElement(new FormField(ResourceId.valueOf("F21")).setLabel("Name").setType(TextType.SIMPLE).setRequired(true));
subFormClass.addElement(new FormField(ResourceId.valueOf("F22")).setLabel("Age").setType(new QuantityType("years")).setRequired(true));
subFormClass.addElement(new FormField(ResourceId.valueOf("F23")).setLabel("Gender").setType(new EnumType(Cardinality.SINGLE, new EnumItem(ResourceId.valueOf("GF"), "Female"), new EnumItem(ResourceId.valueOf("GM"), "Male"))).setRequired(true));
subFormClass.addElement(new FormField(ResourceId.valueOf("F24")).setLabel("Vaccinations").setType(new EnumType(Cardinality.MULTIPLE, new EnumItem(ResourceId.valueOf("V1"), "Measles"), new EnumItem(ResourceId.valueOf("V2"), "Mumps"), new EnumItem(ResourceId.valueOf("V3"), "Rubella"))));
surveyForm.addElement(new FormField(ResourceId.valueOf("SF")).setLabel("Household members").setType(new SubFormReferenceType(subFormClass.getId())));
formClassProvider.add(surveyForm);
formClassProvider.add(subFormClass);
}
Aggregations