Search in sources :

Example 1 with ProjectReference

use of de.catma.project.ProjectReference 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 2 with ProjectReference

use of de.catma.project.ProjectReference in project catma by forTEXT.

the class GitlabManagerRestricted method unmarshallProjectReference.

private ProjectReference unmarshallProjectReference(String path, String eventuallyMarshalledMetadata) {
    String name = "unknown";
    String description = "unknown";
    try {
        JsonObject metaDataJson = JsonParser.parseString(eventuallyMarshalledMetadata).getAsJsonObject();
        name = metaDataJson.get(GroupSerializationField.name.name()).getAsString();
        description = metaDataJson.get(GroupSerializationField.description.name()).getAsString();
    } catch (Exception e) {
        logger.log(Level.WARNING, String.format("Error retrieving Project name or description for %1$s from %2$s", path, eventuallyMarshalledMetadata), e);
    }
    return new ProjectReference(path, name, description);
}
Also used : ProjectReference(de.catma.project.ProjectReference) JsonObject(com.google.gson.JsonObject) GitLabApiException(org.gitlab4j.api.GitLabApiException) IOException(java.io.IOException)

Example 3 with ProjectReference

use of de.catma.project.ProjectReference in project catma by forTEXT.

the class ProjectCard method initComponents.

protected void initComponents() {
    addStyleName("projectlist__card");
    CssLayout preview = new CssLayout();
    preview.addStyleName("projectlist__card__preview");
    descriptionLabel = new Label(projectReference.getDescription());
    descriptionLabel.setWidth("100%");
    preview.addComponents(descriptionLabel);
    preview.addLayoutClickListener(evt -> handleOpenProjectRequest());
    addComponent(preview);
    HorizontalFlexLayout descriptionBar = new HorizontalFlexLayout();
    descriptionBar.addStyleName("projectlist__card__descriptionbar");
    descriptionBar.setAlignItems(FlexLayout.AlignItems.BASELINE);
    descriptionBar.setWidth("100%");
    nameLabel = new Label(projectReference.getName());
    nameLabel.setWidth("100%");
    descriptionBar.addComponent(nameLabel);
    IconButton btnRemove = new IconButton(VaadinIcons.TRASH);
    descriptionBar.addComponents(btnRemove);
    btnRemove.addClickListener((event -> {
        ConfirmDialog.show(UI.getCurrent(), "Delete Project", "Do you want to delete the whole Project '" + projectReference.getName() + "'?", "OK", "Cancel", (evt) -> {
            try {
                if (evt.isConfirmed()) {
                    projectManager.delete(projectReference.getProjectId());
                    eventBus.post(new ProjectChangedEvent(projectReference.getProjectId()));
                }
            } catch (Exception e) {
                errorLogger.showAndLogError("can't delete Project " + projectReference.getName(), e);
            }
        });
    }));
    IconButton btnEdit = new IconButton(VaadinIcons.PENCIL);
    btnEdit.addClickListener(click -> {
        new EditProjectDialog(projectReference, projectManager, result -> {
            try {
                projectManager.updateProject(result);
                descriptionLabel.setValue(result.getDescription());
                nameLabel.setValue(result.getName());
            } catch (IOException e) {
                errorLogger.showAndLogError("Failed to update Project", e);
                eventBus.post(new ProjectChangedEvent());
            }
        }).show();
    });
    descriptionBar.addComponent(btnEdit);
    IconButton btnLeave = new IconButton(VaadinIcons.EXIT);
    btnLeave.addClickListener((event -> {
        ConfirmDialog.show(UI.getCurrent(), "Leave Project", "Do you want to leave '" + projectReference.getName() + "'?", "OK", "Cancel", (evt) -> {
            try {
                if (evt.isConfirmed()) {
                    projectManager.leaveProject(projectReference.getProjectId());
                }
            } catch (Exception e) {
                errorLogger.showAndLogError("can't leave project " + projectReference.getName(), e);
            }
            eventBus.post(new ProjectChangedEvent());
        });
    }));
    descriptionBar.addComponent(btnLeave);
    rbacEnforcer.register(RBACConstraint.ifNotAuthorized((role) -> (rbacManager.hasPermission(role, RBACPermission.PROJECT_EDIT)), () -> {
        btnEdit.setVisible(false);
        btnEdit.setEnabled(false);
    }));
    rbacEnforcer.register(RBACConstraint.ifNotAuthorized((role) -> (rbacManager.hasPermission(role, RBACPermission.PROJECT_DELETE)), () -> {
        btnRemove.setVisible(false);
        btnRemove.setEnabled(false);
    }));
    rbacEnforcer.register(RBACConstraint.ifNotAuthorized((role) -> rbacManager.hasPermission(role, RBACPermission.PROJECT_LEAVE) && !rbacManager.hasPermission(role, RBACPermission.PROJECT_DELETE), () -> {
        btnLeave.setVisible(false);
        btnLeave.setEnabled(false);
    }));
    // IconButton buttonAction = new IconButton(VaadinIcons.ELLIPSIS_DOTS_V);
    // descriptionBar.addComponents(buttonAction);
    addComponents(descriptionBar);
}
Also used : FlexLayout(de.catma.ui.layout.FlexLayout) ProjectManager(de.catma.project.ProjectManager) RouteToProjectEvent(de.catma.ui.events.routing.RouteToProjectEvent) UI(com.vaadin.ui.UI) VerticalFlexLayout(de.catma.ui.layout.VerticalFlexLayout) RBACConstraint(de.catma.rbac.RBACConstraint) IOException(java.io.IOException) ConfirmDialog(org.vaadin.dialogs.ConfirmDialog) CssLayout(com.vaadin.ui.CssLayout) RBACRole(de.catma.rbac.RBACRole) ProjectReference(de.catma.project.ProjectReference) Objects(java.util.Objects) EventBus(com.google.common.eventbus.EventBus) HorizontalFlexLayout(de.catma.ui.layout.HorizontalFlexLayout) ErrorHandler(de.catma.ui.module.main.ErrorHandler) Label(com.vaadin.ui.Label) IRBACManager(de.catma.rbac.IRBACManager) RBACConstraintEnforcer(de.catma.rbac.RBACConstraintEnforcer) VaadinIcons(com.vaadin.icons.VaadinIcons) IconButton(de.catma.ui.component.IconButton) RBACPermission(de.catma.rbac.RBACPermission) ProjectChangedEvent(de.catma.ui.events.ProjectChangedEvent) CssLayout(com.vaadin.ui.CssLayout) IconButton(de.catma.ui.component.IconButton) Label(com.vaadin.ui.Label) IOException(java.io.IOException) HorizontalFlexLayout(de.catma.ui.layout.HorizontalFlexLayout) IOException(java.io.IOException) ProjectChangedEvent(de.catma.ui.events.ProjectChangedEvent)

