Search in sources :

Example 31 with AnnotationCollectionReference

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

the class GitProjectHandler method getCollectionReferences.

public List<AnnotationCollectionReference> getCollectionReferences() {
    ArrayList<AnnotationCollectionReference> collectionReferences = new ArrayList<>();
    try (ILocalGitRepositoryManager localRepoManager = this.localGitRepositoryManager) {
        try {
            localRepoManager.open(projectId, GitProjectManager.getProjectRootRepositoryName(projectId));
            List<Path> paths = localRepoManager.getSubmodulePaths().stream().filter(path -> path != null && path.startsWith(ANNOTATION_COLLECTION_SUBMODULES_DIRECTORY_NAME)).map(path -> Paths.get(localRepoManager.getRepositoryWorkTree().toURI()).resolve(path)).collect(Collectors.toList());
            localRepoManager.detach();
            GitMarkupCollectionHandler gitMarkupCollectionHandler = new GitMarkupCollectionHandler(localRepoManager, this.remoteGitServerManager, this.credentialsProvider);
            for (Path collectionPath : paths) {
                String collectionId = collectionPath.getFileName().toString();
                RBACRole resourceRole = rolesPerResource.get(collectionId);
                if ((resourceRole != null) && hasPermission(resourceRole, RBACPermission.COLLECTION_READ)) {
                    try {
                        collectionReferences.add(gitMarkupCollectionHandler.getCollectionReference(projectId, collectionId));
                    } catch (Exception e) {
                        logger.log(Level.SEVERE, String.format("error loading Collection reference %1$s for project %2$s", collectionPath, projectId), e);
                    }
                }
            }
        } catch (Exception e) {
            logger.log(Level.SEVERE, String.format("error loading Collection references for project %1$s", projectId), e);
        }
    }
    return collectionReferences;
}
Also used : Path(java.nio.file.Path) ILocalGitRepositoryManager(de.catma.repository.git.interfaces.ILocalGitRepositoryManager) Reply(de.catma.document.comment.Reply) java.util(java.util) UsernamePasswordCredentialsProvider(org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider) Status(org.eclipse.jgit.api.Status) RBACRole(de.catma.rbac.RBACRole) User(de.catma.user.User) Level(java.util.logging.Level) IRemoteGitManagerRestricted(de.catma.repository.git.interfaces.IRemoteGitManagerRestricted) Comment(de.catma.document.comment.Comment) Member(de.catma.user.Member) Pair(de.catma.util.Pair) IDGenerator(de.catma.util.IDGenerator) RBACSubject(de.catma.rbac.RBACSubject) CommitInfo(de.catma.project.CommitInfo) Nonnull(javax.annotation.Nonnull) Path(java.nio.file.Path) CATMAPropertyKey(de.catma.properties.CATMAPropertyKey) ProgressListener(de.catma.backgroundservice.ProgressListener) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) Files(java.nio.file.Files) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) TermInfo(de.catma.indexer.TermInfo) CredentialsProvider(org.eclipse.jgit.transport.CredentialsProvider) FileUtils(org.apache.commons.io.FileUtils) Constants(org.eclipse.jgit.lib.Constants) IOException(java.io.IOException) SourceDocument(de.catma.document.source.SourceDocument) AnnotationCollection(de.catma.document.annotation.AnnotationCollection) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) SourceDocumentInfo(de.catma.document.source.SourceDocumentInfo) File(java.io.File) TagReference(de.catma.document.annotation.TagReference) de.catma.project.conflict(de.catma.project.conflict) de.catma.tag(de.catma.tag) JsonLdWebAnnotation(de.catma.repository.git.serialization.models.json_ld.JsonLdWebAnnotation) JGitInternalException(org.eclipse.jgit.api.errors.JGitInternalException) Paths(java.nio.file.Paths) MergeResult(org.eclipse.jgit.api.MergeResult) JGitRepoManager(de.catma.repository.git.managers.JGitRepoManager) ContentInfoSet(de.catma.document.source.ContentInfoSet) RBACPermission(de.catma.rbac.RBACPermission) FilenameUtils(org.apache.commons.io.FilenameUtils) StatusPrinter(de.catma.repository.git.managers.StatusPrinter) InputStream(java.io.InputStream) ILocalGitRepositoryManager(de.catma.repository.git.interfaces.ILocalGitRepositoryManager) RBACRole(de.catma.rbac.RBACRole) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IOException(java.io.IOException) JGitInternalException(org.eclipse.jgit.api.errors.JGitInternalException)

