use of org.opennms.features.topology.api.topo.CollapsibleCriteria 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<SearchResult>();
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.CollapsibleCriteria in project opennms by OpenNMS.
the class AlarmSearchProvider method onToggleCollapse.
@Override
public void onToggleCollapse(SearchResult searchResult, GraphContainer graphContainer) {
LOG.debug("SearchProvider.onToggleCollapse: called with search result: '{}'", searchResult);
CollapsibleCriteria criteria = getMatchingCriteriaById(graphContainer, searchResult.getId());
if (criteria != null) {
criteria.setCollapsed(!criteria.isCollapsed());
graphContainer.redoLayout();
}
}
use of org.opennms.features.topology.api.topo.CollapsibleCriteria in project opennms by OpenNMS.
the class SavedHistory method getFocusVertices.
private static Set<VertexRef> getFocusVertices(GraphContainer graphContainer) {
final Set<VertexRef> retVal = new HashSet<>();
Criteria[] criterias = graphContainer.getCriteria();
for (Criteria crit : criterias) {
if (crit instanceof VertexHopGraphProvider.VertexHopCriteria && !(crit instanceof CollapsibleCriteria)) {
retVal.addAll(((VertexHopGraphProvider.VertexHopCriteria) crit).getVertices());
}
}
return retVal;
}
use of org.opennms.features.topology.api.topo.CollapsibleCriteria in project opennms by OpenNMS.
the class VertexHopGraphProvider method getMapOfVerticesToCollapsedVertices.
public static Map<VertexRef, Set<Vertex>> getMapOfVerticesToCollapsedVertices(CollapsibleCriteria[] criteria) {
// Make a map of all of the vertices to their new collapsed representations
Map<VertexRef, Set<Vertex>> vertexToCollapsedVertices = new TreeMap<VertexRef, Set<Vertex>>(new RefComparator());
for (CollapsibleCriteria criterium : criteria) {
Set<VertexRef> criteriaVertices = criterium.getVertices();
if (criteriaVertices.size() > 0) {
Vertex collapsedVertex = criterium.getCollapsedRepresentation();
for (VertexRef criteriaVertex : criteriaVertices) {
Set<Vertex> collapsedVertices = vertexToCollapsedVertices.get(criteriaVertex);
if (collapsedVertices == null) {
collapsedVertices = new HashSet<Vertex>();
vertexToCollapsedVertices.put(criteriaVertex, collapsedVertices);
}
collapsedVertices.add(collapsedVertex);
}
}
}
return vertexToCollapsedVertices;
}
use of org.opennms.features.topology.api.topo.CollapsibleCriteria in project opennms by OpenNMS.
the class VEProviderGraphContainerTest method testContainerWithHopProvider.
@Test
public void testContainerWithHopProvider() throws Exception {
VertexHopGraphProvider vertexHopGraphProvider = new VertexHopGraphProvider(m_graphProvider);
DefaultTopologyService topologyService = new DefaultTopologyService();
SimpleMetaTopologyProvider simpleMetaTopologyProvider = new SimpleMetaTopologyProvider(vertexHopGraphProvider);
topologyService.setServiceLocator(new SimpleServiceLocator(simpleMetaTopologyProvider));
// Wrap the test GraphProvider in a VertexHopGraphProvider
VEProviderGraphContainer graphContainer = new VEProviderGraphContainer();
graphContainer.setSemanticZoomLevel(0);
graphContainer.setTopologyService(topologyService);
graphContainer.setMetaTopologyId(simpleMetaTopologyProvider.getId());
graphContainer.setSelectedNamespace(vertexHopGraphProvider.getNamespace());
m_graphContainer = graphContainer;
// There should be zero vertices or edges if no focus vertices are set
Graph graph = m_graphContainer.getGraph();
assertEquals(0, graph.getDisplayVertices().size());
assertEquals(0, graph.getDisplayEdges().size());
// Add one focus vertex
VertexHopGraphProvider.DefaultVertexHopCriteria hopCriteria = new VertexHopGraphProvider.DefaultVertexHopCriteria(new DefaultVertexRef("nodes", "v1"));
m_graphContainer.addCriteria(hopCriteria);
// This needs to be 2 because there is a SemanticZoomLevelCriteria in there also
assertEquals(2, m_graphContainer.getCriteria().length);
// Verify that a single vertex is in the graph
graph = m_graphContainer.getGraph();
assertEquals(1, graph.getDisplayVertices().size());
assertEquals(0, graph.getDisplayEdges().size());
expectVertex("nodes", "v1", "vertex");
graph.visit(verifier());
verify();
verifyConnectedness(graph);
reset();
// Change SZL to 1
m_graphContainer.setSemanticZoomLevel(1);
assertEquals(2, m_graphContainer.getCriteria().length);
// Focus vertex
expectVertex("nodes", "v1", "vertex");
expectVertex("nodes", "v2", "vertex");
/*
This is a problem with the VEProviderGraphContainer... it wraps a delegate GraphProvider
in a MergingGraphProvider like so:
VEProviderGraphContainer { MergingGraphProvider { VertexHopGraphProvider } } }
But for the VertexHopProvider to calculate the SZL correctly, it needs to be aware of all
edges, including those provided by the MergingGraphProvider. So we should rearrange things
so that they are laid out like:
VEProviderGraphContainer { VertexHopGraphProvider { MergingGraphProvider } } }
We should decouple the MergingGraphProvider from the VEProviderGraphContainer and then just
inject them in the correct order. When this problem is fixed, uncomment all of the lines that
are commented out in this test.
*/
//expectVertex("nodes", "v3", "vertex");
expectVertex("nodes", "v4", "vertex");
expectEdge("nodes", "e1", "edge");
//expectEdge("nodes", "e2", "edge");
//expectEdge("nodes", "e3", "edge");
expectEdge("nodes", "e4", "edge");
graph = m_graphContainer.getGraph();
//assertEquals(4, graph.getDisplayVertices().size());
//assertEquals(5, graph.getDisplayEdges().size());
assertEquals(3, graph.getDisplayVertices().size());
assertEquals(2, graph.getDisplayEdges().size());
graph.visit(verifier());
verify();
verifyConnectedness(graph);
reset();
// Add a collapsed criteria to the container
Criteria collapsibleCriteria = new TestCriteria1();
m_graphContainer.addCriteria(collapsibleCriteria);
assertEquals(3, m_graphContainer.getCriteria().length);
// Make sure that the TestCollapsibleCriteria is mapping "v2" and "v4" to the collapsed "test" vertex
Map<VertexRef, Set<Vertex>> collapsed = VertexHopGraphProvider.getMapOfVerticesToCollapsedVertices(VertexHopGraphProvider.getCollapsedCriteria(m_graphContainer.getCriteria()));
assertTrue(collapsed.containsKey(new DefaultVertexRef("nodes", "v2")));
assertTrue(collapsed.containsKey(new DefaultVertexRef("nodes", "v4")));
assertTrue(collapsed.get(new DefaultVertexRef("nodes", "v2")).equals(Collections.singleton(new DefaultVertexRef("nodes", "test"))));
assertTrue(collapsed.get(new DefaultVertexRef("nodes", "v4")).equals(Collections.singleton(new DefaultVertexRef("nodes", "test"))));
assertEquals(m_graphContainer.getGraph().getDisplayVertices().toString(), 3, m_graphContainer.getGraph().getDisplayVertices().size());
assertEquals(m_graphContainer.getTopologyServiceClient().getGraphProviderBy("nodes").getVertices(new TestCriteria1()).toString(), 3, m_graphContainer.getTopologyServiceClient().getGraphProviderBy("nodes").getVertices(new TestCriteria1()).size());
expectVertex("nodes", "v1", "vertex");
expectVertex("nodes", "v3", "vertex");
// Collapsed vertex that contains v2 and v4
expectVertex("nodes", "test", "test");
expectEdge("nodes", "collapsedTarget-e1", "edge");
expectEdge("nodes", "collapsedSource-e2", "edge");
expectEdge("nodes", "collapsedTarget-e3", "edge");
expectEdge("nodes", "collapsedSource-e4", "edge");
graph = m_graphContainer.getGraph();
assertEquals(3, graph.getDisplayVertices().size());
assertEquals(4, graph.getDisplayEdges().size());
for (Edge edge : graph.getDisplayEdges()) {
if (edge.getId().equals("collapsedTarget-e1")) {
assertEquals("v1", edge.getSource().getVertex().getId());
assertEquals("test", edge.getTarget().getVertex().getId());
} else if (edge.getId().equals("collapsedSource-e2")) {
assertEquals("test", edge.getSource().getVertex().getId());
assertEquals("v3", edge.getTarget().getVertex().getId());
} else if (edge.getId().equals("collapsedTarget-e3")) {
assertEquals("v3", edge.getSource().getVertex().getId());
assertEquals("test", edge.getTarget().getVertex().getId());
} else if (edge.getId().equals("collapsedSource-e4")) {
assertEquals("test", edge.getSource().getVertex().getId());
assertEquals("v1", edge.getTarget().getVertex().getId());
} else if (edge.getId().equals("ncs1")) {
assertEquals("v1", edge.getSource().getVertex().getId());
assertEquals("v3", edge.getTarget().getVertex().getId());
} else {
fail("Unknown edge ID: " + edge.getId());
}
}
graph.visit(verifier());
verify();
verifyConnectedness(graph);
reset();
// Remove the collapsed criteria and make sure that the state reverts correctly
m_graphContainer.removeCriteria(collapsibleCriteria);
graph = m_graphContainer.getGraph();
//assertEquals(4, graph.getDisplayVertices().size());
//assertEquals(5, graph.getDisplayEdges().size());
assertEquals(3, graph.getDisplayVertices().size());
assertEquals(2, graph.getDisplayEdges().size());
collapsibleCriteria = new TestCriteria1();
m_graphContainer.addCriteria(collapsibleCriteria);
collapsibleCriteria = new TestCriteria2();
m_graphContainer.addCriteria(collapsibleCriteria);
assertEquals(4, m_graphContainer.getCriteria().length);
graph = m_graphContainer.getGraph();
assertEquals(3, m_graphContainer.getGraph().getDisplayVertices().size());
/*
* One edge is missing because of the VertexHopGraphProvider issue mentioned above.
assertEquals(
ArrayUtils.toString(m_graphContainer.getGraph().getDisplayEdges()),
5,
m_graphContainer.getGraph().getDisplayEdges().size()
);
*/
assertEquals(4, m_graphContainer.getGraph().getDisplayEdges().size());
for (Edge edge : graph.getDisplayEdges()) {
if (edge.getId().equals("collapsedTarget-e1")) {
assertEquals("v1", edge.getSource().getVertex().getId());
assertEquals("test", edge.getTarget().getVertex().getId());
} else if (edge.getId().equals("collapsed-e2")) {
assertEquals("test", edge.getSource().getVertex().getId());
assertEquals("collapse-v3", edge.getTarget().getVertex().getId());
} else if (edge.getId().equals("collapsed-e3")) {
assertEquals("collapse-v3", edge.getSource().getVertex().getId());
assertEquals("test", edge.getTarget().getVertex().getId());
} else if (edge.getId().equals("collapsedSource-e4")) {
assertEquals("test", edge.getSource().getVertex().getId());
assertEquals("v1", edge.getTarget().getVertex().getId());
/**
* This edge is not found because of the issue mentioned above.
} else if (edge.getId().equals("collapsedTarget-ncs1")) {
assertEquals("v1", edge.getSource().getVertex().getId());
assertEquals("collapse-v3", edge.getTarget().getVertex().getId());
*/
} else {
fail("Unknown edge ID: " + edge.getId());
}
}
}
Aggregations