Search in sources :

Example 1 with OnmsServiceManager

use of org.opennms.osgi.OnmsServiceManager 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 OnmsServiceManager

use of org.opennms.osgi.OnmsServiceManager in project opennms by OpenNMS.

the class OSGiVerticesUpdateManagerTest method testVertexRefSelectedUpdate.

@Test
public void testVertexRefSelectedUpdate() {
    MockEventProxy mockEventProxy = new MockEventProxy();
    OnmsServiceManager serviceManager = new DummyOnmsServiceManager();
    VaadinApplicationContext vaadinApplicationContext = new DummyVaadinApplicationContext(mockEventProxy);
    OsgiVerticesUpdateManager updateManager = new OsgiVerticesUpdateManager(serviceManager, vaadinApplicationContext);
    updateManager.selectionChanged(createContextWithVertRefIds(1, 2, 3, 4));
    assertEquals(1, mockEventProxy.getFireEventCalls());
    VerticesUpdateManager.VerticesUpdateEvent event = mockEventProxy.getLastFiredEvent();
    assertEquals(4, event.getVertexRefs().size());
    updateManager.selectionChanged(createContextWithVertRefIds(1, 2, 3, 4));
    assertEquals(1, mockEventProxy.getFireEventCalls());
    VerticesUpdateManager.VerticesUpdateEvent event2 = mockEventProxy.getLastFiredEvent();
    assertNull(event2);
    updateManager.selectionChanged(createContextWithVertRefIds(2, 3, 4, 5));
    assertEquals(2, mockEventProxy.getFireEventCalls());
    VerticesUpdateManager.VerticesUpdateEvent event3 = mockEventProxy.getLastFiredEvent();
    assertEquals(4, event3.getVertexRefs().size());
    updateManager.selectionChanged(createContextWithVertRefIds(5, 6));
    assertEquals(3, mockEventProxy.getFireEventCalls());
    VerticesUpdateManager.VerticesUpdateEvent event4 = mockEventProxy.getLastFiredEvent();
    assertEquals(2, event4.getVertexRefs().size());
}
Also used : OnmsServiceManager(org.opennms.osgi.OnmsServiceManager) VerticesUpdateManager(org.opennms.features.topology.api.VerticesUpdateManager) VaadinApplicationContext(org.opennms.osgi.VaadinApplicationContext) Test(org.junit.Test)

Example 3 with OnmsServiceManager

use of org.opennms.osgi.OnmsServiceManager in project opennms by OpenNMS.

the class TopologyUI method init.

