Search in sources :

Example 1 with ExpressionImpl

use of org.apache.commons.jexl2.ExpressionImpl in project opennms by OpenNMS.

the class GraphResultsController method getSuggestedReports.

/**
     * <p>getSuggestedReports</p>
     *
     * @return an array of {@link java.lang.String} objects.
     */
public String[] getSuggestedReports(ResourceId resourceId, String matching) {
    List<String> metricList = new ArrayList<String>();
    JexlEngine expressionParser = new JexlEngine();
    try {
        ExpressionImpl e = (ExpressionImpl) expressionParser.createExpression(matching);
        for (List<String> list : e.getVariables()) {
            if (list.get(0).equalsIgnoreCase("math")) {
                continue;
            }
            if (list.get(0).equalsIgnoreCase("datasources")) {
                metricList.add(list.get(1).intern());
            } else {
                metricList.add(list.get(0).intern());
            }
        }
    } catch (Exception e) {
    }
    if (!metricList.isEmpty()) {
        List<String> templates = new ArrayList<String>();
        for (PrefabGraph graph : m_graphResultsService.getAllPrefabGraphs(resourceId)) {
            boolean found = false;
            for (String c : graph.getColumns()) {
                if (metricList.contains(c)) {
                    found = true;
                    continue;
                }
            }
            if (found) {
                templates.add(graph.getName());
            }
        }
        if (!templates.isEmpty()) {
            return templates.toArray(new String[templates.size()]);
        }
    }
    return new String[] { "all" };
}
Also used : ExpressionImpl(org.apache.commons.jexl2.ExpressionImpl) PrefabGraph(org.opennms.netmgt.model.PrefabGraph) JexlEngine(org.apache.commons.jexl2.JexlEngine) ArrayList(java.util.ArrayList) MissingParameterException(org.opennms.web.servlet.MissingParameterException) RrdException(org.jrobin.core.RrdException)

Aggregations

ArrayList (java.util.ArrayList)1 ExpressionImpl (org.apache.commons.jexl2.ExpressionImpl)1 JexlEngine (org.apache.commons.jexl2.JexlEngine)1 RrdException (org.jrobin.core.RrdException)1 PrefabGraph (org.opennms.netmgt.model.PrefabGraph)1 MissingParameterException (org.opennms.web.servlet.MissingParameterException)1