The JavaScript library provides encapsulated access to the REST APIs that are commonly needed. The following methods are available:
createSession
deleteSession
ping
readElementValue
readElementAttributes
readElementChildren
readElementAlarmsRealtime
performElementOperation
To learn more about the JavaScript library, see the following sections:
<script type="text/ecmascript" src="scripts/1.0/bsm.web2connect.js"></script>
<script language="text/ecmascript"> var w = new Web2Connect(); w.Session.Protocol = "http"; w.Session.Host = "localhost"; w.Session.Port = "80"; w.Session.Username = "admin"; w.Session.Password = "formula"; w.createSession(logonSuccess, logonFail); function logonSuccess() { alert("yippee!"); w.deleteSession(null, null); } function logonFail() { alert("boo hoo"); } </script>
All methods must be passed references to handler functions for success and fail asynchronous callbacks. Null references can be used if callbacks are not required.
/* Web 2.0 Connect Lib */ // Namespaces if (!BSM) { var BSM = { __bsm : this, __namespace : true }; } if (!BSM.Utils) { BSM.Utils = { __utils : this, __namespace :true }; } /* BSM utility class */ BSM.Utils.ColorSettings = { BackgroundColors : { UNKNOWN : "#808080", BUSY : "#43CFED", ACTIVE : "#43CFED", UNMANAGED : "#BAA860", IDLE : "#80FF80", INITIAL : "#BAA860", CRITICAL : "#ff4040", MAJOR : "#FEA342", MINOR : "#F3F171", INFORMATIONAL : "#43CFED", OK : "#80FF80" }, ForegroundColors : { UNKNOWN : "#FFFFFF", BUSY : "#000000", ACTIVE : "#000000", UNMANAGED : "#FFFFFF", IDLE : "#000000", INITIAL : "#FFFFFF", CRITICAL : "#FFFFFF", MAJOR : "#000000", MINOR : "#000000", INFORMATIONAL : "#FFFFFF", OK : "#000000" } }; /* Web2Connect API manager class */ BSM.Web2Connect = function() { _w2c = this; // Constants this._W2C_EXTERNAL_ROOT_CONTEXT = "/moweb2cn/"; this._W2C_INTERNAL_ROOT_CONTEXT = "/ManagedObjectsPortlets/"; // Namespaces this.Data = {}; this.Data.JSON = {}; this.Utils = {}; this.Interface = {}; // Enums this.HttpProtocol = { HTTP: "http", HTTPS: "https" }; this.HttpMethod = { GET: "GET", POST: "POST", UPDATE: "UPDATE", DELETE: "DELETE" }; this.HttpResponseCode = { SUCCESS: 200, NOT_AUTHORIZED: 403, NOT_FOUND: 404, SERVER_ERROR: 500 }; this.XmlHttpRequestState = { STARTED: 1, PROCESSING: 2, COMPLETE: 4 }; this.RootContext = { EXTERNAL_ROOT_CONTEXT: _w2c._W2C_EXTERNAL_ROOT_CONTEXT, INTERNAL_ROOT_CONTEXT: _w2c._W2C_INTERNAL_ROOT_CONTEXT }; this.ApiFormat = { JSON: "json", REST: "rest", XML: "xml" }; this.ApiMethodUri = { SESSION: "session", USER: "user", PING: "ping", COLOR_SETTINGS: "colorSettings", ELEMENT_VALUE: "element/value/", ELEMENT_ATTRIBUTES: "element/attributes/", ELEMENT_CHILDREN: "element/children/", ELEMENT_CHILDREN_ATTRIBUTES: "element/childrenAttributes/", ELEMENT_RELATIONSHIPS: "element/relationships/", ELEMENT_RELATED: "element/related/", ELEMENT_PERFORM: "element/perform/", ELEMENT_ALARMS_REALTIME: "element/alarms/{CHANNEL}/realtime/", ELEMENT_QUERY_PERFORMANCE_SERIES: "element/query/performance/{PROFILE}/{EXPRESSION}/series/", ELEMENT_QUERY_PERFORMANCE: "element/query/performance/" }; this.ApiMethodParameter = { USERNAME: "username", PASSWORD: "password", ATTRIBUTE_NAMES: "attributeNames", OPERATION_NAME: "operationName", LIMIT: "limit", FROM: "from", TO: "to" }; this.AlarmChannel = { ALL: "ALL", ANNOTATION: "ANNOTATION", AUDIT: "AUDIT", CHANGE: "CHANGE", GENERAL: "GENERAL", HISTORY: "HISTORY", SLA: "SLA", SLA_METRIC: "SLA_METRIC", OUTAGE: "OUTAGE" }; this.ChildType = { BOTH: "Both", LINKED: "Linked", STORED: "Stored" }; this.AttributeType = { STRING_LIST: "StringListType", STRING: "StringType", BOOLEAN: "BooleanType", INTEGER: "IntegerType", DOUBLE: "DoubleType", FLOAT: "FloatType", LONG: "LongType", DATE: "DateType", NULL: "NullType", UNKNOWN: "UnknownType" }; this.Synchronicity = { ASYNCHRONOUS: true, SYNCHRONOUS: false }; this.Data.JSON.Constants = { ALARMS: "moweb2cn.alarms", ELEMENTS: "moweb2cn.elements", ATTRIBUTES: "moweb2cn.attributes", PERFORMANCE_INFO: "moweb2cn.performanceInfo", PERFORMANCE_SERIES: "moweb2cn.performanceSeries" }; /* API methods */ // Create session this.createSession = function(successHandler, faultHandler) { var _createSession = {}; _createSession._sh = successHandler; _createSession._fh = faultHandler; _createSession.createSessionStateHandler = function(response) { if (_w2c.Session.getStatus() == _w2c.Session.State.READY) { _createSession._sh(response); } else { _createSession._fh(response); } }; _createSession.url = ""; _createSession.url += _w2c.ApiMethodUri.SESSION; _createSession.url += "?" + _w2c.ApiMethodParameter.USERNAME + "=" + _w2c.Session.Username; _createSession.url += "&" + _w2c.ApiMethodParameter.PASSWORD + "=" + _w2c.Session.Password; _createSession.request = new _w2c._remoteServiceRequest(); _createSession.request.method = _w2c.HttpMethod.GET; _createSession.request.handleSuccess = _createSession.createSessionStateHandler; _createSession.request.handleFault = _createSession.createSessionStateHandler; _createSession.request.setUrl(_createSession.url); _createSession.request.execute(_w2c.Synchronicity.SYNCHRONOUS); }; // Delete session this.deleteSession = function(successHandler, faultHandler) { var _deleteSession = {}; _deleteSession.url = ""; _deleteSession.url += _w2c.ApiMethodUri.SESSION; _deleteSession.request = new _w2c._remoteServiceRequest(); _deleteSession.request.method = _w2c.HttpMethod.DELETE; _deleteSession.request.handleSuccess = successHandler; _deleteSession.request.handleFault = faultHandler; _deleteSession.request.setUrl(_deleteSession.url); _deleteSession.request.execute(); }; // Element value this.readElementValue = function(elementIdentity, successHandler, faultHandler) { var _readElementValue = {}; _readElementValue.url = ""; _readElementValue.url += _w2c.ApiMethodUri.ELEMENT_VALUE; _readElementValue.url += elementIdentity; _readElementValue.request = new _w2c._remoteServiceRequest(); _readElementValue.request.method = _w2c.HttpMethod.GET; _readElementValue.request.handleSuccess = successHandler; _readElementValue.request.handleFault = faultHandler; _readElementValue.request.setUrl(_readElementValue.url); _readElementValue.request.execute(); }; // Element attributes this.readElementAttributes = function(elementIdentity, attributeNames, successHandler, faultHandler) { var _readElementAttributes = {}; _readElementAttributes.url = ""; _readElementAttributes.url += _w2c.ApiMethodUri.ELEMENT_ATTRIBUTES; _readElementAttributes.url += elementIdentity; _readElementAttributes.url += "?" + _w2c.ApiMethodParameter.ATTRIBUTE_NAMES + "=" + attributeNames.getDelimitedList(); _readElementAttributes.request = new _w2c._remoteServiceRequest(); _readElementAttributes.request.method = _w2c.HttpMethod.GET; _readElementAttributes.request.handleSuccess = successHandler; _readElementAttributes.request.handleFault = faultHandler; _readElementAttributes.request.setUrl(_readElementAttributes.url); _readElementAttributes.request.execute(); }; // Element attribute variant (singule attribute) this.readElementAttribute = function(elementIdentity, attributeName, successHandler, faultHandler, synchronicity) { var _readElementAttribute = {}; _readElementAttribute.url = ""; _readElementAttribute.url += _w2c.ApiMethodUri.ELEMENT_ATTRIBUTES; _readElementAttribute.url += elementIdentity; _readElementAttribute.url += "?" + _w2c.ApiMethodParameter.ATTRIBUTE_NAMES + "=" + attributeName; _readElementAttribute.request = new _w2c._remoteServiceRequest(); _readElementAttribute.request.method = _w2c.HttpMethod.GET; _readElementAttribute.request.handleSuccess = successHandler; _readElementAttribute.request.handleFault = faultHandler; _readElementAttribute.request.setUrl(_readElementAttribute.url); _readElementAttribute.request.execute(synchronicity); }; // Element children this.readElementChildren = function(elementIdentity, successHandler, faultHandler) { var _readElementChildren = {}; _readElementChildren._responseFormat = _w2c.Session.ApiFormat; _readElementChildren._successHandlerCallback = successHandler; _readElementChildren._faultHandlerCallback = faultHandler; _readElementChildren._successHandler = function(response) { var elements = null; try { if (_readElementChildren._responseFormat == _w2c.ApiFormat.JSON) { elements = _w2c.Data.JSON.parseElements(response); } } catch (ex) { response.exception = ex; _readElementChildren._faultHandlerCallback(response); } _readElementChildren._successHandlerCallback(response, elements); }; _readElementChildren.url = ""; _readElementChildren.url += _w2c.ApiMethodUri.ELEMENT_CHILDREN; _readElementChildren.url += elementIdentity; _readElementChildren.request = new _w2c._remoteServiceRequest(); _readElementChildren.request.method = _w2c.HttpMethod.GET; _readElementChildren.request.handleSuccess = _readElementChildren._successHandler; _readElementChildren.request.handleFault = faultHandler; _readElementChildren.request.setUrl(_readElementChildren.url); _readElementChildren.request.execute(); }; // Element children attributes this.readElementChildrenAttributes = function(elementIdentity, attributeNames, successHandler, faultHandler) { var _readElementChildrenAttributes = {}; _readElementChildrenAttributes.url = ""; _readElementChildrenAttributes.url += _w2c.ApiMethodUri.ELEMENT_CHILDREN_ATTRIBUTES; _readElementChildrenAttributes.url += elementIdentity; _readElementChildrenAttributes.url += "?" + _w2c.ApiMethodParameter.ATTRIBUTE_NAMES + "=" + attributeNames.getDelimitedList(); _readElementChildrenAttributes.request = new _w2c._remoteServiceRequest(); _readElementChildrenAttributes.request.method = _w2c.HttpMethod.GET; _readElementChildrenAttributes.request.handleSuccess = successHandler; _readElementChildrenAttributes.request.handleFault = faultHandler; _readElementChildrenAttributes.request.setUrl(_readElementChildrenAttributes.url); _readElementChildrenAttributes.request.execute(); }; // Element relationships this.readElementRelationships = function(elementIdentity, successHandler, faultHandler) { _readElementRelationships = {}; _readElementRelationships.url = ""; _readElementRelationships.url += _w2c.ApiMethodUri.ELEMENT_RELATIONSHIPS; _readElementRelationships.url += elementIdentity; _readElementRelationships.request = new _w2c._remoteServiceRequest(); _readElementRelationships.request.method = _w2c.HttpMethod.GET; _readElementRelationships.request.handleSuccess = successHandler; _readElementRelationships.request.handleFault = faultHandler; _readElementRelationships.request.setUrl(_readElementRelationships.url); _readElementRelationships.request.execute(); }; // Element related this.readElementRelated = function(elementIdentity, successHandler, faultHandler) { var _readElementRelated = {}; _readElementRelated.url = ""; _readElementRelated.url += _w2c.ApiMethodUri.ELEMENT_RELATED; _readElementRelated.url += elementIdentity; _readElementRelated.request = new _w2c._remoteServiceRequest(); _readElementRelated.request.method = _w2c.HttpMethod.GET; _readElementRelated.request.handleSuccess = successHandler; _readElementRelated.request.handleFault = faultHandler; _readElementRelated.request.setUrl(_readElementRelated.url); _readElementRelated.request.execute(); }; // Ping this.ping = function(successHandler, faultHandler, synchronicity) { if (typeof synchronicity == "undefined") { synchronicity = _w2c.Synchronicity.ASYNCHRONOUS; } var _ping = {}; _ping.url = ""; _ping.url += _w2c.ApiMethodUri.PING; _ping.request = new _w2c._remoteServiceRequest(); _ping.request.method = _w2c.HttpMethod.GET; _ping.request.handleSuccess = successHandler; _ping.request.handleFault = faultHandler; _ping.request.setUrl(_ping.url); _ping.request.execute(synchronicity); }; // User this.readUser = function(successHandler, faultHandler, synchronicity) { if (typeof synchronicity == "undefined") { synchronicity = _w2c.Synchronicity.ASYNCHRONOUS; } _user = {}; _user.url = ""; _user.url += _w2c.ApiMethodUri.USER; _user.request = new _w2c._remoteServiceRequest(); _user.request.method = _w2c.HttpMethod.GET; _user.request.handleSuccess = successHandler; _user.request.handleFault = faultHandler; _user.request.setUrl(_user.url); _user.request.execute(synchronicity); }; // Color settings this.readColorSettings = function(successHandler, faultHandler) { var _colorSettings = {}; _colorSettings.url = ""; _colorSettings.url += _w2c.ApiMethodUri.COLOR_SETTINGS; _colorSettings.request = new _w2c._remoteServiceRequest(); _colorSettings.request.method = _w2c.HttpMethod.GET; _colorSettings.request.handleSuccess = successHandler; _colorSettings.request.handleFault = faultHandler; _colorSettings.request.setUrl(_colorSettings.url); _colorSettings.request.execute(synchronicity); }; // Perform element operation this.performElementOperation = function(elementIdentity, operationName, successHandler, faultHandler) { var _peo = {}; _peo.url = ""; _peo.url += _w2c.ApiMethodUri.ELEMENT_PERFORM; _peo.url += elementIdentity; _peo.url += "?" + _w2c.ApiMethodParameter.OPERATION_NAME + "=" + operationName; _peo.request = new _w2c._remoteServiceRequest(); _peo.request.method = _w2c.HttpMethod.GET; _peo.request.handleSuccess = successHandler; _peo.request.handleFault = faultHandler; _peo.request.setUrl(_peo.url); _peo.request.execute(); }; // Read element alarms this.readElementAlarmsRealtime = function(elementIdentity, channel, params, successHandler, faultHandler) { var _readElementAlarms = {}; _readElementAlarms._responseFormat = _w2c.Session.ApiFormat; _readElementAlarms._successHandlerCallback = successHandler; _readElementAlarms._faultHandlerCallback = faultHandler; _readElementAlarms._successHandler = function(response) { var alarms = null; try { if (_readElementAlarms._responseFormat == _w2c.ApiFormat.JSON) { alarms = _w2c.Data.JSON.parseAlarms(response); } _readElementAlarms._successHandlerCallback(response, alarms); } catch (ex) { response.exception = ex; _readElementAlarms._faultHandlerCallback(response); } }; _readElementAlarms.url = ""; _readElementAlarms.url += _w2c.ApiMethodUri.ELEMENT_ALARMS_REALTIME.replace(/\{CHANNEL\}/, channel); _readElementAlarms.url += elementIdentity; _readElementAlarms.request = new _w2c._remoteServiceRequest(); _readElementAlarms.request.method = _w2c.HttpMethod.GET; _readElementAlarms.request.handleSuccess = _readElementAlarms._successHandler; _readElementAlarms.request.handleFault = faultHandler; _readElementAlarms.request.setUrl(_readElementAlarms.url); _readElementAlarms.request.execute(); }; // Read element performance information this.readElementPerformanceInfo = function(elementIdentity, successHandler, faultHandler) { var readElementPerformanceInfo = {}; readElementPerformanceInfo.url = ""; readElementPerformanceInfo.url += _w2c.ApiMethodUri.ELEMENT_QUERY_PERFORMANCE; readElementPerformanceInfo.url += elementIdentity; readElementPerformanceInfo.request = new _w2c._remoteServiceRequest(); readElementPerformanceInfo.request.method = _w2c.HttpMethod.GET; readElementPerformanceInfo.request.handleSuccess = successHandler; readElementPerformanceInfo.request.handleFault = faultHandler; readElementPerformanceInfo.request.setUrl(readElementPerformanceInfo.url); readElementPerformanceInfo.request.execute(); }; // Read element performance series this.readElementPerformanceSeries = function(elementIdentity, performanceSeriesQuery, successHandler, faultHandler) { var _readElementPerformanceSeries = {}; _readElementPerformanceSeries._responseFormat = _w2c.Session.ApiFormat; _readElementPerformanceSeries._successHandlerCallback = successHandler; _readElementPerformanceSeries._faultHandlerCallback = faultHandler; _readElementPerformanceSeries._successHandler = function(response) { var series = null; try { if (_readElementPerformanceSeries._responseFormat == _w2c.ApiFormat.JSON) { series = _w2c.Data.JSON.parsePerformanceSeries(response); } _readElementPerformanceSeries._successHandlerCallback(response, series); } catch (ex) { response.exception = ex; _readElementPerformanceSeries._faultHandlerCallback(response); } }; var uriQueryString = _w2c.ApiMethodUri.ELEMENT_QUERY_PERFORMANCE_SERIES; uriQueryString = uriQueryString.replace(/\{PROFILE\}/, performanceSeriesQuery.profileName); uriQueryString = uriQueryString.replace(/\{EXPRESSION\}/, performanceSeriesQuery.expressionName); _readElementPerformanceSeries.url = ""; _readElementPerformanceSeries.url += uriQueryString; _readElementPerformanceSeries.url += elementIdentity; _readElementPerformanceSeries.url += "?from=" + performanceSeriesQuery.fromTimeEpoch; _readElementPerformanceSeries.url += "&to=" + performanceSeriesQuery.toTimeEpoch; _readElementPerformanceSeries.url += "&limit=" + performanceSeriesQuery.limitCount; _readElementPerformanceSeries.request = new _w2c._remoteServiceRequest(); _readElementPerformanceSeries.request.method = _w2c.HttpMethod.GET; _readElementPerformanceSeries.request.handleSuccess = _readElementPerformanceSeries._successHandler; _readElementPerformanceSeries.request.handleFault = faultHandler; _readElementPerformanceSeries.request.setUrl(_readElementPerformanceSeries.url); _readElementPerformanceSeries.request.execute(); }; // Data classes this.Data.ElementItem = function() { _item = this; _item.identity = null; _item.name = null; _item.condition = null; _item.conditionNumeric = null; _item.elementClassName = null; _item.icon = null; _item.notes = null; _item.lastUpdate = 0; }; this.Data.ElementCollection = function() { _collection = this; _collection.list = {}; _collection.indexer = []; _collection.count = 0; _collection.clear = function() { delete _collection.list; delete _collection.indexer; _collection.list = {}; _collection.indexer = []; _collection.count = 0; }; _collection.getItem = function(index) { return _collection.list[_collection.indexer[index]]; }; _collection.add = function(elementIdentity, elementItem) { var key = elementIdentity; _collection.count++; _collection.indexer[_collection.count] = key; _collection.list[key] = elementItem; }; }; // ElementCollection this.Data.AlarmItem = function() { _item = this; _item.id = 0; _item.description = null; _item.lastUpdate = 0; _item.severityNumeric = null; _item.affectedElement = null; _item.affectedElementName = null; }; this.Data.AlarmCollection = function() { _collection = this; _collection.list = {}; _collection.indexer = []; _collection.count = 0; _collection.clear = function() { delete _collection.list; delete _collection.indexer; _collection.list = {}; _collection.indexer = []; _collection.count = 0; }; _collection.getItem = function(index) { return _collection.list[_collection.indexer[index]]; }; _collection.add = function(alarmId, alarmItem) { var key = alarmId; _collection.count++; _collection.indexer[_collection.count] = key; _collection.list[key] = alarmItem; }; }; // AlarmCollection this.Data.PerformanceSeriesItem = function(dateValue, seriesValue, discontinuityValue) { _item = this; _item.dateValue = (typeof dateValue == "undefined") ? 0 : dateValue; _item.seriesValue = (typeof seriesValue == "undefined") ? 0 : seriesValue; _item.discontinuity = (typeof discontinuityValue == "undefined") ? false : discontinuityValue == "true"; }; this.Data.PerformanceSeriesCollection = function() { _collection = this; _collection.list = {}; _collection.indexer = []; _collection.count = 0; _collection.profile = ""; _collection.expression = ""; _collection.lowestValue = Number.MAX_VALUE; _collection.highestValue = Number.MIN_VALUE; _collection.earliestDate = Number.MAX_VALUE; _collection.latestDate = Number.MIN_VALUE; _collection.clear = function() { delete _collection.list; delete _collection.indexer; _collection.list = {}; _collection.indexer = []; _collection.count = 0; }; _collection.add = function(dateValue, seriesValue, discontinuityValue) { var key = dateValue; var newItem = new _w2c.Data.PerformanceSeriesItem(dateValue, seriesValue, discontinuityValue); _collection.count++; _collection.indexer[_collection.count] = key; _collection.list[key] = newItem; _collection.earliestDate = Math.min(_collection.earliestDate, dateValue); _collection.latestDate = Math.max(_collection.latestDate, dateValue); _collection.lowestValue = Math.min(_collection.lowestValue, seriesValue); _collection.highestValue = Math.max(_collection.highestValue, seriesValue); }; _collection.getItem = function(index) { return _collection.list[_collection.indexer[index]]; }; _collection.getItemByDateEpoch = function(dateEpochKey) { return _collection.list[dateEpochKey]; }; }; // PerformanceSeriesCollection // Data JSON helpers this.Data.JSON.parseAttributeValueType = function(attribute) { var value = attribute.value; switch (attribute.type) { case _w2c.AttributeType.INTEGER: value = parseInt(value, 10); break; case _w2c.AttributeType.FLOAT || _w2c.AttributeType.DOUBLE: value = parseFloat(value); break; default: } return value; }; this.Data.JSON.parseElementAttributes = function(json) { var o = eval("(" + json + ")"); var attributesMap = o[_w2c.Data.JSON.Constants.ATTRIBUTES].attributes; var attributes = {}; for (var p in attributesMap) { if (attributesMap.hasOwnProperty(p)) { attributes[p] = _w2c.Data.JSON.parseAttributeValueType(attributesMap[p]); } } return attributes; }; this.Data.JSON.parseAlarms = function(json) { var o = eval("(" + json + ")"); var _JSON_ = _w2c.Data.JSON.Constants.ALARMS; var alarmCollection = new _w2c.Data.AlarmCollection(); if (o[_JSON_].alarm) { for (var index = 0; index < o[_JSON_].alarm.length; index++) { var alarmItem = new _w2c.Data.AlarmItem(); alarmItem.id = o[_JSON_].alarm[index].id; alarmItem.description = o[_JSON_].alarm[index].Summary ? o[_JSON_].alarm[index].Summary : ""; alarmItem.lastUpdate = o[_JSON_].alarm[index].lastUpdate; alarmItem.severityNumeric = o[_JSON_].alarm[index].severityNumeric; alarmItem.affectedElement = o[_JSON_].alarm[index].affectedElement; alarmItem.affectedElementName = o[_JSON_].alarm[index].affectedElementName; alarmCollection.add(alarmItem.id, alarmItem); } } return alarmCollection; }; this.Data.JSON.parseElements = function(json) { var o = eval("(" + json + ")"); var _JSON_ = _w2c.Data.JSON.Constants.ELEMENTS; var elementCollection = new _w2c.Data.ElementCollection(); var elementItem; if (o[_JSON_].element) { if (typeof o[_JSON_].element.length == "undefined") { // Single item elementItem = new _w2c.Data.ElementItem(); elementItem.identity = o[_JSON_].element.identity; elementItem.name = o[_JSON_].element.name; elementItem.condition = o[_JSON_].element.condition; elementItem.conditionNumeric = o[_JSON_].element.conditionNumeric; elementItem.elementClassName = o[_JSON_].element.elementClassName; elementItem.icon = o[_JSON_].element.icon; elementItem.notes = o[_JSON_].element.notes; elementItem.lastUpdate = o[_JSON_].element.lastUpdateString; elementCollection.add(elementItem.identity, elementItem); } else { // Multiple items for (var index = 0; index < o[_JSON_].element.length; index++) { elementItem = new _w2c.Data.ElementItem(); elementItem.identity = o[_JSON_].element[index].identity; elementItem.name = o[_JSON_].element[index].name; elementItem.condition = o[_JSON_].element[index].condition; elementItem.conditionNumeric = o[_JSON_].element[index].conditionNumeric; elementItem.elementClassName = o[_JSON_].element[index].elementClassName; elementItem.icon = o[_JSON_].element[index].icon; elementItem.notes = o[_JSON_].element[index].notes; elementItem.lastUpdate = o[_JSON_].element[index].lastUpdateString; elementCollection.add(elementItem.identity, elementItem); } } } return elementCollection; }; this.Data.JSON.parsePerformanceSeries = function(json) { var o = eval("(" + json + ")"); var _JSON_ = _w2c.Data.JSON.Constants.PERFORMANCE_SERIES; var dates = []; var series = []; var discontinuities = []; dates = o[_JSON_].dateValues.split(" "); series = o[_JSON_].seriesValues.split(" "); discontinuities = o[_JSON_].discontinuityValues.split(" "); var seriesCollection = new _w2c.Data.PerformanceSeriesCollection(); seriesCollection.profile = o[_JSON_].profile; seriesCollection.expression = o[_JSON_].expression; for (var index = 0; index < dates.length; index++) { seriesCollection.add(dates[index], series[index], discontinuities[index]); } return seriesCollection; }; // Utility functions this.Utils.PerformanceSeriesQuery = function() { _psq = this; this.profileName = ""; this.expressionName = ""; this.fromTimeEpoch = 0; this.toTimeEpoch = 0; this.limitCount = 100; }; this.Utils.AssociativeList = function() { _eac = this; _eac.list = {}; _eac.clear = function() { delete _eac.list; _eac.list = {}; }; _eac.add = function(listItem) { _eac.list[listItem] = listItem; }; _eac.getDelimitedList = function(delimiter) { delimiter = (delimiter) ? delimiter : ","; var listString = ""; for (var listItem in _eac.list) { if (_eac.list.hasOwnProperty(listItem)) { listString += _eac.list[listItem] + delimiter; } } return listString.substring(0, listString.lastIndexOf(delimiter)); }; }; // Interface helper methods this.Interface.getMethodUri = function(apiMethodUri) { return _w2c._getApiRootContext() + apiMethodUri; }; // XML HTTP request object this._xmlHttpRequest = function() { if (window.XMLHttpRequest) { return new XMLHttpRequest(); } else if (window.ActiveXObject) { return new ActiveXObject("Microsoft.XMLHTTP"); } else { return null; } }; // Generic wrapper for HTTP requester this._remoteServiceRequest = function() { _rpc = this; _rpc.xhr = _w2c._xmlHttpRequest(); _rpc._callback = function() { if (_rpc.xhr.readyState == _w2c.XmlHttpRequestState.COMPLETE) { if (_rpc.xhr.status == _w2c.HttpResponseCode.SUCCESS) { _w2c.Fault.clear(); _w2c.Fault.Code = _rpc.xhr.status; if (_rpc.handleSuccess) { _rpc.handleSuccess(_rpc.xhr.responseText); } } else { try { _w2c.Fault.clear(); _w2c.Fault.Code = _rpc.xhr.status; _w2c.Fault.Message = _rpc.xhr.responseText; _w2c.Fault.RemoteServiceUrl = _rpc.url; if (_rpc.handleFault) { _rpc.handleFault(_rpc.xhr.responseText); } } catch (ignoredException) { alert("XHR callback exception"); } finally { } } } }; // _rpc._callback() _rpc.setUrl = function(urlString) { _rpc.url = _w2c.Interface.getMethodUri(urlString); _w2c.Internal.RemoteServiceUrl = _rpc.url; }; // _rpc.setUrl() _rpc.execute = function(synchronicity) { if (typeof synchronicity == "undefined") { synchronicity = _w2c.Synchronicity.ASYNCHRONOUS; } _w2c.Internal.LastSynchronicity = synchronicity; _w2c.Internal.LastRequestEpoch = new Date().getTime(); _rpc.xhr.abort(); _rpc.xhr.onreadystatechange = function(){}; if (synchronicity == _w2c.Synchronicity.ASYNCHRONOUS) { _rpc.xhr.onreadystatechange = _rpc._callback; } _rpc.xhr.open(_rpc.method, _rpc.url, synchronicity); _rpc.xhr.send(_rpc.payload); if (synchronicity == _w2c.Synchronicity.SYNCHRONOUS) { _rpc._callback(); } }; // _rpc.execute() _rpc.url = _w2c._getApiRootContext(); _rpc.method = _w2c.HttpMethod.GET; _rpc.payload = null; _rpc.handleSuccess = null; _rpc.handleFault = null; }; // API root context this._getApiRootContext = function() { var apiRoot = ""; if (_w2c.Session.Host.length > 0) { apiRoot += _w2c.Session.Protocol + "://"; apiRoot += _w2c.Session.Host + ":"; apiRoot += _w2c.Session.Port; } apiRoot += _w2c.Session.RootContext; apiRoot += _w2c.Session.ApiFormat + "/"; return apiRoot; }; // Fault capture this._FaultDetails = function() { _faultDetails = this; this.Code = 0; this.Message = ""; this.FunctionName = ""; this.RemoteServiceUrl = ""; this.clear = function() { _faultDetails.Code = 0; _faultDetails.Message = ""; _faultDetails.FunctionName = ""; _faultDetails.RemoteServiceUrl = ""; }; }; this._Log = function() { _log = this; _log.LoggingLevel = { ERROR: 4, INFO: 2, DEBUG: 1, NONE: 0 }; _log.level = _log.LoggingLevel.NONE; _log.htmlElement = null; _log.setHtmlElement = function(logElementId) { _log.htmlElement = document.getElementById(logElementId); }; _log.error = function(message) { if (_log.level & _log.LoggingLevel.ERROR) { _log.write("ERROR - " + message); } }; _log.info = function(message) { if (_log.level & _log.LoggingLevel.INFO) { _log.write("INFO - " + message); } }; _log.debug = function(message) { if (_log.level & _log.LoggingLevel.DEBUG) { _log.write("DEBUG - " + message); } }; _log.write = function(message) { if (_log.htmlElement !== null) { _log.htmlElement.innerHtml += message + "<br/>"; } }; }; // Defaults this._SessionObject = function() { _sessionDefaults = this; _sessionDefaults.State = { READY: "READY", CLOSED: "CLOSED" }; _sessionDefaults.Protocol = ""; _sessionDefaults.Host = ""; _sessionDefaults.Port = ""; _sessionDefaults.Username = "admin"; _sessionDefaults.Password = "formula"; _sessionDefaults.RootContext = _w2c.RootContext.EXTERNAL_ROOT_CONTEXT; _sessionDefaults.ApiFormat = _w2c.ApiFormat.REST; _sessionDefaults.Synchronicity = _w2c.Synchronicity.ASYNCHRONOUS; _sessionDefaults.Status = _sessionDefaults.State.CLOSED; _sessionDefaults.getStatus = function() { _getStatus = this; _getStatus.pingSuccessHandler = function() { _sessionDefaults.Status = _sessionDefaults.State.READY; }; _getStatus.pingFaultHandler = function() { _sessionDefaults.Status = _sessionDefaults.State.CLOSED; }; _w2c.ping(_getStatus.pingSuccessHandler, _getStatus.pingFaultHandler, _w2c.Synchronicity.SYNCHRONOUS); return _sessionDefaults.Status; }; _sessionDefaults.isSessionActive = function() { return _sessionDefaults.getStatus(); }; }; this._SessionInternals = function() { this.RemoteServiceUrl = ""; this.LastSynchronicity = _w2c.Synchronicity; this.LastRequestEpoch = 0; }; _w2c.Internal = new _w2c._SessionInternals(); _w2c.Session = new _w2c._SessionObject(); _w2c.Fault = new _w2c._FaultDetails(); _w2c.Log = new _w2c._Log(); }; // End of file
The following objects and properties are available:
Session
The following methods are available:
createSession()
deleteSession()
ping()
readElementValue()
readElementAttributes()
readElementChildren()
readElementAlarmsRealtime()
performElementOperation()
The following describes the methods and their arguments:
createSession(successHandler, faultHandler): Creates a new session using the credentials provided in Session.Username and Session.Password. This method is synchronous.
Arguments:
successHandler: Callback for successful creation of a session.
faultHandler: Callback when session creation fails.
deleteSession(successHandler, faultHandler): Deletes an existing session. This method is asynchronous.
Arguments:
successHandler: Callback if successful.
faultHandler: Callback if error.
ping(successHandler, faultHandler, synchronicity): Performs a session ping. This method can synchronous or asynchronous.
Arguments:
successHandler: Callback if successful.
faultHandler: Callback if error.
Synchronicity: (Synchronicity.ASYNCHRONOUS || Synchronicity.SYNCHRONOUS) Synchronicity flag (True is asynchronous, False if synchronous).
readElementValue(elementIdentity, successHandler, faultHandler): Retrieves generic element status. This method is asynchronous.
Arguments:
elementIdentity: Element DName in x.500 or base64 encoded format.
successHandler: Callback if successful.
faultHandler: Callback if error.
readElementAttributes(elementIdentity, attributeNames, successHandler, faultHandler): Retrieves specified element attributes. This method is asynchronous.
Arguments:
elementIdentity: Element DName in x.500 or base64 encoded format.
attributeNames: Type is Utils.AssociativeList[], which is a list of attribute names.
successHandler: Callback if successful.
faultHandler: Callback if error.
readElementChildren(elementIdentity, successHandler, faultHandler): Retrieves all children of an element. This method is asynchronous.
Arguments:
elementIdentity: Element DName in x.500 or base64 encoded format.
successHandler: Callback if successful.
faultHandler: Callback if error.
readElementAlarmsRealtime(elementIdentity, channel, successHandler, faultHandler): Retrieves real-time element alarms. This method is asynchronous.
Arguments:
elementIdentity: Element DName in x.500 or base64 encoded format.
channel: Enum: AlarmChannels Alarm data channel.
successHandler: Callback if successful.
faultHandler: Callback if error.