use of de.tudarmstadt.ukp.clarin.webanno.brat.message.NormDataResponse in project webanno by webanno.
the class BratAnnotationEditor method actionLookupNormData.
private Object actionLookupNormData(AjaxRequestTarget aTarget, IRequestParameters request, VID paramId) throws AnnotationException, IOException {
NormDataResponse response = new NormDataResponse();
// We interpret the databaseParam as the feature which we need to look up the feature
// support
StringValue databaseParam = request.getParameterValue("database");
// We interpret the key as the feature value or as a kind of query to be handled by the
// feature support
StringValue keyParam = request.getParameterValue("key");
StringValue layerParam = request.getParameterValue(PARAM_SPAN_TYPE);
if (layerParam.isEmpty() || keyParam.isEmpty() || databaseParam.isEmpty()) {
return response;
}
String database = databaseParam.toString();
long layerId = decodeTypeName(layerParam.toString());
AnnotatorState state = getModelObject();
AnnotationLayer layer = annotationService.getLayer(state.getProject(), layerId).orElseThrow(() -> new AnnotationException("Layer with ID [" + layerId + "] does not exist in project [" + state.getProject().getName() + "](" + state.getProject().getId() + ")"));
AnnotationFeature feature = annotationService.getFeature(database, layer);
// Check where the query needs to be routed: to an editor extension or to a feature support
if (paramId.isSynthetic()) {
String extensionId = paramId.getExtensionId();
response.setResults(extensionRegistry.getExtension(extensionId).renderLazyDetails(state.getDocument(), state.getUser(), paramId, feature, keyParam.toString()).stream().map(d -> new NormalizationQueryResult(d.getLabel(), d.getValue())).collect(Collectors.toList()));
return response;
}
try {
response.setResults(featureSupportRegistry.findExtension(feature).renderLazyDetails(feature, keyParam.toString()).stream().map(d -> new NormalizationQueryResult(d.getLabel(), d.getValue())).collect(Collectors.toList()));
} catch (Exception e) {
LOG.error("Unable to load data", e);
error("Unable to load data: " + ExceptionUtils.getRootCauseMessage(e));
}
return response;
}
Aggregations