@Override
protected void init(final VaadinRequest request) {
    // Register a cleanup
    request.getService().addSessionDestroyListener((SessionDestroyListener) event -> m_widgetManager.removeUpdateListener(TopologyUI.this));
    try {
        m_headerHtml = getHeader(((VaadinServletRequest) request).getHttpServletRequest());
    } catch (final Exception e) {
        LOG.error("failed to get header HTML for request " + request.getPathInfo(), e.getCause());
    }
    // create VaadinApplicationContext
    m_applicationContext = m_serviceManager.createApplicationContext(new VaadinApplicationContextCreator() {

        @Override
        public VaadinApplicationContext create(OnmsServiceManager manager) {
            VaadinApplicationContextImpl context = new VaadinApplicationContextImpl();
            context.setSessionId(request.getWrappedSession().getId());
            context.setUiId(getUIId());
            context.setUsername(request.getRemoteUser());
            return context;
        }
    });
    m_verticesUpdateManager = new OsgiVerticesUpdateManager(m_serviceManager, m_applicationContext);
    m_serviceManager.getEventRegistry().addPossibleEventConsumer(this, m_applicationContext);
    // Set the algorithm last so that the criteria and SZLs are
    // in place before we run the layout algorithm.
    m_graphContainer.setApplicationContext(m_applicationContext);
    createLayouts();
    // Set up an error handler for UI-level exceptions
    setupErrorHandler();
    // Add an auto refresh handler to the GraphContainer
    setupAutoRefresher();
    loadUserSettings();
    // If no Topology Provider was selected (due to loadUserSettings(), fallback to default
    if (Strings.isNullOrEmpty(m_graphContainer.getMetaTopologyId())) {
        CheckedOperation defaultTopologySelectorOperation = getDefaultTopologySelectorOperation(m_bundlecontext);
        // no default found, abort
        Objects.requireNonNull(defaultTopologySelectorOperation, "No default GraphProvider found.");
        defaultTopologySelectorOperation.execute(Lists.newArrayList(), new DefaultOperationContext(TopologyUI.this, m_graphContainer, DisplayLocation.MENUBAR));
    }
    // Add a request handler that parses incoming focusNode and szl query parameters
    TopologyUIRequestHandler handler = new TopologyUIRequestHandler();
    getSession().addRequestHandler(handler);
    // deal with those in init case
    handler.handleRequestParameter(request);
    // Add the default criteria if we do not have already a criteria set
    if (getWrappedVertexHopCriteria(m_graphContainer).isEmpty() && noAdditionalFocusCriteria()) {
        List<Criteria> defaultCriteriaList = m_graphContainer.getTopologyServiceClient().getDefaults().getCriteria();
        if (defaultCriteriaList != null) {
            // set default
            defaultCriteriaList.forEach(m_graphContainer::addCriteria);
        }
    }
    // We set the listeners at the end, to not fire them all the time when initializing the UI
    setupListeners();
    // We force a reload to trigger a fireGraphChanged()
    m_graphContainer.setDirty(true);
    m_graphContainer.redoLayout();
    // Trigger a selectionChanged
    m_selectionManager.selectionChanged(m_selectionManager);
}
Also used : HasExtraComponents(org.opennms.features.topology.api.HasExtraComponents) VerticalSplitPanel(com.vaadin.ui.VerticalSplitPanel) Alignment(com.vaadin.ui.Alignment) SelectionAwareTable(org.opennms.features.topology.api.browsers.SelectionAwareTable) SearchBox(org.opennms.features.topology.app.internal.ui.SearchBox) VertexHopGraphProvider.getWrappedVertexHopCriteria(org.opennms.features.topology.api.support.VertexHopGraphProvider.getWrappedVertexHopCriteria) CategoryHopCriteria(org.opennms.features.topology.app.internal.support.CategoryHopCriteria) Map(java.util.Map) ServiceReference(org.osgi.framework.ServiceReference) RedoLayoutOperation(org.opennms.features.topology.app.internal.operations.RedoLayoutOperation) VaadinResponse(com.vaadin.server.VaadinResponse) Property(com.vaadin.data.Property) HistoryManager(org.opennms.features.topology.api.HistoryManager) Set(java.util.Set) AbsoluteLayout(com.vaadin.ui.AbsoluteLayout) IconRepositoryManager(org.opennms.features.topology.app.internal.support.IconRepositoryManager) Criteria(org.opennms.features.topology.api.topo.Criteria) VaadinApplicationContextImpl(org.opennms.osgi.VaadinApplicationContextImpl) VertexRef(org.opennms.features.topology.api.topo.VertexRef) MenuUpdateListener(org.opennms.features.topology.app.internal.menu.MenuUpdateListener) DefaultErrorHandler(com.vaadin.server.DefaultErrorHandler) UriFragmentChangedListener(com.vaadin.server.Page.UriFragmentChangedListener) Title(com.vaadin.annotations.Title) VerticalLayout(com.vaadin.ui.VerticalLayout) TreeSet(java.util.TreeSet) VertexHopGraphProvider(org.opennms.features.topology.api.support.VertexHopGraphProvider) VertexUpdateListener(org.opennms.features.topology.app.internal.TopologyComponent.VertexUpdateListener) DefaultTopologyProviderInfo(org.opennms.features.topology.api.topo.DefaultTopologyProviderInfo) Strings(com.google.common.base.Strings) HttpServletRequest(javax.servlet.http.HttpServletRequest) Lists(com.google.common.collect.Lists) VaadinApplicationContextCreator(org.opennms.osgi.VaadinApplicationContextCreator) TopologyMenuBar(org.opennms.features.topology.app.internal.menu.TopologyMenuBar) OnmsHeaderProvider(org.opennms.web.api.OnmsHeaderProvider) InfoPanelItem(org.opennms.features.topology.api.info.item.InfoPanelItem) IOException(java.io.IOException) PreserveOnRefresh(com.vaadin.annotations.PreserveOnRefresh) Refresher(com.github.wolfie.refresher.Refresher) LayoutHintComponent(org.opennms.features.topology.app.internal.ui.LayoutHintComponent) HorizontalLayout(com.vaadin.ui.HorizontalLayout) TopologyProviderInfo(org.opennms.features.topology.api.topo.TopologyProviderInfo) InfoPanelItemProvider(org.opennms.features.topology.api.info.InfoPanelItemProvider) OperationManager(org.opennms.features.topology.app.internal.menu.OperationManager) ContentType(org.opennms.features.topology.api.browsers.ContentType) EventConsumer(org.opennms.osgi.EventConsumer) GraphContainer(org.opennms.features.topology.api.GraphContainer) CollapsibleCriteria(org.opennms.features.topology.api.topo.CollapsibleCriteria) ConfirmationDialog(org.opennms.netmgt.vaadin.core.ConfirmationDialog) RequestHandler(com.vaadin.server.RequestHandler) ToolbarPanel(org.opennms.features.topology.app.internal.ui.ToolbarPanel) LoggerFactory(org.slf4j.LoggerFactory) UI(com.vaadin.ui.UI) CheckedOperation(org.opennms.features.topology.api.CheckedOperation) Window(com.vaadin.ui.Window) VaadinRequest(com.vaadin.server.VaadinRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) DefaultInfoPanelItem(org.opennms.features.topology.api.info.item.DefaultInfoPanelItem) SelectionListener(org.opennms.features.topology.api.SelectionListener) VaadinApplicationContext(org.opennms.osgi.VaadinApplicationContext) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) Collection(java.util.Collection) OnmsServiceManager(org.opennms.osgi.OnmsServiceManager) Collectors(java.util.stream.Collectors) BundleContext(org.osgi.framework.BundleContext) Objects(java.util.Objects) List(java.util.List) Theme(com.vaadin.annotations.Theme) HudDisplay(org.opennms.features.topology.app.internal.ui.HudDisplay) TabSheet(com.vaadin.ui.TabSheet) TransactionOperations(org.springframework.transaction.support.TransactionOperations) VertexHopCriteria(org.opennms.features.topology.api.support.VertexHopGraphProvider.VertexHopCriteria) TopologyContextMenu(org.opennms.features.topology.app.internal.menu.TopologyContextMenu) Optional(java.util.Optional) WidgetUpdateListener(org.opennms.features.topology.api.WidgetUpdateListener) IViewContribution(org.opennms.features.topology.api.IViewContribution) SessionDestroyListener(com.vaadin.server.SessionDestroyListener) VerticesUpdateManager(org.opennms.features.topology.api.VerticesUpdateManager) WidgetManager(org.opennms.features.topology.api.WidgetManager) LayoutManager(org.opennms.features.topology.app.internal.support.LayoutManager) TopologyLinkBuilder(org.opennms.features.topology.link.TopologyLinkBuilder) SelectionContext(org.opennms.features.topology.api.SelectionContext) Vertex(org.opennms.features.topology.api.topo.Vertex) MapViewManager(org.opennms.features.topology.api.MapViewManager) BreadcrumbComponent(org.opennms.features.topology.app.internal.ui.breadcrumbs.BreadcrumbComponent) CustomLayout(com.vaadin.ui.CustomLayout) SelectionNotifier(org.opennms.features.topology.api.SelectionNotifier) OnmsServiceManagerLocator(org.opennms.osgi.locator.OnmsServiceManagerLocator) Notification(com.vaadin.ui.Notification) Label(com.vaadin.ui.Label) WidgetContext(org.opennms.features.topology.api.WidgetContext) Logger(org.slf4j.Logger) SelectedTabChangeEvent(com.vaadin.ui.TabSheet.SelectedTabChangeEvent) DisplayLocation(org.opennms.features.topology.api.OperationContext.DisplayLocation) MapViewManagerListener(org.opennms.features.topology.api.MapViewManagerListener) InfoPanel(org.opennms.features.topology.app.internal.ui.InfoPanel) VaadinServletRequest(com.vaadin.server.VaadinServletRequest) SelectedTabChangeListener(com.vaadin.ui.TabSheet.SelectedTabChangeListener) UriFragmentChangedEvent(com.vaadin.server.Page.UriFragmentChangedEvent) VaadinSession(com.vaadin.server.VaadinSession) OperationContext(org.opennms.features.topology.api.OperationContext) ToolbarPanelController(org.opennms.features.topology.app.internal.ui.ToolbarPanelController) SelectionManager(org.opennms.features.topology.api.SelectionManager) NoSuchProviderException(org.opennms.features.topology.app.internal.service.NoSuchProviderException) NoContentAvailableWindow(org.opennms.features.topology.app.internal.ui.NoContentAvailableWindow) Collections(java.util.Collections) InputStream(java.io.InputStream) Component(com.vaadin.ui.Component) OnmsServiceManager(org.opennms.osgi.OnmsServiceManager) VaadinApplicationContextCreator(org.opennms.osgi.VaadinApplicationContextCreator) VaadinServletRequest(com.vaadin.server.VaadinServletRequest) VertexHopGraphProvider.getWrappedVertexHopCriteria(org.opennms.features.topology.api.support.VertexHopGraphProvider.getWrappedVertexHopCriteria) CategoryHopCriteria(org.opennms.features.topology.app.internal.support.CategoryHopCriteria) Criteria(org.opennms.features.topology.api.topo.Criteria) CollapsibleCriteria(org.opennms.features.topology.api.topo.CollapsibleCriteria) VertexHopCriteria(org.opennms.features.topology.api.support.VertexHopGraphProvider.VertexHopCriteria) IOException(java.io.IOException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) NoSuchProviderException(org.opennms.features.topology.app.internal.service.NoSuchProviderException) VaadinApplicationContextImpl(org.opennms.osgi.VaadinApplicationContextImpl) CheckedOperation(org.opennms.features.topology.api.CheckedOperation)