Example 32 with AnnotationCollectionReference

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

the class GitProjectHandler method hasUncommittedChanges.

public boolean hasUncommittedChanges() throws Exception {
    try (ILocalGitRepositoryManager localGitRepoManager = this.localGitRepositoryManager) {
        GitMarkupCollectionHandler collectionHandler = new GitMarkupCollectionHandler(localGitRepoManager, this.remoteGitServerManager, this.credentialsProvider);
        // TODO: better get collectionRefs from graph
        for (AnnotationCollectionReference collectionRef : getCollectionReferences()) {
            if (collectionHandler.hasUncommittedChanges(projectId, collectionRef.getId())) {
                return true;
            }
        }
        // open the project root repo
        localGitRepoManager.open(projectId, GitProjectManager.getProjectRootRepositoryName(projectId));
        return localGitRepoManager.hasUncommitedChangesWithSubmodules(getReadableSubmodules(localGitRepoManager));
    }
}
Also used : ILocalGitRepositoryManager(de.catma.repository.git.interfaces.ILocalGitRepositoryManager) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference)

Example 33 with AnnotationCollectionReference

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

the class TaggerView method initListeners.

private void initListeners() {
    this.tagReferencesChangedListener = new PropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent evt) {
            if (evt.getNewValue() != null) {
                @SuppressWarnings("unchecked") Pair<AnnotationCollection, List<TagReference>> changeValue = (Pair<AnnotationCollection, List<TagReference>>) evt.getNewValue();
                List<TagReference> tagReferences = changeValue.getSecond();
                List<TagReference> relevantTagReferences = new ArrayList<TagReference>();
                for (TagReference tr : tagReferences) {
                    if (isRelevantTagReference(tr, userMarkupCollectionManager.getUserMarkupCollections())) {
                        relevantTagReferences.add(tr);
                    }
                }
                tagger.setVisible(relevantTagReferences, true);
                Set<String> tagInstanceUuids = new HashSet<String>();
                for (TagReference tr : relevantTagReferences) {
                    tagInstanceUuids.add(tr.getTagInstance().getUuid());
                }
                tagInstanceUuids.forEach(annotationId -> tagger.updateAnnotation(annotationId));
            } else if (evt.getOldValue() != null) {
                @SuppressWarnings("unchecked") Pair<String, Collection<String>> changeValue = (Pair<String, Collection<String>>) evt.getOldValue();
                String collectionId = changeValue.getFirst();
                Collection<String> annotationIds = changeValue.getSecond();
                if (userMarkupCollectionManager.contains(collectionId)) {
                    userMarkupCollectionManager.removeTagInstance(annotationIds, false);
                }
                tagger.removeTagInstances(annotationIds);
                annotationPanel.removeAnnotations(annotationIds);
            }
        }
    };
    project.addPropertyChangeListener(RepositoryChangeEvent.tagReferencesChanged, tagReferencesChangedListener);
    annotationPropertiesChangedListener = new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            TagInstance tagInstance = (TagInstance) evt.getOldValue();
            tagger.updateAnnotation(tagInstance.getUuid());
        }
    };
    project.addPropertyChangeListener(RepositoryChangeEvent.propertyValueChanged, annotationPropertiesChangedListener);
    tagChangedListener = new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            Object newValue = evt.getNewValue();
            Object oldValue = evt.getOldValue();
            if (oldValue == null) {
            // created
            // noop
            } else if (newValue == null) {
                // removed
                @SuppressWarnings("unchecked") Pair<TagsetDefinition, TagDefinition> deleted = (Pair<TagsetDefinition, TagDefinition>) oldValue;
                for (AnnotationCollectionReference ref : userMarkupCollectionManager.getCollections(deleted.getSecond())) {
                    setAnnotationCollectionSelected(ref, false);
                    setAnnotationCollectionSelected(ref, true);
                }
            } else {
                // update
                TagDefinition tag = (TagDefinition) newValue;
                for (AnnotationCollection collection : userMarkupCollectionManager.getUserMarkupCollections()) {
                    List<TagReference> relevantTagReferences = collection.getTagReferences(tag);
                    tagger.setVisible(relevantTagReferences, false);
                    tagger.setVisible(relevantTagReferences, true);
                }
            }
        }
    };
    project.getTagManager().addPropertyChangeListener(TagManagerEvent.tagDefinitionChanged, tagChangedListener);
}
Also used : BackgroundServiceProvider(de.catma.backgroundservice.BackgroundServiceProvider) ZonedDateTime(java.time.ZonedDateTime) VerticalSplitPanel(com.vaadin.ui.VerticalSplitPanel) EditAnnotationPropertiesDialog(de.catma.ui.module.annotate.annotationpanel.EditAnnotationPropertiesDialog) IndexedProject(de.catma.indexer.IndexedProject) ClientCommentReply(de.catma.ui.client.ui.tagger.shared.ClientCommentReply) KwicProvider(de.catma.indexer.KwicProvider) ValueOutOfBoundsException(com.vaadin.ui.Slider.ValueOutOfBoundsException) ExpansionListener(de.catma.ui.module.analyze.visualization.ExpansionListener) ExecutionListener(de.catma.backgroundservice.ExecutionListener) Slider(com.vaadin.ui.Slider) Set(java.util.Set) TagInstance(de.catma.tag.TagInstance) ClosableTab(de.catma.ui.component.tabbedview.ClosableTab) Pager(de.catma.ui.module.annotate.pager.Pager) Type(com.vaadin.ui.Notification.Type) PropertyChangeListener(java.beans.PropertyChangeListener) SliderMode(org.vaadin.sliderpanel.client.SliderMode) DefaultProgressCallable(de.catma.backgroundservice.DefaultProgressCallable) Range(de.catma.document.Range) TagManager(de.catma.tag.TagManager) VerticalLayout(com.vaadin.ui.VerticalLayout) SplitterPositionChangedListener(de.catma.ui.module.annotate.TaggerSplitPanel.SplitterPositionChangedListener) CommentMessage(de.catma.ui.events.CommentMessage) ArrayList(java.util.ArrayList) Pair(de.catma.util.Pair) SaveCancelListener(de.catma.ui.dialog.SaveCancelListener) ResourceSelectionListener(de.catma.ui.module.annotate.resourcepanel.ResourceSelectionListener) Property(de.catma.tag.Property) QueryResultRow(de.catma.queryengine.result.QueryResultRow) IOException(java.io.IOException) SourceDocument(de.catma.document.source.SourceDocument) AnnotationCollection(de.catma.document.annotation.AnnotationCollection) ValueChangeListener(com.vaadin.data.HasValue.ValueChangeListener) Annotation(de.catma.document.annotation.Annotation) TagManagerEvent(de.catma.tag.TagManager.TagManagerEvent) ClientTagInstance(de.catma.ui.client.ui.tagger.shared.ClientTagInstance) Button(com.vaadin.ui.Button) ChangeType(de.catma.project.event.ChangeType) TextRange(de.catma.ui.client.ui.tagger.shared.TextRange) HorizontalLayout(com.vaadin.ui.HorizontalLayout) AnnotateResourcePanel(de.catma.ui.module.annotate.resourcepanel.AnnotateResourcePanel) SplitterPositionChangedEvent(de.catma.ui.module.annotate.TaggerSplitPanel.SplitterPositionChangedEvent) Reply(de.catma.document.comment.Reply) ClientComment(de.catma.ui.client.ui.tagger.shared.ClientComment) URISyntaxException(java.net.URISyntaxException) UI(com.vaadin.ui.UI) ConfirmDialog(org.vaadin.dialogs.ConfirmDialog) RouteToAnalyzeEvent(de.catma.ui.events.routing.RouteToAnalyzeEvent) TaggerContextMenu(de.catma.ui.module.annotate.contextmenu.TaggerContextMenu) ErrorHandler(de.catma.ui.module.main.ErrorHandler) CatmaApplication(de.catma.ui.CatmaApplication) SliderPanel(org.vaadin.sliderpanel.SliderPanel) VaadinIcons(com.vaadin.icons.VaadinIcons) Version(de.catma.tag.Version) IconButton(de.catma.ui.component.IconButton) Collection(java.util.Collection) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) MarginInfo(com.vaadin.shared.ui.MarginInfo) TagReference(de.catma.document.annotation.TagReference) List(java.util.List) TaggerListener(de.catma.ui.module.annotate.Tagger.TaggerListener) Corpus(de.catma.document.corpus.Corpus) TagDefinition(de.catma.tag.TagDefinition) Optional(java.util.Optional) HazelCastService(de.catma.hazelcast.HazelCastService) SliderPanelBuilder(org.vaadin.sliderpanel.SliderPanelBuilder) ValueChangeEvent(com.vaadin.data.HasValue.ValueChangeEvent) KwicPanel(de.catma.ui.module.analyze.visualization.kwic.KwicPanel) ClickListener(com.vaadin.ui.Button.ClickListener) PagerComponent(de.catma.ui.module.annotate.pager.PagerComponent) AnnotationPanel(de.catma.ui.module.annotate.annotationpanel.AnnotationPanel) AnnotationCollectionManager(de.catma.document.annotation.AnnotationCollectionManager) PageChangeListener(de.catma.ui.module.annotate.pager.PagerComponent.PageChangeListener) UIMessageListener(de.catma.ui.UIMessageListener) User(de.catma.user.User) 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) Notification(com.vaadin.ui.Notification) Page(de.catma.ui.module.annotate.pager.Page) HazelcastConfiguration(de.catma.hazelcast.HazelcastConfiguration) TagsetDefinition(de.catma.tag.TagsetDefinition) IDGenerator(de.catma.util.IDGenerator) Subscribe(com.google.common.eventbus.Subscribe) TagLibrary(de.catma.tag.TagLibrary) PropertyChangeEvent(java.beans.PropertyChangeEvent) ClickEvent(com.vaadin.ui.Button.ClickEvent) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) Project(de.catma.project.Project) RepositoryChangeEvent(de.catma.project.Project.RepositoryChangeEvent) ReplyChangeEvent(de.catma.project.event.ReplyChangeEvent) TabCaptionChangeListener(de.catma.ui.component.tabbedview.TabCaptionChangeListener) DateTimeFormatter(java.time.format.DateTimeFormatter) ITopic(com.hazelcast.core.ITopic) TagDefinition(de.catma.tag.TagDefinition) PropertyChangeEvent(java.beans.PropertyChangeEvent) AnnotationCollection(de.catma.document.annotation.AnnotationCollection) Set(java.util.Set) HashSet(java.util.HashSet) PropertyChangeListener(java.beans.PropertyChangeListener) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) TagsetDefinition(de.catma.tag.TagsetDefinition) TagInstance(de.catma.tag.TagInstance) ClientTagInstance(de.catma.ui.client.ui.tagger.shared.ClientTagInstance) AnnotationCollection(de.catma.document.annotation.AnnotationCollection) Collection(java.util.Collection) TagReference(de.catma.document.annotation.TagReference) ArrayList(java.util.ArrayList) List(java.util.List) Pair(de.catma.util.Pair)

