Search in sources :

Example 1 with ProjectAssetListUpdated

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

the class PopulatedLibraryScreenTest method testOnAssetListUpdated.

@Test
public void testOnAssetListUpdated() {
    setupProjectContext(SPACE_NAME);
    libraryScreen.onAssetListUpdated(new ProjectAssetListUpdated(project1));
    ArgumentCaptor<WorkspaceProject> projectCaptor = ArgumentCaptor.forClass(WorkspaceProject.class);
    verify(libraryService, times(4)).getNumberOfAssets(projectCaptor.capture());
    Assert.assertSame(project1, projectCaptor.getValue());
    verify(libraryScreen.libraryTiles.first(), times(2)).setNumberOfAssets(anyInt());
}
Also used : ProjectAssetListUpdated(org.kie.workbench.common.screens.library.api.ProjectAssetListUpdated) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) Test(org.junit.Test)

Example 2 with ProjectAssetListUpdated

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

Example 3 with ProjectAssetListUpdated

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

the class LibraryAssetUpdateNotifier method onProjectIndexingFinishedEvent.

private void onProjectIndexingFinishedEvent(@Observes IndexingFinishedEvent event) {
    if (!isUpdateNotifierEnabled()) {
        return;
    }
    WorkspaceProject project = projectService.resolveProject(event.getPath());
    if (project == null) {
        throw new IllegalStateException("Cannot resolve Project for KClusterId: '" + event.getkClusterId() + "' and path: '" + event.getPath().toString() + "'.");
    }
    assetListUpdateEvent.fire(new ProjectAssetListUpdated(project));
}
Also used : ProjectAssetListUpdated(org.kie.workbench.common.screens.library.api.ProjectAssetListUpdated) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject)

Example 4 with ProjectAssetListUpdated

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

the class PopulatedLibraryScreenTest method createAssetListUpdatedEvent.

private ProjectAssetListUpdated createAssetListUpdatedEvent(String spaceName, String projectName) {
    ProjectAssetListUpdated projectAssetListUpdated = mock(ProjectAssetListUpdated.class);
    WorkspaceProject project = this.mockProject(projectName);
    when(project.getSpace()).thenReturn(new Space(spaceName));
    when(projectAssetListUpdated.getProject()).thenReturn(project);
    return projectAssetListUpdated;
}
Also used : Space(org.uberfire.spaces.Space) ProjectAssetListUpdated(org.kie.workbench.common.screens.library.api.ProjectAssetListUpdated) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject)

Aggregations

WorkspaceProject (org.guvnor.common.services.project.model.WorkspaceProject)4 ProjectAssetListUpdated (org.kie.workbench.common.screens.library.api.ProjectAssetListUpdated)4 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 Named (javax.inject.Named)1 WorkspaceProjectService (org.guvnor.common.services.project.service.WorkspaceProjectService)1 Test (org.junit.Test)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 Paths (org.uberfire.backend.server.util.Paths)1 BatchIndexEvent (org.uberfire.ext.metadata.event.BatchIndexEvent)1 DeletedEvent (org.uberfire.ext.metadata.event.IndexEvent.DeletedEvent)1 NewlyIndexedEvent (org.uberfire.ext.metadata.event.IndexEvent.NewlyIndexedEvent)1 RenamedEvent (org.uberfire.ext.metadata.event.IndexEvent.RenamedEvent)1 FileSystemUtils (org.uberfire.java.nio.file.api.FileSystemUtils)1