UNPKG

opennms

Version:

Client API for the OpenNMS network monitoring platform

1 lines 37.7 kB
{"remainingRequest":"/data/node_modules/babel-loader/lib/index.js!/data/node_modules/ts-loader/index.js!/data/src/dao/AbstractDAO.ts","dependencies":[{"path":"/data/src/dao/AbstractDAO.ts","mtime":1553611371628},{"path":"/data/node_modules/typescript-logging/dist/commonjs/typescript-logging.d.ts","mtime":1553611387808},{"path":"/data/node_modules/typescript-logging/dist/commonjs/control/LogGroupControl.d.ts","mtime":1553611387932},{"path":"/data/node_modules/typescript-logging/dist/commonjs/control/CategoryServiceControl.d.ts","mtime":1553611387932},{"path":"/data/node_modules/typescript-logging/dist/commonjs/extension/MessagesToExtensionJSON.d.ts","mtime":1553611387932},{"path":"/data/node_modules/typescript-logging/dist/commonjs/extension/MessagesFromExtensionJSON.d.ts","mtime":1553611387932},{"path":"/data/node_modules/typescript-logging/dist/commonjs/extension/ExtensionMessageJSON.d.ts","mtime":1553611387932},{"path":"/data/node_modules/typescript-logging/dist/commonjs/extension/ExtensionHelper.d.ts","mtime":1553611387932},{"path":"/data/node_modules/typescript-logging/dist/commonjs/log/category/AbstractCategoryLogger.d.ts","mtime":1553611388000},{"path":"/data/node_modules/typescript-logging/dist/commonjs/log/LoggerOptions.d.ts","mtime":1553611387932},{"path":"/data/node_modules/typescript-logging/dist/commonjs/log/category/CategoryLogger.d.ts","mtime":1553611388000},{"path":"/data/node_modules/typescript-logging/dist/commonjs/log/category/CategoryService.d.ts","mtime":1553611388000},{"path":"/data/node_modules/typescript-logging/dist/commonjs/log/category/CategoryConsoleLoggerImpl.d.ts","mtime":1553611388000},{"path":"/data/node_modules/typescript-logging/dist/commonjs/log/category/CategoryDelegateLoggerImpl.d.ts","mtime":1553611388000},{"path":"/data/node_modules/typescript-logging/dist/commonjs/log/category/CategoryMessageBufferImpl.d.ts","mtime":1553611388000},{"path":"/data/node_modules/typescript-logging/dist/commonjs/log/standard/Logger.d.ts","mtime":1553611388000},{"path":"/data/node_modules/typescript-logging/dist/commonjs/log/standard/LoggerFactory.d.ts","mtime":1553611388004},{"path":"/data/node_modules/typescript-logging/dist/commonjs/log/standard/LoggerFactoryService.d.ts","mtime":1553611388004},{"path":"/data/node_modules/typescript-logging/dist/commonjs/log/standard/LoggerFactoryRuntimeSettings.d.ts","mtime":1553611388004},{"path":"/data/node_modules/typescript-logging/dist/commonjs/log/standard/AbstractLogger.d.ts","mtime":1553611388000},{"path":"/data/node_modules/typescript-logging/dist/commonjs/log/standard/ConsoleLoggerImpl.d.ts","mtime":1553611388000},{"path":"/data/node_modules/typescript-logging/dist/commonjs/log/standard/MessageBufferLoggerImpl.d.ts","mtime":1553611388004},{"path":"/data/node_modules/typescript-logging/dist/commonjs/utils/DataStructures.d.ts","mtime":1553611387936},{"path":"/data/node_modules/typescript-logging/dist/commonjs/utils/JSONHelper.d.ts","mtime":1553611387936},{"path":"/data/node_modules/typescript-logging/dist/commonjs/utils/MessageUtils.d.ts","mtime":1553611387936},{"path":"/data/node_modules/moment/moment.d.ts","mtime":1553611386704},{"path":"/data/node_modules/axios/index.d.ts","mtime":1553611386356},{"path":"/data/typings/index.d.ts","mtime":1553611371628},{"path":"/data/node_modules/@types/fs-extra/index.d.ts","mtime":1553611386380},{"path":"/data/node_modules/@types/node/index.d.ts","mtime":1553611386380},{"path":"/data/node_modules/@types/node/inspector.d.ts","mtime":1553611386380},{"path":"/data/node_modules/@types/glob/index.d.ts","mtime":1553611386380},{"path":"/data/node_modules/@types/minimatch/index.d.ts","mtime":1553611386380},{"path":"/data/node_modules/@types/glob/node_modules/@types/minimatch/index.d.ts","mtime":1553611386368},{"path":"/data/node_modules/@types/handlebars/index.d.ts","mtime":1553611386368},{"path":"/data/node_modules/@types/highlight.js/index.d.ts","mtime":1553611386368},{"path":"/data/node_modules/@types/jest/index.d.ts","mtime":1553611386368},{"path":"/data/node_modules/@types/jquery/index.d.ts","mtime":1553611386368},{"path":"/data/node_modules/@types/lodash/index.d.ts","mtime":1553611386320},{"path":"/data/node_modules/@types/lodash/common/common.d.ts","mtime":1553611386984},{"path":"/data/node_modules/@types/lodash/common/array.d.ts","mtime":1553611386984},{"path":"/data/node_modules/@types/lodash/common/collection.d.ts","mtime":1553611386984},{"path":"/data/node_modules/@types/lodash/common/date.d.ts","mtime":1553611386984},{"path":"/data/node_modules/@types/lodash/common/function.d.ts","mtime":1553611386984},{"path":"/data/node_modules/@types/lodash/common/lang.d.ts","mtime":1553611386984},{"path":"/data/node_modules/@types/lodash/common/math.d.ts","mtime":1553611386984},{"path":"/data/node_modules/@types/lodash/common/number.d.ts","mtime":1553611386984},{"path":"/data/node_modules/@types/lodash/common/object.d.ts","mtime":1553611386984},{"path":"/data/node_modules/@types/lodash/common/seq.d.ts","mtime":1553611386984},{"path":"/data/node_modules/@types/lodash/common/string.d.ts","mtime":1553611386984},{"path":"/data/node_modules/@types/lodash/common/util.d.ts","mtime":1553611386984},{"path":"/data/node_modules/@types/marked/index.d.ts","mtime":1553611386368},{"path":"/data/node_modules/@types/shelljs/index.d.ts","mtime":1553611386380},{"path":"/data/node_modules/@types/urijs/index.d.ts","mtime":1553611386380},{"path":"/data/node_modules/typescript/lib/lib.es2015.d.ts","mtime":1553611387384},{"path":"/data/node_modules/typescript/lib/lib.es2015.core.d.ts","mtime":1553611387384},{"path":"/data/node_modules/typescript/lib/lib.es2015.collection.d.ts","mtime":1553611387384},{"path":"/data/node_modules/typescript/lib/lib.es2015.generator.d.ts","mtime":1553611387384},{"path":"/data/node_modules/typescript/lib/lib.es2015.promise.d.ts","mtime":1553611387384},{"path":"/data/node_modules/typescript/lib/lib.es2015.iterable.d.ts","mtime":1553611387384},{"path":"/data/node_modules/typescript/lib/lib.es2015.symbol.d.ts","mtime":1553611387384},{"path":"/data/node_modules/typescript/lib/lib.es2015.proxy.d.ts","mtime":1553611387384},{"path":"/data/node_modules/typescript/lib/lib.es2015.reflect.d.ts","mtime":1553611387384},{"path":"/data/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","mtime":1553611387384},{"path":"/data/node_modules/typescript/lib/lib.es5.d.ts","mtime":1553611387388},{"path":"/data/node_modules/typescript/lib/lib.dom.d.ts","mtime":1553611387384},{"path":"/data/src/api/IFilterProcessor.ts","mtime":1553611371624},{"path":"/data/src/api/IHasHTTP.ts","mtime":1553611371624},{"path":"/data/src/api/IOnmsHTTP.ts","mtime":1553611371624},{"path":"/data/src/api/OnmsError.ts","mtime":1553611371624},{"path":"/data/src/api/Filter.ts","mtime":1553611371624},{"path":"/data/src/api/OnmsHTTPOptions.ts","mtime":1553611371624},{"path":"/data/src/api/SearchProperty.ts","mtime":1553611371628},{"path":"/data/src/api/SearchPropertyType.ts","mtime":1553611371628},{"path":"/data/src/api/Log.ts","mtime":1553611371624},{"path":"/data/src/dao/V1FilterProcessor.ts","mtime":1553611371628},{"path":"/data/src/dao/V2FilterProcessor.ts","mtime":1553611371628},{"path":"/data/src/dao/PropertiesCache.ts","mtime":1553611371628},{"path":"/data/src/dao/BaseDAO.ts","mtime":1553611371628},{"path":"/data/node_modules/moment/moment.d.ts","mtime":1553611386704},{"path":"/data/src/dao/IValueProvider.ts","mtime":1553611371628},{"path":"/data/.babelrc","mtime":1553611371556},{"path":"/data/node_modules/cache-loader/dist/cjs.js","mtime":1553611387012},{"path":"/data/node_modules/babel-loader/lib/index.js","mtime":1553611386992},{"path":"/data/node_modules/ts-loader/index.js","mtime":1553611386824}],"contextDependencies":[],"result":["\"use strict\";\n\nvar _regenerator = require(\"babel-runtime/regenerator\");\n\nvar _regenerator2 = _interopRequireDefault(_regenerator);\n\nvar _typeof = typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; };\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return call && (typeof call === \"object\" || typeof call === \"function\") ? call : self; }\n\nfunction _inherits(subClass, superClass) { if (typeof superClass !== \"function\" && superClass !== null) { throw new TypeError(\"Super expression must either be null or a function, not \" + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }\n\nvar __awaiter = undefined && undefined.__awaiter || function (thisArg, _arguments, P, generator) {\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) {\n try {\n step(generator.next(value));\n } catch (e) {\n reject(e);\n }\n }\n function rejected(value) {\n try {\n step(generator[\"throw\"](value));\n } catch (e) {\n reject(e);\n }\n }\n function step(result) {\n result.done ? resolve(result.value) : new P(function (resolve) {\n resolve(result.value);\n }).then(fulfilled, rejected);\n }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar OnmsError_1 = require(\"../api/OnmsError\");\nvar OnmsHTTPOptions_1 = require(\"../api/OnmsHTTPOptions\");\nvar SearchProperty_1 = require(\"../api/SearchProperty\");\nvar SearchPropertyType_1 = require(\"../api/SearchPropertyType\");\nvar V1FilterProcessor_1 = require(\"./V1FilterProcessor\");\nvar V2FilterProcessor_1 = require(\"./V2FilterProcessor\");\nvar PropertiesCache_1 = require(\"./PropertiesCache\");\nvar BaseDAO_1 = require(\"./BaseDAO\");\n/** @hidden */\n// tslint:disable-next-line\nvar moment = require('moment');\n/**\n * An abstract data access layer API, meant to (somewhat) mirror the DAO interfaces\n * inside OpenNMS. Used to retrieve model data like alarms, events, etc. from the\n * OpenNMS ReST API in a consistent way.\n *\n * @module AbstractDAO\n * @param K the ID/key type (number, string, etc.)\n * @param T the model type (OnmsAlarm, OnmsEvent, etc.)\n */\n\nvar AbstractDAO = function (_BaseDAO_1$BaseDAO) {\n _inherits(AbstractDAO, _BaseDAO_1$BaseDAO);\n\n function AbstractDAO() {\n _classCallCheck(this, AbstractDAO);\n\n return _possibleConstructorReturn(this, (AbstractDAO.__proto__ || Object.getPrototypeOf(AbstractDAO)).apply(this, arguments));\n }\n\n _createClass(AbstractDAO, [{\n key: \"getFilterProcessor\",\n\n /**\n * Returns the Promise for a [[IFilterProcessor]].\n * @returns {Promise}\n */\n value: function getFilterProcessor() {\n return __awaiter(this, void 0, void 0, /*#__PURE__*/_regenerator2.default.mark(function _callee() {\n return _regenerator2.default.wrap(function _callee$(_context) {\n while (1) {\n switch (_context.prev = _context.next) {\n case 0:\n _context.t0 = this.getApiVersion();\n _context.next = _context.t0 === 2 ? 3 : 4;\n break;\n\n case 3:\n return _context.abrupt(\"return\", this.getPropertiesCache().then(function (cache) {\n return new V2FilterProcessor_1.V2FilterProcessor(cache);\n }));\n\n case 4:\n return _context.abrupt(\"return\", Promise.resolve(new V1FilterProcessor_1.V1FilterProcessor()));\n\n case 5:\n case \"end\":\n return _context.stop();\n }\n }\n }, _callee, this);\n }));\n }\n /**\n * Get the list properties that can be used in queries.\n * @version ReST v2\n */\n\n }, {\n key: \"searchProperties\",\n value: function searchProperties() {\n return __awaiter(this, void 0, void 0, /*#__PURE__*/_regenerator2.default.mark(function _callee2() {\n return _regenerator2.default.wrap(function _callee2$(_context2) {\n while (1) {\n switch (_context2.prev = _context2.next) {\n case 0:\n return _context2.abrupt(\"return\", this.getPropertiesCache().then(function (cache) {\n return cache.getProperties();\n }));\n\n case 1:\n case \"end\":\n return _context2.stop();\n }\n }\n }, _callee2, this);\n }));\n }\n /**\n * Gets the property identified by the id if it exists.\n *\n * @param id The id to search the property by.\n */\n\n }, {\n key: \"searchProperty\",\n value: function searchProperty(id) {\n return __awaiter(this, void 0, void 0, /*#__PURE__*/_regenerator2.default.mark(function _callee3() {\n return _regenerator2.default.wrap(function _callee3$(_context3) {\n while (1) {\n switch (_context3.prev = _context3.next) {\n case 0:\n return _context3.abrupt(\"return\", this.getPropertiesCache().then(function (cache) {\n return cache.getProperty(id);\n }));\n\n case 1:\n case \"end\":\n return _context3.stop();\n }\n }\n }, _callee3, this);\n }));\n }\n /**\n * Returns or creates the [[PropertiesCache]] for this dao.\n *\n * @return the [[PropertiesCache]] for this dao. It is created if it does not exist.\n */\n\n }, {\n key: \"getPropertiesCache\",\n value: function getPropertiesCache() {\n return __awaiter(this, void 0, void 0, /*#__PURE__*/_regenerator2.default.mark(function _callee4() {\n var _this2 = this;\n\n return _regenerator2.default.wrap(function _callee4$(_context4) {\n while (1) {\n switch (_context4.prev = _context4.next) {\n case 0:\n if (!(this.getApiVersion() === 1)) {\n _context4.next = 2;\n break;\n }\n\n throw new OnmsError_1.OnmsError('Search property metadata is only available in OpenNMS ' + 'versions that support the ReSTv2 API.');\n\n case 2:\n if (PropertiesCache_1.PropertiesCache.get(this)) {\n _context4.next = 4;\n break;\n }\n\n return _context4.abrupt(\"return\", this.getOptions().then(function (opts) {\n opts.headers.accept = 'application/json';\n return _this2.http.get(_this2.searchPropertyPath(), opts).then(function (result) {\n var searchProperties = _this2.parseResultList(result, 'searchProperty', _this2.searchPropertyPath(), function (prop) {\n return _this2.toSearchProperty(prop);\n });\n PropertiesCache_1.PropertiesCache.put(_this2, searchProperties);\n return Promise.resolve(PropertiesCache_1.PropertiesCache.get(_this2));\n });\n }));\n\n case 4:\n return _context4.abrupt(\"return\", Promise.resolve(PropertiesCache_1.PropertiesCache.get(this)));\n\n case 5:\n case \"end\":\n return _context4.stop();\n }\n }\n }, _callee4, this);\n }));\n }\n /**\n * Finds the values for the given propertyId, if it exists.\n *\n * @param {string} propertyId The propertyId to find the values for\n * @param options Some additional options. May be implementer dependent, such as limit, or value restrictions\n * @returns {Promise<any>} A promise containing the values.\n */\n\n }, {\n key: \"findValues\",\n value: function findValues(propertyId, options) {\n return __awaiter(this, void 0, void 0, /*#__PURE__*/_regenerator2.default.mark(function _callee5() {\n var _this3 = this;\n\n return _regenerator2.default.wrap(function _callee5$(_context5) {\n while (1) {\n switch (_context5.prev = _context5.next) {\n case 0:\n return _context5.abrupt(\"return\", this.searchProperty(propertyId).then(function (property) {\n return _this3.getOptions().then(function (opts) {\n var path = _this3.searchPropertyPath() + '/' + property.id;\n opts.headers.accept = 'application/json';\n if (options) {\n Object.assign(opts, options);\n }\n return _this3.http.get(path, opts).then(function (result) {\n return _this3.parseResultList(result, 'value', path, function (value) {\n return value;\n });\n });\n });\n }));\n\n case 1:\n case \"end\":\n return _context5.stop();\n }\n }\n }, _callee5, this);\n }));\n }\n /**\n * Fetches the data from the result and verfifes that the <code>dataFieldName</code> exists in the data property.\n * If it does not exist, an exception is thrown.\n *\n * @param result The result to fetch the data from\n * @param dataFieldName The property name (basically <code>result.data[dataFieldName]</code>.\n * @param path The path where the result was fetched from. This is for error handling\n * @param mapCallbackFunction Callback function to convert each entry from <code>result.data[dataFieldName]</code>.\n */\n\n }, {\n key: \"parseResultList\",\n value: function parseResultList(result, dataFieldName, path, mapCallbackFunction) {\n var data = result.data;\n if (this.getCount(data) > 0 && data[dataFieldName]) {\n data = data[dataFieldName];\n } else {\n data = [];\n }\n if (!Array.isArray(data)) {\n throw new OnmsError_1.OnmsError('Expected an array but got \"' + (typeof data === \"undefined\" ? \"undefined\" : _typeof(data)) + '\" instead: ' + path);\n }\n if (mapCallbackFunction) {\n return data.map(mapCallbackFunction);\n }\n return data;\n }\n /**\n * Create an [[OnmsHTTPOptions]] object for DAO calls given an optional filter.\n * @param filter - the filter to use\n */\n\n }, {\n key: \"getOptions\",\n value: function getOptions(filter) {\n return __awaiter(this, void 0, void 0, /*#__PURE__*/_regenerator2.default.mark(function _callee6() {\n var _this4 = this;\n\n return _regenerator2.default.wrap(function _callee6$(_context6) {\n while (1) {\n switch (_context6.prev = _context6.next) {\n case 0:\n return _context6.abrupt(\"return\", Promise.resolve(new OnmsHTTPOptions_1.OnmsHTTPOptions()).then(function (options) {\n if (_this4.useJson()) {\n options.headers.accept = 'application/json';\n } else {\n // always use application/xml in DAO calls when we're not sure how\n // usable JSON output will be.\n options.headers.accept = 'application/xml';\n }\n if (filter) {\n return _this4.getFilterProcessor().then(function (processor) {\n options.parameters = processor.getParameters(filter);\n return options;\n });\n }\n return options;\n }));\n\n case 1:\n case \"end\":\n return _context6.stop();\n }\n }\n }, _callee6, this);\n }));\n }\n /**\n * Generate a [[SearchProperty]] from the given dictionary.\n * @hidden\n */\n\n }, {\n key: \"toSearchProperty\",\n value: function toSearchProperty(data) {\n if (!data) {\n return null;\n }\n var prop = new SearchProperty_1.SearchProperty(this);\n prop.id = data.id;\n prop.name = data.name;\n prop.orderBy = !!data.orderBy;\n prop.type = SearchPropertyType_1.SearchPropertyType.forId(data.type);\n prop.values = data.values;\n return prop;\n }\n /**\n * Retrieve the API version from the currently configured server.\n */\n\n }, {\n key: \"getApiVersion\",\n value: function getApiVersion() {\n if (this.http === undefined || this.http.server === undefined || this.http.server.metadata === undefined) {\n throw new OnmsError_1.OnmsError('Server meta-data must be populated prior to making DAO calls.');\n }\n return this.http.server.metadata.apiVersion();\n }\n }]);\n\n return AbstractDAO;\n}(BaseDAO_1.BaseDAO);\n\nexports.AbstractDAO = AbstractDAO;",{"version":3,"file":"/data/src/dao/AbstractDAO.ts","sourceRoot":"","sources":["/data/src/dao/AbstractDAO.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,0BAA2C;AAG3C,gCAAuD;AACvD,+BAAqD;AACrD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AAAE,KAAG,AAAI,KAAC,AAAE,AAAC;AAClB,AAAI,iBAAC,AAAI,OAAG,AAAI,KAAC,AAAI,AAAC;AACtB,AAAI,iBAAC,AAAO,UAAG,CAAC,CAAC,AAAI,KAAC,AAAO,AAAC;AAC9B,AAAI,iBAAC,AAAI,OAAG,qBAAkB,mBAAC,AAAK,MAAC,AAAI,KAAC,AAAI,AAAC,AAAC;AAChD,AAAI,iBAAC,AAAM,SAAG,AAAI,KAAC,AAAM,AAAC;AAC1B,AAAM,mBAAC,AAAI,AAAC,AACd;AAAC;AAED,AAEG,AACO,AAAa;;;;;;;AACrB,AAAE,AAAC,gBAAC,AAAI,KAAC,AAAI,SAAK,AAAS,aAAI,AAAI,KAAC,AAAI,KAAC,AAAM,WAAK,AAAS,aAAI,AAAI,KAAC,AAAI,KAAC,AAAM,OAAC,AAAQ,aAAK,AAAS,AAAC,WAAC,AAAC;AACzG,sBAAM,IAAI,YAAS,UAAC,AAA+D,AAAC,AAAC,AACvF;AAAC;AACD,AAAM,mBAAC,AAAI,KAAC,AAAI,KAAC,AAAM,OAAC,AAAQ,SAAC,AAAU,AAAE,AAAC,AAChD;AAAC,AACF;;;;EAtL+C,UAAO;;AAAvD,sBAsLC","sourcesContent":["import {IFilterProcessor} from '../api/IFilterProcessor';\nimport {IHasHTTP} from '../api/IHasHTTP';\nimport {IOnmsHTTP} from '../api/IOnmsHTTP';\nimport {OnmsError} from '../api/OnmsError';\n\nimport {Filter} from '../api/Filter';\nimport {OnmsHTTPOptions} from '../api/OnmsHTTPOptions';\nimport {SearchProperty} from '../api/SearchProperty';\nimport {SearchPropertyType} from '../api/SearchPropertyType';\n\nimport {log, catDao} from '../api/Log';\n\nimport {V1FilterProcessor} from './V1FilterProcessor';\nimport {V2FilterProcessor} from './V2FilterProcessor';\n\nimport {PropertiesCache} from './PropertiesCache';\n\nimport {BaseDAO} from './BaseDAO';\n\n/** @hidden */\n// tslint:disable-next-line\nconst moment = require('moment');\n\n/** @hidden */\n// tslint:disable-next-line\nimport {Moment} from 'moment';\nimport {IValueProvider} from './IValueProvider';\n\n/**\n * An abstract data access layer API, meant to (somewhat) mirror the DAO interfaces\n * inside OpenNMS. Used to retrieve model data like alarms, events, etc. from the\n * OpenNMS ReST API in a consistent way.\n *\n * @module AbstractDAO\n * @param K the ID/key type (number, string, etc.)\n * @param T the model type (OnmsAlarm, OnmsEvent, etc.)\n */\nexport abstract class AbstractDAO<K, T> extends BaseDAO implements IValueProvider {\n /**\n * Returns the Promise for a [[IFilterProcessor]].\n * @returns {Promise}\n */\n public async getFilterProcessor(): Promise<IFilterProcessor> {\n switch (this.getApiVersion()) {\n case 2:\n return this.getPropertiesCache().then((cache) => {\n return new V2FilterProcessor(cache);\n });\n default:\n return Promise.resolve(new V1FilterProcessor());\n }\n }\n\n /**\n * Retrieve a model object.\n * @param id - the ID of the object\n */\n public abstract async get(id: K): Promise<T>;\n\n /**\n * Find all model objects given an optional filter.\n * @param filter - the filter to use when retrieving a list of model objects\n */\n public abstract async find(filter?: Filter): Promise<T[]>;\n\n /**\n * Get the list properties that can be used in queries.\n * @version ReST v2\n */\n public async searchProperties(): Promise<SearchProperty[]> {\n return this.getPropertiesCache().then((cache) => {\n return cache.getProperties();\n });\n }\n\n /**\n * Gets the property identified by the id if it exists.\n *\n * @param id The id to search the property by.\n */\n public async searchProperty(id: string): Promise<SearchProperty> {\n return this.getPropertiesCache().then((cache) => {\n return cache.getProperty(id);\n });\n }\n\n /**\n * Returns or creates the [[PropertiesCache]] for this dao.\n *\n * @return the [[PropertiesCache]] for this dao. It is created if it does not exist.\n */\n public async getPropertiesCache(): Promise<PropertiesCache> {\n if (this.getApiVersion() === 1) {\n throw new OnmsError('Search property metadata is only available in OpenNMS ' +\n 'versions that support the ReSTv2 API.');\n }\n\n // Cache not yet initialized\n if (!PropertiesCache.get(this)) {\n return this.getOptions().then((opts) => {\n opts.headers.accept = 'application/json';\n return this.http.get(this.searchPropertyPath(), opts).then((result) => {\n const searchProperties = this.parseResultList(result, 'searchProperty',\n this.searchPropertyPath(), (prop) => {\n return this.toSearchProperty(prop);\n });\n PropertiesCache.put(this, searchProperties);\n return Promise.resolve(PropertiesCache.get(this));\n });\n });\n }\n // Cache already initialized, use value\n return Promise.resolve(PropertiesCache.get(this));\n }\n\n /**\n * Finds the values for the given propertyId, if it exists.\n *\n * @param {string} propertyId The propertyId to find the values for\n * @param options Some additional options. May be implementer dependent, such as limit, or value restrictions\n * @returns {Promise<any>} A promise containing the values.\n */\n public async findValues(propertyId: string, options?: any): Promise<any> {\n return this.searchProperty(propertyId).then((property) => {\n return this.getOptions().then((opts) => {\n const path = this.searchPropertyPath() + '/' + property.id;\n opts.headers.accept = 'application/json';\n if (options) {\n Object.assign(opts, options);\n }\n return this.http.get(path, opts).then((result) => {\n return this.parseResultList(result, 'value', path, (value) => value);\n });\n });\n });\n }\n\n /**\n * The path to retrieve search properties for this DAO.\n */\n protected abstract searchPropertyPath(): string;\n\n /**\n * Fetches the data from the result and verfifes that the <code>dataFieldName</code> exists in the data property.\n * If it does not exist, an exception is thrown.\n *\n * @param result The result to fetch the data from\n * @param dataFieldName The property name (basically <code>result.data[dataFieldName]</code>.\n * @param path The path where the result was fetched from. This is for error handling\n * @param mapCallbackFunction Callback function to convert each entry from <code>result.data[dataFieldName]</code>.\n */\n protected parseResultList(result: any, dataFieldName: string, path: string, mapCallbackFunction: any): any {\n let data = result.data;\n if (this.getCount(data) > 0 && data[dataFieldName]) {\n data = data[dataFieldName];\n } else {\n data = [];\n }\n\n if (!Array.isArray(data)) {\n throw new OnmsError('Expected an array but got \"' + (typeof data) + '\" instead: ' + path);\n }\n if (mapCallbackFunction) {\n return data.map(mapCallbackFunction);\n }\n return data;\n }\n\n /**\n * Create an [[OnmsHTTPOptions]] object for DAO calls given an optional filter.\n * @param filter - the filter to use\n */\n protected async getOptions(filter?: Filter): Promise<OnmsHTTPOptions> {\n return Promise.resolve(new OnmsHTTPOptions())\n .then((options) => {\n if (this.useJson()) {\n options.headers.accept = 'application/json';\n } else {\n // always use application/xml in DAO calls when we're not sure how\n // usable JSON output will be.\n options.headers.accept = 'application/xml';\n }\n if (filter) {\n return this.getFilterProcessor().then((processor) => {\n options.parameters = processor.getParameters(filter);\n return options;\n });\n }\n return options;\n });\n }\n\n /**\n * Generate a [[SearchProperty]] from the given dictionary.\n * @hidden\n */\n protected toSearchProperty(data: any): SearchProperty {\n if (!data) {\n return null;\n }\n\n const prop = new SearchProperty(this);\n prop.id = data.id;\n prop.name = data.name;\n prop.orderBy = !!data.orderBy;\n prop.type = SearchPropertyType.forId(data.type);\n prop.values = data.values;\n return prop;\n }\n\n /**\n * Retrieve the API version from the currently configured server.\n */\n protected getApiVersion(): number {\n if (this.http === undefined || this.http.server === undefined || this.http.server.metadata === undefined) {\n throw new OnmsError('Server meta-data must be populated prior to making DAO calls.');\n }\n return this.http.server.metadata.apiVersion();\n }\n}\n"]}]}