Search in sources :

Example 1 with SearchProvider

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);
}
Also used : SearchResult(org.opennms.features.topology.api.topo.SearchResult) SearchProvider(org.opennms.features.topology.api.topo.SearchProvider)

Example 2 with SearchProvider

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());
}
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 3 with SearchProvider

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());
}
Also used : HistoryOperation(org.opennms.features.topology.api.HistoryOperation) SearchProvider(org.opennms.features.topology.api.topo.SearchProvider) SearchResult(org.opennms.features.topology.api.topo.SearchResult) CollapsibleCriteria(org.opennms.features.topology.api.topo.CollapsibleCriteria) SearchCriteria(org.opennms.features.topology.api.topo.SearchCriteria) Criteria(org.opennms.features.topology.api.topo.Criteria)

Aggregations

SearchProvider (org.opennms.features.topology.api.topo.SearchProvider)3 SearchResult (org.opennms.features.topology.api.topo.SearchResult)2 IOException (java.io.IOException)1 Hashtable (java.util.Hashtable)1 List (java.util.List)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 HistoryOperation (org.opennms.features.topology.api.HistoryOperation)1 OperationContext (org.opennms.features.topology.api.OperationContext)1 CollapsibleCriteria (org.opennms.features.topology.api.topo.CollapsibleCriteria)1 Criteria (org.opennms.features.topology.api.topo.Criteria)1 SearchCriteria (org.opennms.features.topology.api.topo.SearchCriteria)1 VEProviderGraphContainer (org.opennms.features.topology.app.internal.VEProviderGraphContainer)1 SearchSuggestion (org.opennms.features.topology.app.internal.gwt.client.SearchSuggestion)1 DefaultTopologyService (org.opennms.features.topology.app.internal.service.DefaultTopologyService)1 SimpleServiceLocator (org.opennms.features.topology.app.internal.service.SimpleServiceLocator)1