Search in sources :

Example 11 with JsonBuilder

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

the class ActionStats method execGetItem.

@Override
protected JsonValue execGetItem(HttpAction action) {
    action.log.info(format("[%d] GET stats dataset %s", action.id, action.getDatasetName()));
    JsonBuilder builder = new JsonBuilder();
    String datasetPath = DataAccessPoint.canonical(action.getDatasetName());
    builder.startObject("TOP");
    builder.key(JsonConst.datasets);
    builder.startObject("datasets");
    statsDataset(builder, datasetPath, action.getDataAccessPointRegistry());
    builder.finishObject("datasets");
    builder.finishObject("TOP");
    return builder.build();
}
Also used : JsonBuilder(org.apache.jena.atlas.json.JsonBuilder)

Example 12 with JsonBuilder

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

the class ActionStats method generateStats.

public static JsonObject generateStats(DataAccessPoint access) {
    JsonBuilder builder = new JsonBuilder();
    statsDataset(builder, access);
    return builder.build().getAsObject();
}
Also used : JsonBuilder(org.apache.jena.atlas.json.JsonBuilder)

Example 13 with JsonBuilder

use of org.apache.jena.atlas.json.JsonBuilder 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 14 with JsonBuilder

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

the class QueryValidatorJSON method execute.

public static JsonObject execute(ValidationAction action) {
    JsonBuilder obj = new JsonBuilder();
    obj.startObject();
    final String queryString = getArg(action, paramQuery);
    String querySyntax = getArgOrNull(action, paramSyntax);
    if (querySyntax == null || querySyntax.equals(""))
        querySyntax = "SPARQL";
    Syntax language = Syntax.lookup(querySyntax);
    if (language == null) {
        ServletOps.errorBadRequest("Unknown syntax: " + querySyntax);
        return null;
    }
    boolean outputSPARQL = true;
    boolean outputAlgebra = true;
    boolean outputQuads = true;
    boolean outputOptimized = true;
    boolean outputOptimizedQuads = true;
    obj.key(jInput).value(queryString);
    // Attempt to parse it.
    Query query = null;
    try {
        query = QueryFactory.create(queryString, "http://example/base/", language);
    } catch (QueryParseException ex) {
        obj.key(jErrors);
        // Errors array
        obj.startArray();
        obj.startObject();
        obj.key(jParseError).value(ex.getMessage());
        obj.key(jParseErrorLine).value(ex.getLine());
        obj.key(jParseErrorCol).value(ex.getColumn());
        obj.finishObject();
        obj.finishArray();
        // Outer object
        obj.finishObject();
        return obj.build().getAsObject();
    }
    if (query != null) {
        if (outputSPARQL)
            formatted(obj, query);
        if (outputAlgebra)
            algebra(obj, query);
        if (outputQuads)
            algebraQuads(obj, query);
        if (outputOptimized)
            algebraOpt(obj, query);
        if (outputOptimizedQuads)
            algebraOptQuads(obj, query);
    }
    obj.finishObject();
    return obj.build().getAsObject();
}
Also used : JsonBuilder(org.apache.jena.atlas.json.JsonBuilder) Query(org.apache.jena.query.Query) Syntax(org.apache.jena.query.Syntax) QueryParseException(org.apache.jena.query.QueryParseException)

Example 15 with JsonBuilder

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

the class UpdateValidatorJSON method execute.

public static JsonObject execute(ValidationAction action) {
    JsonBuilder obj = new JsonBuilder();
    obj.startObject();
    final String updateString = getArg(action, paramUpdate);
    String updateSyntax = getArgOrNull(action, paramSyntax);
    if (updateSyntax == null || updateSyntax.equals(""))
        updateSyntax = "SPARQL";
    Syntax language = Syntax.lookup(updateSyntax);
    if (language == null) {
        ServletOps.errorBadRequest("Unknown syntax: " + updateSyntax);
        return null;
    }
    obj.key(jInput).value(updateString);
    UpdateRequest request = null;
    try {
        request = UpdateFactory.create(updateString, "http://example/base/", language);
    } catch (QueryParseException ex) {
        obj.key(jErrors);
        // Errors array
        obj.startArray();
        obj.startObject();
        obj.key(jParseError).value(ex.getMessage());
        obj.key(jParseErrorLine).value(ex.getLine());
        obj.key(jParseErrorCol).value(ex.getColumn());
        obj.finishObject();
        obj.finishArray();
        // Outer object
        obj.finishObject();
        return obj.build().getAsObject();
    }
    formatted(obj, request);
    obj.finishObject();
    return obj.build().getAsObject();
}
Also used : JsonBuilder(org.apache.jena.atlas.json.JsonBuilder) UpdateRequest(org.apache.jena.update.UpdateRequest) Syntax(org.apache.jena.query.Syntax) QueryParseException(org.apache.jena.query.QueryParseException)

Aggregations

JsonBuilder (org.apache.jena.atlas.json.JsonBuilder)15 ArrayList (java.util.ArrayList)2 JsonValue (org.apache.jena.atlas.json.JsonValue)2 QueryParseException (org.apache.jena.query.QueryParseException)2 Syntax (org.apache.jena.query.Syntax)2 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 Path (java.nio.file.Path)1 ServletOutputStream (javax.servlet.ServletOutputStream)1 JsonObject (org.apache.jena.atlas.json.JsonObject)1 AsyncPool (org.apache.jena.fuseki.async.AsyncPool)1 AsyncTask (org.apache.jena.fuseki.async.AsyncTask)1 IRI (org.apache.jena.iri.IRI)1 Violation (org.apache.jena.iri.Violation)1 Query (org.apache.jena.query.Query)1 StreamRDF (org.apache.jena.riot.system.StreamRDF)1 UpdateRequest (org.apache.jena.update.UpdateRequest)1