Search in sources :

Example 11 with DefaultVertexRef

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;
    }
}
Also used : DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) HashMap(java.util.HashMap) Point(org.opennms.features.topology.api.Point) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Example 12 with DefaultVertexRef

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());
}
Also used : DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) HashMap(java.util.HashMap) BoundingBox(org.opennms.features.topology.api.BoundingBox) ArrayList(java.util.ArrayList) SearchResult(org.opennms.features.topology.api.topo.SearchResult) Point(org.opennms.features.topology.api.Point) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Test(org.junit.Test)

Example 13 with DefaultVertexRef

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);
}
Also used : DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) HashMap(java.util.HashMap) BoundingBox(org.opennms.features.topology.api.BoundingBox) Point(org.opennms.features.topology.api.Point) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Test(org.junit.Test)

Example 14 with DefaultVertexRef

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")));
}
Also used : DefaultVertexHopCriteria(org.opennms.features.topology.api.support.VertexHopGraphProvider.DefaultVertexHopCriteria) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) Test(org.junit.Test)

Example 15 with DefaultVertexRef

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;
}
Also used : AbstractEdge(org.opennms.features.topology.api.topo.AbstractEdge) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) SimpleConnector(org.opennms.features.topology.api.topo.SimpleConnector) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Aggregations

DefaultVertexRef (org.opennms.features.topology.api.topo.DefaultVertexRef)27 VertexRef (org.opennms.features.topology.api.topo.VertexRef)19 Test (org.junit.Test)10 Point (org.opennms.features.topology.api.Point)6 HashMap (java.util.HashMap)4 TreeSet (java.util.TreeSet)4 AbstractEdge (org.opennms.features.topology.api.topo.AbstractEdge)4 RefComparator (org.opennms.features.topology.api.topo.RefComparator)4 OnmsNode (org.opennms.netmgt.model.OnmsNode)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 SimpleGraphBuilder (org.opennms.features.topology.api.support.SimpleGraphBuilder)3 VertexHopGraphProvider (org.opennms.features.topology.api.support.VertexHopGraphProvider)3 GraphProvider (org.opennms.features.topology.api.topo.GraphProvider)3 Vertex (org.opennms.features.topology.api.topo.Vertex)3 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2