Search in sources :

Example 11 with AnnotationCollectionReference

use of de.catma.document.annotation.AnnotationCollectionReference 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 12 with AnnotationCollectionReference

use of de.catma.document.annotation.AnnotationCollectionReference in project catma by forTEXT.

the class CollectionXMLExportStreamSource method getStream.

@Override
public InputStream getStream() {
    final UI ui = UI.getCurrent();
    final Project project = projectSupplier.get();
    final Corpus corpus = new Corpus();
    final Collection<SourceDocument> documents = documentSupplier.get();
    final Collection<AnnotationCollectionReference> collectionReferences = collectionReferenceSupplier.get();
    try {
        Set<String> documentIds = documents.stream().map(doc -> doc.getUuid()).collect(Collectors.toSet());
        collectionReferences.stream().forEach(ref -> documentIds.add(ref.getSourceDocumentId()));
        for (String documentId : documentIds) {
            corpus.addSourceDocument(project.getSourceDocument(documentId));
        }
        if (corpus.getSourceDocuments().size() == 0) {
            return null;
        }
        collectionReferences.forEach(ref -> corpus.addUserMarkupCollectionReference(ref));
        File tempFile = File.createTempFile(new IDGenerator().generate() + "_AnnotationCollection_Export", "tgz");
        try (FileOutputStream fos = new FileOutputStream(tempFile)) {
            new CorpusExporter(project, true).export(project.getName(), corpus, fos);
        }
        return new FileInputStream(tempFile);
    } catch (Exception e) {
        ((ErrorHandler) ui).showAndLogError("Error exporting Documents and Collections!", e);
    }
    return null;
}
Also used : CorpusExporter(de.catma.document.corpus.CorpusExporter) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) Project(de.catma.project.Project) Collection(java.util.Collection) UI(com.vaadin.ui.UI) FileOutputStream(java.io.FileOutputStream) Set(java.util.Set) FileInputStream(java.io.FileInputStream) SourceDocument(de.catma.document.source.SourceDocument) Supplier(java.util.function.Supplier) Collectors(java.util.stream.Collectors) File(java.io.File) Corpus(de.catma.document.corpus.Corpus) ErrorHandler(de.catma.ui.module.main.ErrorHandler) IDGenerator(de.catma.util.IDGenerator) InputStream(java.io.InputStream) StreamSource(com.vaadin.server.StreamResource.StreamSource) SourceDocument(de.catma.document.source.SourceDocument) CorpusExporter(de.catma.document.corpus.CorpusExporter) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) Corpus(de.catma.document.corpus.Corpus) FileInputStream(java.io.FileInputStream) Project(de.catma.project.Project) UI(com.vaadin.ui.UI) FileOutputStream(java.io.FileOutputStream) File(java.io.File) IDGenerator(de.catma.util.IDGenerator)

Example 13 with AnnotationCollectionReference

use of de.catma.document.annotation.AnnotationCollectionReference in project catma by forTEXT.

the class GitMarkupCollectionHandler method getCollectionReference.

public AnnotationCollectionReference getCollectionReference(String projectId, String markupCollectionId) throws Exception {
    try (ILocalGitRepositoryManager localGitRepoManager = this.localGitRepositoryManager) {
        String projectRootRepositoryName = GitProjectManager.getProjectRootRepositoryName(projectId);
        localGitRepoManager.open(projectId, projectRootRepositoryName);
        String markupCollectionSubmoduleRelDir = String.format("%s/%s", GitProjectHandler.ANNOTATION_COLLECTION_SUBMODULES_DIRECTORY_NAME, markupCollectionId);
        File markupCollectionSubmoduleAbsPath = new File(localGitRepoManager.getRepositoryWorkTree().toString(), markupCollectionSubmoduleRelDir);
        String markupCollectionRevisionHash = localGitRepoManager.getSubmoduleHeadRevisionHash(markupCollectionSubmoduleRelDir);
        // can't call open on an attached instance
        localGitRepoManager.detach();
        File markupCollectionHeaderFile = new File(markupCollectionSubmoduleAbsPath, HEADER_FILE_NAME);
        String serializedMarkupCollectionHeaderFile = FileUtils.readFileToString(markupCollectionHeaderFile, StandardCharsets.UTF_8);
        GitMarkupCollectionHeader markupCollectionHeader = new SerializationHelper<GitMarkupCollectionHeader>().deserialize(serializedMarkupCollectionHeaderFile, GitMarkupCollectionHeader.class);
        ContentInfoSet contentInfoSet = new ContentInfoSet(markupCollectionHeader.getAuthor(), markupCollectionHeader.getDescription(), markupCollectionHeader.getPublisher(), markupCollectionHeader.getName());
        return new AnnotationCollectionReference(markupCollectionId, markupCollectionRevisionHash, contentInfoSet, markupCollectionHeader.getSourceDocumentId(), markupCollectionHeader.getSourceDocumentVersion());
    }
}
Also used : ContentInfoSet(de.catma.document.source.ContentInfoSet) ILocalGitRepositoryManager(de.catma.repository.git.interfaces.ILocalGitRepositoryManager) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) File(java.io.File) GitMarkupCollectionHeader(de.catma.repository.git.serialization.models.GitMarkupCollectionHeader)

