Search in sources :

Example 1 with BackgroundService

use of de.catma.backgroundservice.BackgroundService 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 BackgroundService

use of de.catma.backgroundservice.BackgroundService in project catma by forTEXT.

the class GitProjectHandlerTest method setUp.

@BeforeEach
public void setUp() throws Exception {
    // create a fake CATMA user which we'll use to instantiate GitlabManagerRestricted (using the corresponding impersonation token) & JGitRepoManager
    Integer randomUserId = Integer.parseInt(RandomStringUtils.randomNumeric(3));
    String username = String.format("testuser-%s", randomUserId);
    String email = String.format("%s@catma.de", username);
    String name = String.format("Test User %s", randomUserId);
    gitlabManagerPrivileged = new GitlabManagerPrivileged();
    String impersonationToken = gitlabManagerPrivileged.acquireImpersonationToken(username, "catma", email, name).getSecond();
    EventBus mockEventBus = mock(EventBus.class);
    BackgroundService mockBackgroundService = mock(BackgroundService.class);
    gitlabManagerRestricted = new GitlabManagerRestricted(mockEventBus, mockBackgroundService, impersonationToken);
}
Also used : BackgroundService(de.catma.backgroundservice.BackgroundService) GitlabManagerPrivileged(de.catma.repository.git.managers.GitlabManagerPrivileged) GitlabManagerRestricted(de.catma.repository.git.managers.GitlabManagerRestricted) EventBus(com.google.common.eventbus.EventBus) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with BackgroundService

use of de.catma.backgroundservice.BackgroundService in project catma by forTEXT.

the class GitProjectHandlerTest method create.

@Test
public void create() throws Exception {
    try (ILocalGitRepositoryManager jGitRepoManager = new JGitRepoManager(CATMAPropertyKey.GitBasedRepositoryBasePath.getValue(), gitlabManagerRestricted.getUser())) {
        directoriesToDeleteOnTearDown.add(jGitRepoManager.getRepositoryBasePath());
        BackgroundService mockBackgroundService = mock(BackgroundService.class);
        EventBus mockEventBus = mock(EventBus.class);
        GitProjectManager gitProjectManager = new GitProjectManager(CATMAPropertyKey.GitBasedRepositoryBasePath.getValue(), gitlabManagerRestricted, // noop deletion handler
        (projectId) -> {
        }, mockBackgroundService, mockEventBus);
        String projectId = gitProjectManager.create("Test CATMA Project", "This is a test CATMA project");
        // we don't add the projectId to projectsToDeleteOnTearDown as deletion of the user will take care of that for us
        assertNotNull(projectId);
        assert projectId.startsWith("CATMA_");
        // the JGitRepoManager instance should always be in a detached state after GitProjectManager calls return
        assertFalse(jGitRepoManager.isAttached());
        String expectedRootRepositoryName = GitProjectManager.getProjectRootRepositoryName(projectId);
        File expectedRootRepositoryPath = Paths.get(jGitRepoManager.getRepositoryBasePath().getPath(), projectId, expectedRootRepositoryName).toFile();
        assert expectedRootRepositoryPath.exists();
        assert expectedRootRepositoryPath.isDirectory();
    }
}
Also used : BackgroundService(de.catma.backgroundservice.BackgroundService) ILocalGitRepositoryManager(de.catma.repository.git.interfaces.ILocalGitRepositoryManager) JGitRepoManager(de.catma.repository.git.managers.JGitRepoManager) EventBus(com.google.common.eventbus.EventBus) File(java.io.File) GitLabServerManagerTest(de.catma.repository.git.managers.GitLabServerManagerTest) Test(org.junit.jupiter.api.Test)

Example 4 with BackgroundService

use of de.catma.backgroundservice.BackgroundService in project catma by forTEXT.

the class GitSourceDocumentHandlerTest method setUp.

@BeforeEach
public void setUp() throws Exception {
    // create a fake CATMA user which we'll use to instantiate GitlabManagerRestricted (using the corresponding impersonation token) & JGitRepoManager
    Integer randomUserId = Integer.parseInt(RandomStringUtils.randomNumeric(3));
    String username = String.format("testuser-%s", randomUserId);
    String email = String.format("%s@catma.de", username);
    String name = String.format("Test User %s", randomUserId);
    gitlabManagerPrivileged = new GitlabManagerPrivileged();
    String impersonationToken = gitlabManagerPrivileged.acquireImpersonationToken(username, "catma", email, name).getSecond();
    EventBus mockEventBus = mock(EventBus.class);
    BackgroundService mockBackgroundService = mock(BackgroundService.class);
    gitlabManagerRestricted = new GitlabManagerRestricted(mockEventBus, mockBackgroundService, impersonationToken);
}
Also used : BackgroundService(de.catma.backgroundservice.BackgroundService) GitlabManagerPrivileged(de.catma.repository.git.managers.GitlabManagerPrivileged) GitlabManagerRestricted(de.catma.repository.git.managers.GitlabManagerRestricted) EventBus(com.google.common.eventbus.EventBus) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with BackgroundService

use of de.catma.backgroundservice.BackgroundService in project catma by forTEXT.

the class GitLabServerManagerTest method setUp.

@BeforeEach
public void setUp() throws Exception {
    // create a fake CATMA user which we'll use to instantiate GitlabManagerRestricted (using the corresponding impersonation token)
    Integer randomUserId = Integer.parseInt(RandomStringUtils.randomNumeric(3));
    String username = String.format("testuser-%s", randomUserId);
    String email = String.format("%s@catma.de", username);
    String name = String.format("Test User %s", randomUserId);
    gitlabManagerPrivileged = new GitlabManagerPrivileged();
    String impersonationToken = gitlabManagerPrivileged.acquireImpersonationToken(username, "catma", email, name).getSecond();
    EventBus mockEventBus = mock(EventBus.class);
    BackgroundService mockBackgroundService = mock(BackgroundService.class);
    gitlabManagerRestricted = new GitlabManagerRestricted(mockEventBus, mockBackgroundService, impersonationToken);
}
Also used : BackgroundService(de.catma.backgroundservice.BackgroundService) EventBus(com.google.common.eventbus.EventBus) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

BackgroundService (de.catma.backgroundservice.BackgroundService)14 EventBus (com.google.common.eventbus.EventBus)12 File (java.io.File)9 ContentInfoSet (de.catma.document.source.ContentInfoSet)5 TermExtractor (de.catma.indexer.TermExtractor)5 IDGenerator (de.catma.util.IDGenerator)5 UI (com.vaadin.ui.UI)4 SourceDocument (de.catma.document.source.SourceDocument)4 SourceDocumentInfo (de.catma.document.source.SourceDocumentInfo)4 FileInputStream (java.io.FileInputStream)4 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)3 Multimap (com.google.common.collect.Multimap)3 BackgroundServiceProvider (de.catma.backgroundservice.BackgroundServiceProvider)3 ExecutionListener (de.catma.backgroundservice.ExecutionListener)3 ProgressListener (de.catma.backgroundservice.ProgressListener)3 AnnotationCollection (de.catma.document.annotation.AnnotationCollection)3 AnnotationCollectionReference (de.catma.document.annotation.AnnotationCollectionReference)3 TagReference (de.catma.document.annotation.TagReference)3 IndexInfoSet (de.catma.document.source.IndexInfoSet)3 TechInfoSet (de.catma.document.source.TechInfoSet)3