Search in sources :

Example 1 with SearchResult

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

the class ApplicationSearchProvider method query.

@Override
public List<SearchResult> query(SearchQuery searchQuery, GraphContainer container) {
    LOG.info("ApplicationServiceSearchProvider->query: called with search query: '{}'", searchQuery);
    List<SearchResult> results = Lists.newArrayList();
    String queryString = searchQuery.getQueryString();
    CriteriaBuilder bldr = new CriteriaBuilder(OnmsApplication.class);
    if (queryString != null && queryString.length() > 0) {
        bldr.ilike("name", String.format("%%%s%%", queryString));
    }
    bldr.orderBy("name", true);
    bldr.limit(10);
    Criteria dbQueryCriteria = bldr.toCriteria();
    for (OnmsApplication application : applicationDao.findMatching(dbQueryCriteria)) {
        final ApplicationVertex applicationVertex = new ApplicationVertex(application);
        SearchResult searchResult = new SearchResult(applicationVertex, true, false);
        results.add(searchResult);
    }
    LOG.info("ApplicationServiceSearchProvider->query: found {} results: {}", results.size(), results);
    return results;
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) SearchResult(org.opennms.features.topology.api.topo.SearchResult) Criteria(org.opennms.core.criteria.Criteria) OnmsApplication(org.opennms.netmgt.model.OnmsApplication)

Example 2 with SearchResult

use of org.opennms.features.topology.api.topo.SearchResult 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 SearchResult

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

the class BusinessServiceSearchProviderIT method verifyQuery.

@Test
public void verifyQuery() {
    BusinessServiceEntity bs1 = new BusinessServiceEntityBuilder().name("Test Service").reduceFunction(new HighestSeverityEntity()).addReductionKey("bs1.key1", new IdentityEntity(), 1).addReductionKey("bs1.key2", new IdentityEntity(), 1).toEntity();
    BusinessServiceEntity bs2 = new BusinessServiceEntityBuilder().name("Real Service 2").reduceFunction(new HighestSeverityEntity()).addReductionKey("bs2.key1", new IdentityEntity(), 1).addReductionKey("bs2.key2", new IdentityEntity(), 1).toEntity();
    businessServiceDao.save(bs1);
    businessServiceDao.save(bs2);
    businessServiceDao.flush();
    // prepare mocks
    TopologyServiceClient topologyServiceClientMock = EasyMock.createNiceMock(TopologyServiceClient.class);
    EasyMock.expect(topologyServiceClientMock.getVertex(EasyMock.anyObject(BusinessServiceVertex.class))).andReturn(// always return a vertex, it just needs to be not null
    new AbstractVertex("bsm", "0", "Dummy Vertex"));
    GraphContainer graphContainerMock = EasyMock.createNiceMock(GraphContainer.class);
    EasyMock.expect(graphContainerMock.getTopologyServiceClient()).andReturn(topologyServiceClientMock).anyTimes();
    EasyMock.replay(graphContainerMock, topologyServiceClientMock);
    // try searching
    final BusinessServiceSearchProvider provider = new BusinessServiceSearchProvider();
    provider.setBusinessServiceManager(businessServiceManager);
    final SearchQuery query = new AbstractSearchQuery("Test") {

        @Override
        public boolean matches(String label) {
            // always match, it does not matter
            return true;
        }
    };
    final List<SearchResult> result = provider.query(query, graphContainerMock);
    Assert.assertEquals(1, result.size());
    EasyMock.verify(graphContainerMock, topologyServiceClientMock);
}
Also used : SearchQuery(org.opennms.features.topology.api.topo.SearchQuery) AbstractSearchQuery(org.opennms.features.topology.api.topo.AbstractSearchQuery) SearchResult(org.opennms.features.topology.api.topo.SearchResult) HighestSeverityEntity(org.opennms.netmgt.bsm.persistence.api.functions.reduce.HighestSeverityEntity) AbstractVertex(org.opennms.features.topology.api.topo.AbstractVertex) GraphContainer(org.opennms.features.topology.api.GraphContainer) TopologyServiceClient(org.opennms.features.topology.api.TopologyServiceClient) AbstractSearchQuery(org.opennms.features.topology.api.topo.AbstractSearchQuery) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) BusinessServiceEntityBuilder(org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder) IdentityEntity(org.opennms.netmgt.bsm.persistence.api.functions.map.IdentityEntity) Test(org.junit.Test)

