use of org.activityinfo.model.type.enumerated.EnumItem in project activityinfo by bedatadriven.
the class EnumFieldImporter method persistSingleValuedEnum.
private boolean persistSingleValuedEnum(SourceRow row, FormInstance instance) {
if (validateSingleValuedEnum(row).isPersistable()) {
final Set<ResourceId> result = Sets.newHashSet();
String value = sources.get(0).getValue(row);
for (EnumItem enumItem : enumType.getValues()) {
if (enumItem.getLabel().equalsIgnoreCase(value)) {
result.add(enumItem.getId());
break;
}
}
if (!result.isEmpty()) {
instance.set(targets.get(0).getFormField().getId(), new EnumValue(result));
return true;
}
}
return false;
}
use of org.activityinfo.model.type.enumerated.EnumItem in project activityinfo by bedatadriven.
the class EnumImportStrategy method createImporter.
@Override
public FieldImporter createImporter(FormTree.Node node, Map<TargetSiteId, ColumnAccessor> mappings, ImportModel model) {
EnumType type = (EnumType) node.getType();
List<ColumnAccessor> sourceColumns = Lists.newArrayList();
if (type.getCardinality() == Cardinality.SINGLE) {
sourceColumns.add(mappings.get(VALUE));
} else {
for (EnumItem item : type.getValues()) {
ColumnAccessor accessor = mappings.get(new TargetSiteId(item.getId().asString()));
if (accessor == null) {
accessor = new EmptyColumn(item.getLabel());
}
sourceColumns.add(accessor);
}
}
return new EnumFieldImporter(sourceColumns, getImportSites(node), type);
}
use of org.activityinfo.model.type.enumerated.EnumItem in project activityinfo by bedatadriven.
the class XPathBuilderTest method createFormClass.
private static TFormClass createFormClass() {
EnumItem male = new EnumItem(ResourceId.generateId(), "Male");
EnumItem female = new EnumItem(ResourceId.generateId(), "Female");
EnumItem pregnantYes = new EnumItem(ResourceId.generateId(), "Yes");
EnumItem pregnantNo = new EnumItem(ResourceId.generateId(), "No");
FormField genderField = new FormField(GENDER_FIELD_ID);
genderField.setLabel("Gender");
genderField.setType(new EnumType(Cardinality.SINGLE, Arrays.asList(male, female)));
FormField pregnantField = new FormField(PREGNANT_FIELD_ID);
pregnantField.setLabel("are you currently pregnant?");
pregnantField.setType(new EnumType(Cardinality.SINGLE, Arrays.asList(pregnantYes, pregnantNo)));
FormField textField = new FormField(TEXT_FIELD_ID);
textField.setLabel("Text");
textField.setType(TextType.SIMPLE);
FormField quantityField = new FormField(QUANTITY_FIELD_ID);
quantityField.setLabel("Quantity");
quantityField.setType(QuantityType.TYPE_CLASS.createType());
final FormClass formClass = new FormClass(CuidAdapter.activityFormClass(1));
formClass.addElement(genderField);
formClass.addElement(pregnantField);
formClass.addElement(textField);
formClass.addElement(quantityField);
return new TFormClass(formClass);
}
use of org.activityinfo.model.type.enumerated.EnumItem in project activityinfo by bedatadriven.
the class SchemaImporterV3 method addChoice.
private void addChoice(FormClass formClass, SourceRow row) {
String fieldLabel = fieldName.get(row);
String fieldKey = formClass.getId() + fieldLabel;
EnumBuilder enumField = enumMap.get(fieldKey);
if (enumField == null) {
FormField newField = addField(formClass, EnumType.TYPE_CLASS, row);
enumField = new EnumBuilder(newField, parseCardinality(row));
enumMap.put(fieldKey, enumField);
}
enumField.items.add(new EnumItem(EnumItem.generateId(), choiceLabel.get(row)));
}
Aggregations