Search in sources :

Example 6 with SearchResult

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;
}
Also used : OnmsCategory(org.opennms.netmgt.model.OnmsCategory) CollapsibleCriteria(org.opennms.features.topology.api.topo.CollapsibleCriteria) ArrayList(java.util.ArrayList) SearchResult(org.opennms.features.topology.api.topo.SearchResult)

Example 7 with SearchResult

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;
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) ArrayList(java.util.ArrayList) SearchResult(org.opennms.features.topology.api.topo.SearchResult) CollapsibleCriteria(org.opennms.features.topology.api.topo.CollapsibleCriteria) Criteria(org.opennms.core.criteria.Criteria) IpLikeHopCriteria(org.opennms.features.topology.app.internal.support.IpLikeHopCriteria) HashSet(java.util.HashSet)

Example 8 with SearchResult

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

Example 9 with SearchResult

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();
}
Also used : CRC32(java.util.zip.CRC32) SearchResult(org.opennms.features.topology.api.topo.SearchResult) Point(org.opennms.features.topology.api.Point) VertexRef(org.opennms.features.topology.api.topo.VertexRef) HashMap(java.util.HashMap) Map(java.util.Map)

Example 10 with SearchResult

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;
}
Also used : NCSComponent(org.opennms.netmgt.model.ncs.NCSComponent) ArrayList(java.util.ArrayList) SearchResult(org.opennms.features.topology.api.topo.SearchResult)

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