Search in sources :

Example 81 with JsonValue

use of org.activityinfo.json.JsonValue in project activityinfo by bedatadriven.

the class Resource method toJson.

@Override
public JsonValue toJson() {
    JsonValue object = Json.createObject();
    object.put("id", id.asString());
    object.put("parentId", parentId.asString());
    object.put("label", label);
    object.put("type", type.name());
    return object;
}
Also used : JsonValue(org.activityinfo.json.JsonValue)

Example 82 with JsonValue

use of org.activityinfo.json.JsonValue in project activityinfo by bedatadriven.

the class UserPermissionModel method toJson.

@Override
public JsonValue toJson() {
    JsonValue grantsArray = Json.createArray();
    for (GrantModel grant : grants) {
        grantsArray.add(grant.toJson());
    }
    JsonValue object = Json.createObject();
    object.put("userId", userId);
    object.put("databaseId", databaseId);
    object.put("grants", grantsArray);
    return object;
}
Also used : JsonValue(org.activityinfo.json.JsonValue)

Example 83 with JsonValue

use of org.activityinfo.json.JsonValue in project activityinfo by bedatadriven.

the class EnumTypeTest method deserializationCheckboxes.

@Test
public void deserializationCheckboxes() {
    JsonValue object = createObject();
    object.put("presentation", "CHECKBOX");
    object.put("cardinality", "SINGLE");
    object.put("values", Json.createArray());
    EnumType enumType = EnumType.TYPE_CLASS.deserializeType(object);
    assertThat(enumType.getPresentation(), equalTo(EnumType.Presentation.RADIO_BUTTON));
}
Also used : JsonValue(org.activityinfo.json.JsonValue) Test(org.junit.Test)

Example 84 with JsonValue

use of org.activityinfo.json.JsonValue in project activityinfo by bedatadriven.

the class FormClassTest method serializationWithMissingLabel.

@Test
public void serializationWithMissingLabel() {
    FormClass formClass = new FormClass(ResourceId.generateId());
    formClass.setLabel("Form");
    FormField field = new FormField(ResourceId.generateId());
    field.setType(TextType.SIMPLE);
    formClass.addElement(field);
    JsonValue jsonObject = formClass.toJson();
    FormClass reform = FormClass.fromJson(jsonObject);
    assertThat(reform.getFields(), hasSize(1));
}
Also used : JsonValue(org.activityinfo.json.JsonValue) Test(org.junit.Test)

Example 85 with JsonValue

use of org.activityinfo.json.JsonValue in project activityinfo by bedatadriven.

the class FormTreeTest method toJson.

@Test
public void toJson() {
    FormTreeBuilder builder = new FormTreeBuilder(forms);
    FormTree formTree = builder.queryTree(forms.student.getId());
    checkStudentTree(formTree);
    JsonValue object = JsonFormTreeBuilder.toJson(formTree);
    System.out.println(JsonUtil.stringify(object, 2));
    FormTree reTree = JsonFormTreeBuilder.fromJson(object);
    checkStudentTree(reTree);
}
Also used : JsonValue(org.activityinfo.json.JsonValue) Test(org.junit.Test)

Aggregations

JsonValue (org.activityinfo.json.JsonValue)117 Test (org.junit.Test)24 ResourceId (org.activityinfo.model.resource.ResourceId)19 FormClass (org.activityinfo.model.form.FormClass)13 FormField (org.activityinfo.model.form.FormField)9 FieldValue (org.activityinfo.model.type.FieldValue)8 HashMap (java.util.HashMap)6 Map (java.util.Map)6 QuantityType (org.activityinfo.model.type.number.QuantityType)5 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Annotation (java.lang.annotation.Annotation)3 ArrayList (java.util.ArrayList)3 FormTreeBuilder (org.activityinfo.model.formTree.FormTreeBuilder)3 JaxRsJsonReader (org.activityinfo.server.endpoint.rest.JaxRsJsonReader)3 TypedRecordUpdate (org.activityinfo.store.spi.TypedRecordUpdate)3 EmbeddedEntity (com.google.appengine.api.datastore.EmbeddedEntity)2 URL (java.net.URL)2 JsonException (org.activityinfo.json.JsonException)2 JsonMappingException (org.activityinfo.json.JsonMappingException)2