use of org.opennms.features.topology.api.topo.DefaultVertexRef in project opennms by OpenNMS.
the class VertexRefPointMapAdapter method unmarshal.
@Override
public Map<VertexRef, Point> unmarshal(VertexRefPointMapAdapter.VertexRefPointMap v) throws Exception {
if (v == null) {
return null;
} else {
Map<VertexRef, Point> retval = new HashMap<VertexRef, Point>();
for (VertexRefPointEntry entry : v.entry) {
VertexRef ref = new DefaultVertexRef(entry.key.namespace, entry.key.id, entry.key.label);
Point point = new Point(entry.value.x, entry.value.y);
retval.put(ref, point);
}
return retval;
}
}
use of org.opennms.features.topology.api.topo.DefaultVertexRef in project opennms by OpenNMS.
the class SavedHistoryTest method verifyCRCIncludesSearchResult.
/**
* This methods tests whether the CRC checksums for {@link SavedHistory} object with {@link SearchResult}s are generated correctly,
* namely that they now take into account the search results
*/
@Test
public void verifyCRCIncludesSearchResult() {
Map<String, String> settings = new HashMap<String, String>();
settings.put("hello", "world");
VertexRef vert1 = new DefaultVertexRef("nodes", "1");
VertexRef vert2 = new DefaultVertexRef("nodes", "2", "HasALabel");
Map<VertexRef, Point> locations = new HashMap<VertexRef, Point>();
locations.put(vert1, new Point(0, 0));
locations.put(vert2, new Point(0, 0));
// Creating SavedHistory object with no search results
SavedHistory history1 = new SavedHistory(1, new BoundingBox(0, 0, 100, 100), locations, Collections.singleton(vert2), Collections.emptySet(), settings, Collections.emptyList());
List<SearchResult> searchResults = new ArrayList<>();
searchResults.add(new SearchResult("alarm", "alarmID", "someLabel", searchQuery, SearchResult.COLLAPSIBLE, !SearchResult.COLLAPSED));
// Creating SavedHistory object with a single search result with ID = "alarmID"
SavedHistory history2 = new SavedHistory(1, new BoundingBox(0, 0, 100, 100), locations, Collections.singleton(vert2), Collections.emptySet(), settings, searchResults);
// Assertion that the SavedHistory with no search results is different from the one with one
Assert.assertNotEquals(history1.getFragment(), history2.getFragment());
// Creating another SavedHistory WITH search result, identical to the 2nd one
SavedHistory history3 = new SavedHistory(1, new BoundingBox(0, 0, 100, 100), locations, Collections.singleton(vert2), Collections.emptySet(), settings, searchResults);
// Assertion that two SavedHistory objects with the same search results are identical
Assert.assertEquals(history2.getFragment(), history3.getFragment());
}
use of org.opennms.features.topology.api.topo.DefaultVertexRef in project opennms by OpenNMS.
the class SavedHistoryTest method testMarshall.
@Test
public void testMarshall() {
Map<String, String> settings = new HashMap<String, String>();
settings.put("hello", "world");
VertexRef vert1 = new DefaultVertexRef("nodes", "1");
VertexRef vert2 = new DefaultVertexRef("nodes", "2", "HasALabel");
Map<VertexRef, Point> locations = new HashMap<VertexRef, Point>();
locations.put(vert1, new Point(0, 0));
locations.put(vert2, new Point(0, 0));
SavedHistory savedHistory = new SavedHistory(0, new BoundingBox(0, 0, 100, 100), locations, Collections.singleton(vert2), Collections.emptySet(), settings, Collections.emptyList());
JAXB.marshal(savedHistory, System.out);
// Specify a focus node
savedHistory = new SavedHistory(0, new BoundingBox(0, 0, 100, 100), locations, Collections.singleton(vert2), Collections.singleton(vert1), settings, Collections.emptyList());
JAXB.marshal(savedHistory, System.out);
}
use of org.opennms.features.topology.api.topo.DefaultVertexRef in project opennms by OpenNMS.
the class VertexHopGraphProviderTest method testGraphProvider.
@Test
public void testGraphProvider() {
DefaultVertexHopCriteria criteria = new DefaultVertexHopCriteria(new DefaultVertexRef("nodes", "g0"));
m_provider.getVertices(criteria);
assertEquals(0, m_provider.getSemanticZoomLevel(new DefaultVertexRef("nodes", "g0")));
assertEquals(1, m_provider.getSemanticZoomLevel(new DefaultVertexRef("nodes", "g1")));
assertEquals(1, m_provider.getSemanticZoomLevel(new DefaultVertexRef("nodes", "g2")));
assertEquals(2, m_provider.getSemanticZoomLevel(new DefaultVertexRef("nodes", "v1")));
assertEquals(2, m_provider.getSemanticZoomLevel(new DefaultVertexRef("nodes", "v2")));
assertEquals(2, m_provider.getSemanticZoomLevel(new DefaultVertexRef("nodes", "v3")));
assertEquals(2, m_provider.getSemanticZoomLevel(new DefaultVertexRef("nodes", "v4")));
// Make sure that the hop provider isn't showing nodes with parent/child relationships like the
// older grouping providers did
assertNull(m_provider.getParent(new DefaultVertexRef("nodes", "g0")));
assertNull(m_provider.getParent(new DefaultVertexRef("nodes", "g1")));
assertNull(m_provider.getParent(new DefaultVertexRef("nodes", "g2")));
assertNull(m_provider.getParent(new DefaultVertexRef("nodes", "v1")));
assertNull(m_provider.getParent(new DefaultVertexRef("nodes", "v2")));
assertNull(m_provider.getParent(new DefaultVertexRef("nodes", "v3")));
assertNull(m_provider.getParent(new DefaultVertexRef("nodes", "v4")));
criteria = new DefaultVertexHopCriteria(new DefaultVertexRef("nodes", "v1"));
m_provider.getVertices(criteria);
assertEquals(2, m_provider.getSemanticZoomLevel(new DefaultVertexRef("nodes", "g0")));
assertEquals(1, m_provider.getSemanticZoomLevel(new DefaultVertexRef("nodes", "g1")));
assertEquals(3, m_provider.getSemanticZoomLevel(new DefaultVertexRef("nodes", "g2")));
assertEquals(0, m_provider.getSemanticZoomLevel(new DefaultVertexRef("nodes", "v1")));
assertEquals(2, m_provider.getSemanticZoomLevel(new DefaultVertexRef("nodes", "v2")));
assertEquals(4, m_provider.getSemanticZoomLevel(new DefaultVertexRef("nodes", "v3")));
assertEquals(4, m_provider.getSemanticZoomLevel(new DefaultVertexRef("nodes", "v4")));
// Make sure that the hop provider isn't showing nodes with parent/child relationships like the
// older grouping providers did
assertNull(m_provider.getParent(new DefaultVertexRef("nodes", "g0")));
assertNull(m_provider.getParent(new DefaultVertexRef("nodes", "g1")));
assertNull(m_provider.getParent(new DefaultVertexRef("nodes", "g2")));
assertNull(m_provider.getParent(new DefaultVertexRef("nodes", "v1")));
assertNull(m_provider.getParent(new DefaultVertexRef("nodes", "v2")));
assertNull(m_provider.getParent(new DefaultVertexRef("nodes", "v3")));
assertNull(m_provider.getParent(new DefaultVertexRef("nodes", "v4")));
}
use of org.opennms.features.topology.api.topo.DefaultVertexRef in project opennms by OpenNMS.
the class SimpleGraphBuilder method edge.
public SimpleGraphBuilder edge(String id, String srcId, String tgtId) {
VertexRef srcVertex = m_graphProvider.getVertex(ns(), srcId);
if (srcVertex == null) {
srcVertex = new DefaultVertexRef(ns(), srcId);
}
VertexRef tgtVertex = m_graphProvider.getVertex(ns(), tgtId);
if (tgtVertex == null) {
tgtVertex = new DefaultVertexRef(ns(), tgtId);
}
SimpleConnector source = new SimpleConnector(ns(), srcId + "-" + id + "-connector", srcVertex);
SimpleConnector target = new SimpleConnector(ns(), tgtId + "-" + id + "-connector", tgtVertex);
m_currentEdge = new AbstractEdge(ns(), id, source, target);
source.setEdge(m_currentEdge);
target.setEdge(m_currentEdge);
m_graphProvider.addEdges(m_currentEdge);
return this;
}
Aggregations