From 216264515987b639daab98091e956a858295aee9 Mon Sep 17 00:00:00 2001 From: Ronald Roskens Date: Tue, 8 Oct 2013 11:52:28 -0500 Subject: [PATCH] Fix for NMS-5334: Category and Scheduled Outage GUI Enhancment Request Fix for NMS-2207: allow categories when creating downtime schedules Fix for NMS-5762: Scheduled Outages - Node selection I added a couple of enhancements to the Scheduled Outages page that should make things a little bit easier when selecting nodes. In the nodelabel search box, you can now prefix the search string with a couple of special symbols to alter the search behavior: '@' will let you search for surveillance categories '#' Will search for nodes who are in the specified surveillance category '$' will let you search for requisition names '%' will search for nodes in a requisition that starts with the search string. --- .../main/webapp/admin/sched-outages/editoutage.jsp | 14 +- .../main/webapp/admin/sched-outages/jsonNodes.jsp | 156 +++++++++++++++------ 2 files changed, 125 insertions(+), 45 deletions(-) diff --git a/opennms-webapp/src/main/webapp/admin/sched-outages/editoutage.jsp b/opennms-webapp/src/main/webapp/admin/sched-outages/editoutage.jsp index bc0d6d1..362d249 100644 --- a/opennms-webapp/src/main/webapp/admin/sched-outages/editoutage.jsp +++ b/opennms-webapp/src/main/webapp/admin/sched-outages/editoutage.jsp @@ -541,6 +541,18 @@ Could not find an outage to edit because no outage name parameter was specified String newNode = request.getParameter("newNode"); if (newNode == null || "".equals(newNode.trim())) { // No node was specified + } else if (newNode.startsWith("@")) { + String category = newNode.substring(1); + for (OnmsNode node : NetworkElementFactory.getInstance(getServletContext()).getNodesWithCategories(new String[] { category }, false)) { + addNode(theOutage, node.getId()); + } + } else if (newNode.startsWith("$")) { + String foreignSource = newNode.substring(1); + for (OnmsNode node : NetworkElementFactory.getInstance(getServletContext()).getAllNodes()) { + if (node.getForeignSource() != null && node.getForeignSource().equals(foreignSource)) { + addNode(theOutage, node.getId()); + } + } } else { int newNodeId = WebSecurityUtils.safeParseInt(newNode); addNode(theOutage, newNodeId); @@ -863,7 +875,7 @@ function updateOutageTypeDisplay(selectElement) {
-

Search (max 200 results):

+

Search (max 200 results, Prefix search string with '@' to search for categories,
'#' to search for nodes in a category, '$' for requisitions,
and '%' for nodes in a requisition):

Add with path outage dependency diff --git a/opennms-webapp/src/main/webapp/admin/sched-outages/jsonNodes.jsp b/opennms-webapp/src/main/webapp/admin/sched-outages/jsonNodes.jsp index f1553cd..9768a2b 100644 --- a/opennms-webapp/src/main/webapp/admin/sched-outages/jsonNodes.jsp +++ b/opennms-webapp/src/main/webapp/admin/sched-outages/jsonNodes.jsp @@ -37,6 +37,7 @@ org.opennms.netmgt.config.poller.*, org.opennms.core.utils.WebSecurityUtils, org.opennms.web.element.*, + org.opennms.netmgt.model.OnmsCategory, org.opennms.netmgt.model.OnmsNode, org.opennms.netmgt.EventConstants, org.opennms.netmgt.xml.event.Event, @@ -56,66 +57,133 @@ * format that the jQuery autocomplete is expecting. */ public static class AutocompleteRecord { - private String m_label; - private int m_value; + private String m_label; + private String m_value; - public AutocompleteRecord(String label, int value) { - m_label = label; - m_value = value; - } + public AutocompleteRecord(String label, int value) { + m_label = label; + m_value = Integer.toString(value); + } - public String getLabel() { - return m_label; - } + public AutocompleteRecord(String label, String value) { + m_label = label; + m_value = value; + } - public int getValue() { - return m_value; - } + public String getLabel() { + return m_label; + } + + public String getValue() { + return m_value; + } } %> +[ <% List items = NetworkElementFactory.getInstance(getServletContext()).getAllNodes(); %> -[ <% boolean printedFirst = false; +boolean listCategories = false; +boolean listForeignSources = false; int recordCounter = 1; final int recordLimit = 200; String autocomplete = request.getParameter("term"); +String category = null; +String foreignSource = null; Pattern pattern = null; if (autocomplete != null && !"".equals(autocomplete)) { - pattern = Pattern.compile(autocomplete, Pattern.LITERAL + Pattern.CASE_INSENSITIVE); + if (autocomplete.startsWith("#")) { + category = autocomplete.substring(1); + } else if (autocomplete.startsWith("@")) { + category = autocomplete.substring(1); + listCategories = true; + } else if (autocomplete.startsWith("%")) { + foreignSource = autocomplete.substring(1); + } else if (autocomplete.startsWith("$")) { + foreignSource = autocomplete.substring(1); + listForeignSources = true; + } else { + pattern = Pattern.compile(autocomplete, Pattern.LITERAL + Pattern.CASE_INSENSITIVE); + } } -for (OnmsNode item : items) { - // Check to see if the item matches the search term - Matcher matcher = null; - if (pattern != null) { - matcher = pattern.matcher(item.getLabel()); - } - if (pattern == null || (matcher != null && matcher.find())) { - StringBuffer result = new StringBuffer(); - if (pattern != null) { - matcher.reset(); - while (matcher.find()) { - matcher.appendReplacement(result, "" + matcher.group(0) + ""); - } - matcher.appendTail(result); - } else { - result.append(item.getLabel()); - } - result.append(" (Node ID ").append(item.getId()).append(")"); - // If we've already printed the first item, separate the items with a comma - if (printedFirst) { - out.println(","); - } - out.println(JSONSerializer.toJSON(new AutocompleteRecord(result.toString(), item.getId()))); - printedFirst = true; - // Don't print more than a certain number of records to limit the - // performance impact in the web browser - if (recordCounter++ >= recordLimit) { - break; - } - } +if (listCategories) { + Set set = new HashSet(); + for (OnmsNode item : items) { + set.addAll(item.getCategories()); + } + for (OnmsCategory cat : set) { + if (cat.getName().startsWith(category)) { + if (printedFirst) { + out.println(","); + } + out.println(JSONSerializer.toJSON(new AutocompleteRecord("@"+cat.getName(), "@"+cat.getName()))); + printedFirst = true; + } + } + +} else if (listForeignSources) { + Set set = new HashSet(); + for (OnmsNode item : items) { + if (item.getForeignSource() != null && !"".equals(item.getForeignSource())) { + set.add(item.getForeignSource()); + } + } + for (String fSource : set) { + if (fSource.startsWith(foreignSource)) { + if (printedFirst) { + out.println(","); + } + out.println(JSONSerializer.toJSON(new AutocompleteRecord("$"+cat.getName(), "$"+cat.getName()))); + printedFirst = true; + } + } + +} else { + for (OnmsNode item : items) { + // Check to see if the item matches the search term + Matcher matcher = null; + if (pattern != null) { + matcher = pattern.matcher(item.getLabel()); + } + if (pattern == null || (matcher != null && matcher.find())) { + StringBuffer result = new StringBuffer(); + if (pattern != null) { + matcher.reset(); + while (matcher.find()) { + matcher.appendReplacement(result, "" + matcher.group(0) + ""); + } + matcher.appendTail(result); + } else if (category != null) { + if (item.hasCategory(category)) { + result.append(item.getLabel()); + } else { + continue; + } + } else if (foreignSource != null) { + if (item.getForeignSource() != null && item.getForeignSource().startsWith(foreignSource)) { + result.append(item.getLabel()); + } else { + continue; + } + } else { + result.append(item.getLabel()); + } + result.append(" (Node ID ").append(item.getId()).append(")"); + // If we've already printed the first item, separate the items with a comma + if (printedFirst) { + out.println(","); + } + out.println(JSONSerializer.toJSON(new AutocompleteRecord(result.toString(), item.getId()))); + printedFirst = true; + // Don't print more than a certain number of records to limit the + // performance impact in the web browser + if (recordCounter++ >= recordLimit) { + break; + } + } + } } %> ] -- 1.8.3.1