use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.IllegalFeatureValueException in project webanno by webanno.
the class CasMerge method copyFeatures.
private void copyFeatures(SourceDocument aDocument, String aUsername, TypeAdapter aAdapter, FeatureStructure aTargetFS, FeatureStructure aSourceFs) throws AnnotationException {
// Cache the feature list instead of hammering the database
List<AnnotationFeature> features = featureCache.computeIfAbsent(aAdapter.getLayer(), key -> schemaService.listSupportedFeatures(key));
for (AnnotationFeature feature : features) {
Type sourceFsType = aAdapter.getAnnotationType(aSourceFs.getCAS());
Feature sourceFeature = sourceFsType.getFeatureByBaseName(feature.getName());
if (sourceFeature == null) {
throw new IllegalStateException("Target CAS type [" + sourceFsType.getName() + "] does not define a feature named [" + feature.getName() + "]");
}
if (shouldIgnoreFeatureOnMerge(aSourceFs, sourceFeature)) {
continue;
}
Object value = aAdapter.getFeatureValue(feature, aSourceFs);
try {
aAdapter.setFeatureValue(aDocument, aUsername, aTargetFS.getCAS(), getAddr(aTargetFS), feature, value);
} catch (IllegalArgumentException e) {
// cannot be extended.
throw new IllegalFeatureValueException("Cannot set value of feature [" + feature.getUiName() + "] to [" + value + "]: " + e.getMessage(), e);
}
}
}
Aggregations