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;
}
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);
}
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);
}
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);
}
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();
}
}
Aggregations