Search in sources :

Example 26 with JsonValue

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

the class AttachmentType method parseJsonValue.

@Override
public AttachmentValue parseJsonValue(JsonValue value) {
    if (value.isJsonObject()) {
        value = value.get("values");
    }
    AttachmentValue fieldValue = new AttachmentValue();
    JsonValue array = value;
    for (JsonValue attachmentItem : array.values()) {
        JsonValue attachmentObject = (JsonValue) attachmentItem;
        String mimeType = attachmentObject.get("mimeType").asString();
        String filename = attachmentObject.get("filename").asString();
        String blobId = attachmentObject.get("blobId").asString();
        Attachment attachment = new Attachment(mimeType, filename, blobId);
        attachment.setWidth(attachmentObject.get("width").asInt());
        attachment.setHeight(attachmentObject.get("height").asInt());
        fieldValue.getValues().add(attachment);
    }
    return fieldValue;
}
Also used : JsonValue(org.activityinfo.json.JsonValue)

Example 27 with JsonValue

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

the class AttachmentType method getParametersAsJson.

@Override
public JsonValue getParametersAsJson() {
    JsonValue object = createObject();
    object.put("cardinality", cardinality.name().toLowerCase());
    object.put("kind", kind.name().toLowerCase());
    return object;
}
Also used : JsonValue(org.activityinfo.json.JsonValue)

Example 28 with JsonValue

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

the class AttachmentValue method fromJson.

public static AttachmentValue fromJson(String json) {
    org.activityinfo.json.JsonParser jsonParser = new org.activityinfo.json.JsonParser();
    JsonValue array;
    JsonValue root = jsonParser.parse(json);
    if (root.isJsonObject()) {
        array = root.get("values");
    } else {
        array = root;
    }
    List<Attachment> list = new ArrayList<>();
    for (JsonValue value : array.values()) {
        list.add(Attachment.fromJson(value));
    }
    return new AttachmentValue(list);
}
Also used : JsonValue(org.activityinfo.json.JsonValue) ArrayList(java.util.ArrayList)

Example 29 with JsonValue

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

the class QueryModel method toJson.

@Override
public JsonValue toJson() {
    JsonValue object = createObject();
    object.put("rowSources", Json.toJson(rowSources));
    object.put("columns", Json.toJson(columns));
    if (filter != null) {
        object.put("filter", filter.asExpression());
    }
    return object;
}
Also used : JsonValue(org.activityinfo.json.JsonValue)

Example 30 with JsonValue

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

the class QueryModel method fromJson.

public static QueryModel fromJson(JsonValue jsonObject) {
    QueryModel queryModel = new QueryModel();
    JsonValue rowSources = jsonObject.get("rowSources");
    for (JsonValue rowSource : rowSources.values()) {
        queryModel.getRowSources().add(RowSource.fromJson(rowSource));
    }
    for (JsonValue column : jsonObject.get("columns").values()) {
        queryModel.getColumns().add(ColumnModel.fromJson(column));
    }
    String filter = jsonObject.getString("filter");
    if (!Strings.isNullOrEmpty(filter)) {
        queryModel.setFilter(filter);
    }
    return queryModel;
}
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