Search in sources :

Example 6 with AnnotationCollectionReference

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);
}
Also used : TreeDataProvider(com.vaadin.data.provider.TreeDataProvider) SourceDocument(de.catma.document.source.SourceDocument) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) Subscribe(com.google.common.eventbus.Subscribe)

Example 7 with AnnotationCollectionReference

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);
    }
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) Reply(de.catma.document.comment.Reply) LoadingCache(com.google.common.cache.LoadingCache) Status(org.eclipse.jgit.api.Status) UI(com.vaadin.ui.UI) IndexedProject(de.catma.indexer.IndexedProject) TermExtractor(de.catma.indexer.TermExtractor) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInfoProvider(de.catma.repository.git.graph.FileInfoProvider) ErrorHandler(de.catma.ui.module.main.ErrorHandler) Locale(java.util.Locale) Map(java.util.Map) DocumentChangeEvent(de.catma.project.event.DocumentChangeEvent) URI(java.net.URI) Path(java.nio.file.Path) CommitInfo(de.catma.project.CommitInfo) CATMAPropertyKey(de.catma.properties.CATMAPropertyKey) ExecutionListener(de.catma.backgroundservice.ExecutionListener) Collection(java.util.Collection) Set(java.util.Set) TagInstance(de.catma.tag.TagInstance) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) ProjectReference(de.catma.project.ProjectReference) TagReference(de.catma.document.annotation.TagReference) CacheLoader(com.google.common.cache.CacheLoader) List(java.util.List) PropertyChangeListener(java.beans.PropertyChangeListener) TPGraphProjectHandler(de.catma.repository.git.graph.tp.TPGraphProjectHandler) TagDefinition(de.catma.tag.TagDefinition) CacheBuilder(com.google.common.cache.CacheBuilder) ContentInfoSet(de.catma.document.source.ContentInfoSet) CollectionChangeEvent(de.catma.project.event.CollectionChangeEvent) RBACPermission(de.catma.rbac.RBACPermission) StatusPrinter(de.catma.repository.git.managers.StatusPrinter) PropertyDefinition(de.catma.tag.PropertyDefinition) TagManager(de.catma.tag.TagManager) CommentProvider(de.catma.repository.git.graph.CommentProvider) RBACRole(de.catma.rbac.RBACRole) MediaType(org.apache.tika.mime.MediaType) Multimap(com.google.common.collect.Multimap) Function(java.util.function.Function) User(de.catma.user.User) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) HashSet(java.util.HashSet) EventBus(com.google.common.eventbus.EventBus) CommentChangeEvent(de.catma.project.event.CommentChangeEvent) Comment(de.catma.document.comment.Comment) Charset(java.nio.charset.Charset) TeiTagLibrarySerializationHandler(de.catma.serialization.tei.TeiTagLibrarySerializationHandler) Member(de.catma.user.Member) StandardContentHandler(de.catma.document.source.contenthandler.StandardContentHandler) TagsetDefinition(de.catma.tag.TagsetDefinition) Pair(de.catma.util.Pair) IDGenerator(de.catma.util.IDGenerator) RBACSubject(de.catma.rbac.RBACSubject) TagLibrary(de.catma.tag.TagLibrary) PropertyChangeEvent(java.beans.PropertyChangeEvent) OpenProjectListener(de.catma.project.OpenProjectListener) TeiSerializationHandlerFactory(de.catma.serialization.tei.TeiSerializationHandlerFactory) RemovalNotification(com.google.common.cache.RemovalNotification) ProgressListener(de.catma.backgroundservice.ProgressListener) Property(de.catma.tag.Property) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) TermInfo(de.catma.indexer.TermInfo) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) SourceDocument(de.catma.document.source.SourceDocument) AnnotationCollection(de.catma.document.annotation.AnnotationCollection) File(java.io.File) TagsetDefinitionImportStatus(de.catma.serialization.TagsetDefinitionImportStatus) TagManagerEvent(de.catma.tag.TagManager.TagManagerEvent) TagLibrarySerializationHandler(de.catma.serialization.TagLibrarySerializationHandler) Indexer(de.catma.indexer.Indexer) ChangeType(de.catma.project.event.ChangeType) GraphProjectHandler(de.catma.repository.git.graph.GraphProjectHandler) ReplyChangeEvent(de.catma.project.event.ReplyChangeEvent) Paths(java.nio.file.Paths) PropertyChangeSupport(java.beans.PropertyChangeSupport) RemovalListener(com.google.common.cache.RemovalListener) BackgroundService(de.catma.backgroundservice.BackgroundService) InputStream(java.io.InputStream) TeiUserMarkupCollectionDeserializer(de.catma.serialization.tei.TeiUserMarkupCollectionDeserializer) SourceDocument(de.catma.document.source.SourceDocument) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) TagsetDefinition(de.catma.tag.TagsetDefinition) TagManager(de.catma.tag.TagManager) ProgressListener(de.catma.backgroundservice.ProgressListener)

