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();
}
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();
}
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();
}
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();
}
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();
}
Aggregations