Search in sources :

Example 11 with GraphProvider

use of org.opennms.features.topology.api.topo.GraphProvider in project opennms by OpenNMS.

the class DefaultTopologyService method getPreferredLayoutAlgorithm.

// Determines default layout
@Override
public LayoutAlgorithm getPreferredLayoutAlgorithm(String metaTopologyId, String namespace) {
    Objects.requireNonNull(metaTopologyId);
    Objects.requireNonNull(namespace);
    final GraphProvider graphProvider = getGraphProvider(metaTopologyId, namespace);
    final String preferredLayout = graphProvider.getDefaults().getPreferredLayout();
    final LayoutAlgorithm preferredLayoutAlgorithm = serviceLocator != null ? findLayoutAlgorithm(preferredLayout) : DEFAULT_LAYOUT_ALGORITHM;
    return preferredLayoutAlgorithm;
}
Also used : D3TopoLayoutAlgorithm(org.opennms.features.topology.app.internal.jung.D3TopoLayoutAlgorithm) LayoutAlgorithm(org.opennms.features.topology.api.LayoutAlgorithm) GraphProvider(org.opennms.features.topology.api.topo.GraphProvider)

Example 12 with GraphProvider

use of org.opennms.features.topology.api.topo.GraphProvider in project opennms by OpenNMS.

the class ManualLayoutAlgorithmTest method verifyLayoutCoordinatesHavePriority.

/*
     * If persisted layout is defined, verify that it has priority.
     */
@Test
public void verifyLayoutCoordinatesHavePriority() {
    final GraphProvider graphProvider = new SimpleGraphBuilder("dummy").vertex("vertex1").vX(1).vY(1).get();
    final ManualTest test = new ManualTest(graphProvider);
    final LayoutEntity persistedLayout = new LayoutEntity();
    int x = 5;
    int y = 5;
    for (VertexRef eachVertex : graphProvider.getVertices()) {
        VertexPositionEntity vertexPositionEntity = new VertexPositionEntity();
        vertexPositionEntity.setVertexRef(LayoutManager.toVertexRefEntity(eachVertex));
        vertexPositionEntity.setPosition(new PointEntity(x++, y++));
        persistedLayout.addVertexPosition(vertexPositionEntity);
    }
    Mockito.when(test.layoutManager.loadLayout(test.graph)).thenReturn(persistedLayout);
    new ManualLayoutAlgorithm(test.layoutManager).updateLayout(test.graph);
    Assert.assertEquals(ImmutableMap.builder().put(new DefaultVertexRef("dummy", "vertex1"), new Point(5, 5)).build(), test.layout.getLocations());
}
Also used : VertexPositionEntity(org.opennms.netmgt.topology.persistence.api.VertexPositionEntity) SimpleGraphBuilder(org.opennms.features.topology.api.support.SimpleGraphBuilder) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) GraphProvider(org.opennms.features.topology.api.topo.GraphProvider) LayoutEntity(org.opennms.netmgt.topology.persistence.api.LayoutEntity) PointEntity(org.opennms.netmgt.topology.persistence.api.PointEntity) Point(org.opennms.features.topology.api.Point) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Point(org.opennms.features.topology.api.Point) Test(org.junit.Test)

Aggregations

GraphProvider (org.opennms.features.topology.api.topo.GraphProvider)12 VertexRef (org.opennms.features.topology.api.topo.VertexRef)6 List (java.util.List)5 Objects (java.util.Objects)4 Collectors (java.util.stream.Collectors)4 Test (org.junit.Test)4 GraphContainer (org.opennms.features.topology.api.GraphContainer)4 Vertex (org.opennms.features.topology.api.topo.Vertex)4 Lists (com.google.common.collect.Lists)3 Optional (java.util.Optional)3 Set (java.util.Set)3 DefaultVertexRef (org.opennms.features.topology.api.topo.DefaultVertexRef)3 Maps (com.google.common.collect.Maps)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 Map (java.util.Map)2 Before (org.junit.Before)2 SimpleGraphBuilder (org.opennms.features.topology.api.support.SimpleGraphBuilder)2