Example 4 with OnmsServiceManager

use of org.opennms.osgi.OnmsServiceManager in project opennms by OpenNMS.

the class OSGiVerticesUpdateManagerTest method testGraphUpdated.

@Test
public void testGraphUpdated() {
    MockEventProxy mockEventProxy = new MockEventProxy();
    OnmsServiceManager serviceManager = new DummyOnmsServiceManager();
    VaadinApplicationContext vaadinApplicationContext = new DummyVaadinApplicationContext(mockEventProxy);
    OsgiVerticesUpdateManager updateManager = new OsgiVerticesUpdateManager(serviceManager, vaadinApplicationContext);
    updateManager.graphChanged(createGraph(1, 2, 3, 4, 5, 6, 7));
    assertEquals(1, mockEventProxy.getFireEventCalls());
    updateManager.selectionChanged(createContextWithVertRefIds(1, 2, 3, 4));
    assertEquals(2, mockEventProxy.getFireEventCalls());
    updateManager.graphChanged(createGraph(1, 2, 3, 4, 5, 6, 7));
    assertEquals(2, mockEventProxy.getFireEventCalls());
}
Also used : OnmsServiceManager(org.opennms.osgi.OnmsServiceManager) VaadinApplicationContext(org.opennms.osgi.VaadinApplicationContext) Test(org.junit.Test)

