Search in sources :

Example 46 with SourceDocument

use of de.catma.document.source.SourceDocument in project catma by forTEXT.

the class GitProjectHandler method getDocuments.

public List<SourceDocument> getDocuments() {
    ArrayList<SourceDocument> documents = new ArrayList<>();
    try (ILocalGitRepositoryManager localRepoManager = this.localGitRepositoryManager) {
        localRepoManager.open(projectId, GitProjectManager.getProjectRootRepositoryName(projectId));
        List<Path> paths = localRepoManager.getSubmodulePaths().stream().filter(path -> path != null && path.startsWith(SOURCE_DOCUMENT_SUBMODULES_DIRECTORY_NAME)).map(path -> Paths.get(localRepoManager.getRepositoryWorkTree().toURI()).resolve(path)).collect(Collectors.toList());
        localRepoManager.detach();
        GitSourceDocumentHandler gitSourceDocumentHandler = new GitSourceDocumentHandler(localRepoManager, this.remoteGitServerManager, this.credentialsProvider);
        for (Path sourceDocPath : paths) {
            String sourceDocumentId = sourceDocPath.getFileName().toString();
            if (hasPermission(getRoleForDocument(sourceDocumentId), RBACPermission.DOCUMENT_READ)) {
                try {
                    documents.add(gitSourceDocumentHandler.open(projectId, sourceDocumentId));
                } catch (Exception e) {
                    logger.log(Level.SEVERE, String.format("error loading Document %1$s for project %2$s", sourceDocPath, projectId), e);
                }
            }
        }
    } catch (Exception e) {
        logger.log(Level.SEVERE, String.format("error loading Documents for project %1$s", projectId), e);
    }
    return documents;
}
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) SourceDocument(de.catma.document.source.SourceDocument) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IOException(java.io.IOException) JGitInternalException(org.eclipse.jgit.api.errors.JGitInternalException)

Example 47 with SourceDocument

use of de.catma.document.source.SourceDocument in project catma by forTEXT.

the class GraphLoadJob method call.

@Override
public Pair<TagManager, Graph> call() throws Exception {
    getProgressListener().setProgress("Start loading project %1$s...", projectReference.getName());
    logger.info("Start loading " + projectReference.getName() + " " + projectReference.getProjectId());
    Vertex userV = graph.addVertex(nt(User));
    userV.property("userId", user.getIdentifier());
    Vertex projectV = graph.addVertex(nt(Project));
    projectV.property("propertyId", projectReference.getProjectId());
    userV.addEdge(rt(hasProject), projectV);
    Vertex projectRevV = graph.addVertex(nt(ProjectRevision));
    projectRevV.property("revisionHash", revisionHash);
    projectV.addEdge(rt(hasRevision), projectRevV);
    List<TagsetDefinition> tagsets = tagsetsSupplier.get();
    getProgressListener().setProgress("Loading Tagsets...");
    tagManager.load(tagsets);
    for (TagsetDefinition tagset : tagsets) {
        getProgressListener().setProgress("Indexing Tagset %1$s...", tagset.getName());
        Vertex tagsetV = graphWriter.addTagset(projectRevV, tagset);
        graphWriter.addHasParentRelations(tagsetV, tagset);
    }
    final List<SourceDocument> documents = documentsSupplier.get();
    for (SourceDocument document : documents) {
        getProgressListener().setProgress("Indexing Document %1$s...", document.toString());
        graphWriter.addDocument(projectRevV, document);
    }
    final List<AnnotationCollection> collections = collectionsSupplier.get(tagManager.getTagLibrary());
    for (AnnotationCollection collection : collections) {
        getProgressListener().setProgress("Indexing Collection %1$s...", collection.toString());
        graphWriter.addCollection(revisionHash, revisionHash, collection);
    }
    getProgressListener().setProgress("Finished loading project %1$s", projectReference.getName());
    logger.info("Finished loading " + projectReference.getName() + " " + projectReference.getProjectId());
    return new Pair<>(tagManager, graph);
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) TagsetDefinition(de.catma.tag.TagsetDefinition) AnnotationCollection(de.catma.document.annotation.AnnotationCollection) SourceDocument(de.catma.document.source.SourceDocument) Pair(de.catma.util.Pair)

Example 48 with SourceDocument

use of de.catma.document.source.SourceDocument 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

SourceDocument (de.catma.document.source.SourceDocument)48 AnnotationCollectionReference (de.catma.document.annotation.AnnotationCollectionReference)23 Project (de.catma.project.Project)17 AnnotationCollection (de.catma.document.annotation.AnnotationCollection)15 List (java.util.List)15 TagsetDefinition (de.catma.tag.TagsetDefinition)13 IOException (java.io.IOException)13 Collectors (java.util.stream.Collectors)13 UI (com.vaadin.ui.UI)12 IDGenerator (de.catma.util.IDGenerator)12 HashSet (java.util.HashSet)12 ErrorHandler (de.catma.ui.module.main.ErrorHandler)11 EventBus (com.google.common.eventbus.EventBus)10 Subscribe (com.google.common.eventbus.Subscribe)10 CollectionChangeEvent (de.catma.project.event.CollectionChangeEvent)10 TreeDataProvider (com.vaadin.data.provider.TreeDataProvider)9 ChangeType (de.catma.project.event.ChangeType)9 RBACPermission (de.catma.rbac.RBACPermission)9 Pair (de.catma.util.Pair)9 Indexer (de.catma.indexer.Indexer)8