use of org.opennms.features.topology.api.topo.VertexRef in project opennms by OpenNMS.
the class PathTree method addPath.
public void addPath(List<VertexRef> vertexRefs) {
if (vertexRefs != null && !vertexRefs.isEmpty()) {
Node parent = root;
for (VertexRef eachRef : vertexRefs) {
Node createdNode = parent.addChild(eachRef);
parent = createdNode;
}
}
}
use of org.opennms.features.topology.api.topo.VertexRef in project opennms by OpenNMS.
the class FRLayoutTest method runFRLayout.
private TopoFRLayout<VertexRef, EdgeRef> runFRLayout(Graph g, Layout graphLayout, List<Vertex> vertices) {
TopoFRLayout<VertexRef, EdgeRef> layout = new TopoFRLayout<>(createJungGraph(g));
Dimension size = selectLayoutSize(m_graphContainer);
//layout.setRepulsionMultiplier(3/8.0);
//layout.setAttractionMultiplier(3/8.0);
layout.setInitializer(initializer(graphLayout, size));
layout.setSize(size);
while (!layout.done()) {
layout.step();
}
LOG.info("/******** FRLayout Run **********/");
for (Vertex v : vertices) {
graphLayout.setLocation(v, new Point(layout.getX(v) - size.getWidth() / 2.0, layout.getY(v) - size.getHeight() / 2.0));
LOG.info("layout.getX(): " + layout.getX(v) + " layout.getY(): " + layout.getY(v));
}
LOG.info("/******** End FRLayout Run **********/");
return layout;
}
use of org.opennms.features.topology.api.topo.VertexRef in project opennms by OpenNMS.
the class IpLikeHopCriteria method getVertices.
@Override
public Set<VertexRef> getVertices() {
CriteriaBuilder bldr = new CriteriaBuilder(OnmsIpInterface.class);
bldr.iplike("ipAddress", m_ipQuery);
List<OnmsIpInterface> ips = ipInterfaceProvider.findMatching(bldr.toCriteria());
Set<VertexRef> vertices = new TreeSet<VertexRef>(new RefComparator());
for (OnmsIpInterface ip : ips) {
OnmsNode node = ip.getNode();
vertices.add(new DefaultVertexRef("nodes", String.valueOf(node.getId()), node.getLabel()));
}
return vertices;
}
use of org.opennms.features.topology.api.topo.VertexRef 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);
}
use of org.opennms.features.topology.api.topo.VertexRef 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;
}
Aggregations