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