Search in sources :

Example 11 with SearchResult

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

the class BundleContextHistoryManagerTest method initProvidersAndCriteria.

/**
 * In this method all starting {@link SearchCriteria} and {@link SearchProvider} objects are initialized
 */
private void initProvidersAndCriteria() {
    // Preparing SearchProviders
    CategoryProvider vertexProvider = new CategoryProvider() {

        @Override
        public Collection<OnmsCategory> getAllCategories() {
            return Lists.newArrayList(findCategoryByName("somename"));
        }

        @Override
        public OnmsCategory findCategoryByName(String m_categoryName) {
            OnmsCategory cat = new OnmsCategory("test", "test");
            cat.setId(Integer.valueOf(idCategory));
            return cat;
        }

        @Override
        public List<OnmsNode> findNodesForCategory(OnmsCategory category) {
            return new ArrayList<>();
        }
    };
    IpInterfaceProvider ipInterfaceProvider = new IpInterfaceProvider() {

        @Override
        public List<OnmsIpInterface> findMatching(org.opennms.core.criteria.Criteria criteria) {
            OnmsNode node = new OnmsNode();
            node.setId(Integer.valueOf(idIpLike));
            String ipAddr = "127.0.0.1";
            OnmsIpInterface ipInterface = new OnmsIpInterface(ipAddr, node);
            return Lists.newArrayList(ipInterface);
        }
    };
    AlarmProvider alarmProvider = new AlarmProvider() {

        @Override
        public List<OnmsAlarm> findMatchingAlarms(org.opennms.core.criteria.Criteria criteria) {
            Date eventTime = new Date();
            OnmsDistPoller distPoller = new OnmsDistPoller("pollerID");
            OnmsEvent event = new OnmsEvent();
            OnmsAlarm alarm = new OnmsAlarm(Integer.valueOf(idAlarm), "eventUI", distPoller, 2, 3, eventTime, event);
            return Lists.newArrayList(alarm);
        }
    };
    // Creating SearchResults to be used in testing
    SearchResult sResultCategory = new SearchResult(CategoryHopCriteria.NAMESPACE, idCategory, labelCategory, searchQuery, SearchResult.COLLAPSIBLE, !SearchResult.COLLAPSED);
    SearchResult sResultAlarm = new SearchResult(AlarmHopCriteria.NAMESPACE, idAlarm, labelAlarm, searchQuery, SearchResult.COLLAPSIBLE, !SearchResult.COLLAPSED);
    SearchResult sResultIpLike = new SearchResult(IpLikeHopCriteria.NAMESPACE, idIpLike, labelIpLike, searchQuery, SearchResult.COLLAPSIBLE, !SearchResult.COLLAPSED);
    this.startingSearchResults.put(CriteriaTypes.alarm, sResultAlarm);
    this.startingSearchResults.put(CriteriaTypes.ipLike, sResultIpLike);
    this.startingSearchResults.put(CriteriaTypes.category, sResultCategory);
    // Initializing available (initial) SearchProviders
    final DefaultTopologyService topologyService = new DefaultTopologyService();
    topologyService.setServiceLocator(serviceLocatorMock);
    this.startingProviders.put(CriteriaTypes.category, new CategorySearchProvider(topologyService, vertexProvider));
    this.startingProviders.put(CriteriaTypes.ipLike, new IpLikeSearchProvider(ipInterfaceProvider));
    this.startingProviders.put(CriteriaTypes.alarm, new AlarmSearchProvider(alarmProvider));
    // Initializing available (initial) Criteria
    this.startingCriteria.put(CriteriaTypes.category, new CategoryHopCriteria(sResultCategory, vertexProvider, graphContainerMock));
    this.startingCriteria.put(CriteriaTypes.ipLike, new IpLikeHopCriteria(sResultIpLike, ipInterfaceProvider));
    this.startingCriteria.put(CriteriaTypes.alarm, new AlarmHopCriteria(new AlarmSearchProvider(alarmProvider).new AlarmSearchResult(sResultAlarm), alarmProvider));
}
Also used : CategoryProvider(org.opennms.features.topology.app.internal.CategoryProvider) OnmsNode(org.opennms.netmgt.model.OnmsNode) IpInterfaceProvider(org.opennms.features.topology.app.internal.IpInterfaceProvider) DefaultTopologyService(org.opennms.features.topology.app.internal.service.DefaultTopologyService) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) ArrayList(java.util.ArrayList) OnmsDistPoller(org.opennms.netmgt.model.OnmsDistPoller) SearchResult(org.opennms.features.topology.api.topo.SearchResult) CategoryHopCriteria(org.opennms.features.topology.app.internal.support.CategoryHopCriteria) SearchCriteria(org.opennms.features.topology.api.topo.SearchCriteria) Criteria(org.opennms.features.topology.api.topo.Criteria) IpLikeHopCriteria(org.opennms.features.topology.app.internal.support.IpLikeHopCriteria) AlarmHopCriteria(org.opennms.features.topology.app.internal.support.AlarmHopCriteria) Date(java.util.Date) CategorySearchProvider(org.opennms.features.topology.app.internal.CategorySearchProvider) IpLikeHopCriteria(org.opennms.features.topology.app.internal.support.IpLikeHopCriteria) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) AlarmSearchProvider(org.opennms.features.topology.app.internal.AlarmSearchProvider) AlarmProvider(org.opennms.features.topology.app.internal.AlarmProvider) AlarmHopCriteria(org.opennms.features.topology.app.internal.support.AlarmHopCriteria) CategoryHopCriteria(org.opennms.features.topology.app.internal.support.CategoryHopCriteria) IpLikeSearchProvider(org.opennms.features.topology.app.internal.IpLikeSearchProvider)

Example 12 with SearchResult

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

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