Search in sources :

Example 21 with EnumType

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

Example 22 with EnumType

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

Example 23 with EnumType

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));
}
Also used : EnumType(org.activityinfo.model.type.enumerated.EnumType) JsonValue(org.activityinfo.json.JsonValue) EmbeddedEntity(com.google.appengine.api.datastore.EmbeddedEntity) Test(org.junit.Test)

Example 24 with EnumType

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();
        }
    });
}
Also used : Optional(com.google.common.base.Optional) ResourceId(org.activityinfo.model.resource.ResourceId) VoidWork(com.googlecode.objectify.VoidWork) FormClass(org.activityinfo.model.form.FormClass) EnumType(org.activityinfo.model.type.enumerated.EnumType) EnumItem(org.activityinfo.model.type.enumerated.EnumItem) Test(org.junit.Test)

Example 25 with EnumType

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

Aggregations

EnumType (org.activityinfo.model.type.enumerated.EnumType)39 EnumItem (org.activityinfo.model.type.enumerated.EnumItem)30 FormField (org.activityinfo.model.form.FormField)14 FormClass (org.activityinfo.model.form.FormClass)11 ResourceId (org.activityinfo.model.resource.ResourceId)7 QuantityType (org.activityinfo.model.type.number.QuantityType)7 Test (org.junit.Test)7 CalculatedFieldType (org.activityinfo.model.type.expr.CalculatedFieldType)5 SubFormReferenceType (org.activityinfo.model.type.subform.SubFormReferenceType)5 EnumValue (org.activityinfo.model.type.enumerated.EnumValue)4 CuidAdapter.activityFormClass (org.activityinfo.model.legacy.CuidAdapter.activityFormClass)3 JsonValue (org.activityinfo.json.JsonValue)2 CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)2 ColumnView (org.activityinfo.model.query.ColumnView)2 Cardinality (org.activityinfo.model.type.Cardinality)2 FieldType (org.activityinfo.model.type.FieldType)2 FieldValue (org.activityinfo.model.type.FieldValue)2 NarrativeType (org.activityinfo.model.type.NarrativeType)2 ReferenceType (org.activityinfo.model.type.ReferenceType)2 TextType (org.activityinfo.model.type.primitive.TextType)2