Search in sources :

Example 1 with RepositoryFileListUpdatedEvent

use of org.kie.workbench.common.screens.library.api.RepositoryFileListUpdatedEvent in project kie-wb-common by kiegroup.

the class LibraryFileUpdateNotifierTest method onBatchIndexEventDoNothingWhenEmptyEventList.

@Test
public void onBatchIndexEventDoNothingWhenEmptyEventList() {
    BatchIndexEvent event = mock(BatchIndexEvent.class);
    doReturn(Collections.emptyList()).when(event).getIndexEvents();
    libraryFileUpdateNotifier.onBatchIndexEvent(event);
    verify(repositoryFileListUpdatedEvent, never()).fire(any(RepositoryFileListUpdatedEvent.class));
}
Also used : BatchIndexEvent(org.uberfire.ext.metadata.event.BatchIndexEvent) RepositoryFileListUpdatedEvent(org.kie.workbench.common.screens.library.api.RepositoryFileListUpdatedEvent) Test(org.junit.Test)

Example 2 with RepositoryFileListUpdatedEvent

use of org.kie.workbench.common.screens.library.api.RepositoryFileListUpdatedEvent 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

RepositoryFileListUpdatedEvent (org.kie.workbench.common.screens.library.api.RepositoryFileListUpdatedEvent)2 BatchIndexEvent (org.uberfire.ext.metadata.event.BatchIndexEvent)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 Test (org.junit.Test)1 Paths (org.uberfire.backend.server.util.Paths)1 IndexEvent (org.uberfire.ext.metadata.event.IndexEvent)1 Path (org.uberfire.java.nio.file.Path)1 JGitPathImpl (org.uberfire.java.nio.fs.jgit.JGitPathImpl)1