Search in sources :

Example 1 with GraphContainer

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

the class OSGiVerticesUpdateManagerTest method createGraph.

private GraphContainer createGraph(int... vertIds) {
    final List<Vertex> vertexRefsWithIds = createVerticsWithIds(vertIds);
    final Graph graphMock = EasyMock.createNiceMock(Graph.class);
    final GraphContainer graphContainerMock = EasyMock.createNiceMock(GraphContainer.class);
    EasyMock.expect(graphMock.getDisplayVertices()).andReturn(vertexRefsWithIds).anyTimes();
    EasyMock.expect(graphContainerMock.getGraph()).andReturn(graphMock).anyTimes();
    EasyMock.replay(graphMock, graphContainerMock);
    return graphContainerMock;
}
Also used : GraphContainer(org.opennms.features.topology.api.GraphContainer) Vertex(org.opennms.features.topology.api.topo.Vertex) Graph(org.opennms.features.topology.api.Graph)

Example 2 with GraphContainer

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

the class HierarchyLayoutAlgorithmTest method buildLayout.

private void buildLayout() {
    // Mock ALL the things
    final GraphContainer mockGraphContainer = Mockito.mock(GraphContainer.class);
    layout = new DefaultLayout();
    final TestGraph testGraph = new TestGraph(layout, vertices, edges);
    Mockito.when(mockGraphContainer.getGraph()).thenReturn(testGraph);
    // Update layouts and ensure no exception is thrown
    new HierarchyLayoutAlgorithm().updateLayout(testGraph);
}
Also used : GraphContainer(org.opennms.features.topology.api.GraphContainer) DefaultLayout(org.opennms.features.topology.app.internal.DefaultLayout) TestGraph(org.opennms.features.topology.app.internal.TestGraph)

Example 3 with GraphContainer

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

the class OperationManagerTest method getMenuBar.

private static TopologyMenuBar getMenuBar(OperationManager operationManager) {
    // Mock all the things
    GraphContainer graphContainerMock = Mockito.mock(GraphContainer.class);
    SelectionManager selectionManagerMock = Mockito.mock(SelectionManager.class);
    Mockito.when(graphContainerMock.getSelectionManager()).thenReturn(selectionManagerMock);
    Mockito.when(selectionManagerMock.getSelectedVertexRefs()).thenReturn(new ArrayList<>());
    // Create menu bar
    TopologyMenuBar topologyMenuBar = new TopologyMenuBar();
    topologyMenuBar.updateMenu(graphContainerMock, null, operationManager);
    return topologyMenuBar;
}
Also used : GraphContainer(org.opennms.features.topology.api.GraphContainer) SelectionManager(org.opennms.features.topology.api.SelectionManager)

Example 4 with GraphContainer

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

the class LayoutManager method persistLayout.

