use of de.tudarmstadt.ukp.clarin.webanno.brat.metrics.BratMetrics.RenderType in project webanno by webanno.
the class BratAnnotationEditor method bratRenderCommand.
private String bratRenderCommand(JCas aJCas) {
StopWatch timer = new StopWatch();
timer.start();
GetDocumentResponse response = new GetDocumentResponse();
render(response, aJCas);
String json = toJson(response);
// By default, we do a full rendering...
RenderType renderType = RenderType.FULL;
String cmd = "renderData";
String data = json;
// ... try to render diff
String diff = null;
JsonNode current = null;
JsonNode previous = null;
try {
ObjectMapper mapper = JSONUtil.getJsonConverter().getObjectMapper();
current = mapper.readTree(json);
previous = lastRenderedJson != null ? mapper.readTree(lastRenderedJson) : null;
} catch (IOException e) {
LOG.error("Unable to generate diff, falling back to full render.", e);
// Fall-through
}
if (previous != null && current != null) {
diff = JsonDiff.asJson(previous, current).toString();
// pages, the patch usually ends up being twice as large as the full data.
if (diff.length() < json.length()) {
cmd = "renderDataPatch";
data = diff;
renderType = RenderType.DIFFERENTIAL;
}
// LOG.info("Diff: " + diff);
// LOG.info("Full: {} Patch: {} Diff time: {}", json.length(), diff.length(), timer);
}
// Storing the last rendered JSON as string because JsonNodes are not serializable.
lastRenderedJson = json;
timer.stop();
metrics.renderComplete(renderType, timer.getTime(), json, diff);
return "Wicket.$('" + vis.getMarkupId() + "').dispatcher.post('" + cmd + "', [" + data + "]);";
}
Aggregations