Search in sources :

Example 1 with JGitPathImpl

use of org.uberfire.java.nio.fs.jgit.JGitPathImpl in project kie-wb-common by kiegroup.

the class LibraryFileUpdateNotifierTest method buildPathMockForBranch.

private org.uberfire.backend.vfs.Path buildPathMockForBranch(final String branchName, final String pathStr) {
    JGitPathImpl jGitPath = mock(JGitPathImpl.class);
    doReturn(jGitPath).when(libraryFileUpdateNotifier).getPath(pathStr);
    doReturn(branchName).when(jGitPath).getRefTree();
    org.uberfire.backend.vfs.Path vfsPath = mock(Path.class);
    doReturn(vfsPath).when(libraryFileUpdateNotifier).convertPath(jGitPath);
    return vfsPath;
}
Also used : Path(org.uberfire.backend.vfs.Path) JGitPathImpl(org.uberfire.java.nio.fs.jgit.JGitPathImpl)

Example 2 with JGitPathImpl

use of org.uberfire.java.nio.fs.jgit.JGitPathImpl in project kie-wb-common by kiegroup.

the class LibraryFileUpdateNotifier method onBatchIndexEvent.

public void onBatchIndexEvent(@Observes final BatchIndexEvent event) {
    event.getIndexEvents().stream().flatMap(evt -> {
        switch(evt.getKind()) {
            case Deleted:
                return Stream.of(((IndexEvent.DeletedEvent) evt).getDeleted().getKey());
            case NewlyIndexed:
                return Stream.of(((IndexEvent.NewlyIndexedEvent) evt).getKObject().getKey());
            case Renamed:
                return Stream.of(((IndexEvent.RenamedEvent) evt).getTarget().getKey());
            default:
                return Stream.empty();
        }
    }).map(pathStr -> {
        final Path path = getPath(pathStr);
        final WorkspaceProject project = workspaceProjectService.resolveProject(convertPath(path));
        final String repositoryId = project.getRepository().getIdentifier();
        final String branchName = (path instanceof JGitPathImpl) ? ((JGitPathImpl) path).getRefTree() : null;
        return new RepositoryFileListUpdatedEvent(repositoryId, branchName);
    }).distinct().forEach(repositoryFileListUpdatedEvent::fire);
}
Also used : Event(javax.enterprise.event.Event) RepositoryFileListUpdatedEvent(org.kie.workbench.common.screens.library.api.RepositoryFileListUpdatedEvent) Path(org.uberfire.java.nio.file.Path) IndexEvent(org.uberfire.ext.metadata.event.IndexEvent) WorkspaceProjectService(org.guvnor.common.services.project.service.WorkspaceProjectService) JGitPathImpl(org.uberfire.java.nio.fs.jgit.JGitPathImpl) Paths(org.uberfire.backend.server.util.Paths) Inject(javax.inject.Inject) Stream(java.util.stream.Stream) BatchIndexEvent(org.uberfire.ext.metadata.event.BatchIndexEvent) Observes(javax.enterprise.event.Observes) ApplicationScoped(javax.enterprise.context.ApplicationScoped) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) Path(org.uberfire.java.nio.file.Path) IndexEvent(org.uberfire.ext.metadata.event.IndexEvent) BatchIndexEvent(org.uberfire.ext.metadata.event.BatchIndexEvent) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) RepositoryFileListUpdatedEvent(org.kie.workbench.common.screens.library.api.RepositoryFileListUpdatedEvent) JGitPathImpl(org.uberfire.java.nio.fs.jgit.JGitPathImpl)

Aggregations

JGitPathImpl (org.uberfire.java.nio.fs.jgit.JGitPathImpl)2 Stream (java.util.stream.Stream)1 ApplicationScoped (javax.enterprise.context.ApplicationScoped)1 Event (javax.enterprise.event.Event)1 Observes (javax.enterprise.event.Observes)1 Inject (javax.inject.Inject)1 WorkspaceProject (org.guvnor.common.services.project.model.WorkspaceProject)1 WorkspaceProjectService (org.guvnor.common.services.project.service.WorkspaceProjectService)1 RepositoryFileListUpdatedEvent (org.kie.workbench.common.screens.library.api.RepositoryFileListUpdatedEvent)1 Paths (org.uberfire.backend.server.util.Paths)1 Path (org.uberfire.backend.vfs.Path)1 BatchIndexEvent (org.uberfire.ext.metadata.event.BatchIndexEvent)1 IndexEvent (org.uberfire.ext.metadata.event.IndexEvent)1 Path (org.uberfire.java.nio.file.Path)1