use of de.catma.document.annotation.AnnotationCollectionReference in project catma by forTEXT.
the class ProjectView method handleCollectionChanged.
@Subscribe
public void handleCollectionChanged(CollectionChangeEvent collectionChangeEvent) {
if (collectionChangeEvent.getChangeType().equals(ChangeType.CREATED)) {
SourceDocument document = collectionChangeEvent.getDocument();
AnnotationCollectionReference collectionReference = collectionChangeEvent.getCollectionReference();
@SuppressWarnings("unchecked") TreeDataProvider<Resource> resourceDataProvider = (TreeDataProvider<Resource>) documentGrid.getDataProvider();
CollectionResource collectionResource = new CollectionResource(collectionReference, project.getProjectId(), project.hasPermission(project.getRoleForCollection(collectionReference.getId()), RBACPermission.COLLECTION_WRITE));
DocumentResource documentResource = new DocumentResource(document, project.getProjectId(), project.hasPermission(project.getRoleForDocument(document.getUuid()), RBACPermission.DOCUMENT_WRITE));
resourceDataProvider.getTreeData().addItem(documentResource, collectionResource);
resourceDataProvider.refreshAll();
if (isAttached()) {
documentGrid.expand(documentResource);
Notification.show("Info", String.format("Collection %1$s has been created!", collectionReference.toString()), Type.TRAY_NOTIFICATION);
}
} else {
initData();
}
btSynchBell.setVisible(true);
}
use of de.catma.document.annotation.AnnotationCollectionReference in project catma by forTEXT.
the class GraphWorktreeProject method synchronizeWithRemote.
@Override
public void synchronizeWithRemote(OpenProjectListener openProjectListener) throws Exception {
if (hasUncommittedChanges()) {
throw new IllegalStateException("There are uncommitted changes that need to be committed first!");
}
for (TagsetDefinition tagset : getTagsets()) {
gitProjectHandler.synchronizeTagsetWithRemote(tagset.getUuid());
}
for (SourceDocument document : getSourceDocuments()) {
gitProjectHandler.synchronizeSourceDocumentWithRemote(document.getUuid());
for (AnnotationCollectionReference collectionReference : document.getUserMarkupCollectionRefs()) {
gitProjectHandler.synchronizeCollectionWithRemote(collectionReference.getId());
}
}
gitProjectHandler.synchronizeWithRemote();
if (gitProjectHandler.hasConflicts()) {
gitProjectHandler.initAndUpdateSubmodules();
openProjectListener.conflictResolutionNeeded(new GitConflictedProject(projectReference, gitProjectHandler, documentId -> getSourceDocumentURI(documentId)));
} else {
boolean forceGraphReload = gitProjectHandler.loadRolesPerResource();
gitProjectHandler.initAndUpdateSubmodules();
gitProjectHandler.removeStaleSubmoduleDirectories();
gitProjectHandler.ensureDevBranches();
rootRevisionHash = gitProjectHandler.getRootRevisionHash();
ProgressListener progressListener = new ProgressListener() {
@Override
public void setProgress(String value, Object... args) {
openProjectListener.progress(value, args);
}
};
graphProjectHandler.ensureProjectRevisionIsLoaded(new ExecutionListener<TagManager>() {
@Override
public void error(Throwable t) {
openProjectListener.failure(t);
}
@Override
public void done(TagManager result) {
tagManager.load(result.getTagLibrary());
openProjectListener.ready(GraphWorktreeProject.this);
}
}, progressListener, rootRevisionHash, tagManager, () -> gitProjectHandler.getTagsets(), () -> gitProjectHandler.getDocuments(), (tagLibrary) -> gitProjectHandler.getCollections(tagLibrary, progressListener), forceGraphReload, backgroundService);
}
}
use of de.catma.document.annotation.AnnotationCollectionReference 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.document.annotation.AnnotationCollectionReference in project catma by forTEXT.
the class GraphWriter method addCollection.
void addCollection(String oldRevisionHash, String revisionHash, AnnotationCollection collection) {
GraphTraversalSource g = graph.traversal();
GraphTraversal<Vertex, Vertex> graphTraversal = g.V().has(nt(ProjectRevision), "revisionHash", oldRevisionHash).property("revisionHash", revisionHash).outE(rt(hasDocument)).inV().has(nt(SourceDocument), "documentId", collection.getSourceDocumentId());
if (graphTraversal.hasNext()) {
Vertex documentV = graphTraversal.next();
documentV.property("document").ifPresent(doc -> ((SourceDocument) doc).addUserMarkupCollectionReference(new AnnotationCollectionReference(collection.getUuid(), collection.getRevisionHash(), collection.getContentInfoSet(), collection.getSourceDocumentId(), collection.getSourceDocumentRevisionHash())));
Vertex collectionV = graph.addVertex(nt(MarkupCollection));
collectionV.property("collectionId", collection.getId());
// collectionV.property("name", collection.getName());
// collectionV.property("revisionHash", collection.getRevisionHash());
collectionV.property("collection", collection);
documentV.addEdge(rt(hasCollection), collectionV);
addTagReferences(revisionHash, collectionV, collection.getTagReferences());
} else {
logger.info(String.format("Skipping loading Collection %1$s with ID %2$s, couldn't find Document with ID %3$s", collection.getName(), collection.getId(), collection.getSourceDocumentId()));
}
}
use of de.catma.document.annotation.AnnotationCollectionReference in project catma by forTEXT.
the class GraphWorktreeProject method delete.
@Override
public void delete(SourceDocument sourceDocument) throws Exception {
for (AnnotationCollectionReference collectionRef : new HashSet<>(sourceDocument.getUserMarkupCollectionRefs())) {
delete(collectionRef);
}
documentCache.invalidate(sourceDocument.getUuid());
String oldRootRevisionHash = this.rootRevisionHash;
gitProjectHandler.removeDocument(sourceDocument);
this.rootRevisionHash = gitProjectHandler.getRootRevisionHash();
graphProjectHandler.removeDocument(this.rootRevisionHash, sourceDocument, oldRootRevisionHash);
eventBus.post(new DocumentChangeEvent(sourceDocument, ChangeType.DELETED));
}
Aggregations