Search in sources :

Example 76 with JsonValue

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

the class CatalogEntry method toJsonElement.

public JsonValue toJsonElement() {
    JsonValue jsonObject = createObject();
    jsonObject.put("id", id);
    jsonObject.put("type", type.name().toLowerCase());
    jsonObject.put("label", label);
    jsonObject.put("leaf", leaf);
    return jsonObject;
}
Also used : JsonValue(org.activityinfo.json.JsonValue)

Example 77 with JsonValue

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

the class FormClass method toJson.

@Override
public JsonValue toJson() {
    JsonValue object = createObject();
    object.put("id", id.asString());
    object.put("schemaVersion", schemaVersion);
    if (databaseId != null) {
        object.put("databaseId", databaseId.asString());
    }
    object.put("label", label);
    if (!Strings.isNullOrEmpty(description)) {
        object.put("description", description);
    }
    if (subFormKind != null) {
        object.put("parentFormId", parentFormId.asString());
        object.put("subFormKind", subFormKind.name().toLowerCase());
    }
    object.put("elements", toJsonArray(elements));
    return object;
}
Also used : JsonValue(org.activityinfo.json.JsonValue)

Example 78 with JsonValue

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

the class FormClass method fromJsonArray.

static List<FormElement> fromJsonArray(JsonValue elementsArray) {
    List<FormElement> elements = new ArrayList<>();
    for (int i = 0; i < elementsArray.length(); i++) {
        JsonValue elementObject = elementsArray.get(i);
        elements.add(elementFromJson(elementObject));
    }
    return elements;
}
Also used : ArrayList(java.util.ArrayList) JsonValue(org.activityinfo.json.JsonValue)

Example 79 with JsonValue

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

the class FormClass method fromJson.

public static FormClass fromJson(JsonValue object) {
    // Deal with previous encoding
    ResourceId id;
    if (object.hasKey("@id")) {
        id = ResourceId.valueOf(object.get("@id").asString());
    } else {
        id = ResourceId.valueOf(object.get("id").asString());
    }
    FormClass formClass = new FormClass(id);
    if (object.hasKey("schemaVersion")) {
        formClass.setSchemaVersion(object.get("schemaVersion").asLong());
    }
    if (object.hasKey("databaseId")) {
        formClass.setDatabaseId(ResourceId.valueOf(object.get("databaseId").asString()));
    }
    if (object.hasKey("_class_label")) {
        formClass.setLabel(JsonParsing.toNullableString(object.get("_class_label")));
    } else {
        formClass.setLabel(JsonParsing.toNullableString(object.get("label")));
    }
    if (object.hasKey("subFormKind")) {
        formClass.setSubFormKind(SubFormKind.valueOf(object.get("subFormKind").asString().toUpperCase()));
        formClass.setParentFormId(ResourceId.valueOf(object.get("parentFormId").asString()));
    }
    if (object.hasKey("elements")) {
        JsonValue elements = object.get("elements");
        if (elements.isJsonArray()) {
            JsonValue elementsArray = elements;
            formClass.elements.addAll(fromJsonArray(elementsArray));
        }
    }
    return formClass;
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) JsonValue(org.activityinfo.json.JsonValue)

Example 80 with JsonValue

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

the class TableModel method fromJson.

public static TableModel fromJson(JsonValue object) {
    ImmutableTableModel.Builder model = ImmutableTableModel.builder();
    model.formId(ResourceId.valueOf(object.getString("formId")));
    if (object.hasKey("columns")) {
        JsonValue columnArray = object.get("columns");
        for (int i = 0; i < columnArray.length(); i++) {
            model.addColumns(TableColumn.fromJson(columnArray.get(i)));
        }
    }
    return model.build();
}
Also used : JsonValue(org.activityinfo.json.JsonValue)

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