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