Search in sources :

Example 1 with JsonArray

use of org.apache.jena.atlas.json.JsonArray in project jena by apache.

the class StatsServlet method statsJSON.

private void statsJSON(JsonObject datasets, String ds) {
    DatasetRef desc = DatasetRegistry.get().get(ds);
    JsonObject stats = new JsonObject();
    datasets.put(ds, stats);
    stats.put(CounterName.Requests.name(), desc.getCounters().value(CounterName.Requests));
    stats.put(CounterName.RequestsGood.name(), desc.getCounters().value(CounterName.RequestsGood));
    stats.put(CounterName.RequestsBad.name(), desc.getCounters().value(CounterName.RequestsBad));
    JsonObject services = new JsonObject();
    // There can be several endpoints for one service.
    for (ServiceRef srvRef : desc.getServiceRefs()) {
        JsonObject epStats = new JsonObject();
        statsJSON(epStats, srvRef);
        services.put(srvRef.name, epStats);
        JsonArray endpoints = new JsonArray();
        epStats.put("endpoints", endpoints);
        for (String ep : srvRef.endpoints) {
            endpoints.add(ep);
        }
    }
    stats.put("services", services);
}
Also used : JsonArray(org.apache.jena.atlas.json.JsonArray) JsonObject(org.apache.jena.atlas.json.JsonObject)

Example 2 with JsonArray

use of org.apache.jena.atlas.json.JsonArray in project jena by apache.

the class StoreParamsCodec method getStringArray.

private static String[] getStringArray(JsonObject json, String key) {
    if (!json.hasKey(key))
        throw new TDBException("StoreParamsCodec.getStringArray: no such key: " + key);
    JsonArray a = json.get(key).getAsArray();
    String[] x = new String[a.size()];
    for (int i = 0; i < a.size(); i++) {
        x[i] = a.get(i).getAsString().value();
    }
    return x;
}
Also used : JsonArray(org.apache.jena.atlas.json.JsonArray) TDBException(org.apache.jena.tdb.TDBException)

Example 3 with JsonArray

use of org.apache.jena.atlas.json.JsonArray in project jena by apache.

the class TestAdmin method checkJsonDatasetsAll.

private static void checkJsonDatasetsAll(JsonValue v) {
    assertNotNull(v.getAsObject().get("datasets"));
    JsonArray a = v.getAsObject().get("datasets").getAsArray();
    for (JsonValue v2 : a) checkJsonDatasetsOne(v2);
}
Also used : JsonArray(org.apache.jena.atlas.json.JsonArray) JsonValue(org.apache.jena.atlas.json.JsonValue)

Example 4 with JsonArray

use of org.apache.jena.atlas.json.JsonArray in project jena by apache.

the class TestAdmin method checkInTasks.

private static void checkInTasks(String x) {
    String url = ServerCtl.urlRoot() + "$/tasks";
    JsonValue v = httpGetJson(url);
    assertTrue(v.isArray());
    JsonArray array = v.getAsArray();
    int found = 0;
    for (int i = 0; i < array.size(); i++) {
        JsonValue jv = array.get(i);
        assertTrue(jv.isObject());
        JsonObject obj = jv.getAsObject();
        checkTask(obj);
        if (obj.get("taskId").getAsString().value().equals(x)) {
            found++;
        }
    }
    assertEquals("Occurence of taskId count", 1, found);
}
Also used : JsonArray(org.apache.jena.atlas.json.JsonArray) JsonValue(org.apache.jena.atlas.json.JsonValue) JsonObject(org.apache.jena.atlas.json.JsonObject)

Example 5 with JsonArray

use of org.apache.jena.atlas.json.JsonArray in project jena by apache.

the class JSONInput method parseVars.

private List<Var> parseVars(JsonObject obj) {
    if (!obj.get(kVars).isArray())
        throw new ResultSetException("Key 'vars' must be a JSON array");
    JsonArray a = obj.get(kVars).getAsArray();
    Iterator<JsonValue> iter = a.iterator();
    List<Var> vars = new ArrayList<>();
    for (; iter.hasNext(); ) {
        JsonValue v = iter.next();
        if (!v.isString())
            throw new ResultSetException("Entries in vars array must be strings");
        Var var = Var.alloc(v.getAsString().value());
        vars.add(var);
    }
    return vars;
}
Also used : JsonArray(org.apache.jena.atlas.json.JsonArray) Var(org.apache.jena.sparql.core.Var) JsonValue(org.apache.jena.atlas.json.JsonValue)

Aggregations

JsonArray (org.apache.jena.atlas.json.JsonArray)6 JsonValue (org.apache.jena.atlas.json.JsonValue)4 JsonObject (org.apache.jena.atlas.json.JsonObject)3 Node (org.apache.jena.graph.Node)1 LabelToNode (org.apache.jena.riot.lang.LabelToNode)1 Var (org.apache.jena.sparql.core.Var)1 BindingMap (org.apache.jena.sparql.engine.binding.BindingMap)1 TDBException (org.apache.jena.tdb.TDBException)1