Search in sources :

Example 1 with ItemProvider

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);
        }
    });
}
Also used : Logger(org.slf4j.Logger) FilterParser(org.opennms.features.topology.plugins.topo.asset.filter.FilterParser) GraphMLNode(org.opennms.features.graphml.model.GraphMLNode) IdGenerator(org.opennms.features.topology.plugins.topo.asset.layers.IdGenerator) LoggerFactory(org.slf4j.LoggerFactory) LayerDefinition(org.opennms.features.topology.plugins.topo.asset.layers.LayerDefinition) GraphML(org.opennms.features.graphml.model.GraphML) LayerDefinitionRepository(org.opennms.features.topology.plugins.topo.asset.layers.LayerDefinitionRepository) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Objects(java.util.Objects) List(java.util.List) GraphMLProperties(org.opennms.features.topology.plugins.topo.graphml.GraphMLProperties) ItemProvider(org.opennms.features.topology.plugins.topo.asset.layers.ItemProvider) Map(java.util.Map) Filter(org.opennms.features.topology.plugins.topo.asset.filter.Filter) LayerBuilder(org.opennms.features.topology.plugins.topo.asset.layers.LayerBuilder) Layer(org.opennms.features.topology.plugins.topo.asset.layers.Layer) GraphMLEdge(org.opennms.features.graphml.model.GraphMLEdge) GraphMLGraph(org.opennms.features.graphml.model.GraphMLGraph) OnmsNode(org.opennms.netmgt.model.OnmsNode) ItemProvider(org.opennms.features.topology.plugins.topo.asset.layers.ItemProvider) OnmsNode(org.opennms.netmgt.model.OnmsNode) Filter(org.opennms.features.topology.plugins.topo.asset.filter.Filter) LayerDefinition(org.opennms.features.topology.plugins.topo.asset.layers.LayerDefinition) Layer(org.opennms.features.topology.plugins.topo.asset.layers.Layer)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Collectors (java.util.stream.Collectors)1 GraphML (org.opennms.features.graphml.model.GraphML)1 GraphMLEdge (org.opennms.features.graphml.model.GraphMLEdge)1 GraphMLGraph (org.opennms.features.graphml.model.GraphMLGraph)1 GraphMLNode (org.opennms.features.graphml.model.GraphMLNode)1 Filter (org.opennms.features.topology.plugins.topo.asset.filter.Filter)1 FilterParser (org.opennms.features.topology.plugins.topo.asset.filter.FilterParser)1 IdGenerator (org.opennms.features.topology.plugins.topo.asset.layers.IdGenerator)1 ItemProvider (org.opennms.features.topology.plugins.topo.asset.layers.ItemProvider)1 Layer (org.opennms.features.topology.plugins.topo.asset.layers.Layer)1 LayerBuilder (org.opennms.features.topology.plugins.topo.asset.layers.LayerBuilder)1 LayerDefinition (org.opennms.features.topology.plugins.topo.asset.layers.LayerDefinition)1 LayerDefinitionRepository (org.opennms.features.topology.plugins.topo.asset.layers.LayerDefinitionRepository)1 GraphMLProperties (org.opennms.features.topology.plugins.topo.graphml.GraphMLProperties)1 OnmsNode (org.opennms.netmgt.model.OnmsNode)1 Logger (org.slf4j.Logger)1