use of org.opennms.features.topology.api.topo.SearchProvider in project opennms by OpenNMS.
the class SearchBox method getQueryResults.
public List<SearchSuggestion> getQueryResults(final String query) {
LOG.debug("SearchBox->getQueryResults: called with query {}", query);
String namespace = m_operationContext.getGraphContainer().getTopologyServiceClient().getNamespace();
List<SearchResult> results = Lists.newArrayList();
if (m_serviceManager == null) {
return mapToSuggestions(results);
}
List<SearchProvider> providers = m_serviceManager.getServices(SearchProvider.class, null, new Hashtable<>());
LOG.debug("SearchBox->getQueryResults: service manager reports {} SearchProviders.", providers.size());
for (SearchProvider provider : providers) {
if (provider.getSearchProviderNamespace().equals(namespace) || provider.contributesTo(namespace)) {
if (provider.supportsPrefix(query)) {
// If there is an '=' divider, strip it off. Otherwise, use an empty query string
String queryOnly = query.indexOf('=') > 0 ? query.substring(query.indexOf('=') + 1) : "";
List<SearchResult> q = provider.query(getSearchQuery(queryOnly), m_operationContext.getGraphContainer());
results.addAll(q);
if (m_suggestionMap.containsKey(provider)) {
m_suggestionMap.get(provider).addAll(q);
} else {
m_suggestionMap.putAll(provider, q);
}
} else {
List<SearchResult> q = provider.query(getSearchQuery(query), m_operationContext.getGraphContainer());
results.addAll(q);
if (m_suggestionMap.containsKey(provider)) {
m_suggestionMap.get(provider).addAll(q);
} else {
m_suggestionMap.putAll(provider, q);
}
}
}
}
return mapToSuggestions(results);
}
use of org.opennms.features.topology.api.topo.SearchProvider 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.features.topology.api.topo.SearchProvider in project opennms by OpenNMS.
the class SavedHistory method apply.
public void apply(GraphContainer graphContainer, Collection<HistoryOperation> operations, ServiceLocator serviceLocator) {
LOG.debug("Applying " + toString());
graphContainer.clearCriteria();
// Apply the history for each registered HistoryOperation
for (HistoryOperation operation : operations) {
try {
operation.applyHistory(graphContainer, m_settings);
} catch (Throwable e) {
LOG.warn("Failed to perform applyHistory() operation", e);
}
}
// Browse through all available search providers that have a "history" functionality
List<SearchProvider> searchProviders = serviceLocator.findServices(SearchProvider.class, null);
for (SearchProvider searchProvider : searchProviders) {
if (searchProvider instanceof HistoryAwareSearchProvider) {
// Add resulting Criteria to the graph container
for (SearchResult searchQuery : m_searchQueries) {
if (searchProvider.getSearchProviderNamespace().equals(searchQuery.getNamespace()) || searchProvider.contributesTo(searchQuery.getNamespace())) {
Criteria searchCriteria = ((HistoryAwareSearchProvider) searchProvider).buildCriteriaFromQuery(searchQuery);
graphContainer.addCriteria(searchCriteria);
}
}
}
}
// Set Vertices in Focus after all other operations are applied, otherwise the topology provider may have changed
// which results in a graphContainer.clearCriteria()
applyVerticesInFocus(m_focusVertices, graphContainer);
applySavedLocations(m_locations, graphContainer.getGraph().getLayout());
graphContainer.setSemanticZoomLevel(getSemanticZoomLevel());
// Apply the selected vertices
graphContainer.getSelectionManager().setSelectedVertexRefs(m_selectedVertices);
graphContainer.getMapViewManager().setBoundingBox(getBoundingBox());
}
Aggregations