Search in sources :

Example 1 with VertexRefEntity

use of org.opennms.netmgt.topology.persistence.api.VertexRefEntity in project opennms by OpenNMS.

the class LayoutDaoIT method createVertexPosition.

private VertexPositionEntity createVertexPosition(String vertexNamespace, String vertexId, int x, int y) {
    VertexPositionEntity vertexPositionEntity = new VertexPositionEntity();
    vertexPositionEntity.setPosition(new PointEntity(x, y));
    vertexPositionEntity.setVertexRef(new VertexRefEntity(vertexNamespace, vertexId));
    return vertexPositionEntity;
}
Also used : VertexPositionEntity(org.opennms.netmgt.topology.persistence.api.VertexPositionEntity) VertexRefEntity(org.opennms.netmgt.topology.persistence.api.VertexRefEntity) PointEntity(org.opennms.netmgt.topology.persistence.api.PointEntity)

Example 2 with VertexRefEntity

use of org.opennms.netmgt.topology.persistence.api.VertexRefEntity in project opennms by OpenNMS.

the class LayoutManager method isPersistedLayoutEqualToCurrentLayout.

public boolean isPersistedLayoutEqualToCurrentLayout(Graph graph) {
    LayoutEntity layoutEntity = loadLayout(graph);
    if (layoutEntity != null) {
        // If we have a layout persisted, we verify if it is equal.
        final Map<VertexRef, Point> persistedLocations = layoutEntity.getVertexPositions().stream().collect(Collectors.toMap((Function<VertexPositionEntity, VertexRef>) vertexPositionEntity -> {
            VertexRefEntity vertexRefEntity = vertexPositionEntity.getVertexRef();
            return new DefaultVertexRef(vertexRefEntity.getNamespace(), vertexRefEntity.getId());
        }, vertexPositionEntity -> {
            PointEntity position = vertexPositionEntity.getPosition();
            return new Point(position.getX(), position.getY());
        }));
        // The locations may contain elements currently not visible, we filter them
        final Map<VertexRef, Point> manualLocations = new HashMap<>();
        graph.getLayout().getLocations().forEach((key, value) -> {
            if (persistedLocations.containsKey(key)) {
                // layoutEntity stores int coordinates, but manualLocations are stored as double.
                // Convert to int to make it comparable.
                manualLocations.put(key, new Point((int) value.getX(), (int) value.getY()));
            }
        });
        final boolean layoutIsEqual = manualLocations.equals(persistedLocations);
        return layoutIsEqual;
    }
    // We don't have anything persisted, so they are not equal
    return false;
}
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) Function(java.util.function.Function) VertexRefEntity(org.opennms.netmgt.topology.persistence.api.VertexRefEntity) DefaultVertexRef(org.opennms.features.topology.api.topo.DefaultVertexRef) HashMap(java.util.HashMap) 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)

Example 3 with VertexRefEntity

use of org.opennms.netmgt.topology.persistence.api.VertexRefEntity in project opennms by OpenNMS.

the class LayoutManager method toVertexRefEntity.

public static VertexRefEntity toVertexRefEntity(VertexRef vertexRef) {
    Objects.requireNonNull(vertexRef);
    VertexRefEntity vertexRefEntity = new VertexRefEntity();
    vertexRefEntity.setId(vertexRef.getId());
    vertexRefEntity.setNamespace(vertexRef.getNamespace());
    return vertexRefEntity;
}
Also used : VertexRefEntity(org.opennms.netmgt.topology.persistence.api.VertexRefEntity)

Aggregations

VertexRefEntity (org.opennms.netmgt.topology.persistence.api.VertexRefEntity)3 PointEntity (org.opennms.netmgt.topology.persistence.api.PointEntity)2 VertexPositionEntity (org.opennms.netmgt.topology.persistence.api.VertexPositionEntity)2 Hashing (com.google.common.hash.Hashing)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Collection (java.util.Collection)1 Comparator (java.util.Comparator)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 Graph (org.opennms.features.topology.api.Graph)1 GraphContainer (org.opennms.features.topology.api.GraphContainer)1 Layout (org.opennms.features.topology.api.Layout)1 Point (org.opennms.features.topology.api.Point)1 DefaultVertexRef (org.opennms.features.topology.api.topo.DefaultVertexRef)1 Vertex (org.opennms.features.topology.api.topo.Vertex)1