Example 4 with SearchResult

use of org.opennms.features.topology.api.topo.SearchResult 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 5 with SearchResult

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

the class SavedHistoryTest method verifyCRCIncludesSearchResult.

/**
 * This methods tests whether the CRC checksums for {@link SavedHistory} object with {@link SearchResult}s are generated correctly,
 * namely that they now take into account the search results
 */
@Test
public void verifyCRCIncludesSearchResult() {
    Map<String, String> settings = new HashMap<String, String>();
    settings.put("hello", "world");
    VertexRef vert1 = new DefaultVertexRef("nodes", "1");
    VertexRef vert2 = new DefaultVertexRef("nodes", "2", "HasALabel");
    Map<VertexRef, Point> locations = new HashMap<VertexRef, Point>();
    locations.put(vert1, new Point(0, 0));
    locations.put(vert2, new Point(0, 0));
    // Creating SavedHistory object with no search results
    SavedHistory history1 = new SavedHistory(1, new BoundingBox(0, 0, 100, 100), locations, Collections.singleton(vert2), Collections.emptySet(), settings, Collections.emptyList());
    List<SearchResult> searchResults = new ArrayList<>();
    searchResults.add(new SearchResult("alarm", "alarmID", "someLabel", searchQuery, SearchResult.COLLAPSIBLE, !SearchResult.COLLAPSED));
    // Creating SavedHistory object with a single search result with ID = "alarmID"
    SavedHistory history2 = new SavedHistory(1, new BoundingBox(0, 0, 100, 100), locations, Collections.singleton(vert2), Collections.emptySet(), settings, searchResults);
    // Assertion that the SavedHistory with no search results is different from the one with one
    Assert.assertNotEquals(history1.getFragment(), history2.getFragment());
    // Creating another SavedHistory WITH search result, identical to the 2nd one
    SavedHistory history3 = new SavedHistory(1, new BoundingBox(0, 0, 100, 100), locations, Collections.singleton(vert2), Collections.emptySet(), settings, searchResults);
    // Assertion that two SavedHistory objects with the same search results are identical
    Assert.assertEquals(history2.getFragment(), history3.getFragment());
}
Also used : DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) HashMap(java.util.HashMap) BoundingBox(org.opennms.features.topology.api.BoundingBox) ArrayList(java.util.ArrayList) SearchResult(org.opennms.features.topology.api.topo.SearchResult) Point(org.opennms.features.topology.api.Point) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Test(org.junit.Test)

Aggregations

SearchResult (org.opennms.features.topology.api.topo.SearchResult)12 ArrayList (java.util.ArrayList)6 CollapsibleCriteria (org.opennms.features.topology.api.topo.CollapsibleCriteria)3 VertexRef (org.opennms.features.topology.api.topo.VertexRef)3 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 Criteria (org.opennms.core.criteria.Criteria)2 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)2 GraphContainer (org.opennms.features.topology.api.GraphContainer)2 Point (org.opennms.features.topology.api.Point)2 AbstractVertex (org.opennms.features.topology.api.topo.AbstractVertex)2 Criteria (org.opennms.features.topology.api.topo.Criteria)2 DefaultVertexRef (org.opennms.features.topology.api.topo.DefaultVertexRef)2 SearchCriteria (org.opennms.features.topology.api.topo.SearchCriteria)2 SearchProvider (org.opennms.features.topology.api.topo.SearchProvider)2 SearchQuery (org.opennms.features.topology.api.topo.SearchQuery)2 IpLikeHopCriteria (org.opennms.features.topology.app.internal.support.IpLikeHopCriteria)2 OnmsCategory (org.opennms.netmgt.model.OnmsCategory)2 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)2 Date (java.util.Date)1