use of de.catma.document.annotation.AnnotationCollectionManager in project catma by forTEXT.
the class KwicPanel method annotateSelection.
@SuppressWarnings("unchecked")
private void annotateSelection(Set<QueryResultRow> selectedRows, WizardContext result) throws Exception {
List<Property> properties = (List<Property>) result.get(AnnotationWizardContextKey.PROPERTIES);
Map<String, AnnotationCollectionReference> collectionRefsByDocId = (Map<String, AnnotationCollectionReference>) result.get(AnnotationWizardContextKey.COLLECTIONREFS_BY_DOCID);
TagDefinition tag = (TagDefinition) result.get(AnnotationWizardContextKey.TAG);
AnnotationCollectionManager collectionManager = new AnnotationCollectionManager(project);
for (AnnotationCollectionReference ref : collectionRefsByDocId.values()) {
collectionManager.add(project.getUserMarkupCollection(ref));
}
for (QueryResultRow row : selectedRows) {
AnnotationCollectionReference collectionRef = collectionRefsByDocId.get(row.getSourceDocumentId());
TagInstance tagInstance = new TagInstance(idGenerator.generate(), tag.getUuid(), project.getUser().getIdentifier(), ZonedDateTime.now().format(DateTimeFormatter.ofPattern(Version.DATETIMEPATTERN)), tag.getUserDefinedPropertyDefinitions(), tag.getTagsetDefinitionUuid());
List<TagReference> tagReferences = new ArrayList<TagReference>();
for (Property protoProp : properties) {
tagInstance.getUserDefinedPropetyByUuid(protoProp.getPropertyDefinitionId()).setPropertyValueList(protoProp.getPropertyValueList());
}
Set<Range> ranges = row.getRanges();
for (Range range : ranges) {
TagReference tagReference = new TagReference(tagInstance, row.getSourceDocumentId(), range, collectionRef.getId());
tagReferences.add(tagReference);
}
collectionManager.addTagReferences(tagReferences, collectionRef.getId());
}
}
use of de.catma.document.annotation.AnnotationCollectionManager in project catma by forTEXT.
the class KwicPanel method handleRemoveAnnotationsRequest.
private void handleRemoveAnnotationsRequest(EventBus eventBus) {
final Set<QueryResultRow> selectedRows = kwicGrid.getSelectedItems();
if (selectedRows.isEmpty()) {
Notification.show("Info", "Please select one or more Annotation rows!", Type.HUMANIZED_MESSAGE);
return;
}
int annotationRows = 0;
List<AnnotationCollectionReference> annotationCollectionReferences = new ArrayList<>();
boolean resourcesMissing = false;
boolean permissionsMissing = false;
Set<String> tagInstanceIdsToBeRemoved = new HashSet<String>();
Set<QueryResultRow> rowsToBeRemoved = new HashSet<>();
try {
LoadingCache<String, Boolean> collectionIdToHasWritePermission = CacheBuilder.newBuilder().build(new CacheLoader<String, Boolean>() {
@Override
public Boolean load(String collectionId) throws Exception {
return project.hasPermission(project.getRoleForCollection(collectionId), RBACPermission.COLLECTION_WRITE);
}
});
for (QueryResultRow row : selectedRows) {
if (row instanceof TagQueryResultRow) {
annotationRows++;
if (project.hasDocument(row.getSourceDocumentId())) {
SourceDocument document = project.getSourceDocument(row.getSourceDocumentId());
AnnotationCollectionReference collRef = document.getUserMarkupCollectionReference(((TagQueryResultRow) row).getMarkupCollectionId());
if (collRef != null) {
if (collectionIdToHasWritePermission.get(collRef.getId())) {
annotationCollectionReferences.add(collRef);
tagInstanceIdsToBeRemoved.add(((TagQueryResultRow) row).getTagInstanceId());
rowsToBeRemoved.add(row);
} else {
permissionsMissing = true;
}
} else {
resourcesMissing = true;
}
} else {
resourcesMissing = true;
}
}
}
if (permissionsMissing) {
Notification.show("Info", "You do not have the write permission for one or more Collections referenced by your selection. Those Collections will be ignored!", Type.HUMANIZED_MESSAGE);
}
if (annotationRows == 0) {
Notification.show("Info", "Your selection does not contain any Annotations! Please select Annotations only!", Type.HUMANIZED_MESSAGE);
return;
}
if (annotationCollectionReferences.isEmpty()) {
Notification.show("Info", "The Documents and/or Collections referenced by your selection are no longer part of the Project!", Type.HUMANIZED_MESSAGE);
return;
}
if (resourcesMissing) {
Notification.show("Info", "Some of the Documents and/or Collections referenced by your selection " + "are no longer part of the Project and will be ignored, " + "see columns 'Document' and 'Collection' for details!", Type.HUMANIZED_MESSAGE);
}
if (annotationRows != selectedRows.size()) {
Notification.show("Info", "Some rows of your selection do not represent Annotations and will be ignored, see column 'Tag' for details!", Type.HUMANIZED_MESSAGE);
}
AnnotationCollectionManager collectionManager = new AnnotationCollectionManager(project);
for (AnnotationCollectionReference ref : annotationCollectionReferences) {
collectionManager.add(project.getUserMarkupCollection(ref));
}
collectionManager.removeTagInstance(tagInstanceIdsToBeRemoved, true);
kwicDataProvider.getItems().removeAll(rowsToBeRemoved);
kwicDataProvider.refreshAll();
} catch (Exception e) {
((ErrorHandler) UI.getCurrent()).showAndLogError("error deleting Annotations!", e);
}
}
Aggregations