use of de.catma.project.event.CollectionChangeEvent in project catma by forTEXT.
the class GraphWorktreeProject method importCollection.
public void importCollection(List<TagsetDefinitionImportStatus> tagsetDefinitionImportStatusList, AnnotationCollection importAnnotationCollection) throws IOException {
// if updates to existing Tagsets are needed, update only the Tags
// that are actually referenced in the Collection
Set<String> tagDefinitionIds = importAnnotationCollection.getTagReferences().stream().map(tagRef -> tagRef.getTagDefinitionId()).collect(Collectors.toSet());
for (TagsetDefinitionImportStatus tagsetDefinitionImportStatus : tagsetDefinitionImportStatusList) {
tagsetDefinitionImportStatus.setUpdateFilter(tagDefinitionIds);
}
importTagsets(tagsetDefinitionImportStatusList);
importAnnotationCollection.setTagLibrary(tagManager.getTagLibrary());
try {
SourceDocument sourceDocument = getSourceDocument(importAnnotationCollection.getSourceDocumentId());
String umcRevisionHash = gitProjectHandler.createMarkupCollection(importAnnotationCollection.getId(), importAnnotationCollection.getName(), // description
importAnnotationCollection.getContentInfoSet().getDescription(), importAnnotationCollection.getSourceDocumentId(), importAnnotationCollection.getSourceDocumentRevisionHash());
String oldRootRevisionHash = this.rootRevisionHash;
this.rootRevisionHash = gitProjectHandler.getRootRevisionHash();
graphProjectHandler.addCollection(rootRevisionHash, importAnnotationCollection.getId(), importAnnotationCollection.getName(), umcRevisionHash, sourceDocument, tagManager.getTagLibrary(), oldRootRevisionHash);
AnnotationCollectionReference annotationCollectionReference = sourceDocument.getUserMarkupCollectionReference(importAnnotationCollection.getId());
eventBus.post(new CollectionChangeEvent(annotationCollectionReference, sourceDocument, ChangeType.CREATED));
AnnotationCollection createdAnnotationCollection = getUserMarkupCollection(annotationCollectionReference);
createdAnnotationCollection.addTagReferences(importAnnotationCollection.getTagReferences());
ArrayListMultimap<String, TagReference> tagReferencesByTagInstanceId = ArrayListMultimap.create();
importAnnotationCollection.getTagReferences().stream().forEach(tagReference -> tagReferencesByTagInstanceId.put(tagReference.getTagInstanceId(), tagReference));
for (String tagInstanceId : tagReferencesByTagInstanceId.keySet()) {
update(createdAnnotationCollection, tagReferencesByTagInstanceId.get(tagInstanceId));
}
commitChanges(String.format("Imported Annotations from Collection %1$s with ID %2$s", createdAnnotationCollection.getName(), createdAnnotationCollection.getId()));
} catch (Exception e) {
throw new IOException(String.format("Import of Collection %1$s failed! The import has been aborted.", importAnnotationCollection.getName()), e);
}
}
use of de.catma.project.event.CollectionChangeEvent in project catma by forTEXT.
the class GraphWorktreeProject method createUserMarkupCollectionWithAssignment.
@Override
public void createUserMarkupCollectionWithAssignment(String name, SourceDocument sourceDocument, Integer userId, RBACRole role) {
try {
String collectionId = idGenerator.generateCollectionId();
String umcRevisionHash = gitProjectHandler.createMarkupCollection(collectionId, name, // description
null, sourceDocument.getUuid(), sourceDocument.getRevisionHash());
String oldRootRevisionHash = this.rootRevisionHash;
this.rootRevisionHash = gitProjectHandler.getRootRevisionHash();
graphProjectHandler.addCollection(rootRevisionHash, collectionId, name, umcRevisionHash, sourceDocument, tagManager.getTagLibrary(), oldRootRevisionHash);
if ((userId != null) && !role.equals(RBACRole.OWNER)) {
assignOnResource(() -> userId, role, collectionId);
}
eventBus.post(new CollectionChangeEvent(sourceDocument.getUserMarkupCollectionReference(collectionId), sourceDocument, ChangeType.CREATED));
} catch (Exception e) {
propertyChangeSupport.firePropertyChange(RepositoryChangeEvent.exceptionOccurred.name(), null, e);
}
}
use of de.catma.project.event.CollectionChangeEvent in project catma by forTEXT.
the class AnnotateResourcePanel method handleCollectionChanged.
@Subscribe
public void handleCollectionChanged(CollectionChangeEvent collectionChangeEvent) {
if (collectionChangeEvent.getChangeType().equals(ChangeType.CREATED)) {
SourceDocument document = collectionChangeEvent.getDocument();
AnnotationCollectionReference collectionReference = collectionChangeEvent.getCollectionReference();
CollectionDataItem collectionDataItem = new CollectionDataItem(collectionReference, project.hasPermission(project.getRoleForCollection(collectionReference.getId()), RBACPermission.COLLECTION_WRITE));
documentData.getRootItems().stream().filter(item -> ((DocumentDataItem) item).getDocument().equals(document)).findAny().ifPresent(documentDataItem -> {
documentData.addItem(documentDataItem, collectionDataItem);
documentTree.getDataProvider().refreshAll();
});
if (isAttached()) {
Notification.show("Info", String.format("Collection %1$s has been created!", collectionReference.toString()), Type.TRAY_NOTIFICATION);
}
if (getSelectedDocument() != null && getSelectedDocument().equals(document)) {
collectionDataItem.fireSelectedEvent(this.resourceSelectionListener);
}
} else if (collectionChangeEvent.getChangeType().equals(ChangeType.DELETED)) {
Optional<DocumentTreeItem> optionalDocResource = documentData.getRootItems().stream().filter(item -> ((DocumentDataItem) item).getDocument().equals(collectionChangeEvent.getDocument())).findAny();
if (optionalDocResource.isPresent()) {
documentData.getChildren(optionalDocResource.get()).stream().filter(item -> ((CollectionDataItem) item).getCollectionRef().equals(collectionChangeEvent.getCollectionReference())).findAny().ifPresent(item -> documentData.removeItem(item));
}
} else {
documentTree.getDataProvider().refreshAll();
}
}
use of de.catma.project.event.CollectionChangeEvent in project catma by forTEXT.
the class GraphWorktreeProject method update.
@Override
public void update(AnnotationCollectionReference collectionReference, ContentInfoSet contentInfoSet) throws Exception {
String collectionRevision = gitProjectHandler.updateCollection(collectionReference);
collectionReference.setRevisionHash(collectionRevision);
String oldRootRevisionHash = this.rootRevisionHash;
// project commit
this.rootRevisionHash = gitProjectHandler.addCollectionSubmoduleToStagedAndCommit(collectionReference.getId(), String.format("Updated metadata of Collection %1$s with ID %2$s", collectionReference.getName(), collectionReference.getId()), false);
graphProjectHandler.updateCollection(this.rootRevisionHash, collectionReference, oldRootRevisionHash);
SourceDocument document = getSourceDocument(collectionReference.getSourceDocumentId());
eventBus.post(new CollectionChangeEvent(collectionReference, document, ChangeType.UPDATED));
}
use of de.catma.project.event.CollectionChangeEvent in project catma by forTEXT.
the class GraphWorktreeProject method delete.
@Override
public void delete(AnnotationCollectionReference collectionReference) throws Exception {
String oldRootRevisionHash = this.rootRevisionHash;
SourceDocument document = getSourceDocument(collectionReference.getSourceDocumentId());
this.rootRevisionHash = gitProjectHandler.removeCollection(collectionReference);
graphProjectHandler.removeCollection(this.rootRevisionHash, collectionReference, oldRootRevisionHash);
document.removeUserMarkupCollectionReference(collectionReference);
eventBus.post(new CollectionChangeEvent(collectionReference, document, ChangeType.DELETED));
}
Aggregations