Search in sources :

Example 61 with JsonValue

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

the class FormRecordUpdate method fromJson.

public static FormRecordUpdate fromJson(JsonValue jsonElement) {
    JsonValue jsonObject = jsonElement;
    FormRecordUpdate model = new FormRecordUpdate();
    model.deleted = jsonObject.get("deleted").asBoolean();
    model.fieldValues = jsonObject.get("fieldValues");
    return model;
}
Also used : JsonValue(org.activityinfo.json.JsonValue)

Example 62 with JsonValue

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

the class ActivityInfoClient method getRecord.

public FormRecord getRecord(ResourceId formId, ResourceId recordId) {
    String json = client.resource(root).path("resources").path("form").path(formId.asString()).path("record").path(recordId.asString()).accept(MediaType.APPLICATION_JSON_TYPE).get(String.class);
    JsonValue jsonObject = (JsonValue) parser.parse(json);
    return FormRecord.fromJson(jsonObject);
}
Also used : JsonValue(org.activityinfo.json.JsonValue)

Example 63 with JsonValue

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

the class ActivityInfoClient method queryTable.

public ColumnSet queryTable(QueryModel queryModel) {
    String json = client.resource(root).path("query").path("columns").type(MediaType.APPLICATION_JSON_TYPE).post(String.class, queryModel.toJsonString());
    JsonValue object = (JsonValue) parser.parse(json);
    int numRows = object.get("rows").asInt();
    Map<String, ColumnView> columnMap = new HashMap<>();
    for (Map.Entry<String, JsonValue> column : object.get("columns").entrySet()) {
        JsonValue columnValue = column.getValue();
        String storage = columnValue.get("storage").asString();
        switch(storage) {
            case "array":
                columnMap.put(column.getKey(), new ColumnViewWrapper(numRows, columnValue.get("values")));
                break;
            case "empty":
                columnMap.put(column.getKey(), parseEmpty(numRows, columnValue));
                break;
            case "constant":
                columnMap.put(column.getKey(), parseConstantColumn(numRows, columnValue));
                break;
            default:
                throw new UnsupportedOperationException(storage);
        }
    }
    return new ColumnSet(numRows, columnMap);
}
Also used : HashMap(java.util.HashMap) JsonValue(org.activityinfo.json.JsonValue) HashMap(java.util.HashMap) Map(java.util.Map)

Example 64 with JsonValue

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

the class ActivityInfoClient method createDatabase.

public ResourceId createDatabase(String databaseName) {
    JsonValue properties = Json.createObject();
    properties.put("name", databaseName);
    JsonValue createEntity = Json.createObject();
    createEntity.put("entityName", "UserDatabase");
    createEntity.add("properties", properties);
    JsonValue command = Json.createObject();
    command.put("type", "CreateEntity");
    command.add("command", createEntity);
    String result = client.resource(root).path("command").post(String.class, command.toJson());
    JsonValue resultObject = (JsonValue) parser.parse(result);
    int newId = resultObject.get("newId").asInt();
    return CuidAdapter.databaseId(newId);
}
Also used : JsonValue(org.activityinfo.json.JsonValue)

Example 65 with JsonValue

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

the class ColumnViewWrapper method getString.

@Override
public String getString(int row) {
    Preconditions.checkPositionIndex(row, numRows);
    JsonValue jsonElement = array.get(row);
    if (jsonElement.isJsonNull()) {
        return null;
    } else {
        return jsonElement.asString();
    }
}
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