Search in sources :

Example 1 with BatchIndexEvent

use of org.uberfire.ext.metadata.event.BatchIndexEvent in project kie-wb-common by kiegroup.

the class LibraryFileUpdateNotifierTest method buildBatchIndexEvent.

private BatchIndexEvent buildBatchIndexEvent(final List<IndexEvent> indexEvents) {
    BatchIndexEvent event = mock(BatchIndexEvent.class);
    doReturn(indexEvents).when(event).getIndexEvents();
    return event;
}
Also used : BatchIndexEvent(org.uberfire.ext.metadata.event.BatchIndexEvent)

Example 2 with BatchIndexEvent

use of org.uberfire.ext.metadata.event.BatchIndexEvent 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 3 with BatchIndexEvent

use of org.uberfire.ext.metadata.event.BatchIndexEvent 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)

Example 4 with BatchIndexEvent

use of org.uberfire.ext.metadata.event.BatchIndexEvent in project kie-wb-common by kiegroup.

the class LibraryAssetUpdateNotifier method notifyOnUpdatedAssets.

public void notifyOnUpdatedAssets(@Observes @Named(Constants.INDEXER_ID) BatchIndexEvent event) {
    if (!isUpdateNotifierEnabled()) {
        return;
    }
    // Assume that all indexed items are from the same project.
    event.getIndexEvents().stream().flatMap(evt -> {
        switch(evt.getKind()) {
            case Deleted:
                return Stream.of(((DeletedEvent) evt).getDeleted().getKey());
            case NewlyIndexed:
                return Stream.of(((NewlyIndexedEvent) evt).getKObject().getKey());
            case Renamed:
                return Stream.of(((RenamedEvent) evt).getTarget().getKey());
            default:
                return Stream.empty();
        }
    }).map(path -> org.uberfire.java.nio.file.Paths.get(path)).filter(path -> libraryIndexer.supportsPath(path)).flatMap(path -> {
        try {
            WorkspaceProject project = projectService.resolveProject(Paths.convert(path));
            return (project == null) ? Stream.empty() : Stream.of(project);
        } catch (Throwable t) {
            return Stream.empty();
        }
    }).map(project -> new ProjectAssetListUpdated(project)).findFirst().ifPresent(clientEvent -> {
        logger.info("Sending indexing notification for project [{}].", clientEvent.getProject().getRepository().getIdentifier());
        assetListUpdateEvent.fire(clientEvent);
    });
}
Also used : Event(javax.enterprise.event.Event) Logger(org.slf4j.Logger) Remote(org.kie.workbench.common.screens.library.api.Remote) RenamedEvent(org.uberfire.ext.metadata.event.IndexEvent.RenamedEvent) DeletedEvent(org.uberfire.ext.metadata.event.IndexEvent.DeletedEvent) WorkspaceProjectService(org.guvnor.common.services.project.service.WorkspaceProjectService) ProjectAssetListUpdated(org.kie.workbench.common.screens.library.api.ProjectAssetListUpdated) Paths(org.uberfire.backend.server.util.Paths) Inject(javax.inject.Inject) NewlyIndexedEvent(org.uberfire.ext.metadata.event.IndexEvent.NewlyIndexedEvent) Stream(java.util.stream.Stream) BatchIndexEvent(org.uberfire.ext.metadata.event.BatchIndexEvent) Observes(javax.enterprise.event.Observes) FileSystemUtils(org.uberfire.java.nio.file.api.FileSystemUtils) IndexingFinishedEvent(org.kie.workbench.common.services.refactoring.model.index.events.IndexingFinishedEvent) ApplicationScoped(javax.enterprise.context.ApplicationScoped) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) Named(javax.inject.Named) Constants(org.kie.workbench.common.screens.library.api.index.Constants) ProjectAssetListUpdated(org.kie.workbench.common.screens.library.api.ProjectAssetListUpdated) NewlyIndexedEvent(org.uberfire.ext.metadata.event.IndexEvent.NewlyIndexedEvent) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) DeletedEvent(org.uberfire.ext.metadata.event.IndexEvent.DeletedEvent) RenamedEvent(org.uberfire.ext.metadata.event.IndexEvent.RenamedEvent)

Aggregations

BatchIndexEvent (org.uberfire.ext.metadata.event.BatchIndexEvent)4 Stream (java.util.stream.Stream)2 ApplicationScoped (javax.enterprise.context.ApplicationScoped)2 Event (javax.enterprise.event.Event)2 Observes (javax.enterprise.event.Observes)2 Inject (javax.inject.Inject)2 WorkspaceProject (org.guvnor.common.services.project.model.WorkspaceProject)2 WorkspaceProjectService (org.guvnor.common.services.project.service.WorkspaceProjectService)2 RepositoryFileListUpdatedEvent (org.kie.workbench.common.screens.library.api.RepositoryFileListUpdatedEvent)2 Paths (org.uberfire.backend.server.util.Paths)2 Named (javax.inject.Named)1 Test (org.junit.Test)1 ProjectAssetListUpdated (org.kie.workbench.common.screens.library.api.ProjectAssetListUpdated)1 Remote (org.kie.workbench.common.screens.library.api.Remote)1 Constants (org.kie.workbench.common.screens.library.api.index.Constants)1 IndexingFinishedEvent (org.kie.workbench.common.services.refactoring.model.index.events.IndexingFinishedEvent)1 Logger (org.slf4j.Logger)1 IndexEvent (org.uberfire.ext.metadata.event.IndexEvent)1 DeletedEvent (org.uberfire.ext.metadata.event.IndexEvent.DeletedEvent)1 NewlyIndexedEvent (org.uberfire.ext.metadata.event.IndexEvent.NewlyIndexedEvent)1