Search in sources :

Example 1 with CollectionChangeEvent

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);
    }
}
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 2 with CollectionChangeEvent

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);
    }
}
Also used : CollectionChangeEvent(de.catma.project.event.CollectionChangeEvent) IOException(java.io.IOException)

Example 3 with CollectionChangeEvent

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();
    }
}
Also used : SelectionEvent(com.vaadin.event.selection.SelectionEvent) UI(com.vaadin.ui.UI) SearchFilterProvider(de.catma.ui.component.actiongrid.SearchFilterProvider) ErrorHandler(de.catma.ui.module.main.ErrorHandler) TreeDataProvider(com.vaadin.data.provider.TreeDataProvider) VaadinIcons(com.vaadin.icons.VaadinIcons) DocumentChangeEvent(de.catma.project.event.DocumentChangeEvent) Version(de.catma.tag.Version) Collection(java.util.Collection) Set(java.util.Set) TreeGrid(com.vaadin.ui.TreeGrid) Collectors(java.util.stream.Collectors) MarginInfo(com.vaadin.shared.ui.MarginInfo) List(java.util.List) Type(com.vaadin.ui.Notification.Type) RendererClickEvent(com.vaadin.ui.renderers.ClickableRenderer.RendererClickEvent) PropertyChangeListener(java.beans.PropertyChangeListener) Optional(java.util.Optional) SingleTextInputDialog(de.catma.ui.dialog.SingleTextInputDialog) CollectionChangeEvent(de.catma.project.event.CollectionChangeEvent) SelectionMode(com.vaadin.ui.Grid.SelectionMode) RBACPermission(de.catma.rbac.RBACPermission) Column(com.vaadin.ui.Grid.Column) VerticalLayout(com.vaadin.ui.VerticalLayout) ActionGridComponent(de.catma.ui.component.actiongrid.ActionGridComponent) HashSet(java.util.HashSet) EventBus(com.google.common.eventbus.EventBus) Notification(com.vaadin.ui.Notification) Label(com.vaadin.ui.Label) TagsetDefinition(de.catma.tag.TagsetDefinition) TreeGridFactory(de.catma.ui.component.TreeGridFactory) IDGenerator(de.catma.util.IDGenerator) Subscribe(com.google.common.eventbus.Subscribe) ButtonRenderer(com.vaadin.ui.renderers.ButtonRenderer) SaveCancelListener(de.catma.ui.dialog.SaveCancelListener) PropertyChangeEvent(java.beans.PropertyChangeEvent) ListDataProvider(com.vaadin.data.provider.ListDataProvider) TreeData(com.vaadin.data.TreeData) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) Project(de.catma.project.Project) RepositoryChangeEvent(de.catma.project.Project.RepositoryChangeEvent) SourceDocument(de.catma.document.source.SourceDocument) ProjectReadyEvent(de.catma.project.event.ProjectReadyEvent) TagManagerEvent(de.catma.tag.TagManager.TagManagerEvent) ChangeType(de.catma.project.event.ChangeType) SerializablePredicate(com.vaadin.server.SerializablePredicate) HtmlRenderer(com.vaadin.ui.renderers.HtmlRenderer) Collections(java.util.Collections) Grid(com.vaadin.ui.Grid) Optional(java.util.Optional) SourceDocument(de.catma.document.source.SourceDocument) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) Subscribe(com.google.common.eventbus.Subscribe)

Example 4 with CollectionChangeEvent

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));
}
Also used : SourceDocument(de.catma.document.source.SourceDocument) CollectionChangeEvent(de.catma.project.event.CollectionChangeEvent)

Example 5 with CollectionChangeEvent

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));
}
Also used : SourceDocument(de.catma.document.source.SourceDocument) CollectionChangeEvent(de.catma.project.event.CollectionChangeEvent)

Aggregations

CollectionChangeEvent (de.catma.project.event.CollectionChangeEvent)5 SourceDocument (de.catma.document.source.SourceDocument)4 EventBus (com.google.common.eventbus.EventBus)2 UI (com.vaadin.ui.UI)2 AnnotationCollectionReference (de.catma.document.annotation.AnnotationCollectionReference)2 ChangeType (de.catma.project.event.ChangeType)2 DocumentChangeEvent (de.catma.project.event.DocumentChangeEvent)2 RBACPermission (de.catma.rbac.RBACPermission)2 TagManagerEvent (de.catma.tag.TagManager.TagManagerEvent)2 TagsetDefinition (de.catma.tag.TagsetDefinition)2 ErrorHandler (de.catma.ui.module.main.ErrorHandler)2 IDGenerator (de.catma.util.IDGenerator)2 PropertyChangeEvent (java.beans.PropertyChangeEvent)2 PropertyChangeListener (java.beans.PropertyChangeListener)2 IOException (java.io.IOException)2 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2