use of org.activityinfo.json.JsonValue in project activityinfo by bedatadriven.
the class RecordLock method toJson.
@Override
public JsonValue toJson() {
JsonValue object = Json.createObject();
object.put("id", id.asString());
object.put("label", label);
object.put("resourceId", resourceId.asString());
object.put("dateRange", dateRange.toJson());
return object;
}
use of org.activityinfo.json.JsonValue in project activityinfo by bedatadriven.
the class UserDatabaseMeta method toJson.
public JsonValue toJson() {
JsonValue object = Json.createObject();
object.put("id", databaseId.asString());
object.put("version", version);
object.put("label", label);
object.put("visible", visible);
object.put("owner", owner);
object.put("userId", userId);
object.put("resources", Json.toJsonArray(resources.values()));
object.put("locks", Json.toJsonArray(locks.values()));
object.put("grants", Json.toJsonArray(grants.values()));
return object;
}
use of org.activityinfo.json.JsonValue in project activityinfo by bedatadriven.
the class UserDatabaseMeta method fromJson.
public static UserDatabaseMeta fromJson(JsonValue object) {
UserDatabaseMeta meta = new UserDatabaseMeta();
meta.databaseId = ResourceId.valueOf(object.getString("id"));
meta.userId = (int) object.getNumber("userId");
meta.version = object.getString("version");
meta.label = object.getString("label");
meta.visible = object.getBoolean("visible");
meta.owner = object.getBoolean("owner");
JsonValue resourceArray = object.get("resources");
for (int i = 0; i < resourceArray.length(); i++) {
Resource resource = Resource.fromJson(resourceArray.get(i));
meta.resources.put(resource.getId(), resource);
}
JsonValue lockArray = object.get("locks");
for (int i = 0; i < lockArray.length(); i++) {
RecordLock lock = RecordLock.fromJson(lockArray.get(i));
meta.locks.put(lock.getResourceId(), lock);
}
JsonValue grantsArray = object.get("grants");
for (int i = 0; i < grantsArray.length(); i++) {
GrantModel grant = GrantModel.fromJson(grantsArray.get(i));
meta.grants.put(grant.getResourceId(), grant);
}
return meta;
}
use of org.activityinfo.json.JsonValue in project activityinfo by bedatadriven.
the class UserPermissionModel method fromJson.
public static UserPermissionModel fromJson(JsonValue jsonValue) {
UserPermissionModel model = new UserPermissionModel();
model.userId = (int) jsonValue.getNumber("userId");
model.databaseId = (int) jsonValue.getNumber("databaseId");
for (JsonValue value : jsonValue.get("grants").values()) {
model.grants.add(GrantModel.fromJson(value));
}
return model;
}
use of org.activityinfo.json.JsonValue in project activityinfo by bedatadriven.
the class FormField method fromJson.
public static FormField fromJson(JsonValue jsonObject) {
FormField field = new FormField(ResourceId.valueOf(jsonObject.get("id").asString()));
field.setLabel(Strings.nullToEmpty(JsonParsing.toNullableString(jsonObject.get("label"))));
field.setCode(JsonParsing.toNullableString(jsonObject.get("code")));
field.setDescription(JsonParsing.toNullableString(jsonObject.get("description")));
if (jsonObject.hasKey("relevanceCondition")) {
field.setRelevanceConditionExpression(JsonParsing.toNullableString(jsonObject.get("relevanceCondition")));
} else if (jsonObject.hasKey("relevanceConditionExpression")) {
field.setRelevanceConditionExpression(JsonParsing.toNullableString(jsonObject.get("relevanceConditionExpression")));
}
if (jsonObject.hasKey("visible")) {
field.setVisible(jsonObject.get("visible").asBoolean());
}
if (jsonObject.hasKey("required")) {
field.setRequired(jsonObject.get("required").asBoolean());
}
if (jsonObject.hasKey("key")) {
field.setKey(jsonObject.get("key").asBoolean());
}
if (jsonObject.hasKey("superProperties")) {
JsonValue superPropertiesArray = jsonObject.get("superProperties");
for (int i = 0; i < superPropertiesArray.length(); i++) {
field.addSuperProperty(ResourceId.valueOf(superPropertiesArray.getString(i)));
}
}
String type;
JsonValue typeParameters;
JsonValue typeElement = jsonObject.get("type");
if (typeElement.isJsonPrimitive()) {
type = typeElement.asString();
typeParameters = jsonObject.get("typeParameters");
} else {
JsonValue typeObject = typeElement;
type = typeObject.get("typeClass").asString();
typeParameters = typeObject.get("parameters");
}
FieldTypeClass typeClass = TypeRegistry.get().getTypeClass(type);
if (typeClass instanceof ParametrizedFieldTypeClass && !typeParameters.isJsonNull()) {
field.setType(((ParametrizedFieldTypeClass) typeClass).deserializeType(typeParameters));
} else {
field.setType(typeClass.createType());
}
return field;
}
Aggregations