use of org.opennms.features.topology.plugins.topo.asset.layers.ItemProvider in project opennms by OpenNMS.
the class AssetGraphGenerator method applyFilters.
public static void applyFilters(List<OnmsNode> nodes, Map<String, Filter> filterMap, LayerDefinitionRepository layerDefinitionRepository) {
final List<LayerDefinition> layersToFilter = layerDefinitionRepository.getDefinitions(filterMap.keySet());
layersToFilter.stream().filter(layerToFilter -> filterMap.get(layerToFilter.getKey()) != null).forEach(layerToFilter -> {
final List<OnmsNode> filteredNodes = nodes.stream().filter(n -> {
ItemProvider itemProvider = layerToFilter.getLayer().getItemProvider();
Filter filter = filterMap.get(layerToFilter.getKey());
return filter.apply(itemProvider.getItem(n));
}).collect(Collectors.toList());
if (!filteredNodes.isEmpty()) {
final Layer layer = layerToFilter.getLayer();
LOG.debug("Found nodes to remove due to filter settings. Removing nodes {}", filteredNodes.stream().map(n -> String.format("(id: %s, label: %s)", n.getId(), n.getLabel())).collect(Collectors.toList()));
nodes.removeAll(filteredNodes);
}
});
}
Aggregations