use of org.opennms.features.topology.api.topo.Criteria in project opennms by OpenNMS.
the class GraphMLEdgeStatusProvider method getStatusForEdges.
@Override
public Map<EdgeRef, Status> getStatusForEdges(EdgeProvider edgeProvider, Collection<EdgeRef> edges, Criteria[] criteria) {
final List<StatusScript> scripts = Lists.newArrayList();
try (final DirectoryStream<Path> stream = Files.newDirectoryStream(getScriptPath())) {
for (final Path path : stream) {
// ignore readme
if (".readme".equals(path.getFileName().toString())) {
LOG.debug("Skipping .readme");
continue;
}
final String extension = FilenameUtils.getExtension(path.toString());
final ScriptEngine scriptEngine = this.scriptEngineManager.getEngineByExtension(extension);
if (scriptEngine == null) {
LOG.warn("No script engine found for extension '{}'", extension);
continue;
}
LOG.debug("Found script: path={}, extension={}, engine={}", path, extension, scriptEngine);
try (final Stream<String> lines = Files.lines(path, Charset.defaultCharset())) {
final String source = lines.collect(Collectors.joining("\n"));
scripts.add(new StatusScript(scriptEngine, source));
}
}
} catch (final IOException e) {
LOG.error("Failed to walk template directory: {}", getScriptPath());
return Collections.emptyMap();
}
return serviceAccessor.getTransactionOperations().execute(transactionStatus -> edges.stream().filter(eachEdge -> eachEdge instanceof GraphMLEdge).map(edge -> (GraphMLEdge) edge).map(edge -> new HashMap.SimpleEntry<>(edge, computeEdgeStatus(scripts, edge))).filter(e -> e.getValue() != null).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
}
use of org.opennms.features.topology.api.topo.Criteria in project opennms by OpenNMS.
the class SavedHistory method getFocusVertices.
private static Set<VertexRef> getFocusVertices(GraphContainer graphContainer) {
final Set<VertexRef> retVal = new HashSet<>();
Criteria[] criterias = graphContainer.getCriteria();
for (Criteria crit : criterias) {
if (crit instanceof VertexHopGraphProvider.VertexHopCriteria && !(crit instanceof CollapsibleCriteria)) {
retVal.addAll(((VertexHopGraphProvider.VertexHopCriteria) crit).getVertices());
}
}
return retVal;
}
use of org.opennms.features.topology.api.topo.Criteria in project opennms by OpenNMS.
the class VertexHopGraphProvider method getFocusNodes.
public Set<VertexRef> getFocusNodes(Criteria... criteria) {
Set<VertexRef> focusNodes = new HashSet<VertexRef>();
for (Criteria criterium : criteria) {
try {
VertexHopCriteria hopCriterium = (VertexHopCriteria) criterium;
focusNodes.addAll(hopCriterium.getVertices());
} catch (ClassCastException e) {
}
}
return focusNodes;
}
use of org.opennms.features.topology.api.topo.Criteria in project opennms by OpenNMS.
the class SearchBox method updateTokenFieldList.
private void updateTokenFieldList(GraphContainer graphContainer) {
final List<SearchSuggestion> suggestions = Lists.newArrayList();
final Criteria[] criterium = graphContainer.getCriteria();
for (Criteria criteria : criterium) {
try {
CollapsibleCriteria crit = (CollapsibleCriteria) criteria;
SearchSuggestion suggestion = new SearchSuggestion(crit.getNamespace(), crit.getId(), crit.getLabel());
suggestion.setCollapsible(true);
suggestion.setCollapsed(crit.isCollapsed());
suggestions.add(suggestion);
continue;
} catch (ClassCastException e) {
}
try {
VertexHopCriteria crit = (VertexHopCriteria) criteria;
SearchSuggestion suggestion = new SearchSuggestion(crit.getNamespace(), crit.getId(), crit.getLabel());
suggestions.add(suggestion);
continue;
} catch (ClassCastException e) {
}
}
getState().setFocused(suggestions);
}
use of org.opennms.features.topology.api.topo.Criteria in project opennms by OpenNMS.
the class SearchBox method removeIfSuggMapEmpty.
private void removeIfSuggMapEmpty(SearchResult searchResult, GraphContainer graphContainer) {
Criteria[] criterias = graphContainer.getCriteria();
for (Criteria criteria : criterias) {
if (criteria == null || !(criteria instanceof VertexHopCriteria)) {
continue;
}
VertexHopCriteria crit = (VertexHopCriteria) criteria;
String critNameSpace = crit.getNamespace();
if (critNameSpace == null) {
continue;
}
String critId = crit.getId();
if (critId == null) {
continue;
}
String critLabel = crit.getLabel();
if (critLabel == null) {
continue;
}
String resultNameSpace = searchResult.getNamespace();
String resultId = searchResult.getId();
String resultLabel = searchResult.getLabel();
if (critNameSpace.equals(resultNameSpace) && critId.equals(resultId) && critLabel.equals(resultLabel)) {
graphContainer.removeCriteria(crit);
}
}
}
Aggregations