Example 34 with AnnotationCollectionReference

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

the class AnnotateResourcePanel method initData.

private void initData(SourceDocument currentlySelectedSourceDocument, Set<String> currentlysSelectedColletionIds) {
    try {
        documentData = new TreeData<>();
        Collection<SourceDocument> documents = project.getSourceDocuments();
        final SourceDocument preselection = currentlySelectedSourceDocument;
        documentData.addRootItems(documents.stream().map(document -> new DocumentDataItem(document, preselection != null && document.equals(preselection))));
        DocumentTreeItem preselectedItem = null;
        for (DocumentTreeItem documentDataItem : documentData.getRootItems()) {
            if (documentDataItem.isSelected()) {
                preselectedItem = documentDataItem;
            }
            for (AnnotationCollectionReference umcRef : ((DocumentDataItem) documentDataItem).getDocument().getUserMarkupCollectionRefs()) {
                documentData.addItem(documentDataItem, new CollectionDataItem(umcRef, project.hasPermission(project.getRoleForCollection(umcRef.getId()), RBACPermission.COLLECTION_WRITE), (currentlysSelectedColletionIds.isEmpty() || currentlysSelectedColletionIds.contains(umcRef.getId()))));
            }
        }
        documentTree.setDataProvider(new TreeDataProvider<>(documentData));
        if (preselectedItem != null) {
            documentTree.expand(preselectedItem);
        }
        tagsetData = new ListDataProvider<TagsetDefinition>(project.getTagsets());
        tagsetGrid.setDataProvider(tagsetData);
        tagsetData.getItems().forEach(tagsetGrid::select);
        documentData.getRootItems().stream().filter(documentItem -> documentItem.isSelected()).findAny().ifPresent(documentItem -> documentTree.expand(documentItem));
    } catch (Exception e) {
        errorHandler.showAndLogError("Error loading data!", e);
    }
}
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) SourceDocument(de.catma.document.source.SourceDocument) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) TagsetDefinition(de.catma.tag.TagsetDefinition)

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