Example 4 with ProjectReference

use of de.catma.project.ProjectReference in project catma by forTEXT.

the class GraphWorktreeProject method open.

@Override
public void open(OpenProjectListener openProjectListener) {
    try {
        logger.info(String.format("Opening Project %1$s with ID %2$s", projectReference.getName(), projectReference.getProjectId()));
        this.rootRevisionHash = gitProjectHandler.getRootRevisionHash();
        logger.info(String.format("Revision Hash for Project %1$s is %2$s", projectReference.getProjectId(), this.rootRevisionHash));
        this.gitProjectHandler.loadRolesPerResource();
        logger.info(String.format("Checking for conflicts in Project %1$s", projectReference.getProjectId()));
        if (gitProjectHandler.hasConflicts()) {
            gitProjectHandler.initAndUpdateSubmodules();
            openProjectListener.conflictResolutionNeeded(new GitConflictedProject(projectReference, gitProjectHandler, documentId -> getSourceDocumentURI(documentId)));
        } else {
            gitProjectHandler.initAndUpdateSubmodules();
            gitProjectHandler.removeStaleSubmoduleDirectories();
            gitProjectHandler.ensureDevBranches();
            gitProjectHandler.verifyCollections();
            ProgressListener progressListener = new ProgressListener() {

                @Override
                public void setProgress(String value, Object... args) {
                    logger.info(String.format(value, 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) {
                    logger.info(String.format("Loading Tag library for Project %1$s", projectReference.getProjectId()));
                    tagManager.load(result.getTagLibrary());
                    initTagManagerListeners();
                    logger.info(String.format("Project %1$s is loaded.", projectReference.getProjectId()));
                    openProjectListener.ready(GraphWorktreeProject.this);
                }
            }, progressListener, rootRevisionHash, tagManager, () -> gitProjectHandler.getTagsets(), () -> gitProjectHandler.getDocuments(), (tagLibrary) -> gitProjectHandler.getCollections(tagLibrary, progressListener), // forceGraphReload
            false, backgroundService);
        }
    } catch (Exception e) {
        openProjectListener.failure(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) TagManager(de.catma.tag.TagManager) ProgressListener(de.catma.backgroundservice.ProgressListener) IOException(java.io.IOException)

Aggregations

ProjectReference (de.catma.project.ProjectReference)4 EventBus (com.google.common.eventbus.EventBus)3 UI (com.vaadin.ui.UI)3 RBACPermission (de.catma.rbac.RBACPermission)3 RBACRole (de.catma.rbac.RBACRole)3 IOException (java.io.IOException)3 CacheBuilder (com.google.common.cache.CacheBuilder)2 CacheLoader (com.google.common.cache.CacheLoader)2 LoadingCache (com.google.common.cache.LoadingCache)2 RemovalListener (com.google.common.cache.RemovalListener)2 RemovalNotification (com.google.common.cache.RemovalNotification)2 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)2 Multimap (com.google.common.collect.Multimap)2 BackgroundService (de.catma.backgroundservice.BackgroundService)2 ExecutionListener (de.catma.backgroundservice.ExecutionListener)2 ProgressListener (de.catma.backgroundservice.ProgressListener)2 AnnotationCollection (de.catma.document.annotation.AnnotationCollection)2 AnnotationCollectionReference (de.catma.document.annotation.AnnotationCollectionReference)2 TagReference (de.catma.document.annotation.TagReference)2 Comment (de.catma.document.comment.Comment)2