Search in sources :

Example 6 with JsonBuilder

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

the class IRIValidatorJSON method execute.

public static JsonObject execute(ValidationAction action) {
    JsonBuilder obj = new JsonBuilder();
    obj.startObject();
    String[] args = getArgs(action, paramIRI);
    if (args.length == 0)
        ServletOps.errorBadRequest("No IRIs supplied");
    obj.key(jIRIs);
    obj.startArray();
    for (String iriStr : args) {
        obj.startObject();
        obj.key(jIRI).value(iriStr);
        IRI iri = iriFactory.create(iriStr);
        List<String> errors = new ArrayList<>();
        List<String> warnings = new ArrayList<>();
        if (iri.isRelative())
            warnings.add("Relative IRI: " + iriStr);
        Iterator<Violation> vIter = iri.violations(true);
        for (; vIter.hasNext(); ) {
            Violation v = vIter.next();
            String str = v.getShortMessage();
            if (v.isError())
                errors.add(str);
            else
                warnings.add(str);
        }
        obj.key(jErrors);
        obj.startArray();
        for (String msg : errors) obj.value(msg);
        obj.finishArray();
        obj.key(jWarnings);
        obj.startArray();
        for (String msg : warnings) obj.value(msg);
        obj.finishArray();
        obj.finishObject();
    }
    obj.finishArray();
    obj.finishObject();
    return obj.build().getAsObject();
}
Also used : JsonBuilder(org.apache.jena.atlas.json.JsonBuilder) Violation(org.apache.jena.iri.Violation) IRI(org.apache.jena.iri.IRI) ArrayList(java.util.ArrayList)

Example 7 with JsonBuilder

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

the class UploadDetails method detailsJson.

public static JsonValue detailsJson(long count, long tripleCount, long quadCount) {
    JsonBuilder b = new JsonBuilder();
    b.startObject("details");
    b.key(jCount).value(count);
    b.key(jTriplesCount).value(tripleCount);
    b.key(jQuadsCount).value(quadCount);
    b.finishObject("details");
    return b.build();
}
Also used : JsonBuilder(org.apache.jena.atlas.json.JsonBuilder)

Example 8 with JsonBuilder

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

the class Async method asJson.

public static JsonValue asJson(AsyncTask asyncTask) {
    JsonBuilder builder = new JsonBuilder();
    builder.startObject("outer");
    builder.key(JsonConst.taskId).value(asyncTask.getTaskId());
    if (asyncTask.getOriginatingRequestId() > 0)
        builder.key(JsonConst.taskRequestId).value(asyncTask.getOriginatingRequestId());
    builder.finishObject("outer");
    return builder.build();
}
Also used : JsonBuilder(org.apache.jena.atlas.json.JsonBuilder)

Example 9 with JsonBuilder

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

the class StoreParamsCodec method encodeToJson.

public static JsonObject encodeToJson(StoreParams params) {
    JsonBuilder builder = new JsonBuilder();
    // "StoreParams" is an internal alignment marker - not in the JSON.
    builder.startObject("StoreParams");
    encode(builder, key(fFileMode), params.getFileMode().name());
    encode(builder, key(fBlockSize), params.getBlockSize());
    encode(builder, key(fBlockReadCacheSize), params.getBlockReadCacheSize());
    encode(builder, key(fBlockWriteCacheSize), params.getBlockWriteCacheSize());
    encode(builder, key(fNode2NodeIdCacheSize), params.getNode2NodeIdCacheSize());
    encode(builder, key(fNodeId2NodeCacheSize), params.getNodeId2NodeCacheSize());
    encode(builder, key(fNodeMissCacheSize), params.getNodeMissCacheSize());
    encode(builder, key(fIndexNode2Id), params.getIndexNode2Id());
    encode(builder, key(fIndexId2Node), params.getIndexId2Node());
    encode(builder, key(fPrimaryIndexTriples), params.getPrimaryIndexTriples());
    encode(builder, key(fTripleIndexes), params.getTripleIndexes());
    encode(builder, key(fPrimaryIndexQuads), params.getPrimaryIndexQuads());
    encode(builder, key(fQuadIndexes), params.getQuadIndexes());
    encode(builder, key(fPrimaryIndexPrefix), params.getPrimaryIndexPrefix());
    encode(builder, key(fPrefixIndexes), params.getPrefixIndexes());
    encode(builder, key(fIndexPrefix), params.getIndexPrefix());
    encode(builder, key(fPrefixNode2Id), params.getPrefixNode2Id());
    encode(builder, key(fPrefixId2Node), params.getPrefixId2Node());
    builder.finishObject("StoreParams");
    return (JsonObject) builder.build();
}
Also used : JsonBuilder(org.apache.jena.atlas.json.JsonBuilder) JsonObject(org.apache.jena.atlas.json.JsonObject)

Example 10 with JsonBuilder

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

the class ActionServerStatus method description.

private void description(HttpAction action) throws IOException {
    ServletOutputStream out = action.response.getOutputStream();
    action.response.setContentType(contentTypeJSON);
    action.response.setCharacterEncoding(charsetUTF8);
    JsonBuilder builder = new JsonBuilder();
    builder.startObject();
    describeServer(builder, action.request.getLocalPort());
    describeDatasets(builder, action.getDataAccessPointRegistry());
    builder.finishObject();
    JsonValue v = builder.build();
    JSON.write(out, v);
    out.println();
    out.flush();
}
Also used : JsonBuilder(org.apache.jena.atlas.json.JsonBuilder) ServletOutputStream(javax.servlet.ServletOutputStream) JsonValue(org.apache.jena.atlas.json.JsonValue)

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