Example 8 with AnnotationCollectionReference

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);
    }
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) Reply(de.catma.document.comment.Reply) LoadingCache(com.google.common.cache.LoadingCache) Status(org.eclipse.jgit.api.Status) UI(com.vaadin.ui.UI) IndexedProject(de.catma.indexer.IndexedProject) TermExtractor(de.catma.indexer.TermExtractor) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInfoProvider(de.catma.repository.git.graph.FileInfoProvider) ErrorHandler(de.catma.ui.module.main.ErrorHandler) Locale(java.util.Locale) Map(java.util.Map) DocumentChangeEvent(de.catma.project.event.DocumentChangeEvent) URI(java.net.URI) Path(java.nio.file.Path) CommitInfo(de.catma.project.CommitInfo) CATMAPropertyKey(de.catma.properties.CATMAPropertyKey) ExecutionListener(de.catma.backgroundservice.ExecutionListener) Collection(java.util.Collection) Set(java.util.Set) TagInstance(de.catma.tag.TagInstance) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) ProjectReference(de.catma.project.ProjectReference) TagReference(de.catma.document.annotation.TagReference) CacheLoader(com.google.common.cache.CacheLoader) List(java.util.List) PropertyChangeListener(java.beans.PropertyChangeListener) TPGraphProjectHandler(de.catma.repository.git.graph.tp.TPGraphProjectHandler) TagDefinition(de.catma.tag.TagDefinition) CacheBuilder(com.google.common.cache.CacheBuilder) ContentInfoSet(de.catma.document.source.ContentInfoSet) CollectionChangeEvent(de.catma.project.event.CollectionChangeEvent) RBACPermission(de.catma.rbac.RBACPermission) StatusPrinter(de.catma.repository.git.managers.StatusPrinter) PropertyDefinition(de.catma.tag.PropertyDefinition) TagManager(de.catma.tag.TagManager) CommentProvider(de.catma.repository.git.graph.CommentProvider) RBACRole(de.catma.rbac.RBACRole) MediaType(org.apache.tika.mime.MediaType) Multimap(com.google.common.collect.Multimap) Function(java.util.function.Function) User(de.catma.user.User) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) HashSet(java.util.HashSet) EventBus(com.google.common.eventbus.EventBus) CommentChangeEvent(de.catma.project.event.CommentChangeEvent) Comment(de.catma.document.comment.Comment) Charset(java.nio.charset.Charset) TeiTagLibrarySerializationHandler(de.catma.serialization.tei.TeiTagLibrarySerializationHandler) Member(de.catma.user.Member) StandardContentHandler(de.catma.document.source.contenthandler.StandardContentHandler) TagsetDefinition(de.catma.tag.TagsetDefinition) Pair(de.catma.util.Pair) IDGenerator(de.catma.util.IDGenerator) RBACSubject(de.catma.rbac.RBACSubject) TagLibrary(de.catma.tag.TagLibrary) PropertyChangeEvent(java.beans.PropertyChangeEvent) OpenProjectListener(de.catma.project.OpenProjectListener) TeiSerializationHandlerFactory(de.catma.serialization.tei.TeiSerializationHandlerFactory) RemovalNotification(com.google.common.cache.RemovalNotification) ProgressListener(de.catma.backgroundservice.ProgressListener) Property(de.catma.tag.Property) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) TermInfo(de.catma.indexer.TermInfo) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) SourceDocument(de.catma.document.source.SourceDocument) AnnotationCollection(de.catma.document.annotation.AnnotationCollection) File(java.io.File) TagsetDefinitionImportStatus(de.catma.serialization.TagsetDefinitionImportStatus) TagManagerEvent(de.catma.tag.TagManager.TagManagerEvent) TagLibrarySerializationHandler(de.catma.serialization.TagLibrarySerializationHandler) Indexer(de.catma.indexer.Indexer) ChangeType(de.catma.project.event.ChangeType) GraphProjectHandler(de.catma.repository.git.graph.GraphProjectHandler) ReplyChangeEvent(de.catma.project.event.ReplyChangeEvent) Paths(java.nio.file.Paths) PropertyChangeSupport(java.beans.PropertyChangeSupport) RemovalListener(com.google.common.cache.RemovalListener) BackgroundService(de.catma.backgroundservice.BackgroundService) InputStream(java.io.InputStream) TeiUserMarkupCollectionDeserializer(de.catma.serialization.tei.TeiUserMarkupCollectionDeserializer) AnnotationCollection(de.catma.document.annotation.AnnotationCollection) SourceDocument(de.catma.document.source.SourceDocument) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) CollectionChangeEvent(de.catma.project.event.CollectionChangeEvent) TagReference(de.catma.document.annotation.TagReference) IOException(java.io.IOException) TagsetDefinitionImportStatus(de.catma.serialization.TagsetDefinitionImportStatus) IOException(java.io.IOException)

Example 9 with AnnotationCollectionReference

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()));
    }
}
Also used : GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference)

Example 10 with AnnotationCollectionReference

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));
}
Also used : AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) DocumentChangeEvent(de.catma.project.event.DocumentChangeEvent) HashSet(java.util.HashSet)

Aggregations

AnnotationCollectionReference (de.catma.document.annotation.AnnotationCollectionReference)34 SourceDocument (de.catma.document.source.SourceDocument)23 List (java.util.List)13 Collectors (java.util.stream.Collectors)13 UI (com.vaadin.ui.UI)12 AnnotationCollection (de.catma.document.annotation.AnnotationCollection)12 ErrorHandler (de.catma.ui.module.main.ErrorHandler)12 HashSet (java.util.HashSet)12 IDGenerator (de.catma.util.IDGenerator)11 IOException (java.io.IOException)11 ArrayList (java.util.ArrayList)11 Collection (java.util.Collection)11 Set (java.util.Set)11 EventBus (com.google.common.eventbus.EventBus)10 Project (de.catma.project.Project)10 ChangeType (de.catma.project.event.ChangeType)10 RBACPermission (de.catma.rbac.RBACPermission)10 TagsetDefinition (de.catma.tag.TagsetDefinition)10 Subscribe (com.google.common.eventbus.Subscribe)9 TagReference (de.catma.document.annotation.TagReference)9