Search in sources :

Example 1 with NormDataResponse

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;
}
Also used : NormalizationQueryResult(de.tudarmstadt.ukp.clarin.webanno.brat.render.model.NormalizationQueryResult) NormDataResponse(de.tudarmstadt.ukp.clarin.webanno.brat.message.NormDataResponse) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) AnnotationException(de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException) StringValue(org.apache.wicket.util.string.StringValue) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) AnnotationException(de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException) IOException(java.io.IOException) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Aggregations

AnnotationException (de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException)1 AnnotatorState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)1 NormDataResponse (de.tudarmstadt.ukp.clarin.webanno.brat.message.NormDataResponse)1 NormalizationQueryResult (de.tudarmstadt.ukp.clarin.webanno.brat.render.model.NormalizationQueryResult)1 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)1 AnnotationLayer (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)1 IOException (java.io.IOException)1 StringValue (org.apache.wicket.util.string.StringValue)1