Search in sources :

Example 1 with OperationContext

use of org.opennms.features.topology.api.OperationContext in project opennms by OpenNMS.

the class GraphMLSearchProviderTest method canSearchAllSearchProviders.

@Test
public void canSearchAllSearchProviders() throws IOException, InvalidGraphException {
    final GraphMLMetaTopologyProvider metaTopologyProvider = new GraphMLMetaTopologyProvider(new GraphMLServiceAccessor());
    metaTopologyProvider.setTopologyLocation("target/test-classes/test-graph.xml");
    metaTopologyProvider.reload();
    Assert.assertNotNull(metaTopologyProvider.getDefaultGraphProvider());
    List<SearchProvider> searchProviders = metaTopologyProvider.getGraphProviders().stream().map(eachProvider -> new GraphMLSearchProvider(metaTopologyProvider.getRawTopologyProvider(eachProvider.getNamespace()))).collect(Collectors.toList());
    Assert.assertEquals(2, searchProviders.size());
    DefaultTopologyService defaultTopologyService = new DefaultTopologyService();
    defaultTopologyService.setServiceLocator(new SimpleServiceLocator(metaTopologyProvider));
    VEProviderGraphContainer graphContainer = new VEProviderGraphContainer();
    graphContainer.setTopologyService(defaultTopologyService);
    graphContainer.setMetaTopologyId(metaTopologyProvider.getId());
    graphContainer.setSelectedNamespace(metaTopologyProvider.getDefaultGraphProvider().getNamespace());
    OperationContext operationContext = EasyMock.niceMock(OperationContext.class);
    EasyMock.expect(operationContext.getGraphContainer()).andReturn(graphContainer).anyTimes();
    OnmsServiceManager onmsServiceManager = EasyMock.niceMock(OnmsServiceManager.class);
    EasyMock.expect(onmsServiceManager.getServices(SearchProvider.class, null, new Hashtable<>())).andReturn(searchProviders).anyTimes();
    EasyMock.replay(onmsServiceManager, operationContext);
    SearchBox searchBox = new SearchBox(onmsServiceManager, operationContext);
    List<SearchSuggestion> results = searchBox.getQueryResults("North");
    Assert.assertEquals(5, results.size());
}
Also used : IOException(java.io.IOException) Test(org.junit.Test) EasyMock(org.easymock.EasyMock) DefaultTopologyService(org.opennms.features.topology.app.internal.service.DefaultTopologyService) OnmsServiceManager(org.opennms.osgi.OnmsServiceManager) Collectors(java.util.stream.Collectors) SearchBox(org.opennms.features.topology.app.internal.ui.SearchBox) List(java.util.List) OperationContext(org.opennms.features.topology.api.OperationContext) InvalidGraphException(org.opennms.features.graphml.model.InvalidGraphException) SearchSuggestion(org.opennms.features.topology.app.internal.gwt.client.SearchSuggestion) VEProviderGraphContainer(org.opennms.features.topology.app.internal.VEProviderGraphContainer) Assert(org.junit.Assert) SimpleServiceLocator(org.opennms.features.topology.app.internal.service.SimpleServiceLocator) GraphMLGraph(org.opennms.features.graphml.model.GraphMLGraph) GraphMLServiceAccessor(org.opennms.features.topology.plugins.topo.graphml.internal.GraphMLServiceAccessor) Hashtable(java.util.Hashtable) SearchProvider(org.opennms.features.topology.api.topo.SearchProvider) OperationContext(org.opennms.features.topology.api.OperationContext) OnmsServiceManager(org.opennms.osgi.OnmsServiceManager) SearchSuggestion(org.opennms.features.topology.app.internal.gwt.client.SearchSuggestion) DefaultTopologyService(org.opennms.features.topology.app.internal.service.DefaultTopologyService) VEProviderGraphContainer(org.opennms.features.topology.app.internal.VEProviderGraphContainer) Hashtable(java.util.Hashtable) SimpleServiceLocator(org.opennms.features.topology.app.internal.service.SimpleServiceLocator) SearchProvider(org.opennms.features.topology.api.topo.SearchProvider) SearchBox(org.opennms.features.topology.app.internal.ui.SearchBox) GraphMLServiceAccessor(org.opennms.features.topology.plugins.topo.graphml.internal.GraphMLServiceAccessor) Test(org.junit.Test)

Example 2 with OperationContext

use of org.opennms.features.topology.api.OperationContext in project opennms by OpenNMS.

the class GraphMLSearchProvider method onFocusSearchResult.

