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