use of org.opennms.features.topology.api.support.SemanticZoomLevelCriteria in project opennms by OpenNMS.
the class VEProviderGraphContainer method setSemanticZoomLevel.
@Override
public void setSemanticZoomLevel(int level) {
int oldLevel = m_semanticZoomLevel;
m_semanticZoomLevel = level;
// Also set the SZL in a Criteria attached to the container so that we can
// use the value to optimize some GraphProvider calls
SemanticZoomLevelCriteria criteria = getSemanticZoomLevelCriteriaForContainer(this);
criteria.setSemanticZoomLevel(level);
if (oldLevel != m_semanticZoomLevel) {
setDirty(true);
}
}
use of org.opennms.features.topology.api.support.SemanticZoomLevelCriteria in project opennms by OpenNMS.
the class VEProviderGraphContainer method getSemanticZoomLevelCriteriaForContainer.
public static SemanticZoomLevelCriteria getSemanticZoomLevelCriteriaForContainer(GraphContainer graphContainer) {
Criteria[] criteria = graphContainer.getCriteria();
if (criteria != null) {
for (Criteria criterium : criteria) {
try {
return (SemanticZoomLevelCriteria) criterium;
} catch (ClassCastException e) {
}
}
}
SemanticZoomLevelCriteria hopCriteria = new SemanticZoomLevelCriteria(graphContainer.getSemanticZoomLevel());
graphContainer.addCriteria(hopCriteria);
return hopCriteria;
}
use of org.opennms.features.topology.api.support.SemanticZoomLevelCriteria 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