@Override
public void onFocusSearchResult(SearchResult searchResult, OperationContext operationContext) {
    final GraphContainer graphContainer = operationContext.getGraphContainer();
    final DefaultVertexRef vertexRef = new DefaultVertexRef(searchResult.getNamespace(), searchResult.getId(), searchResult.getLabel());
    if (graphContainer.getTopologyServiceClient().getVertex(vertexRef) == null) {
        // The vertex to add to focus is not in the current layer
        // Find the GraphProvider it belongs to
        Optional<GraphProvider> first = graphContainer.getTopologyServiceClient().getGraphProviders().stream().filter(eachProvider -> eachProvider.getNamespace().equals(searchResult.getNamespace())).findFirst();
        // If there is a graph provider (which should) select it
        if (first.isPresent() && first.get().getVertex(vertexRef) != null) {
            graphContainer.selectTopologyProvider(first.get());
            graphContainer.clearCriteria();
        }
    }
    super.onFocusSearchResult(searchResult, operationContext);
}
Also used : GraphContainer(org.opennms.features.topology.api.GraphContainer) Objects(java.util.Objects) GraphContainer(org.opennms.features.topology.api.GraphContainer) List(java.util.List) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) SearchResult(org.opennms.features.topology.api.topo.SearchResult) OperationContext(org.opennms.features.topology.api.OperationContext) SimpleSearchProvider(org.opennms.features.topology.api.topo.SimpleSearchProvider) Optional(java.util.Optional) SearchQuery(org.opennms.features.topology.api.topo.SearchQuery) VertexRef(org.opennms.features.topology.api.topo.VertexRef) ArrayList(java.util.ArrayList) GraphProvider(org.opennms.features.topology.api.topo.GraphProvider) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) GraphProvider(org.opennms.features.topology.api.topo.GraphProvider)

Example 3 with OperationContext

use of org.opennms.features.topology.api.OperationContext in project opennms by OpenNMS.

the class TopologyContextMenu method updateMenu.

public void updateMenu(GraphContainer graphContainer, UI mainWindow, OperationManager operationManager, List<VertexRef> targets) {
    final OperationContext operationContext = new DefaultOperationContext(mainWindow, graphContainer, OperationContext.DisplayLocation.CONTEXTMENU);
    // Clear Menu
    removeAllItems();
    // Rebuild menu
    MenuBuilder menuBuilder = new MenuBuilder();
    for (OperationServiceWrapper operationServiceWrapper : operationManager.getOperationWrappers()) {
        if (operationServiceWrapper.getContextMenuPosition() != null) {
            MenuItem item = new OperationMenuItem(operationServiceWrapper);
            menuBuilder.addMenuItem(item, operationServiceWrapper.getContextMenuPosition().isEmpty() ? null : operationServiceWrapper.getContextMenuPosition().split("\\|"));
        }
    }
    addNavigateToItems(menuBuilder, targets, operationContext);
    MenuBar menu = menuBuilder.build(targets, operationContext, this::notifyMenuUpdateListener);
    addItems(menu);
}
Also used : DefaultOperationContext(org.opennms.features.topology.app.internal.DefaultOperationContext) OperationContext(org.opennms.features.topology.api.OperationContext) DefaultOperationContext(org.opennms.features.topology.app.internal.DefaultOperationContext) MenuBar(com.vaadin.ui.MenuBar)

Example 4 with OperationContext

use of org.opennms.features.topology.api.OperationContext in project opennms by OpenNMS.

the class IconSelectionOperation method execute.

@Override
public void execute(List<VertexRef> targets, OperationContext operationContext) {
    final AbstractVertex vertex = (AbstractVertex) targets.get(0);
    final String preSelectedIconId = operationContext.getGraphContainer().getIconManager().getSVGIconId(vertex);
    new IconSelectionDialog(preSelectedIconId).withOkAction(iconWindow -> {
        final IconManager iconManager = operationContext.getGraphContainer().getIconManager();
        final String newIconId = iconWindow.getSelectedIcon();
        String newIconKey = iconManager.setIconMapping(vertex, newIconId);
        if (newIconKey != null) {
            // We have to temporary update the icon key, otherwise the icon is not updated (redoLayout has no effect)
            vertex.setIconKey(newIconKey);
            // Redo the layout to apply new icon
            operationContext.getGraphContainer().setDirty(true);
            operationContext.getGraphContainer().redoLayout();
        }
    }).open();
}
Also used : AbstractVertex(org.opennms.features.topology.api.topo.AbstractVertex) List(java.util.List) IconSelectionDialog(org.opennms.features.topology.app.internal.ui.icons.IconSelectionDialog) Operation(org.opennms.features.topology.api.Operation) OperationContext(org.opennms.features.topology.api.OperationContext) IconManager(org.opennms.features.topology.api.IconManager) AbstractVertex(org.opennms.features.topology.api.topo.AbstractVertex) VertexRef(org.opennms.features.topology.api.topo.VertexRef) IconSelectionDialog(org.opennms.features.topology.app.internal.ui.icons.IconSelectionDialog) IconManager(org.opennms.features.topology.api.IconManager)

Aggregations

OperationContext (org.opennms.features.topology.api.OperationContext)4 List (java.util.List)3 VertexRef (org.opennms.features.topology.api.topo.VertexRef)2 MenuBar (com.vaadin.ui.MenuBar)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Hashtable (java.util.Hashtable)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 EasyMock (org.easymock.EasyMock)1 Assert (org.junit.Assert)1 Test (org.junit.Test)1 GraphMLGraph (org.opennms.features.graphml.model.GraphMLGraph)1 InvalidGraphException (org.opennms.features.graphml.model.InvalidGraphException)1 GraphContainer (org.opennms.features.topology.api.GraphContainer)1 IconManager (org.opennms.features.topology.api.IconManager)1 Operation (org.opennms.features.topology.api.Operation)1 AbstractVertex (org.opennms.features.topology.api.topo.AbstractVertex)1 DefaultVertexRef (org.opennms.features.topology.api.topo.DefaultVertexRef)1