Search in sources :

Example 11 with JsonValue

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

the class ActivityInfoClientAsyncImpl method getFormTree.

@Override
public Promise<FormTree> getFormTree(final ResourceId formId) {
    return get(formUrl(formId) + "/tree", jsonElement -> {
        JsonValue root = jsonElement;
        JsonValue forms = root.get("forms");
        final Map<ResourceId, FormClass> formMap = new HashMap<>();
        for (Map.Entry<String, JsonValue> entry : forms.entrySet()) {
            FormClass formClass = FormClass.fromJson(entry.getValue());
            formMap.put(formClass.getId(), formClass);
        }
        FormTreeBuilder builder = new FormTreeBuilder(new FormClassProvider() {

            @Override
            public FormClass getFormClass(ResourceId formId1) {
                FormClass formClass = formMap.get(formId1);
                assert formClass != null;
                return formClass;
            }
        });
        return builder.queryTree(formId);
    });
}
Also used : FormClassProvider(org.activityinfo.model.formTree.FormClassProvider) ResourceId(org.activityinfo.model.resource.ResourceId) HashMap(java.util.HashMap) JsonValue(org.activityinfo.json.JsonValue) HashMap(java.util.HashMap) Map(java.util.Map) FormTreeBuilder(org.activityinfo.model.formTree.FormTreeBuilder)

Example 12 with JsonValue

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

the class NewFormRecord method fromJson.

public static NewFormRecord fromJson(JsonValue jsonElement) {
    JsonValue jsonObject = jsonElement;
    NewFormRecord model = new NewFormRecord();
    model.id = JsonParsing.toNullableString(jsonObject.get("id"));
    model.parentRecordId = JsonParsing.toNullableString(jsonObject.get("parentRecordId"));
    model.keyId = JsonParsing.toNullableString(jsonObject.get("keyId"));
    model.fieldValues = jsonObject.get("fieldValues");
    return model;
}
Also used : JsonValue(org.activityinfo.json.JsonValue)

Example 13 with JsonValue

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

the class ActivityInfoClient method getFormSchema.

public FormClass getFormSchema(ResourceId formId) {
    String json = client.resource(root).path("resources").path("form").path(formId.asString()).path("schema").accept(MediaType.APPLICATION_JSON_TYPE).get(String.class);
    JsonValue jsonObject = parse(json);
    FormClass formClass = FormClass.fromJson(jsonObject);
    return formClass;
}
Also used : FormClass(org.activityinfo.model.form.FormClass) JsonValue(org.activityinfo.json.JsonValue)

Example 14 with JsonValue

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

the class TableModel method toJson.

@Value.Lazy
@Override
public JsonValue toJson() {
    JsonValue object = Json.createObject();
    object.put("formId", getFormId().asString());
    if (getColumns().size() != 0) {
        JsonValue columnArray = Json.createArray();
        for (TableColumn tableColumn : getColumns()) {
            columnArray.add(tableColumn.toJson());
        }
        object.put("columns", columnArray);
    }
    return object;
}
Also used : JsonValue(org.activityinfo.json.JsonValue)

Example 15 with JsonValue

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

the class GrantModel method toJson.

@Override
public JsonValue toJson() {
    JsonValue operationsArray = Json.createArray();
    for (Operation operation : operations) {
        operationsArray.add(Json.create(operation.name()));
    }
    JsonValue object = Json.createObject();
    object.put("folderId", resourceId.asString());
    object.put("operations", operationsArray);
    return object;
}
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