Search in sources :

Example 16 with JsonValue

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;
}
Also used : JsonValue(org.activityinfo.json.JsonValue)

Example 17 with JsonValue

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;
}
Also used : JsonValue(org.activityinfo.json.JsonValue)

Example 18 with JsonValue

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;
}
Also used : JsonValue(org.activityinfo.json.JsonValue)

Example 19 with JsonValue

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;
}
Also used : JsonValue(org.activityinfo.json.JsonValue)

Example 20 with JsonValue

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;
}
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