Search in sources :

Example 41 with EnumItem

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;
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) EnumValue(org.activityinfo.model.type.enumerated.EnumValue) EnumItem(org.activityinfo.model.type.enumerated.EnumItem)

Example 42 with EnumItem

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);
}
Also used : EnumType(org.activityinfo.model.type.enumerated.EnumType) EnumItem(org.activityinfo.model.type.enumerated.EnumItem)

Example 43 with EnumItem

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);
}
Also used : EnumType(org.activityinfo.model.type.enumerated.EnumType) FormClass(org.activityinfo.model.form.FormClass) TFormClass(org.activityinfo.model.form.TFormClass) TFormClass(org.activityinfo.model.form.TFormClass) EnumItem(org.activityinfo.model.type.enumerated.EnumItem) FormField(org.activityinfo.model.form.FormField)

Example 44 with EnumItem

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)));
}
Also used : EnumItem(org.activityinfo.model.type.enumerated.EnumItem) FormField(org.activityinfo.model.form.FormField)

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