Search in sources :

Example 6 with EmbeddedEntity

use of com.google.appengine.api.datastore.EmbeddedEntity 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 7 with EmbeddedEntity

use of com.google.appengine.api.datastore.EmbeddedEntity in project activityinfo by bedatadriven.

the class FormRecordEntity method setFieldValues.

public void setFieldValues(FormClass formClass, Map<ResourceId, FieldValue> values) {
    if (fieldValues == null) {
        fieldValues = new EmbeddedEntity();
    }
    for (FormField field : formClass.getFields()) {
        if (values.containsKey(field.getId())) {
            FieldValue value = values.get(field.getId());
            if (value == null) {
                fieldValues.removeProperty(field.getName());
            } else {
                FieldConverter converter = FieldConverters.forType(field.getType());
                fieldValues.setUnindexedProperty(field.getName(), converter.toHrdProperty(value));
            }
        }
    }
}
Also used : FieldConverter(org.activityinfo.store.hrd.FieldConverter) FieldValue(org.activityinfo.model.type.FieldValue) EmbeddedEntity(com.google.appengine.api.datastore.EmbeddedEntity) FormField(org.activityinfo.model.form.FormField)

Aggregations

EmbeddedEntity (com.google.appengine.api.datastore.EmbeddedEntity)7 Entity (com.google.appengine.api.datastore.Entity)3 Test (org.junit.Test)3 JsonValue (org.activityinfo.json.JsonValue)2 Key (com.google.appengine.api.datastore.Key)1 List (java.util.List)1 FormField (org.activityinfo.model.form.FormField)1 FieldValue (org.activityinfo.model.type.FieldValue)1 EnumType (org.activityinfo.model.type.enumerated.EnumType)1 FieldConverter (org.activityinfo.store.hrd.FieldConverter)1