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;
}
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;
}
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;
}
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;
}
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();
}
Aggregations