use of de.tudarmstadt.ukp.clarin.webanno.curation.casmerge.MergeConflictException in project webanno by webanno.
the class SuggestionViewPanel method actionAcceptAll.
private void actionAcceptAll(AjaxRequestTarget aTarget, UserAnnotationSegment aSegment, AnnotationLayer aLayer) throws IOException {
CAS targetCas = readEditorCas(aSegment.getAnnotatorState());
CAS sourceCas = readAnnotatorCas(aSegment);
AnnotatorState sourceState = aSegment.getAnnotatorState();
TypeAdapter adapter = schemaService.getAdapter(aLayer);
int mergeConflict = 0;
int alreadyMerged = 0;
int updated = 0;
int created = 0;
Set<String> otherErrors = new LinkedHashSet<>();
CasMerge casMerge = new CasMerge(schemaService);
casMerge.setSilenceEvents(true);
nextAnnotation: for (AnnotationFS ann : select(sourceCas, adapter.getAnnotationType(sourceCas))) {
try {
CasMergeOperationResult result;
switch(aLayer.getType()) {
case SPAN_TYPE:
result = mergeSpan(casMerge, targetCas, sourceCas, new VID(ann), sourceState.getDocument(), sourceState.getUser().getUsername(), aLayer);
break;
case RELATION_TYPE:
result = mergeRelation(casMerge, targetCas, sourceCas, new VID(ann), sourceState.getDocument(), sourceState.getUser().getUsername(), aLayer);
break;
default:
continue nextAnnotation;
}
switch(result.getState()) {
case CREATED:
created++;
break;
case UPDATED:
updated++;
break;
}
} catch (AlreadyMergedException e) {
alreadyMerged++;
} catch (MergeConflictException e) {
mergeConflict++;
} catch (Exception e) {
otherErrors.add(e.getMessage());
}
}
writeEditorCas(sourceState, targetCas);
int success = created + updated;
if (success > 0) {
success(String.format("Annotations were changed: %d (%d created, %d updated)", success, created, updated));
} else {
info("No annotations were changed");
}
if (alreadyMerged > 0) {
info("Annotations had already been merged: " + alreadyMerged);
}
if (mergeConflict > 0) {
info("Annotations skipped due to conflicts: " + mergeConflict);
}
if (!otherErrors.isEmpty()) {
otherErrors.forEach(this::error);
}
applicationEventPublisher.get().publishEvent(new BulkAnnotationEvent(this, sourceState.getDocument(), sourceState.getUser().getUsername(), adapter.getLayer()));
aTarget.addChildren(getPage(), IFeedback.class);
onChange(aTarget);
}
Aggregations