use of org.activityinfo.json.JsonValue in project activityinfo by bedatadriven.
the class JsonFormTreeBuilder method fromJson.
public static FormTree fromJson(JsonValue object) {
ResourceId rootFormClassId = ResourceId.valueOf(object.get("root").asString());
JsonValue forms = object.get("forms");
final Map<ResourceId, FormClass> formMap = new HashMap<>();
for (String key : forms.keys()) {
JsonValue value = forms.get(key);
FormClass formClass = FormClass.fromJson(value);
formMap.put(formClass.getId(), formClass);
}
FormClassProvider provider = new FormClassProvider() {
@Override
public FormClass getFormClass(ResourceId formId) {
FormClass formClass = formMap.get(formId);
assert formClass != null : "FormClass " + formId + " was referenced but not include in the " + "list of forms";
return formClass;
}
};
FormTreeBuilder builder = new FormTreeBuilder(provider);
return builder.queryTree(rootFormClassId);
}
use of org.activityinfo.json.JsonValue in project activityinfo by bedatadriven.
the class JsonFormTreeBuilder method toJson.
public static JsonValue toJson(FormTree tree) {
ResourceId rootFormClassId = tree.getRootFormId();
JsonValue forms = createObject();
collectForms(forms, tree.getRootFields());
JsonValue object = createObject();
object.put("root", rootFormClassId.asString());
object.put("forms", forms);
return object;
}
use of org.activityinfo.json.JsonValue in project activityinfo by bedatadriven.
the class FormField method toJsonObject.
@Override
public JsonValue toJsonObject() {
JsonValue object = createObject();
object.put("id", id.asString());
object.put("code", code);
object.put("label", label);
object.put("description", description);
object.put("relevanceCondition", relevanceConditionExpression);
object.put("visible", visible);
object.put("required", required);
object.put("type", type.getTypeClass().getId());
if (key) {
object.put("key", true);
}
if (!superProperties.isEmpty()) {
JsonValue superPropertiesArray = Json.createArray();
for (ResourceId superProperty : superProperties) {
superPropertiesArray.add(Json.createFromNullable(superProperty.asString()));
}
object.put("superProperties", superPropertiesArray);
}
if (type instanceof ParametrizedFieldType) {
object.put("typeParameters", ((ParametrizedFieldType) type).getParametersAsJson());
}
return object;
}
use of org.activityinfo.json.JsonValue in project activityinfo by bedatadriven.
the class FormInstance method toJsonObject.
public JsonValue toJsonObject() {
JsonValue fields = createObject();
for (Map.Entry<ResourceId, FieldValue> entry : fieldMap.entrySet()) {
if (entry.getValue() != null) {
fields.put(entry.getKey().asString(), entry.getValue().toJson());
}
}
JsonValue object = createObject();
object.put("formId", getFormId().asString());
object.put("recordId", getId().asString());
object.put("fieldValues", fields);
return object;
}
use of org.activityinfo.json.JsonValue in project activityinfo by bedatadriven.
the class FormInstance method toFormInstance.
public static FormInstance toFormInstance(FormClass formClass, FormRecord record) {
FormInstance instance = new FormInstance(ResourceId.valueOf(record.getRecordId()), formClass.getId());
if (record.getParentRecordId() != null) {
instance.setParentRecordId(ResourceId.valueOf(record.getParentRecordId()));
}
JsonValue fieldsObject = record.getFields();
for (FormField field : formClass.getFields()) {
if (fieldsObject.hasKey(field.getName())) {
JsonValue fieldValue = fieldsObject.get(field.getName());
if (!fieldValue.isJsonNull()) {
instance.set(field.getId(), field.getType().parseJsonValue(fieldValue));
}
}
}
return instance;
}
Aggregations