Search in sources :

Example 16 with JsonValue

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

the class ActionTasks method execGet.

private void execGet(HttpAction action, String name) {
    if (name == null)
        log.info(format("[%d] Tasks", action.id));
    else
        log.info(format("[%d] Task %s", action.id, name));
    JsonValue responseBody = null;
    if (name == null) {
        JsonBuilder builder = new JsonBuilder();
        builder.startArray();
        for (AsyncPool pool : pools) {
            for (AsyncTask aTask : pool.tasks()) {
                //builder.value(aTask.getTaskId()) ;
                descOneTask(builder, aTask);
            }
        }
        builder.finishArray();
        responseBody = builder.build();
    } else {
        for (AsyncPool pool : pools) {
            // Assumes first is only.
            AsyncTask aTask = pool.getTask(name);
            if (aTask != null) {
                JsonBuilder builder = new JsonBuilder();
                descOneTask(builder, aTask);
                responseBody = builder.build();
            }
        }
    }
    if (responseBody == null)
        ServletOps.errorNotFound("Task '" + name + "' not found");
    ServletOps.setNoCache(action);
    ServletOps.sendJsonReponse(action, responseBody);
}
Also used : JsonBuilder(org.apache.jena.atlas.json.JsonBuilder) JsonValue(org.apache.jena.atlas.json.JsonValue) AsyncTask(org.apache.jena.fuseki.async.AsyncTask) AsyncPool(org.apache.jena.fuseki.async.AsyncPool)

Example 17 with JsonValue

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

the class LibJsonTest method read.

/** Round trip string->json->string->json, compare two JOSN steps */
public static void read(String string) {
    JsonValue v = JSON.parseAny(string);
    writeRead(v);
}
Also used : JsonValue(org.apache.jena.atlas.json.JsonValue)

Example 18 with JsonValue

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

the class ServletOps method uploadResponse.

/** response to a upload operation of some kind. */
public static void uploadResponse(HttpAction action, UploadDetails details) {
    if (details.getExistedBefore().equals(PreState.ABSENT))
        ServletOps.successCreated(action);
    else
        // successNoContent if empty body.
        ServletOps.success(action);
    JsonValue v = details.detailsJson();
    ServletOps.sendJson(action, v);
}
Also used : JsonValue(org.apache.jena.atlas.json.JsonValue)

Example 19 with JsonValue

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

the class TestAdmin method task_4.

@Test
public void task_4() {
    // Timing dependent.
    // Create a "short" running task  
    String x = execSleepTask(null, 1);
    // Check exists in the list of all tasks (should be "finished")
    checkInTasks(x);
    String url = ServerCtl.urlRoot() + "$/tasks/" + x;
    boolean finished = false;
    for (int i = 0; i < 10; i++) {
        if (i != 0)
            Lib.sleep(25);
        JsonValue v = httpGetJson(url);
        checkTask(v);
        if (v.getAsObject().hasKey("finished")) {
            finished = true;
            break;
        }
    }
    if (!finished)
        fail("Task has not finished");
}
Also used : JsonValue(org.apache.jena.atlas.json.JsonValue) Test(org.junit.Test)

Example 20 with JsonValue

use of org.apache.jena.atlas.json.JsonValue 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)

Aggregations

JsonValue (org.apache.jena.atlas.json.JsonValue)28 Test (org.junit.Test)7 JsonArray (org.apache.jena.atlas.json.JsonArray)4 JsonObject (org.apache.jena.atlas.json.JsonObject)4 TypedInputStream (org.apache.jena.atlas.web.TypedInputStream)3 JsonBuilder (org.apache.jena.atlas.json.JsonBuilder)2 AsyncTask (org.apache.jena.fuseki.async.AsyncTask)2 ServletOutputStream (javax.servlet.ServletOutputStream)1 JsonParseException (org.apache.jena.atlas.json.JsonParseException)1 JsonString (org.apache.jena.atlas.json.JsonString)1 HttpException (org.apache.jena.atlas.web.HttpException)1 AsyncPool (org.apache.jena.fuseki.async.AsyncPool)1 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