From: Alex Bennee <[email protected]>
This is another pre-requisite for slippy maps. This adds a number of
servlets that allow fetching of node data in a JSON encoded form for
processing by client side JavaScript. The new servlets are:
* getMapViewCategories - fetch a list of categories
* getMapNodes - fetch a list of nodes based on category
---
.../org/opennms/web/nodemap/CategoryResult.java | 57 +++
.../org/opennms/web/nodemap/CategoryServlet.java | 154 +++++++
.../org/opennms/web/nodemap/MapNodeServlet.java | 449 ++++++++++++++++++++
.../java/org/opennms/web/nodemap/NodeResult.java | 152 +++++++
opennms-webapp/src/main/webapp/WEB-INF/web.xml | 21 +
5 files changed, 833 insertions(+), 0 deletions(-)
create mode 100644
opennms-webapp/src/main/java/org/opennms/web/nodemap/CategoryResult.java
create mode 100644
opennms-webapp/src/main/java/org/opennms/web/nodemap/CategoryServlet.java
create mode 100644
opennms-webapp/src/main/java/org/opennms/web/nodemap/MapNodeServlet.java
create mode 100644
opennms-webapp/src/main/java/org/opennms/web/nodemap/NodeResult.java
diff --git
a/opennms-webapp/src/main/java/org/opennms/web/nodemap/CategoryResult.java
b/opennms-webapp/src/main/java/org/opennms/web/nodemap/CategoryResult.java
new file mode 100644
index 0000000..e9b0f21
--- /dev/null
+++ b/opennms-webapp/src/main/java/org/opennms/web/nodemap/CategoryResult.java
@@ -0,0 +1,57 @@
+
+package org.opennms.web.nodemap;
+
+
+public class CategoryResult {
+
+ private int id;
+ private String name;
+ private String description;
+
+ public int getId() {
+ return id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getDesc() {
+ return description;
+ }
+
+ public void setDesc(String desc) {
+ this.description = desc;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+
+ public CategoryResult(int id, String name, String desc) {
+ this.id = id;
+ this.name = name;
+ this.description = desc;
+ }
+
+ public CategoryResult() {
+ }
+
+ public String toJson() {
+ String out = "{ ";
+
+ out += "\"id\": " + id + ", ";
+ out += "\"name\": \"" + name + "\", ";
+ out += "\"description\": \"" + description + "\"";
+ out += " }";
+
+ return out;
+
+ }
+
+}
diff --git
a/opennms-webapp/src/main/java/org/opennms/web/nodemap/CategoryServlet.java
b/opennms-webapp/src/main/java/org/opennms/web/nodemap/CategoryServlet.java
new file mode 100644
index 0000000..5621b60
--- /dev/null
+++ b/opennms-webapp/src/main/java/org/opennms/web/nodemap/CategoryServlet.java
@@ -0,0 +1,154 @@
+//
+// This file is part of the OpenNMS(R) Application.
+//
+// OpenNMS(R) is Copyright (C) 2002-2003 The OpenNMS Group, Inc. All rights
reserved.
+// OpenNMS(R) is a derivative work, containing both original code, included
code and modified
+// code that was published under the GNU General Public License. Copyrights
for modified
+// and included code are below.
+//
+// OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
+//
+// Copyright (C) 1999-2001 Oculan Corp. All rights reserved.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+// For more information contact:
+// OpenNMS Licensing <[email protected]>
+// http://www.opennms.org/
+// http://www.opennms.com/
+//
+
+package org.opennms.web.nodemap;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.opennms.core.utils.DBUtils;
+import org.opennms.netmgt.config.DataSourceFactory;
+
+public class CategoryServlet extends HttpServlet {
+ private static final long serialVersionUID = 1L;
+
+
+ public void init() throws ServletException {
+ try {
+ DataSourceFactory.init();
+ } catch (Exception e) {
+ }
+ }
+
+ private static final String GET_CAT_QUERY = "SELECT categoryid,
categoryname, categorydescription FROM categories";
+
+
+ private List<CategoryResult> getCats() throws SQLException {
+ final DBUtils d = new DBUtils();
+ Connection connection = null;
+ List<CategoryResult> categories = new ArrayList<CategoryResult>();
+
+ try {
+ PreparedStatement stmt;
+ ResultSet results;
+
+ connection = DataSourceFactory.getInstance().getConnection();
+ d.watch(connection);
+
+ stmt = connection.prepareStatement(GET_CAT_QUERY);
+ d.watch(stmt);
+
+ results = stmt.executeQuery();
+ d.watch(results);
+
+ if (results != null) {
+ while (results.next()) {
+ CategoryResult cat = new CategoryResult();
+
+ cat.setId(results.getInt(1));
+ cat.setName(results.getString(2));
+ cat.setDesc(results.getString(3));
+
+ categories.add(cat);
+ }
+ }
+ } finally {
+ d.cleanUp();
+ }
+
+
+ return categories;
+ }
+
+ private String getResponse() throws SQLException {
+ String out = "";
+ List<CategoryResult> cats = getCats();
+
+ out += "[";
+ for (CategoryResult cat : cats) {
+ out += cat.toJson() + ",\n";
+ }
+ out += "]";
+
+ return out;
+ }
+
+
+ protected void doGet(HttpServletRequest req,
+ HttpServletResponse res)
+ throws ServletException, IOException
+ {
+ String out_str;
+
+
+ PrintWriter out = res.getWriter();
+
+ try {
+ String obj_str = getResponse();
+ res.setContentType("text/plain");
+ out_str = obj_str;
+ } catch (Exception e) {
+ final StackTraceElement[] stackTrace = e.getStackTrace();
+ String st = "";
+ for (StackTraceElement element : stackTrace) {
+ st += "Exception thrown from " + element.getMethodName() +
+ " in class " + element.getClassName() +
+ " [on line number " + element.getLineNumber() +
+ " of file " + element.getFileName() + "]<br/>";
+ }
+
+ res.setContentType("text/html");
+ out_str = "<HTML><HEAD><TITLE>Hello Client</TITLE>"+
+ "</HEAD><BODY>"+ e + "<br/>"+ st + "</BODY></HTML>";
+ }
+
+
+ out.println(out_str);
+ out.close();
+ }
+
+ public String getServletInfo()
+ {
+ return "HelloClientServlet 1.0 by Stefan Zeiger";
+ }
+}
diff --git
a/opennms-webapp/src/main/java/org/opennms/web/nodemap/MapNodeServlet.java
b/opennms-webapp/src/main/java/org/opennms/web/nodemap/MapNodeServlet.java
new file mode 100644
index 0000000..6d5612e
--- /dev/null
+++ b/opennms-webapp/src/main/java/org/opennms/web/nodemap/MapNodeServlet.java
@@ -0,0 +1,449 @@
+//
+// This file is part of the OpenNMS(R) Application.
+//
+// OpenNMS(R) is Copyright (C) 2002-2003 The OpenNMS Group, Inc. All rights
reserved.
+// OpenNMS(R) is a derivative work, containing both original code, included
code and modified
+// code that was published under the GNU General Public License. Copyrights
for modified
+// and included code are below.
+//
+// OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
+//
+// Modifications:
+//
+// Copyright (C) 1999-2010 Cambridge Broadband Networks. All rights reserved.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+// For more information contact:
+// OpenNMS Licensing <[email protected]>
+// http://www.opennms.org/
+// http://www.opennms.com/
+//
+
+package org.opennms.web.nodemap;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.HashMap;
+import java.util.List;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.opennms.core.utils.DBUtils;
+import org.opennms.netmgt.config.DataSourceFactory;
+
+/*
+ MapNodeServlet
+
+ This servlet is used to supply a list of nodes to the node_map
implementation.
+ The data is returned as JSON encoded text ready to be processed by the node
map
+ JavaScript.
+ */
+
+public class MapNodeServlet extends HttpServlet {
+ private static final long serialVersionUID = 1L;
+
+
+ private Timestamp getNow() {
+ Calendar cal = new GregorianCalendar();
+ Date end = cal.getTime();
+
+ return new Timestamp(end.getTime());
+ }
+
+ private Timestamp getYesterday() {
+ Calendar cal = new GregorianCalendar();
+ cal.add(Calendar.DATE, -1);
+ Date start = cal.getTime();
+
+ return new Timestamp(start.getTime());
+ }
+
+
+ public void init() throws ServletException {
+ try {
+ DataSourceFactory.init();
+ } catch (Exception e) {
+ }
+ }
+
+ // Get nodes without parents
+ private static final String GET_PARENTS_QUERY = "SELECT node.nodeid,
node.nodelabel, getManagePercentAvailNodeWindow(node.nodeid, ?, ?),
node_geolocation.geolocationlatitude, node_geolocation.geolocationlongitude,
node.foreignid FROM node INNER JOIN node_geolocation ON node_geolocation.nodeid
= node.nodeid WHERE node.nodeparentid IS NULL ORDER BY node.nodeid";
+
+ // Get child nodes
+ private static final String GET_CHILDREN_QUERY = "SELECT node.nodeid,
node.nodelabel, getManagePercentAvailNodeWindow(node.nodeid, ?, ?),
node_geolocation.geolocationlatitude, node_geolocation.geolocationlongitude,
node.nodeparentid, node.foreignid FROM node INNER JOIN node_geolocation ON
node_geolocation.nodeid = node.nodeid WHERE node.nodeparentid IS NOT NULL AND
node.nodeparentid = ? ORDER BY node.nodeparentid";
+
+ private static final String GET_CAT_QUERY = "SELECT node.nodeid,
node.nodelabel, getManagePercentAvailNodeWindow(node.nodeid, ?, ?),
node_geolocation.geolocationlatitude, node_geolocation.geolocationlongitude,
node.nodeparentid, node.foreignid, category_node.categoryid FROM (node INNER
JOIN node_geolocation ON node_geolocation.nodeid = node.nodeid) INNER JOIN
category_node on category_node.nodeid = node.nodeid WHERE
category_node.categoryid = ?";
+
+ private static final String GET_UCAT_QUERY = "SELECT node.nodeid,
node.nodelabel, getManagePercentAvailNodeWindow(node.nodeid, ?, ?),
node_geolocation.geolocationlatitude, node_geolocation.geolocationlongitude,
node.nodeparentid, node.foreignid, category_node.categoryid FROM (node INNER
JOIN node_geolocation ON node_geolocation.nodeid = node.nodeid) LEFT JOIN
category_node on category_node.nodeid = node.nodeid WHERE
category_node.categoryid IS NULL";
+
+ private static final String GET_OUTAGES_QUERY = "SELECT nodeid,
eventuei,severity FROM alarms WHERE nodeid IS NOT NULL ORDER BY nodeid,
lasteventtime desc";
+
+
+ private void getStatus(List< HashMap<Integer, NodeResult> > hashes) throws
SQLException {
+ final DBUtils d = new DBUtils();
+ Connection connection = null;
+
+ try {
+ PreparedStatement stmt;
+ ResultSet results;
+ NodeResult node;
+
+ connection = DataSourceFactory.getInstance().getConnection();
+ d.watch(connection);
+
+ stmt = connection.prepareStatement(GET_OUTAGES_QUERY);
+ d.watch(stmt);
+
+ results = stmt.executeQuery();
+ d.watch(results);
+
+ if (results != null) {
+ while (results.next()) {
+ int nodeid = results.getInt(1);
+ String uei = results.getString(2);
+ int severity = results.getInt(3);
+
+ for (HashMap<Integer, NodeResult> nodes : hashes) {
+ node = nodes.get(nodeid);
+
+ if (node != null) {
+ node.setEventUei(uei);
+ node.setSeverity(severity);
+ }
+ }
+ }
+ }
+
+ } finally {
+ d.cleanUp();
+ }
+
+ }
+
+ // Create a hash map of all children (nodes with parents)
+ private HashMap<Integer, NodeResult> getChildren(int parent_id, int
child_depth) throws SQLException {
+ final DBUtils d = new DBUtils();
+ Connection connection = null;
+ HashMap<Integer, NodeResult> children =
+ new HashMap<Integer, NodeResult>();
+
+ try {
+ PreparedStatement stmt;
+ ResultSet results;
+
+ connection = DataSourceFactory.getInstance().getConnection();
+ d.watch(connection);
+
+ stmt = connection.prepareStatement(GET_CHILDREN_QUERY);
+ stmt.setTimestamp(1, getNow());
+ stmt.setTimestamp(2, getYesterday());
+ stmt.setInt(3, parent_id);
+ d.watch(stmt);
+
+ results = stmt.executeQuery();
+ d.watch(results);
+
+ if (results != null) {
+ while (results.next()) {
+ NodeResult child = new NodeResult();
+
+ child.setNodeId(results.getInt(1));
+ child.setNodeLabel(results.getString(2));
+ child.setAvail(results.getDouble(3));
+ child.setGeolocationLat(results.getDouble(4));
+ child.setGeolocationLon(results.getDouble(5));
+ child.setParentNodeId(results.getInt(6));
+ child.setForeignId(results.getString(7));
+ child.setType(NodeResult.NODE_TYPE_CHILD);
+
+ children.put(child.getNodeId(), child);
+ }
+ }
+ } finally {
+ d.cleanUp();
+ }
+
+ /* recurse deeper? */
+ if (child_depth>0) {
+ List< HashMap<Integer, NodeResult> > hashes = new ArrayList<
HashMap<Integer, NodeResult> >();
+ for (NodeResult p : children.values()) {
+ HashMap<Integer, NodeResult> more_children =
getChildren(p.getNodeId(), child_depth-1);
+ hashes.add(more_children);
+ for (NodeResult child : more_children.values()) {
+ p.addChild(child);
+ }
+ }
+ getStatus(hashes);
+ }
+
+ return children;
+ }
+
+
+ private HashMap<Integer, NodeResult> getCategory(int category_id) throws
SQLException {
+ final DBUtils d = new DBUtils();
+ Connection connection = null;
+ HashMap<Integer, NodeResult> nodes =
+ new HashMap<Integer, NodeResult>();
+
+ try {
+ PreparedStatement stmt;
+ ResultSet results;
+
+ connection = DataSourceFactory.getInstance().getConnection();
+ d.watch(connection);
+
+ if (category_id >= 0) {
+ stmt = connection.prepareStatement(GET_CAT_QUERY);
+ } else {
+ stmt = connection.prepareStatement(GET_UCAT_QUERY);
+ }
+ stmt.setTimestamp(1, getNow());
+ stmt.setTimestamp(2, getYesterday());
+
+ if (category_id >= 0) {
+ stmt.setInt(3, category_id);
+ }
+ d.watch(stmt);
+
+ results = stmt.executeQuery();
+ d.watch(results);
+
+ if (results != null) {
+ while (results.next()) {
+ NodeResult node = new NodeResult();
+
+ node.setNodeId(results.getInt(1));
+ node.setNodeLabel(results.getString(2));
+ node.setAvail(results.getDouble(3));
+ node.setGeolocationLat(results.getDouble(4));
+ node.setGeolocationLon(results.getDouble(5));
+ node.setParentNodeId(results.getInt(6));
+ node.setForeignId(results.getString(7));
+ node.setType(NodeResult.NODE_TYPE_GENERAL);
+
+ nodes.put(node.getNodeId(), node);
+ }
+ }
+ } finally {
+ d.cleanUp();
+ }
+
+ return nodes;
+ }
+
+
+ private HashMap<Integer, NodeResult> getParents() throws SQLException {
+ final DBUtils d = new DBUtils();
+ Connection connection = null;
+ HashMap<Integer, NodeResult> parents = new HashMap<Integer,
NodeResult>();
+
+ try {
+ PreparedStatement stmt;
+ ResultSet results;
+
+ connection = DataSourceFactory.getInstance().getConnection();
+ d.watch(connection);
+
+ stmt = connection.prepareStatement(GET_PARENTS_QUERY);
+ stmt.setTimestamp(1, getNow());
+ stmt.setTimestamp(2, getYesterday());
+ d.watch(stmt);
+
+ results = stmt.executeQuery();
+ d.watch(results);
+
+ if (results != null) {
+ while (results.next()) {
+ NodeResult p = new NodeResult();
+
+ p.setNodeId(results.getInt(1));
+ p.setNodeLabel(results.getString(2));
+ p.setAvail(results.getDouble(3));
+ p.setGeolocationLat(results.getDouble(4));
+ p.setGeolocationLon(results.getDouble(5));
+ p.setForeignId(results.getString(6));
+ p.setType(NodeResult.NODE_TYPE_PARENT);
+
+ parents.put(p.getNodeId(), p);
+ }
+ }
+ } finally {
+ d.cleanUp();
+ }
+
+
+ return parents;
+ }
+
+ private String getFromCat(int category_id, int child_depth) throws
SQLException {
+ String out = "";
+
+ HashMap<Integer, NodeResult> nodes = getCategory(category_id);
+ List< HashMap<Integer, NodeResult> > hashes = new ArrayList<
HashMap<Integer, NodeResult> >();
+ hashes.add(nodes);
+
+
+ out += "/* getFromCat("+category_id+") child_depth:"+child_depth+"\n";
+ if (child_depth>0) {
+ for (NodeResult p : nodes.values()) {
+ HashMap<Integer, NodeResult> children =
getChildren(p.getNodeId(), child_depth-1);
+ hashes.add(children);
+
+ out +=
"Node:"+p.getNodeId()+"/"+p.getNodeLabel()+"/"+p.getForeignId()+" has
"+children.size()+" children\n";
+
+ for (NodeResult child : children.values()) {
+ p.addChild(child);
+ }
+ }
+ }
+ out += "*/\n";
+
+ // process the status of each element
+ getStatus(hashes);
+
+ // The actual json data
+ out += "[";
+ for (NodeResult node : nodes.values()) {
+ out += node.toJson() + ",\n";
+ }
+ out += "]";
+
+ return out;
+ }
+
+ private String getAll(int child_depth) throws SQLException {
+ String out = "";
+
+ HashMap<Integer, NodeResult> parents = getParents();
+
+ List< HashMap<Integer, NodeResult> > hashes = new ArrayList<
HashMap<Integer, NodeResult> >();
+ hashes.add(parents);
+
+
+ // Debugging output in the response, ignored by the JavaScript
+ out += "/* getAll() child_depth:"+child_depth+"\n";
+
+ if (child_depth>0) {
+ for (NodeResult p : parents.values()) {
+ HashMap<Integer, NodeResult> children =
getChildren(p.getNodeId(), child_depth-1);
+ hashes.add(children);
+
+ out +=
"Node:"+p.getNodeId()+"/"+p.getNodeLabel()+"/"+p.getForeignId()+" has
"+children.size()+" children\n";
+
+ for (NodeResult child : children.values()) {
+ p.addChild(child);
+ }
+ }
+ }
+ out += "*/\n";
+
+ // process the status of each element
+ getStatus(hashes);
+
+ // The actual json data
+ out += "[";
+
+ for (NodeResult p : parents.values()) {
+ out += p.toJson() + ",\n";
+ }
+ out += "]";
+
+ return out;
+ }
+
+
+ private String getResponse(String category, String depth) throws
SQLException {
+ int child_depth = 0;
+ try {
+ child_depth = Integer.parseInt(depth);
+ } catch (NumberFormatException e) {
+ child_depth = 0;
+ }
+
+ if (category != null) {
+ if (category.equals("ALL")) {
+ return getAll(child_depth);
+ } else if (category.equals("UCAT")) {
+ return getFromCat(-1, 0);
+ } else {
+ int cat;
+
+ try {
+ cat = Integer.parseInt(category);
+ return getFromCat(cat, child_depth);
+ } catch (NumberFormatException e) {
+ return getAll(child_depth);
+ }
+ }
+ } else {
+ return getAll(child_depth);
+ }
+ }
+
+ // Main entry into servlet
+ protected void doGet(HttpServletRequest req,
+ HttpServletResponse res)
+ throws ServletException, IOException
+ {
+ String out_str;
+
+ String category = req.getParameter("cat");
+ String child_depth = req.getParameter("depth");
+
+ PrintWriter out = res.getWriter();
+
+ try {
+ String obj_str = getResponse(category, child_depth);
+ res.setContentType("text/plain");
+ out_str = obj_str;
+ } catch (Exception e) {
+ final StackTraceElement[] stackTrace = e.getStackTrace();
+ String st = "";
+ for (StackTraceElement element : stackTrace) {
+ st += "Exception thrown from " + element.getMethodName() +
+ " in class " + element.getClassName() +
+ " [on line number " + element.getLineNumber() +
+ " of file " + element.getFileName() + "]<br/>";
+ }
+
+ res.setContentType("text/html");
+ out_str = "<HTML><HEAD><TITLE>Unexpected Error</TITLE>"+
+ "</HEAD><BODY>"+ e + "<br/>"+ st + "</BODY></HTML>";
+ }
+
+
+ out.println(out_str);
+ out.close();
+ }
+
+ public String getServletInfo()
+ {
+ return "HelloClientServlet 1.0 by Stefan Zeiger";
+ }
+}
diff --git
a/opennms-webapp/src/main/java/org/opennms/web/nodemap/NodeResult.java
b/opennms-webapp/src/main/java/org/opennms/web/nodemap/NodeResult.java
new file mode 100644
index 0000000..efd5371
--- /dev/null
+++ b/opennms-webapp/src/main/java/org/opennms/web/nodemap/NodeResult.java
@@ -0,0 +1,152 @@
+
+package org.opennms.web.nodemap;
+
+import java.text.DecimalFormat;
+import java.util.List;
+import java.util.ArrayList;
+
+public class NodeResult {
+
+ private int nodeId;
+ private int parentNodeId;
+ private int type;
+ private String nodeLabel;
+ private String foreignId;
+ private double geolocationLat;
+ private double geolocationLon;
+ private double avail;
+
+ public static final int NODE_TYPE_GENERAL = 0;
+ public static final int NODE_TYPE_CHILD = 1;
+ public static final int NODE_TYPE_PARENT = 2;
+
+ private static final DecimalFormat AVAILABILITY_FORMAT = new
DecimalFormat("0.000");
+
+ // select nodeid, eventuei,severity from alarms where nodeid is not
null and severity > 3 order by nodeid, lasteventtime desc;
+ private String eventuei;
+ private int severity;
+
+ /*
+ Handling for children
+ */
+
+ private List<NodeResult> children;
+
+ NodeResult() {
+ children = new ArrayList<NodeResult>();
+ }
+
+ public void addChild(NodeResult child) {
+ children.add(child);
+ }
+
+ public void setEventUei(String eventuei) {
+ this.eventuei = eventuei;
+ }
+
+ public void setForeignId(String fid) {
+ this.foreignId = fid;
+ }
+
+ public String getEventUei() {
+ return eventuei;
+ }
+
+ public String getForeignId() {
+ return foreignId;
+ }
+
+ public void setSeverity(int severity) {
+ this.severity = severity;
+ }
+
+ public int getSeverity() {
+ return severity;
+ }
+
+ public void setAvail(double avail) {
+ this.avail = avail;
+ }
+
+ public double getAvail() {
+ return avail;
+ }
+
+ public int getType() {
+ return type;
+ }
+
+ public void setNodeId(int nodeId) {
+ this.nodeId = nodeId;
+ }
+
+ public void setType(int type) {
+ this.type = type;
+ }
+
+ public int getNodeId() {
+ return nodeId;
+ }
+
+ public void setParentNodeId(int parentNodeId) {
+ this.parentNodeId = parentNodeId;
+ }
+
+ public int getParentNodeId() {
+ return parentNodeId;
+ }
+
+ public void setNodeLabel(String nodeLabel) {
+ this.nodeLabel = nodeLabel;
+ }
+
+ public String getNodeLabel() {
+ return nodeLabel;
+ }
+
+ public void setGeolocationLat(double lat) {
+ this.geolocationLat = lat;
+ }
+
+ public double getGeolocationLat() {
+ return geolocationLat;
+ }
+
+ public void setGeolocationLon(double lon) {
+ this.geolocationLon = lon;
+ }
+
+ public double getGeolocationLon() {
+ return geolocationLon;
+ }
+
+ public String formatAvailability() {
+ return AVAILABILITY_FORMAT.format(avail);
+ }
+
+ public String toJson() {
+ String out = "{ \"nodeId\" : " + nodeId + ", " +
+ "\"type\" : " + type + ", " +
+ "\"parentnodeid\" : \"" + parentNodeId + "\", " +
+ "\"nodeLabel\" : \"" + nodeLabel + "\", " +
+ "\"avail\" : \"" + formatAvailability() + "\", " +
+ "\"latitude\" : " + geolocationLat + ", " +
+ "\"longitude\" : " + geolocationLon + ", " +
+ "\"eventuei\" : \"" + eventuei + "\", " +
+ "\"foreignId\" : \"" + foreignId + "\", " +
+ "\"severity\" : " + severity;
+
+ // If we have children dump them too...
+ if (!children.isEmpty()) {
+ out += ", \"children\" : [\n";
+ for (NodeResult child : children) {
+ out += "\t" + child.toJson() + ",\n";
+ }
+ out += "]";
+ }
+
+ out += "}\n";
+ return out;
+ }
+
+}
diff --git a/opennms-webapp/src/main/webapp/WEB-INF/web.xml
b/opennms-webapp/src/main/webapp/WEB-INF/web.xml
index 5dc3a6a..c000855 100644
--- a/opennms-webapp/src/main/webapp/WEB-INF/web.xml
+++ b/opennms-webapp/src/main/webapp/WEB-INF/web.xml
@@ -598,6 +598,17 @@
</servlet>
<servlet>
+ <servlet-name>getMapNodes</servlet-name>
+ <servlet-class>org.opennms.web.nodemap.MapNodeServlet</servlet-class>
+ </servlet>
+
+ <servlet>
+ <servlet-name>getMapViewCategories</servlet-name>
+ <servlet-class>org.opennms.web.nodemap.CategoryServlet</servlet-class>
+ </servlet>
+
+
+ <servlet>
<servlet-name>nodeRescan</servlet-name>
<servlet-class>org.opennms.web.element.NodeRescanServlet</servlet-class>
</servlet>
@@ -888,6 +899,16 @@
</servlet-mapping>
<servlet-mapping>
+ <servlet-name>getMapNodes</servlet-name>
+ <url-pattern>/nodemap/getMapNodes</url-pattern>
+ </servlet-mapping>
+
+ <servlet-mapping>
+ <servlet-name>getMapViewCategories</servlet-name>
+ <url-pattern>/nodemap/getMapViewCategories</url-pattern>
+ </servlet-mapping>
+
+ <servlet-mapping>
<servlet-name>nodeRescan</servlet-name>
<url-pattern>/element/rescan</url-pattern>
</servlet-mapping>
--
1.7.5.2
------------------------------------------------------------------------------
Simplify data backup and recovery for your virtual environment with vRanger.
Installation's a snap, and flexible recovery options mean your data is safe,
secure and there when you need it. Data protection magic?
Nope - It's vRanger. Get your free trial download today.
http://p.sf.net/sfu/quest-sfdev2dev
_______________________________________________
Please read the OpenNMS Mailing List FAQ:
http://www.opennms.org/index.php/Mailing_List_FAQ
opennms-devel mailing list
To *unsubscribe* or change your subscription options, see the bottom of this
page:
https://lists.sourceforge.net/lists/listinfo/opennms-devel