Search in sources :

Example 1 with JsonBuilder

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

the class ActionBackupList method description.

private JsonValue description(HttpAction action) {
    if (!Files.isDirectory(FusekiServer.dirBackups))
        ServletOps.errorOccurred(format("[%d] Backup area '%s' is not a directory", action.id, FusekiServer.dirBackups));
    List<Path> paths = new ArrayList<>();
    try (DirectoryStream<Path> stream = Files.newDirectoryStream(FusekiServer.dirBackups, filterVisibleFiles)) {
        stream.forEach(paths::add);
    } catch (IOException ex) {
        action.log.error(format("[%d] Backup file list :: IOException :: %s", action.id, ex.getMessage()));
        ServletOps.errorOccurred(ex);
    }
    List<String> fileNames = paths.stream().map((p) -> p.getFileName().toString()).sorted().collect(Collectors.toList());
    JsonBuilder builder = new JsonBuilder();
    builder.startObject("top");
    builder.key("backups");
    builder.startArray();
    fileNames.forEach(builder::value);
    builder.finishArray();
    builder.finishObject("top");
    return builder.build();
}
Also used : Path(java.nio.file.Path) JsonBuilder(org.apache.jena.atlas.json.JsonBuilder) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 2 with JsonBuilder

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

the class ActionDatasets method execGetItem.

@Override
protected JsonValue execGetItem(HttpAction action) {
    action.log.info(format("[%d] GET dataset %s", action.id, action.getDatasetName()));
    JsonBuilder builder = new JsonBuilder();
    DataAccessPoint dsDesc = action.getDataAccessPointRegistry().get(action.getDatasetName());
    if (dsDesc == null)
        ServletOps.errorNotFound("Not found: dataset " + action.getDatasetName());
    JsonDescription.describe(builder, dsDesc);
    return builder.build();
}
Also used : JsonBuilder(org.apache.jena.atlas.json.JsonBuilder)

Example 3 with JsonBuilder

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

the class ActionDatasets method execGetContainer.

// ---- GET : return details of dataset or datasets.
@Override
protected JsonValue execGetContainer(HttpAction action) {
    action.log.info(format("[%d] GET datasets", action.id));
    JsonBuilder builder = new JsonBuilder();
    builder.startObject("D");
    builder.key(JsonConst.datasets);
    JsonDescription.arrayDatasets(builder, action.getDataAccessPointRegistry());
    builder.finishObject("D");
    return builder.build();
}
Also used : JsonBuilder(org.apache.jena.atlas.json.JsonBuilder)

Example 4 with JsonBuilder

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

the class ActionStats method generateStats.

public static JsonObject generateStats(DataAccessPointRegistry registry) {
    JsonBuilder builder = new JsonBuilder();
    builder.startObject("top");
    builder.key(JsonConst.datasets);
    builder.startObject("datasets");
    registry.forEach((name, access) -> statsDataset(builder, access));
    builder.finishObject("datasets");
    builder.finishObject("top");
    return builder.build().getAsObject();
}
Also used : JsonBuilder(org.apache.jena.atlas.json.JsonBuilder)

Example 5 with JsonBuilder

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

the class DataValidatorJSON method execute.

public static JsonObject execute(ValidationAction action) {
    JsonBuilder obj = new JsonBuilder();
    obj.startObject();
    String syntax = getArgOrNull(action, paramSyntax);
    if (syntax == null || syntax.equals(""))
        syntax = RDFLanguages.NQUADS.getName();
    Lang language = RDFLanguages.shortnameToLang(syntax);
    if (language == null) {
        ServletOps.errorBadRequest("Unknown syntax: " + syntax);
        return null;
    }
    String string = getArg(action, paramData);
    StringReader sr = new StringReader(string);
    obj.key(jInput).value(string);
    StreamRDF dest = StreamRDFLib.sinkNull();
    try {
        RDFParser.create().source(sr).lang(language).parse(dest);
    } catch (RiotParseException 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.getCol());
        obj.finishObject();
        obj.finishArray();
        // Outer object
        obj.finishObject();
        return obj.build().getAsObject();
    } catch (RiotException ex) {
        obj.key(jErrors);
        // Errors array
        obj.startArray();
        obj.startObject();
        obj.key(jParseError).value(ex.getMessage());
        obj.finishObject();
        obj.finishArray();
        // Outer object
        obj.finishObject();
        return obj.build().getAsObject();
    }
    obj.finishObject();
    return obj.build().getAsObject();
}
Also used : JsonBuilder(org.apache.jena.atlas.json.JsonBuilder) StreamRDF(org.apache.jena.riot.system.StreamRDF) StringReader(java.io.StringReader)

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