use of org.opennms.features.topology.api.topo.SearchResult in project opennms by OpenNMS.
the class CategorySearchProvider method query.
@Override
public List<SearchResult> query(SearchQuery searchQuery, GraphContainer graphContainer) {
Collection<OnmsCategory> categories = categoryProvider.getAllCategories();
List<SearchResult> results = new ArrayList<>();
for (OnmsCategory category : categories) {
if (!checkHiddenPrefix(category.getName()) && searchQuery.matches(category.getName())) {
SearchResult result = new SearchResult(CategoryHopCriteria.NAMESPACE, category.getId().toString(), category.getName(), searchQuery.getQueryString(), SearchResult.COLLAPSIBLE, !SearchResult.COLLAPSED);
CollapsibleCriteria criteria = getMatchingCriteria(graphContainer, category.getName());
if (criteria != null) {
result.setCollapsed(criteria.isCollapsed());
}
results.add(result);
}
}
return results;
}
use of org.opennms.features.topology.api.topo.SearchResult in project opennms by OpenNMS.
the class IpLikeSearchProvider method query.
/**
* This method processes the <SearchQuery> that the user has typed and returns a <SearchResult> list
* of matching IP addresses as well as the query string itself, which is collapsible, to act
* as a subnet container.
*/
@Override
public List<SearchResult> query(SearchQuery searchQuery, GraphContainer graphContainer) {
LOG.info("SearchProvider->query: called with search query: '{}'", searchQuery);
List<SearchResult> results = new ArrayList<>();
String queryString = searchQuery.getQueryString();
if (!isIpLikeQuery(queryString)) {
LOG.debug("SearchProvider->query: query not IPLIKE compatible.");
return results;
}
CriteriaBuilder bldr = new CriteriaBuilder(OnmsIpInterface.class);
bldr.iplike("ipAddr", queryString).orderBy("ipAddress", true);
Criteria dbQueryCriteria = bldr.toCriteria();
List<OnmsIpInterface> ips;
// since it seems to do something very similar in its matches method.
try {
ips = ipInterfaceProvider.findMatching(dbQueryCriteria);
if (ips.size() == 0) {
return results;
} else {
if (isIpLikeQuery(queryString)) {
LOG.debug("SearchProvider->query: adding IPLIKE search spec '{}' to the search results.", queryString);
SearchResult searchResult = new SearchResult(getSearchProviderNamespace(), queryString, queryString, queryString, SearchResult.COLLAPSIBLE, !SearchResult.COLLAPSED);
if (!results.contains(searchResult)) {
results.add(searchResult);
}
}
}
Set<String> ipAddrs = new HashSet<>();
LOG.info("SearchProvider->query: creating IP address set.");
for (OnmsIpInterface ip : ips) {
String hostAddress = ip.getIpAddress().getHostAddress();
LOG.debug("SearchProvider->query: adding '{}' to set of IPs.", hostAddress);
ipAddrs.add(hostAddress);
}
LOG.info("SearchProvider->query: building search result from set of IPs.");
IPLOOP: for (String ip : ipAddrs) {
if (findCriterion(ip, graphContainer) != null) {
continue IPLOOP;
} else {
SearchResult searchResult = createSearchResult(ip, queryString);
if (!results.contains(searchResult)) {
results.add(searchResult);
}
}
}
LOG.info("SearchProvider->query: found: '{}' IP interfaces.", ips.size());
} catch (Exception e) {
LOG.error("SearchProvider-query: caught exception during iplike query: {}", e);
}
LOG.info("SearchProvider->query: built search result with {} results.", results.size());
return results;
}
use of org.opennms.features.topology.api.topo.SearchResult in project opennms by OpenNMS.
the class EnhancedLinkdTopologyProvider method query.
@Override
public List<SearchResult> query(SearchQuery searchQuery, GraphContainer graphContainer) {
// LOG.debug("SearchProvider->query: called with search query: '{}'", searchQuery);
List<Vertex> vertices = getFilteredVertices();
List<SearchResult> searchResults = Lists.newArrayList();
for (Vertex vertex : vertices) {
if (searchQuery.matches(vertex.getLabel())) {
searchResults.add(new SearchResult(vertex, false, false));
}
}
// LOG.debug("SearchProvider->query: found {} search results.", searchResults.size());
return searchResults;
}
use of org.opennms.features.topology.api.topo.SearchResult in project opennms by OpenNMS.
the class SavedHistory method getFragment.
public String getFragment() {
final StringBuilder retval = new StringBuilder().append("(").append(m_szl).append("),").append(m_boundBox.fragment()).append(",").append(m_boundBox.getCenter());
// Add a CRC of all of the key-value pairs in m_settings to make the fragment unique
CRC32 settingsCrc = new CRC32();
for (Map.Entry<String, String> entry : m_settings.entrySet()) {
settingsCrc.update(entry.getKey().getBytes(StandardCharsets.UTF_8));
settingsCrc.update(entry.getValue().getBytes(StandardCharsets.UTF_8));
}
retval.append(String.format(",(%X)", settingsCrc.getValue()));
CRC32 locationsCrc = new CRC32();
for (Map.Entry<VertexRef, Point> entry : m_locations.entrySet()) {
locationsCrc.update(entry.getKey().getId().getBytes(StandardCharsets.UTF_8));
// TODO cast to int for now
locationsCrc.update((int) entry.getValue().getX());
locationsCrc.update((int) entry.getValue().getY());
}
retval.append(String.format(",(%X)", locationsCrc.getValue()));
CRC32 selectionsCrc = new CRC32();
for (VertexRef entry : m_selectedVertices) {
selectionsCrc.update(entry.getNamespace().getBytes(StandardCharsets.UTF_8));
selectionsCrc.update(entry.getId().getBytes(StandardCharsets.UTF_8));
}
retval.append(String.format(",(%X)", selectionsCrc.getValue()));
CRC32 focusCrc = new CRC32();
for (VertexRef entry : m_focusVertices) {
focusCrc.update(entry.getNamespace().getBytes(StandardCharsets.UTF_8));
focusCrc.update(entry.getId().getBytes(StandardCharsets.UTF_8));
}
retval.append(String.format(",(%X)", focusCrc.getValue()));
CRC32 historyCrc = new CRC32();
for (SearchResult query : m_searchQueries) {
historyCrc.update(query.toString().getBytes(StandardCharsets.UTF_8));
}
retval.append(String.format(",(%X)", historyCrc.getValue()));
return retval.toString();
}
use of org.opennms.features.topology.api.topo.SearchResult in project opennms by OpenNMS.
the class NCSSearchProvider method query.
@Override
public List<SearchResult> query(SearchQuery searchQuery, GraphContainer graphContainer) {
List<SearchResult> searchResults = new ArrayList<>();
List<NCSComponent> components = m_ncsComponentRepository.findByType("Service");
for (NCSComponent component : components) {
if (searchQuery.matches(component.getName())) {
searchResults.add(new SearchResult(NAMESPACE, String.valueOf(component.getId()), component.getName(), searchQuery.getQueryString(), !SearchResult.COLLAPSIBLE, !SearchResult.COLLAPSED));
}
}
return searchResults;
}
Aggregations