public void persistLayout(GraphContainer graphContainer) {
    final List<VertexRef> vertexRefs = toVertexRef(graphContainer.getGraph().getDisplayVertices());
    final String id = calculateHash(vertexRefs);
    LayoutEntity layoutEntity = layoutDao.get(id);
    if (layoutEntity == null) {
        layoutEntity = new LayoutEntity();
        layoutEntity.setId(id);
        layoutEntity.setCreated(new Date());
        layoutEntity.setCreator(graphContainer.getApplicationContext().getUsername());
    }
    layoutEntity.setUpdated(new Date());
    layoutEntity.setUpdator(graphContainer.getApplicationContext().getUsername());
    final Layout layout = graphContainer.getGraph().getLayout();
    final List<VertexPositionEntity> vertexPositionEntities = vertexRefs.stream().map(vertexRef -> {
        final Point p = layout.getLocation(vertexRef);
        PointEntity pointEntity = new PointEntity();
        pointEntity.setX((int) p.getX());
        pointEntity.setY((int) p.getY());
        final VertexPositionEntity vertexEntity = new VertexPositionEntity();
        vertexEntity.setVertexRef(toVertexRefEntity(vertexRef));
        vertexEntity.setPosition(pointEntity);
        return vertexEntity;
    }).collect(Collectors.toList());
    layoutEntity.getVertexPositions().clear();
    for (VertexPositionEntity eachVertexPosition : vertexPositionEntities) {
        layoutEntity.addVertexPosition(eachVertexPosition);
    }
    layoutDao.saveOrUpdate(layoutEntity);
}
Also used : GraphContainer(org.opennms.features.topology.api.GraphContainer) Date(java.util.Date) Vertex(org.opennms.features.topology.api.topo.Vertex) HashMap(java.util.HashMap) Hashing(com.google.common.hash.Hashing) Function(java.util.function.Function) VertexPositionEntity(org.opennms.netmgt.topology.persistence.api.VertexPositionEntity) Point(org.opennms.features.topology.api.Point) Layout(org.opennms.features.topology.api.Layout) Map(java.util.Map) LayoutDao(org.opennms.netmgt.topology.persistence.api.LayoutDao) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) Collection(java.util.Collection) Graph(org.opennms.features.topology.api.Graph) Collectors(java.util.stream.Collectors) PointEntity(org.opennms.netmgt.topology.persistence.api.PointEntity) StandardCharsets(java.nio.charset.StandardCharsets) Objects(java.util.Objects) TransactionAwareBeanProxyFactory(org.opennms.netmgt.vaadin.core.TransactionAwareBeanProxyFactory) List(java.util.List) VertexRefEntity(org.opennms.netmgt.topology.persistence.api.VertexRefEntity) TransactionOperations(org.springframework.transaction.support.TransactionOperations) LayoutEntity(org.opennms.netmgt.topology.persistence.api.LayoutEntity) Comparator(java.util.Comparator) VertexRef(org.opennms.features.topology.api.topo.VertexRef) VertexPositionEntity(org.opennms.netmgt.topology.persistence.api.VertexPositionEntity) Layout(org.opennms.features.topology.api.Layout) LayoutEntity(org.opennms.netmgt.topology.persistence.api.LayoutEntity) Point(org.opennms.features.topology.api.Point) PointEntity(org.opennms.netmgt.topology.persistence.api.PointEntity) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Date(java.util.Date)

Example 5 with GraphContainer

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

the class RemoveFocusOtherVerticesOperation method enabled.

@Override
public boolean enabled(List<VertexRef> targets, OperationContext operationContext) {
    if (targets == null || targets.isEmpty()) {
        return false;
    }
    final GraphContainer graphContainer = operationContext.getGraphContainer();
    final WrappedVertexHopCriteria wrappedVertexHopCriteria = VertexHopGraphProvider.getWrappedVertexHopCriteria(graphContainer);
    if (wrappedVertexHopCriteria.isEmpty()) {
        return false;
    }
    // Are the selected vertices in focus?
    for (VertexRef target : targets) {
        if (!wrappedVertexHopCriteria.contains(target)) {
            return false;
        }
    }
    // Are there any other vertices in focus?
    for (VertexRef vertex : wrappedVertexHopCriteria.getVertices()) {
        if (!targets.contains(vertex)) {
            return true;
        }
    }
    return false;
}
Also used : GraphContainer(org.opennms.features.topology.api.GraphContainer) WrappedVertexHopCriteria(org.opennms.features.topology.api.support.VertexHopGraphProvider.WrappedVertexHopCriteria) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Aggregations

GraphContainer (org.opennms.features.topology.api.GraphContainer)20 VertexRef (org.opennms.features.topology.api.topo.VertexRef)11 List (java.util.List)7 Collectors (java.util.stream.Collectors)6 Collection (java.util.Collection)5 Collections (java.util.Collections)4 Objects (java.util.Objects)4 Vertex (org.opennms.features.topology.api.topo.Vertex)4 Strings (com.google.common.base.Strings)3 UI (com.vaadin.ui.UI)3 ArrayList (java.util.ArrayList)3 Set (java.util.Set)3 OperationContext (org.opennms.features.topology.api.OperationContext)3 DefaultInfoPanelItem (org.opennms.features.topology.api.info.item.DefaultInfoPanelItem)3 InfoPanelItem (org.opennms.features.topology.api.info.item.InfoPanelItem)3 WrappedVertexHopCriteria (org.opennms.features.topology.api.support.VertexHopGraphProvider.WrappedVertexHopCriteria)3 GraphProvider (org.opennms.features.topology.api.topo.GraphProvider)3 Lists (com.google.common.collect.Lists)2 Component (com.vaadin.ui.Component)2 Label (com.vaadin.ui.Label)2