Example 14 with AnnotationCollectionReference

use of de.catma.document.annotation.AnnotationCollectionReference in project catma by forTEXT.

the class GitProjectHandler method ensureDevBranches.

public void ensureDevBranches() throws Exception {
    logger.info(String.format("Ensuring dev branches for project %1$s", projectId));
    try (ILocalGitRepositoryManager localGitRepoManager = this.localGitRepositoryManager) {
        // tagsets
        GitTagsetHandler gitTagsetHandler = new GitTagsetHandler(localGitRepoManager, this.remoteGitServerManager, this.credentialsProvider);
        for (TagsetDefinition tagset : getTagsets()) {
            logger.info(String.format("Checking out dev branch for tagset \"%1$s\" with ID %2$s", tagset.getName(), tagset.getUuid()));
            gitTagsetHandler.checkout(projectId, tagset.getUuid(), ILocalGitRepositoryManager.DEFAULT_LOCAL_DEV_BRANCH, true);
        }
        // collections
        GitMarkupCollectionHandler collectionHandler = new GitMarkupCollectionHandler(localGitRepoManager, this.remoteGitServerManager, this.credentialsProvider);
        for (AnnotationCollectionReference collectionReference : getCollectionReferences()) {
            logger.info(String.format("Checking out dev branch for collection \"%1$s\" with ID %2$s", collectionReference.getName(), collectionReference.getId()));
            collectionHandler.checkout(projectId, collectionReference.getId(), ILocalGitRepositoryManager.DEFAULT_LOCAL_DEV_BRANCH, true);
        }
        // documents
        GitSourceDocumentHandler gitSourceDocumentHandler = new GitSourceDocumentHandler(localGitRepoManager, remoteGitServerManager, credentialsProvider);
        for (SourceDocument sourceDocument : getDocuments()) {
            logger.info(String.format("Checking out dev branch for document \"%s\" with ID %s", sourceDocument.getSourceContentHandler().getSourceDocumentInfo().getContentInfoSet().getTitle(), sourceDocument.getUuid()));
            gitSourceDocumentHandler.checkout(projectId, sourceDocument.getUuid(), ILocalGitRepositoryManager.DEFAULT_LOCAL_DEV_BRANCH, true);
        }
    }
}
Also used : ILocalGitRepositoryManager(de.catma.repository.git.interfaces.ILocalGitRepositoryManager) SourceDocument(de.catma.document.source.SourceDocument) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference)

Example 15 with AnnotationCollectionReference

use of de.catma.document.annotation.AnnotationCollectionReference in project catma by forTEXT.

the class GitProjectHandler method verifyCollections.

public void verifyCollections() throws Exception {
    List<AnnotationCollectionReference> collectionRefs = getCollectionReferences();
    Set<String> documentIds = getDocuments().stream().map(SourceDocument::getUuid).collect(Collectors.toSet());
    Set<AnnotationCollectionReference> staleCollectionCandidates = new HashSet<>();
    for (AnnotationCollectionReference collectionRef : collectionRefs) {
        String documentId = collectionRef.getSourceDocumentId();
        if (!documentIds.contains(documentId)) {
            staleCollectionCandidates.add(collectionRef);
        }
    }
    if (!staleCollectionCandidates.isEmpty()) {
        try (ILocalGitRepositoryManager localGitRepoManager = this.localGitRepositoryManager) {
            localGitRepoManager.open(projectId, GitProjectManager.getProjectRootRepositoryName(projectId));
            Set<String> verifiedDeleted = localGitRepoManager.verifyDeletedResources(staleCollectionCandidates.stream().map(AnnotationCollectionReference::getSourceDocumentId).collect(Collectors.toSet()));
            localGitRepoManager.detach();
            // TODO: unnecessary to loop over all collections when only the stale candidates can end up in verifiedDeleted
            for (AnnotationCollectionReference collectionRef : collectionRefs) {
                String collectionId = collectionRef.getId();
                RBACRole collectionRole = rolesPerResource.get(collectionId);
                if (collectionRole != null && hasPermission(collectionRole, RBACPermission.COLLECTION_DELETE_OR_EDIT)) {
                    if (verifiedDeleted.contains(collectionRef.getSourceDocumentId())) {
                        logger.info(String.format("Removing stale Collection %1$s with ID %2$s due to removal of corresp. Document with ID %3$s", collectionRef.getName(), collectionRef.getId(), collectionRef.getSourceDocumentId()));
                        removeCollection(collectionRef);
                    }
                }
            }
        }
    }
}
Also used : ILocalGitRepositoryManager(de.catma.repository.git.interfaces.ILocalGitRepositoryManager) RBACRole(de.catma.rbac.RBACRole) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference)

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