use of org.opennms.features.graphml.model.GraphMLGraph in project opennms by OpenNMS.
the class AssetGraphGenerator method getPath.
/**
* Calculates a path through all layers (from top to bottom) to the given <code>node</code>.
*
* Ensure that this path exist, otherwise an Exception is thrown.
*
* @param node The node to calculate the path to.
* @param graphs All generated graphs, containing all nodes created.
* @param layers All layers from which the graphs were created.
*
* @return A list of {@link GraphMLNode}s (the path) through all layers to the given <code>node</code>.
*/
private static List<GraphMLNode> getPath(OnmsNode node, List<GraphMLGraph> graphs, List<Layer> layers) {
// The graphs were created based on the layers. If the count differs, the path cannot be calculated
if (graphs.size() != layers.size()) {
throw new IllegalArgumentException("Cannot calculate path. There are more layers than graphs, but the count must be identical");
}
final List<GraphMLNode> path = new ArrayList<>();
for (int i = 0; i < graphs.size(); i++) {
// the layer graph
final GraphMLGraph graph = graphs.get(i);
// the layer definition
final Layer layer = layers.get(i);
// the the value for the specified node in that layer (it must exist)
final Object item = layer.getItemProvider().getItem(node);
final String itemId = layer.getNodeDecorator().getId(item);
final String nodeId = layer.getIdGenerator().generateId(layers.subList(0, i), node, itemId);
final GraphMLNode GraphMlNode = graph.getNodeById(nodeId);
if (GraphMlNode != null) {
path.add(GraphMlNode);
} else {
throw new IllegalStateException(String.format("Could not find a node with id {} in graph with id {}.", nodeId, graph.getId()));
}
}
return path;
}
Aggregations