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