use of org.activityinfo.model.type.enumerated.EnumType in project activityinfo by bedatadriven.
the class SchemaCsvWriterV3 method writeForm.
private void writeForm(UserDatabaseDTO db, FormClass formClass) throws IOException {
FieldContext context = new FieldContext(db, formClass);
List<FormField> fields = formClass.getFields();
for (FormField field : fields) {
if (field.getType() instanceof EnumType) {
writeEnumItems(context, field, ((EnumType) field.getType()).getValues());
} else if (field.getType() instanceof SubFormReferenceType) {
writeSubForm(context, field);
} else if (!isBuiltinField(formClass, field)) {
writeField(context, field);
}
}
}
use of org.activityinfo.model.type.enumerated.EnumType in project activityinfo by bedatadriven.
the class SchemaCsvWriterV3 method writeSubForm.
private void writeSubForm(FieldContext context, FormField field) throws IOException {
SubFormReferenceType fieldType = (SubFormReferenceType) field.getType();
FormClass subFormClass = catalog.getFormClass(fieldType.getClassId());
FieldContext subFormContext = context.subForm(field, subFormClass);
for (FormField subField : subFormClass.getFields()) {
if (subField.getType() instanceof EnumType) {
writeEnumItems(subFormContext, subField, ((EnumType) subField.getType()).getValues());
} else {
writeField(subFormContext, subField);
}
}
}
use of org.activityinfo.model.type.enumerated.EnumType in project activityinfo by bedatadriven.
the class FormConverterTest method deserializationEnumTypeNoChoices.
@Test
public void deserializationEnumTypeNoChoices() {
EnumType type = new EnumType(Cardinality.SINGLE, EnumType.Presentation.AUTOMATIC, Collections.<EnumItem>emptyList());
JsonValue jsonObject = type.getParametersAsJson();
EmbeddedEntity entity = FormConverter.toEmbeddedEntity(jsonObject);
JsonValue fromEntity = FormConverter.fromEmbeddedEntity(entity);
EnumType reType = EnumType.TYPE_CLASS.deserializeType(fromEntity);
assertThat(reType.getCardinality(), equalTo(Cardinality.SINGLE));
assertThat(reType.getPresentation(), equalTo(EnumType.Presentation.AUTOMATIC));
assertThat(reType.getValues(), hasSize(0));
}
use of org.activityinfo.model.type.enumerated.EnumType in project activityinfo by bedatadriven.
the class HrdCatalogTest method enumWithNoChoices.
@Test
public void enumWithNoChoices() {
final ResourceId formId = ResourceId.generateId();
ResourceId villageField = ResourceId.valueOf("FV");
final ResourceId selectField = ResourceId.valueOf("FC");
FormClass formClass = new FormClass(formId);
formClass.setParentFormId(ResourceId.valueOf("foo"));
formClass.setLabel("NFI Distributions");
formClass.addField(villageField).setLabel("Village name").setCode("VILLAGE").setType(TextType.SIMPLE);
formClass.addField(selectField).setLabel("Favorite color").setType(new EnumType(Cardinality.SINGLE, EnumType.Presentation.AUTOMATIC, Collections.<EnumItem>emptyList()));
HrdStorageProvider catalog = new HrdStorageProvider();
catalog.create(formClass);
// Avoid cache
// objectifyCloseable.close();
ObjectifyService.run(new VoidWork() {
@Override
public void vrun() {
HrdStorageProvider catalog = new HrdStorageProvider();
Optional<FormStorage> storage = catalog.getForm(formId);
FormClass deserializedSchema = storage.get().getFormClass();
}
});
}
use of org.activityinfo.model.type.enumerated.EnumType in project activityinfo by bedatadriven.
the class XPathBuilder method resolveSymbol.
private String resolveSymbol(ConstantNode constantNode) throws XSymbolException {
String resolved;
if (constantNode.getType() instanceof EnumType) {
EnumValue enumValue = (EnumValue) constantNode.getValue();
resolved = symbolHandler.resolveSymbol(enumValue.getValueId().asString());
} else {
resolved = symbolHandler.resolveSymbol(constantNode.getValue().toString());
}
return resolved;
}
Aggregations