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;
}
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));
}
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);
}
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);
});
}
Aggregations