}
final JSONObject sprqlOutput = new JSONObject(sData);
// final JSONObject sprqlOutput = TripleStoreUtil.invokeSparqlQuery(sparqlQuery,
// TripleStoreUtil.defaultModelsRepoUrl);
return new UpdateContainer(new AbstractUpdate() {
@Override
public void generateJson(String prefix, PrintWriter pw,
VWorkspace vWorkspace) {
JSONObject response = new JSONObject();
JSONArray list = new JSONArray();
try {
JSONArray values = sprqlOutput.getJSONObject(sparqlKeys.results.name())
.getJSONArray(sparqlKeys.bindings.name());
// prepare the output
for (int i=0; i<values.length(); i++) {
JSONObject modelObj = new JSONObject();
JSONObject binding = values.getJSONObject(i);
String sourceName = binding.getJSONObject(sparqlKeys.sourceName.name())
.getString(sparqlKeys.value.name());
String modelName = binding.getJSONObject(sparqlKeys.modelName.name())
.getString(sparqlKeys.value.name());
modelObj.put(JsonKeys.modelName.name(), modelName);
modelObj.put(JsonKeys.sourceName.name(), sourceName);
list.put(modelObj);
}
response.put(JsonKeys.updateType.name(), "ExistingModelsList");
response.put(JsonKeys.existingModelNames.name(), list);
response.put(JsonKeys.worksheetName.name(), wkName);
pw.print(response.toString());
} catch (JSONException e) {
logger.error("Error creating JSON response for model names!", e);
}
}
});
} catch (Exception e1) {
logger.error("Error creating JSON response for model names!", e1);
return new UpdateContainer(new ErrorUpdate("Error occured while getting models!"));
}
}