Example 5 with OnmsServiceManager

use of org.opennms.osgi.OnmsServiceManager in project opennms by OpenNMS.

the class Activator method autoExportDefaultServices.

private void autoExportDefaultServices(BundleContext bundleContext) {
    final long bundleId = bundleContext.getBundle().getBundleId();
    Log.info("Auto export of default Services for bundle (id: {}) enabled", bundleId);
    final OnmsServiceManager serviceManager = new OnmsServiceManagerImpl(bundleContext);
    Dictionary<String, Object> props = new Hashtable<String, Object>();
    props.put("bundleId", bundleContext.getBundle().getBundleId());
    Log.info("Registering OnmsServiceManager and SessionListener for bundle (id: {})", bundleId);
    bundleContext.registerService(new String[] { OnmsServiceManager.class.getName(), SessionListener.class.getName() }, serviceManager, props);
    Log.info("Registering EventRegistry for bundle (id: {})", bundleId);
    bundleContext.registerService(EventRegistry.class.getName(), new EventRegistry(bundleContext), props);
}
Also used : OnmsServiceManager(org.opennms.osgi.OnmsServiceManager) EventRegistry(org.opennms.osgi.EventRegistry) Hashtable(java.util.Hashtable) SessionListener(org.opennms.vaadin.extender.SessionListener)

Aggregations

OnmsServiceManager (org.opennms.osgi.OnmsServiceManager)5 Test (org.junit.Test)3 VaadinApplicationContext (org.opennms.osgi.VaadinApplicationContext)3 IOException (java.io.IOException)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 OperationContext (org.opennms.features.topology.api.OperationContext)2 VerticesUpdateManager (org.opennms.features.topology.api.VerticesUpdateManager)2 SearchBox (org.opennms.features.topology.app.internal.ui.SearchBox)2 Refresher (com.github.wolfie.refresher.Refresher)1 Strings (com.google.common.base.Strings)1 Lists (com.google.common.collect.Lists)1 PreserveOnRefresh (com.vaadin.annotations.PreserveOnRefresh)1 Theme (com.vaadin.annotations.Theme)1 Title (com.vaadin.annotations.Title)1 Property (com.vaadin.data.Property)1 DefaultErrorHandler (com.vaadin.server.DefaultErrorHandler)1 UriFragmentChangedEvent (com.vaadin.server.Page.UriFragmentChangedEvent)1 UriFragmentChangedListener (com.vaadin.server.Page.UriFragmentChangedListener)1 RequestHandler (com.vaadin.server.RequestHandler)1