@itentialopensource/adapter-oracle_assure1 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/.eslintignore +5 -0
  2. package/.eslintrc.js +18 -0
  3. package/.jshintrc +3 -0
  4. package/AUTH.md +39 -0
  5. package/BROKER.md +211 -0
  6. package/CALLS.md +249 -0
  7. package/CHANGELOG.md +9 -0
  8. package/CODE_OF_CONDUCT.md +43 -0
  9. package/CONTRIBUTING.md +13 -0
  10. package/ENHANCE.md +69 -0
  11. package/LICENSE +201 -0
  12. package/PROPERTIES.md +646 -0
  13. package/README.md +343 -0
  14. package/SUMMARY.md +9 -0
  15. package/SYSTEMINFO.md +17 -0
  16. package/TAB1.md +10 -0
  17. package/TAB2.md +311 -0
  18. package/TROUBLESHOOT.md +47 -0
  19. package/adapter.js +1410 -0
  20. package/adapterBase.js +1452 -0
  21. package/entities/.generic/action.json +214 -0
  22. package/entities/.generic/schema.json +28 -0
  23. package/entities/.system/action.json +50 -0
  24. package/entities/.system/mockdatafiles/getToken-default.json +3 -0
  25. package/entities/.system/mockdatafiles/healthcheck-default.json +3 -0
  26. package/entities/.system/schema.json +19 -0
  27. package/entities/.system/schemaTokenReq.json +53 -0
  28. package/entities/.system/schemaTokenResp.json +53 -0
  29. package/entities/Devices/action.json +127 -0
  30. package/entities/Devices/schema.json +24 -0
  31. package/entities/PerformanceData/action.json +25 -0
  32. package/entities/PerformanceData/schema.json +96 -0
  33. package/error.json +190 -0
  34. package/metadata.json +74 -0
  35. package/package.json +81 -0
  36. package/pronghorn.json +1442 -0
  37. package/propertiesDecorators.json +14 -0
  38. package/propertiesSchema.json +1574 -0
  39. package/refs?service=git-upload-pack +0 -0
  40. package/report/adapterInfo.json +10 -0
  41. package/report/assure1-api-5.3.3-openapi.json +507 -0
  42. package/report/auto-adapter-openapi.json +405 -0
  43. package/report/creationReport.json +260 -0
  44. package/sampleProperties.json +257 -0
  45. package/test/integration/adapterTestBasicGet.js +83 -0
  46. package/test/integration/adapterTestConnectivity.js +118 -0
  47. package/test/integration/adapterTestIntegration.js +662 -0
  48. package/test/unit/adapterBaseTestUnit.js +1024 -0
  49. package/test/unit/adapterTestUnit.js +1707 -0
  50. package/utils/adapterInfo.js +206 -0
  51. package/utils/addAuth.js +94 -0
  52. package/utils/artifactize.js +146 -0
  53. package/utils/basicGet.js +50 -0
  54. package/utils/checkMigrate.js +63 -0
  55. package/utils/entitiesToDB.js +179 -0
  56. package/utils/findPath.js +74 -0
  57. package/utils/methodDocumentor.js +273 -0
  58. package/utils/modify.js +152 -0
  59. package/utils/packModificationScript.js +35 -0
  60. package/utils/patches2bundledDeps.js +90 -0
  61. package/utils/pre-commit.sh +32 -0
  62. package/utils/removeHooks.js +20 -0
  63. package/utils/setup.js +33 -0
  64. package/utils/taskMover.js +309 -0
  65. package/utils/tbScript.js +239 -0
  66. package/utils/tbUtils.js +489 -0
  67. package/utils/testRunner.js +298 -0
  68. package/utils/troubleshootingAdapter.js +193 -0
package/adapter.js ADDED
@@ -0,0 +1,1410 @@
1
+ /* @copyright Itential, LLC 2019 (pre-modifications) */
2
+
3
+ /* eslint import/no-dynamic-require: warn */
4
+ /* eslint object-curly-newline: warn */
5
+ /* eslint default-param-last: warn */
6
+
7
+ // Set globals
8
+ /* global log */
9
+
10
+ /* Required libraries. */
11
+ const path = require('path');
12
+
13
+ /* Fetch in the other needed components for the this Adaptor */
14
+ const AdapterBaseCl = require(path.join(__dirname, 'adapterBase.js'));
15
+
16
+ /**
17
+ * This is the adapter/interface into Oracle_assure1
18
+ */
19
+
20
+ /* GENERAL ADAPTER FUNCTIONS */
21
+ class OracleAssure1 extends AdapterBaseCl {
22
+ /**
23
+ * OracleAssure1 Adapter
24
+ * @constructor
25
+ */
26
+ /* Working on changing the way we do Emit methods due to size and time constrainsts
27
+ constructor(prongid, properties) {
28
+ // Instantiate the AdapterBase super class
29
+ super(prongid, properties);
30
+
31
+ const restFunctionNames = this.iapGetAdapterWorkflowFunctions();
32
+
33
+ // Dynamically bind emit functions
34
+ for (let i = 0; i < restFunctionNames.length; i += 1) {
35
+ // Bind function to have name fnNameEmit for fnName
36
+ const version = restFunctionNames[i].match(/__v[0-9]+/);
37
+ const baseFnName = restFunctionNames[i].replace(/__v[0-9]+/, '');
38
+ const fnNameEmit = version ? `${baseFnName}Emit${version}` : `${baseFnName}Emit`;
39
+ this[fnNameEmit] = function (...args) {
40
+ // extract the callback
41
+ const callback = args[args.length - 1];
42
+ // slice the callback from args so we can insert our own
43
+ const functionArgs = args.slice(0, args.length - 1);
44
+ // create a random name for the listener
45
+ const eventName = `${restFunctionNames[i]}:${Math.random().toString(36)}`;
46
+ // tell the calling class to start listening
47
+ callback({ event: eventName, status: 'received' });
48
+ // store parent for use of this context later
49
+ const parent = this;
50
+ // store emission function
51
+ const func = function (val, err) {
52
+ parent.removeListener(eventName, func);
53
+ parent.emit(eventName, val, err);
54
+ };
55
+ // Use apply to call the function in a specific context
56
+ this[restFunctionNames[i]].apply(this, functionArgs.concat([func])); // eslint-disable-line prefer-spread
57
+ };
58
+ }
59
+
60
+ // Uncomment if you have things to add to the constructor like using your own properties.
61
+ // Otherwise the constructor in the adapterBase will be used.
62
+ // Capture my own properties - they need to be defined in propertiesSchema.json
63
+ // if (this.allProps && this.allProps.myownproperty) {
64
+ // mypropvariable = this.allProps.myownproperty;
65
+ // }
66
+ }
67
+ */
68
+
69
+ /**
70
+ * @callback healthCallback
71
+ * @param {Object} reqObj - the request to send into the healthcheck
72
+ * @param {Callback} callback - The results of the call
73
+ */
74
+ healthCheck(reqObj, callback) {
75
+ // you can modify what is passed into the healthcheck by changing things in the newReq
76
+ let newReq = null;
77
+ if (reqObj) {
78
+ newReq = Object.assign(...reqObj);
79
+ }
80
+ super.healthCheck(newReq, callback);
81
+ }
82
+
83
+ /**
84
+ * @iapGetAdapterWorkflowFunctions
85
+ */
86
+ iapGetAdapterWorkflowFunctions(inIgnore) {
87
+ let myIgnore = [
88
+ 'healthCheck',
89
+ 'iapGetAdapterWorkflowFunctions',
90
+ 'hasEntities',
91
+ 'getAuthorization'
92
+ ];
93
+ if (!inIgnore && Array.isArray(inIgnore)) {
94
+ myIgnore = inIgnore;
95
+ } else if (!inIgnore && typeof inIgnore === 'string') {
96
+ myIgnore = [inIgnore];
97
+ }
98
+
99
+ // The generic adapter functions should already be ignored (e.g. healthCheck)
100
+ // you can add specific methods that you do not want to be workflow functions to ignore like below
101
+ // myIgnore.push('myMethodNotInWorkflow');
102
+
103
+ return super.iapGetAdapterWorkflowFunctions(myIgnore);
104
+ }
105
+
106
+ /**
107
+ * iapUpdateAdapterConfiguration is used to update any of the adapter configuration files. This
108
+ * allows customers to make changes to adapter configuration without having to be on the
109
+ * file system.
110
+ *
111
+ * @function iapUpdateAdapterConfiguration
112
+ * @param {string} configFile - the name of the file being updated (required)
113
+ * @param {Object} changes - an object containing all of the changes = formatted like the configuration file (required)
114
+ * @param {string} entity - the entity to be changed, if an action, schema or mock data file (optional)
115
+ * @param {string} type - the type of entity file to change, (action, schema, mock) (optional)
116
+ * @param {string} action - the action to be changed, if an action, schema or mock data file (optional)
117
+ * @param {boolean} replace - true to replace entire mock data, false to merge/append
118
+ * @param {Callback} callback - The results of the call
119
+ */
120
+ iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, replace, callback) {
121
+ const meth = 'adapter-iapUpdateAdapterConfiguration';
122
+ const origin = `${this.id}-${meth}`;
123
+ log.trace(origin);
124
+
125
+ super.iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, replace, callback);
126
+ }
127
+
128
+ /**
129
+ * @summary Suspends adapter
130
+ *
131
+ * @function iapSuspendAdapter
132
+ * @param {Callback} callback - callback function
133
+ */
134
+ iapSuspendAdapter(mode, callback) {
135
+ const meth = 'adapter-iapSuspendAdapter';
136
+ const origin = `${this.id}-${meth}`;
137
+ log.trace(origin);
138
+
139
+ try {
140
+ return super.iapSuspendAdapter(mode, callback);
141
+ } catch (error) {
142
+ log.error(`${origin}: ${error}`);
143
+ return callback(null, error);
144
+ }
145
+ }
146
+
147
+ /**
148
+ * @summary Unsuspends adapter
149
+ *
150
+ * @function iapUnsuspendAdapter
151
+ * @param {Callback} callback - callback function
152
+ */
153
+ iapUnsuspendAdapter(callback) {
154
+ const meth = 'adapter-iapUnsuspendAdapter';
155
+ const origin = `${this.id}-${meth}`;
156
+ log.trace(origin);
157
+
158
+ try {
159
+ return super.iapUnsuspendAdapter(callback);
160
+ } catch (error) {
161
+ log.error(`${origin}: ${error}`);
162
+ return callback(null, error);
163
+ }
164
+ }
165
+
166
+ /**
167
+ * @summary Get the Adapter Queue
168
+ *
169
+ * @function iapGetAdapterQueue
170
+ * @param {Callback} callback - callback function
171
+ */
172
+ iapGetAdapterQueue(callback) {
173
+ const meth = 'adapter-iapGetAdapterQueue';
174
+ const origin = `${this.id}-${meth}`;
175
+ log.trace(origin);
176
+
177
+ return super.iapGetAdapterQueue(callback);
178
+ }
179
+
180
+ /* SCRIPT CALLS */
181
+ /**
182
+ * See if the API path provided is found in this adapter
183
+ *
184
+ * @function iapFindAdapterPath
185
+ * @param {string} apiPath - the api path to check on
186
+ * @param {Callback} callback - The results of the call
187
+ */
188
+ iapFindAdapterPath(apiPath, callback) {
189
+ const meth = 'adapter-iapFindAdapterPath';
190
+ const origin = `${this.id}-${meth}`;
191
+ log.trace(origin);
192
+
193
+ super.iapFindAdapterPath(apiPath, callback);
194
+ }
195
+
196
+ /**
197
+ * @summary Runs troubleshoot scripts for adapter
198
+ *
199
+ * @function iapTroubleshootAdapter
200
+ * @param {Object} props - the connection, healthcheck and authentication properties
201
+ *
202
+ * @param {boolean} persistFlag - whether the adapter properties should be updated
203
+ * @param {Callback} callback - The results of the call
204
+ */
205
+ iapTroubleshootAdapter(props, persistFlag, callback) {
206
+ const meth = 'adapter-iapTroubleshootAdapter';
207
+ const origin = `${this.id}-${meth}`;
208
+ log.trace(origin);
209
+
210
+ try {
211
+ return super.iapTroubleshootAdapter(props, persistFlag, this, callback);
212
+ } catch (error) {
213
+ log.error(`${origin}: ${error}`);
214
+ return callback(null, error);
215
+ }
216
+ }
217
+
218
+ /**
219
+ * @summary runs healthcheck script for adapter
220
+ *
221
+ * @function iapRunAdapterHealthcheck
222
+ * @param {Adapter} adapter - adapter instance to troubleshoot
223
+ * @param {Callback} callback - callback function
224
+ */
225
+ iapRunAdapterHealthcheck(callback) {
226
+ const meth = 'adapter-iapRunAdapterHealthcheck';
227
+ const origin = `${this.id}-${meth}`;
228
+ log.trace(origin);
229
+
230
+ try {
231
+ return super.iapRunAdapterHealthcheck(this, callback);
232
+ } catch (error) {
233
+ log.error(`${origin}: ${error}`);
234
+ return callback(null, error);
235
+ }
236
+ }
237
+
238
+ /**
239
+ * @summary runs connectivity check script for adapter
240
+ *
241
+ * @function iapRunAdapterConnectivity
242
+ * @param {Callback} callback - callback function
243
+ */
244
+ iapRunAdapterConnectivity(callback) {
245
+ const meth = 'adapter-iapRunAdapterConnectivity';
246
+ const origin = `${this.id}-${meth}`;
247
+ log.trace(origin);
248
+
249
+ try {
250
+ return super.iapRunAdapterConnectivity(callback);
251
+ } catch (error) {
252
+ log.error(`${origin}: ${error}`);
253
+ return callback(null, error);
254
+ }
255
+ }
256
+
257
+ /**
258
+ * @summary runs basicGet script for adapter
259
+ *
260
+ * @function iapRunAdapterBasicGet
261
+ * @param {Callback} callback - callback function
262
+ */
263
+ iapRunAdapterBasicGet(callback) {
264
+ const meth = 'adapter-iapRunAdapterBasicGet';
265
+ const origin = `${this.id}-${meth}`;
266
+ log.trace(origin);
267
+
268
+ try {
269
+ return super.iapRunAdapterBasicGet(callback);
270
+ } catch (error) {
271
+ log.error(`${origin}: ${error}`);
272
+ return callback(null, error);
273
+ }
274
+ }
275
+
276
+ /**
277
+ * @summary moves entites into Mongo DB
278
+ *
279
+ * @function iapMoveAdapterEntitiesToDB
280
+ * @param {getCallback} callback - a callback function to return the result (Generics)
281
+ * or the error
282
+ */
283
+ iapMoveAdapterEntitiesToDB(callback) {
284
+ const meth = 'adapter-iapMoveAdapterEntitiesToDB';
285
+ const origin = `${this.id}-${meth}`;
286
+ log.trace(origin);
287
+
288
+ try {
289
+ return super.iapMoveAdapterEntitiesToDB(callback);
290
+ } catch (err) {
291
+ log.error(`${origin}: ${err}`);
292
+ return callback(null, err);
293
+ }
294
+ }
295
+
296
+ /**
297
+ * @summary Deactivate adapter tasks
298
+ *
299
+ * @function iapDeactivateTasks
300
+ *
301
+ * @param {Array} tasks - List of tasks to deactivate
302
+ * @param {Callback} callback
303
+ */
304
+ iapDeactivateTasks(tasks, callback) {
305
+ const meth = 'adapter-iapDeactivateTasks';
306
+ const origin = `${this.id}-${meth}`;
307
+ log.trace(origin);
308
+
309
+ try {
310
+ return super.iapDeactivateTasks(tasks, callback);
311
+ } catch (err) {
312
+ log.error(`${origin}: ${err}`);
313
+ return callback(null, err);
314
+ }
315
+ }
316
+
317
+ /**
318
+ * @summary Activate adapter tasks that have previously been deactivated
319
+ *
320
+ * @function iapActivateTasks
321
+ *
322
+ * @param {Array} tasks - List of tasks to activate
323
+ * @param {Callback} callback
324
+ */
325
+ iapActivateTasks(tasks, callback) {
326
+ const meth = 'adapter-iapActivateTasks';
327
+ const origin = `${this.id}-${meth}`;
328
+ log.trace(origin);
329
+
330
+ try {
331
+ return super.iapActivateTasks(tasks, callback);
332
+ } catch (err) {
333
+ log.error(`${origin}: ${err}`);
334
+ return callback(null, err);
335
+ }
336
+ }
337
+
338
+ /* CACHE CALLS */
339
+ /**
340
+ * @summary Populate the cache for the given entities
341
+ *
342
+ * @function iapPopulateEntityCache
343
+ * @param {String/Array of Strings} entityType - the entity type(s) to populate
344
+ * @param {Callback} callback - whether the cache was updated or not for each entity type
345
+ *
346
+ * @returns status of the populate
347
+ */
348
+ iapPopulateEntityCache(entityTypes, callback) {
349
+ const meth = 'adapter-iapPopulateEntityCache';
350
+ const origin = `${this.id}-${meth}`;
351
+ log.trace(origin);
352
+
353
+ try {
354
+ return super.iapPopulateEntityCache(entityTypes, callback);
355
+ } catch (err) {
356
+ log.error(`${origin}: ${err}`);
357
+ return callback(null, err);
358
+ }
359
+ }
360
+
361
+ /**
362
+ * @summary Retrieves data from cache for specified entity type
363
+ *
364
+ * @function iapRetrieveEntitiesCache
365
+ * @param {String} entityType - entity of which to retrieve
366
+ * @param {Object} options - settings of which data to return and how to return it
367
+ * @param {Callback} callback - the data if it was retrieved
368
+ */
369
+ iapRetrieveEntitiesCache(entityType, options, callback) {
370
+ const meth = 'adapter-iapCheckEiapRetrieveEntitiesCachentityCached';
371
+ const origin = `${this.id}-${meth}`;
372
+ log.trace(origin);
373
+
374
+ try {
375
+ return super.iapRetrieveEntitiesCache(entityType, options, callback);
376
+ } catch (err) {
377
+ log.error(`${origin}: ${err}`);
378
+ return callback(null, err);
379
+ }
380
+ }
381
+
382
+ /* BROKER CALLS */
383
+ /**
384
+ * @summary Determines if this adapter supports any in a list of entities
385
+ *
386
+ * @function hasEntities
387
+ * @param {String} entityType - the entity type to check for
388
+ * @param {Array} entityList - the list of entities we are looking for
389
+ *
390
+ * @param {Callback} callback - A map where the entity is the key and the
391
+ * value is true or false
392
+ */
393
+ hasEntities(entityType, entityList, callback) {
394
+ const meth = 'adapter-hasEntities';
395
+ const origin = `${this.id}-${meth}`;
396
+ log.trace(origin);
397
+
398
+ try {
399
+ return super.hasEntities(entityType, entityList, callback);
400
+ } catch (err) {
401
+ log.error(`${origin}: ${err}`);
402
+ return callback(null, err);
403
+ }
404
+ }
405
+
406
+ /**
407
+ * @summary Get Appliance that match the deviceName
408
+ *
409
+ * @function getDevice
410
+ * @param {String} deviceName - the deviceName to find (required)
411
+ *
412
+ * @param {getCallback} callback - a callback function to return the result
413
+ * (appliance) or the error
414
+ */
415
+ getDevice(deviceName, callback) {
416
+ const meth = 'adapter-getDevice';
417
+ const origin = `${this.id}-${meth}`;
418
+ log.trace(origin);
419
+
420
+ try {
421
+ return super.getDevice(deviceName, callback);
422
+ } catch (err) {
423
+ log.error(`${origin}: ${err}`);
424
+ return callback(null, err);
425
+ }
426
+ }
427
+
428
+ /**
429
+ * @summary Get Appliances that match the filter
430
+ *
431
+ * @function getDevicesFiltered
432
+ * @param {Object} options - the data to use to filter the appliances (optional)
433
+ *
434
+ * @param {getCallback} callback - a callback function to return the result
435
+ * (appliances) or the error
436
+ */
437
+ getDevicesFiltered(options, callback) {
438
+ const meth = 'adapter-getDevicesFiltered';
439
+ const origin = `${this.id}-${meth}`;
440
+ log.trace(origin);
441
+
442
+ try {
443
+ return super.getDevicesFiltered(options, callback);
444
+ } catch (err) {
445
+ log.error(`${origin}: ${err}`);
446
+ return callback(null, err);
447
+ }
448
+ }
449
+
450
+ /**
451
+ * @summary Gets the status for the provided appliance
452
+ *
453
+ * @function isAlive
454
+ * @param {String} deviceName - the deviceName of the appliance. (required)
455
+ *
456
+ * @param {configCallback} callback - callback function to return the result
457
+ * (appliance isAlive) or the error
458
+ */
459
+ isAlive(deviceName, callback) {
460
+ const meth = 'adapter-isAlive';
461
+ const origin = `${this.id}-${meth}`;
462
+ log.trace(origin);
463
+
464
+ try {
465
+ return super.isAlive(deviceName, callback);
466
+ } catch (err) {
467
+ log.error(`${origin}: ${err}`);
468
+ return callback(null, err);
469
+ }
470
+ }
471
+
472
+ /**
473
+ * @summary Gets a config for the provided Appliance
474
+ *
475
+ * @function getConfig
476
+ * @param {String} deviceName - the deviceName of the appliance. (required)
477
+ * @param {String} format - the desired format of the config. (optional)
478
+ *
479
+ * @param {configCallback} callback - callback function to return the result
480
+ * (appliance config) or the error
481
+ */
482
+ getConfig(deviceName, format, callback) {
483
+ const meth = 'adapter-getConfig';
484
+ const origin = `${this.id}-${meth}`;
485
+ log.trace(origin);
486
+
487
+ try {
488
+ return super.getConfig(deviceName, format, callback);
489
+ } catch (err) {
490
+ log.error(`${origin}: ${err}`);
491
+ return callback(null, err);
492
+ }
493
+ }
494
+
495
+ /**
496
+ * @summary Gets the device count from the system
497
+ *
498
+ * @function iapGetDeviceCount
499
+ *
500
+ * @param {getCallback} callback - callback function to return the result
501
+ * (count) or the error
502
+ */
503
+ iapGetDeviceCount(callback) {
504
+ const meth = 'adapter-iapGetDeviceCount';
505
+ const origin = `${this.id}-${meth}`;
506
+ log.trace(origin);
507
+
508
+ try {
509
+ return super.iapGetDeviceCount(callback);
510
+ } catch (err) {
511
+ log.error(`${origin}: ${err}`);
512
+ return callback(null, err);
513
+ }
514
+ }
515
+
516
+ /* GENERIC ADAPTER REQUEST - allows extension of adapter without new calls being added */
517
+ /**
518
+ * Makes the requested generic call
519
+ *
520
+ * @function iapExpandedGenericAdapterRequest
521
+ * @param {Object} metadata - metadata for the call (optional).
522
+ * Can be a stringified Object.
523
+ * @param {String} uriPath - the path of the api call - do not include the host, port, base path or version (optional)
524
+ * @param {String} restMethod - the rest method (GET, POST, PUT, PATCH, DELETE) (optional)
525
+ * @param {Object} pathVars - the parameters to be put within the url path (optional).
526
+ * Can be a stringified Object.
527
+ * @param {Object} queryData - the parameters to be put on the url (optional).
528
+ * Can be a stringified Object.
529
+ * @param {Object} requestBody - the body to add to the request (optional).
530
+ * Can be a stringified Object.
531
+ * @param {Object} addlHeaders - additional headers to be put on the call (optional).
532
+ * Can be a stringified Object.
533
+ * @param {getCallback} callback - a callback function to return the result (Generics)
534
+ * or the error
535
+ */
536
+ iapExpandedGenericAdapterRequest(metadata, uriPath, restMethod, pathVars, queryData, requestBody, addlHeaders, callback) {
537
+ const meth = 'adapter-iapExpandedGenericAdapterRequest';
538
+ const origin = `${this.id}-${meth}`;
539
+ log.trace(origin);
540
+
541
+ try {
542
+ return super.iapExpandedGenericAdapterRequest(metadata, uriPath, restMethod, pathVars, queryData, requestBody, addlHeaders, callback);
543
+ } catch (err) {
544
+ log.error(`${origin}: ${err}`);
545
+ return callback(null, err);
546
+ }
547
+ }
548
+
549
+ /**
550
+ * Makes the requested generic call
551
+ *
552
+ * @function genericAdapterRequest
553
+ * @param {String} uriPath - the path of the api call - do not include the host, port, base path or version (required)
554
+ * @param {String} restMethod - the rest method (GET, POST, PUT, PATCH, DELETE) (required)
555
+ * @param {Object} queryData - the parameters to be put on the url (optional).
556
+ * Can be a stringified Object.
557
+ * @param {Object} requestBody - the body to add to the request (optional).
558
+ * Can be a stringified Object.
559
+ * @param {Object} addlHeaders - additional headers to be put on the call (optional).
560
+ * Can be a stringified Object.
561
+ * @param {getCallback} callback - a callback function to return the result (Generics)
562
+ * or the error
563
+ */
564
+ genericAdapterRequest(uriPath, restMethod, queryData, requestBody, addlHeaders, callback) {
565
+ const meth = 'adapter-genericAdapterRequest';
566
+ const origin = `${this.id}-${meth}`;
567
+ log.trace(origin);
568
+
569
+ try {
570
+ return super.genericAdapterRequest(uriPath, restMethod, queryData, requestBody, addlHeaders, callback);
571
+ } catch (err) {
572
+ log.error(`${origin}: ${err}`);
573
+ return callback(null, err);
574
+ }
575
+ }
576
+
577
+ /**
578
+ * Makes the requested generic call with no base path or version
579
+ *
580
+ * @function genericAdapterRequestNoBasePath
581
+ * @param {String} uriPath - the path of the api call - do not include the host, port, base path or version (required)
582
+ * @param {String} restMethod - the rest method (GET, POST, PUT, PATCH, DELETE) (required)
583
+ * @param {Object} queryData - the parameters to be put on the url (optional).
584
+ * Can be a stringified Object.
585
+ * @param {Object} requestBody - the body to add to the request (optional).
586
+ * Can be a stringified Object.
587
+ * @param {Object} addlHeaders - additional headers to be put on the call (optional).
588
+ * Can be a stringified Object.
589
+ * @param {getCallback} callback - a callback function to return the result (Generics)
590
+ * or the error
591
+ */
592
+ genericAdapterRequestNoBasePath(uriPath, restMethod, queryData, requestBody, addlHeaders, callback) {
593
+ const meth = 'adapter-genericAdapterRequestNoBasePath';
594
+ const origin = `${this.id}-${meth}`;
595
+ log.trace(origin);
596
+
597
+ try {
598
+ return super.genericAdapterRequestNoBasePath(uriPath, restMethod, queryData, requestBody, addlHeaders, callback);
599
+ } catch (err) {
600
+ log.error(`${origin}: ${err}`);
601
+ return callback(null, err);
602
+ }
603
+ }
604
+
605
+ /* INVENTORY CALLS */
606
+ /**
607
+ * @summary run the adapter lint script to return the results.
608
+ *
609
+ * @function iapRunAdapterLint
610
+ * @param {Callback} callback - callback function
611
+ */
612
+ iapRunAdapterLint(callback) {
613
+ const meth = 'adapter-iapRunAdapterLint';
614
+ const origin = `${this.id}-${meth}`;
615
+ log.trace(origin);
616
+
617
+ return super.iapRunAdapterLint(callback);
618
+ }
619
+
620
+ /**
621
+ * @summary run the adapter test scripts (baseunit and unit) to return the results.
622
+ * can not run integration as there can be implications with that.
623
+ *
624
+ * @function iapRunAdapterTests
625
+ * @param {Callback} callback - callback function
626
+ */
627
+ iapRunAdapterTests(callback) {
628
+ const meth = 'adapter-iapRunAdapterTests';
629
+ const origin = `${this.id}-${meth}`;
630
+ log.trace(origin);
631
+
632
+ return super.iapRunAdapterTests(callback);
633
+ }
634
+
635
+ /**
636
+ * @summary provide inventory information abbout the adapter
637
+ *
638
+ * @function iapGetAdapterInventory
639
+ * @param {Callback} callback - callback function
640
+ */
641
+ iapGetAdapterInventory(callback) {
642
+ const meth = 'adapter-iapGetAdapterInventory';
643
+ const origin = `${this.id}-${meth}`;
644
+ log.trace(origin);
645
+
646
+ return super.iapGetAdapterInventory(callback);
647
+ }
648
+
649
+ /**
650
+ * @callback healthCallback
651
+ * @param {Object} result - the result of the get request (contains an id and a status)
652
+ */
653
+ /**
654
+ * @callback getCallback
655
+ * @param {Object} result - the result of the get request (entity/ies)
656
+ * @param {String} error - any error that occurred
657
+ */
658
+ /**
659
+ * @callback createCallback
660
+ * @param {Object} item - the newly created entity
661
+ * @param {String} error - any error that occurred
662
+ */
663
+ /**
664
+ * @callback updateCallback
665
+ * @param {String} status - the status of the update action
666
+ * @param {String} error - any error that occurred
667
+ */
668
+ /**
669
+ * @callback deleteCallback
670
+ * @param {String} status - the status of the delete action
671
+ * @param {String} error - any error that occurred
672
+ */
673
+
674
+ /**
675
+ * @function deviceDevicesReadByID
676
+ * @pronghornType method
677
+ * @name deviceDevicesReadByID
678
+ * @summary View one Device
679
+ *
680
+ * @param {number} id - Device ID
681
+ * @param {object} iapMetadata - IAP Metadata object contains additional info needed for the request: payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, etc.
682
+ * @param {getCallback} callback - a callback function to return the result
683
+ * @return {object} results - An object containing the response of the action
684
+ *
685
+ * @route {POST} /deviceDevicesReadByID
686
+ * @roles admin
687
+ * @task true
688
+ */
689
+ /* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
690
+ deviceDevicesReadByID(id, iapMetadata, callback) {
691
+ const meth = 'adapter-deviceDevicesReadByID';
692
+ const origin = `${this.id}-${meth}`;
693
+ log.trace(origin);
694
+
695
+ if (this.suspended && this.suspendMode === 'error') {
696
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
697
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
698
+ return callback(null, errorObj);
699
+ }
700
+
701
+ /* HERE IS WHERE YOU VALIDATE DATA */
702
+ if (id === undefined || id === null || id === '') {
703
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['id'], null, null, null);
704
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
705
+ return callback(null, errorObj);
706
+ }
707
+
708
+ /* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
709
+ const queryParamsAvailable = {};
710
+ const queryParams = {};
711
+ const pathVars = [id];
712
+ const bodyVars = {};
713
+
714
+ // loop in template. long callback arg name to avoid identifier conflicts
715
+ Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
716
+ if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
717
+ && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
718
+ queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
719
+ }
720
+ });
721
+
722
+ // set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
723
+ // see adapter code documentation for more information on the request object's fields
724
+ const reqObj = {
725
+ payload: bodyVars,
726
+ uriPathVars: pathVars,
727
+ uriQuery: queryParams
728
+ };
729
+
730
+ const reqFields = ['payload', 'uriPathVars', 'uriQuery', 'uriOptions', 'addlHeaders', 'authData', 'callProperties', 'filter', 'priority', 'event'];
731
+
732
+ // Merge and add new iapMetadata fields in reqObj
733
+ if (iapMetadata && typeof iapMetadata === 'object') {
734
+ Object.keys(iapMetadata).forEach((iapField) => {
735
+ if (reqFields.includes(iapField) && iapMetadata[iapField]) {
736
+ if (typeof reqObj[iapField] === 'object' && typeof iapMetadata[iapField] === 'object') {
737
+ reqObj[iapField] = { ...reqObj[iapField], ...iapMetadata[iapField] }; // Merge objects
738
+ } else if (Array.isArray(reqObj[iapField]) && Array.isArray(iapMetadata[iapField])) {
739
+ reqObj[iapField] = reqObj[iapField].concat(iapMetadata[iapField]); // Merge arrays
740
+ } else {
741
+ // Otherwise, add new iapMetadata fields to reqObj
742
+ reqObj[iapField] = iapMetadata[iapField];
743
+ }
744
+ }
745
+ });
746
+ // Add iapMetadata to reqObj for further work
747
+ reqObj.iapMetadata = iapMetadata;
748
+ }
749
+
750
+ try {
751
+ // Make the call -
752
+ // identifyRequest(entity, action, requestObj, returnDataFlag, callback)
753
+ return this.requestHandlerInst.identifyRequest('Devices', 'deviceDevicesReadByID', reqObj, true, (irReturnData, irReturnError) => {
754
+ // if we received an error or their is no response on the results
755
+ // return an error
756
+ if (irReturnError) {
757
+ /* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
758
+ return callback(null, irReturnError);
759
+ }
760
+ if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
761
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['deviceDevicesReadByID'], null, null, null);
762
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
763
+ return callback(null, errorObj);
764
+ }
765
+
766
+ /* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
767
+ // return the response
768
+ return callback(irReturnData, null);
769
+ });
770
+ } catch (ex) {
771
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
772
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
773
+ return callback(null, errorObj);
774
+ }
775
+ }
776
+
777
+ /**
778
+ * @function devicesUpdate
779
+ * @pronghornType method
780
+ * @name devicesUpdate
781
+ * @summary Update a Device
782
+ *
783
+ * @param {number} id - Device ID
784
+ * @param {object} [body] - body param
785
+ * @param {object} iapMetadata - IAP Metadata object contains additional info needed for the request: payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, etc.
786
+ * @param {getCallback} callback - a callback function to return the result
787
+ * @return {object} results - An object containing the response of the action
788
+ *
789
+ * @route {POST} /devicesUpdate
790
+ * @roles admin
791
+ * @task true
792
+ */
793
+ /* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
794
+ devicesUpdate(id, body, iapMetadata, callback) {
795
+ const meth = 'adapter-devicesUpdate';
796
+ const origin = `${this.id}-${meth}`;
797
+ log.trace(origin);
798
+
799
+ if (this.suspended && this.suspendMode === 'error') {
800
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
801
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
802
+ return callback(null, errorObj);
803
+ }
804
+
805
+ /* HERE IS WHERE YOU VALIDATE DATA */
806
+ if (id === undefined || id === null || id === '') {
807
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['id'], null, null, null);
808
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
809
+ return callback(null, errorObj);
810
+ }
811
+
812
+ /* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
813
+ const queryParamsAvailable = {};
814
+ const queryParams = {};
815
+ const pathVars = [id];
816
+ const bodyVars = body;
817
+
818
+ // loop in template. long callback arg name to avoid identifier conflicts
819
+ Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
820
+ if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
821
+ && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
822
+ queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
823
+ }
824
+ });
825
+
826
+ // set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
827
+ // see adapter code documentation for more information on the request object's fields
828
+ const reqObj = {
829
+ payload: bodyVars,
830
+ uriPathVars: pathVars,
831
+ uriQuery: queryParams
832
+ };
833
+
834
+ const reqFields = ['payload', 'uriPathVars', 'uriQuery', 'uriOptions', 'addlHeaders', 'authData', 'callProperties', 'filter', 'priority', 'event'];
835
+
836
+ // Merge and add new iapMetadata fields in reqObj
837
+ if (iapMetadata && typeof iapMetadata === 'object') {
838
+ Object.keys(iapMetadata).forEach((iapField) => {
839
+ if (reqFields.includes(iapField) && iapMetadata[iapField]) {
840
+ if (typeof reqObj[iapField] === 'object' && typeof iapMetadata[iapField] === 'object') {
841
+ reqObj[iapField] = { ...reqObj[iapField], ...iapMetadata[iapField] }; // Merge objects
842
+ } else if (Array.isArray(reqObj[iapField]) && Array.isArray(iapMetadata[iapField])) {
843
+ reqObj[iapField] = reqObj[iapField].concat(iapMetadata[iapField]); // Merge arrays
844
+ } else {
845
+ // Otherwise, add new iapMetadata fields to reqObj
846
+ reqObj[iapField] = iapMetadata[iapField];
847
+ }
848
+ }
849
+ });
850
+ // Add iapMetadata to reqObj for further work
851
+ reqObj.iapMetadata = iapMetadata;
852
+ }
853
+
854
+ try {
855
+ // Make the call -
856
+ // identifyRequest(entity, action, requestObj, returnDataFlag, callback)
857
+ return this.requestHandlerInst.identifyRequest('Devices', 'devicesUpdate', reqObj, false, (irReturnData, irReturnError) => {
858
+ // if we received an error or their is no response on the results
859
+ // return an error
860
+ if (irReturnError) {
861
+ /* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
862
+ return callback(null, irReturnError);
863
+ }
864
+ if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
865
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['devicesUpdate'], null, null, null);
866
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
867
+ return callback(null, errorObj);
868
+ }
869
+
870
+ /* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
871
+ // return the response
872
+ return callback(irReturnData, null);
873
+ });
874
+ } catch (ex) {
875
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
876
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
877
+ return callback(null, errorObj);
878
+ }
879
+ }
880
+
881
+ /**
882
+ * @function devicesDelete
883
+ * @pronghornType method
884
+ * @name devicesDelete
885
+ * @summary Delete a Device
886
+ *
887
+ * @param {number} id - Device ID
888
+ * @param {object} iapMetadata - IAP Metadata object contains additional info needed for the request: payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, etc.
889
+ * @param {getCallback} callback - a callback function to return the result
890
+ * @return {object} results - An object containing the response of the action
891
+ *
892
+ * @route {POST} /devicesDelete
893
+ * @roles admin
894
+ * @task true
895
+ */
896
+ /* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
897
+ devicesDelete(id, iapMetadata, callback) {
898
+ const meth = 'adapter-devicesDelete';
899
+ const origin = `${this.id}-${meth}`;
900
+ log.trace(origin);
901
+
902
+ if (this.suspended && this.suspendMode === 'error') {
903
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
904
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
905
+ return callback(null, errorObj);
906
+ }
907
+
908
+ /* HERE IS WHERE YOU VALIDATE DATA */
909
+ if (id === undefined || id === null || id === '') {
910
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['id'], null, null, null);
911
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
912
+ return callback(null, errorObj);
913
+ }
914
+
915
+ /* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
916
+ const queryParamsAvailable = {};
917
+ const queryParams = {};
918
+ const pathVars = [id];
919
+ const bodyVars = {};
920
+
921
+ // loop in template. long callback arg name to avoid identifier conflicts
922
+ Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
923
+ if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
924
+ && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
925
+ queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
926
+ }
927
+ });
928
+
929
+ // set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
930
+ // see adapter code documentation for more information on the request object's fields
931
+ const reqObj = {
932
+ payload: bodyVars,
933
+ uriPathVars: pathVars,
934
+ uriQuery: queryParams
935
+ };
936
+
937
+ const reqFields = ['payload', 'uriPathVars', 'uriQuery', 'uriOptions', 'addlHeaders', 'authData', 'callProperties', 'filter', 'priority', 'event'];
938
+
939
+ // Merge and add new iapMetadata fields in reqObj
940
+ if (iapMetadata && typeof iapMetadata === 'object') {
941
+ Object.keys(iapMetadata).forEach((iapField) => {
942
+ if (reqFields.includes(iapField) && iapMetadata[iapField]) {
943
+ if (typeof reqObj[iapField] === 'object' && typeof iapMetadata[iapField] === 'object') {
944
+ reqObj[iapField] = { ...reqObj[iapField], ...iapMetadata[iapField] }; // Merge objects
945
+ } else if (Array.isArray(reqObj[iapField]) && Array.isArray(iapMetadata[iapField])) {
946
+ reqObj[iapField] = reqObj[iapField].concat(iapMetadata[iapField]); // Merge arrays
947
+ } else {
948
+ // Otherwise, add new iapMetadata fields to reqObj
949
+ reqObj[iapField] = iapMetadata[iapField];
950
+ }
951
+ }
952
+ });
953
+ // Add iapMetadata to reqObj for further work
954
+ reqObj.iapMetadata = iapMetadata;
955
+ }
956
+
957
+ try {
958
+ // Make the call -
959
+ // identifyRequest(entity, action, requestObj, returnDataFlag, callback)
960
+ return this.requestHandlerInst.identifyRequest('Devices', 'devicesDelete', reqObj, false, (irReturnData, irReturnError) => {
961
+ // if we received an error or their is no response on the results
962
+ // return an error
963
+ if (irReturnError) {
964
+ /* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
965
+ return callback(null, irReturnError);
966
+ }
967
+ if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
968
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['devicesDelete'], null, null, null);
969
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
970
+ return callback(null, errorObj);
971
+ }
972
+
973
+ /* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
974
+ // return the response
975
+ return callback(irReturnData, null);
976
+ });
977
+ } catch (ex) {
978
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
979
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
980
+ return callback(null, errorObj);
981
+ }
982
+ }
983
+
984
+ /**
985
+ * @function deviceDevicesRead
986
+ * @pronghornType method
987
+ * @name deviceDevicesRead
988
+ * @summary View all Devices
989
+ *
990
+ * @param {string} [filter] - Filter
991
+ * @param {number} [limit] - Limit
992
+ * @param {string} [sort] - Sort order
993
+ * @param {number} [start] - Start
994
+ * @param {object} iapMetadata - IAP Metadata object contains additional info needed for the request: payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, etc.
995
+ * @param {getCallback} callback - a callback function to return the result
996
+ * @return {object} results - An object containing the response of the action
997
+ *
998
+ * @route {POST} /deviceDevicesRead
999
+ * @roles admin
1000
+ * @task true
1001
+ */
1002
+ /* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
1003
+ deviceDevicesRead(filter, limit, sort, start, iapMetadata, callback) {
1004
+ const meth = 'adapter-deviceDevicesRead';
1005
+ const origin = `${this.id}-${meth}`;
1006
+ log.trace(origin);
1007
+
1008
+ if (this.suspended && this.suspendMode === 'error') {
1009
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
1010
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1011
+ return callback(null, errorObj);
1012
+ }
1013
+
1014
+ /* HERE IS WHERE YOU VALIDATE DATA */
1015
+
1016
+ /* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
1017
+ const queryParamsAvailable = { filter, limit, sort, start };
1018
+ const queryParams = {};
1019
+ const pathVars = [];
1020
+ const bodyVars = {};
1021
+
1022
+ // loop in template. long callback arg name to avoid identifier conflicts
1023
+ Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
1024
+ if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
1025
+ && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
1026
+ queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
1027
+ }
1028
+ });
1029
+
1030
+ // set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
1031
+ // see adapter code documentation for more information on the request object's fields
1032
+ const reqObj = {
1033
+ payload: bodyVars,
1034
+ uriPathVars: pathVars,
1035
+ uriQuery: queryParams
1036
+ };
1037
+
1038
+ const reqFields = ['payload', 'uriPathVars', 'uriQuery', 'uriOptions', 'addlHeaders', 'authData', 'callProperties', 'filter', 'priority', 'event'];
1039
+
1040
+ // Merge and add new iapMetadata fields in reqObj
1041
+ if (iapMetadata && typeof iapMetadata === 'object') {
1042
+ Object.keys(iapMetadata).forEach((iapField) => {
1043
+ if (reqFields.includes(iapField) && iapMetadata[iapField]) {
1044
+ if (typeof reqObj[iapField] === 'object' && typeof iapMetadata[iapField] === 'object') {
1045
+ reqObj[iapField] = { ...reqObj[iapField], ...iapMetadata[iapField] }; // Merge objects
1046
+ } else if (Array.isArray(reqObj[iapField]) && Array.isArray(iapMetadata[iapField])) {
1047
+ reqObj[iapField] = reqObj[iapField].concat(iapMetadata[iapField]); // Merge arrays
1048
+ } else {
1049
+ // Otherwise, add new iapMetadata fields to reqObj
1050
+ reqObj[iapField] = iapMetadata[iapField];
1051
+ }
1052
+ }
1053
+ });
1054
+ // Add iapMetadata to reqObj for further work
1055
+ reqObj.iapMetadata = iapMetadata;
1056
+ }
1057
+
1058
+ try {
1059
+ // Make the call -
1060
+ // identifyRequest(entity, action, requestObj, returnDataFlag, callback)
1061
+ return this.requestHandlerInst.identifyRequest('Devices', 'deviceDevicesRead', reqObj, true, (irReturnData, irReturnError) => {
1062
+ // if we received an error or their is no response on the results
1063
+ // return an error
1064
+ if (irReturnError) {
1065
+ /* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
1066
+ return callback(null, irReturnError);
1067
+ }
1068
+ if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
1069
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['deviceDevicesRead'], null, null, null);
1070
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1071
+ return callback(null, errorObj);
1072
+ }
1073
+
1074
+ /* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
1075
+ // return the response
1076
+ return callback(irReturnData, null);
1077
+ });
1078
+ } catch (ex) {
1079
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
1080
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1081
+ return callback(null, errorObj);
1082
+ }
1083
+ }
1084
+
1085
+ /**
1086
+ * @function devicesCreate
1087
+ * @pronghornType method
1088
+ * @name devicesCreate
1089
+ * @summary Add a Device
1090
+ *
1091
+ * @param {object} [body] - body param
1092
+ * @param {object} iapMetadata - IAP Metadata object contains additional info needed for the request: payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, etc.
1093
+ * @param {getCallback} callback - a callback function to return the result
1094
+ * @return {object} results - An object containing the response of the action
1095
+ *
1096
+ * @route {POST} /devicesCreate
1097
+ * @roles admin
1098
+ * @task true
1099
+ */
1100
+ /* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
1101
+ devicesCreate(body, iapMetadata, callback) {
1102
+ const meth = 'adapter-devicesCreate';
1103
+ const origin = `${this.id}-${meth}`;
1104
+ log.trace(origin);
1105
+
1106
+ if (this.suspended && this.suspendMode === 'error') {
1107
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
1108
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1109
+ return callback(null, errorObj);
1110
+ }
1111
+
1112
+ /* HERE IS WHERE YOU VALIDATE DATA */
1113
+
1114
+ /* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
1115
+ const queryParamsAvailable = {};
1116
+ const queryParams = {};
1117
+ const pathVars = [];
1118
+ const bodyVars = body;
1119
+
1120
+ // loop in template. long callback arg name to avoid identifier conflicts
1121
+ Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
1122
+ if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
1123
+ && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
1124
+ queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
1125
+ }
1126
+ });
1127
+
1128
+ // set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
1129
+ // see adapter code documentation for more information on the request object's fields
1130
+ const reqObj = {
1131
+ payload: bodyVars,
1132
+ uriPathVars: pathVars,
1133
+ uriQuery: queryParams
1134
+ };
1135
+
1136
+ const reqFields = ['payload', 'uriPathVars', 'uriQuery', 'uriOptions', 'addlHeaders', 'authData', 'callProperties', 'filter', 'priority', 'event'];
1137
+
1138
+ // Merge and add new iapMetadata fields in reqObj
1139
+ if (iapMetadata && typeof iapMetadata === 'object') {
1140
+ Object.keys(iapMetadata).forEach((iapField) => {
1141
+ if (reqFields.includes(iapField) && iapMetadata[iapField]) {
1142
+ if (typeof reqObj[iapField] === 'object' && typeof iapMetadata[iapField] === 'object') {
1143
+ reqObj[iapField] = { ...reqObj[iapField], ...iapMetadata[iapField] }; // Merge objects
1144
+ } else if (Array.isArray(reqObj[iapField]) && Array.isArray(iapMetadata[iapField])) {
1145
+ reqObj[iapField] = reqObj[iapField].concat(iapMetadata[iapField]); // Merge arrays
1146
+ } else {
1147
+ // Otherwise, add new iapMetadata fields to reqObj
1148
+ reqObj[iapField] = iapMetadata[iapField];
1149
+ }
1150
+ }
1151
+ });
1152
+ // Add iapMetadata to reqObj for further work
1153
+ reqObj.iapMetadata = iapMetadata;
1154
+ }
1155
+
1156
+ try {
1157
+ // Make the call -
1158
+ // identifyRequest(entity, action, requestObj, returnDataFlag, callback)
1159
+ return this.requestHandlerInst.identifyRequest('Devices', 'devicesCreate', reqObj, true, (irReturnData, irReturnError) => {
1160
+ // if we received an error or their is no response on the results
1161
+ // return an error
1162
+ if (irReturnError) {
1163
+ /* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
1164
+ return callback(null, irReturnError);
1165
+ }
1166
+ if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
1167
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['devicesCreate'], null, null, null);
1168
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1169
+ return callback(null, errorObj);
1170
+ }
1171
+
1172
+ /* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
1173
+ // return the response
1174
+ return callback(irReturnData, null);
1175
+ });
1176
+ } catch (ex) {
1177
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
1178
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1179
+ return callback(null, errorObj);
1180
+ }
1181
+ }
1182
+
1183
+ /**
1184
+ * @function devicesReadForSelect
1185
+ * @pronghornType method
1186
+ * @name devicesReadForSelect
1187
+ * @summary Show Devices for Comboboxes and ItemSelectors
1188
+ *
1189
+ * @param {string} [filter] - Filter
1190
+ * @param {number} [limit] - Limit
1191
+ * @param {string} [query] - Query parameter
1192
+ * @param {string} [sort] - Sort order
1193
+ * @param {number} [start] - Start
1194
+ * @param {object} iapMetadata - IAP Metadata object contains additional info needed for the request: payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, etc.
1195
+ * @param {getCallback} callback - a callback function to return the result
1196
+ * @return {object} results - An object containing the response of the action
1197
+ *
1198
+ * @route {POST} /devicesReadForSelect
1199
+ * @roles admin
1200
+ * @task true
1201
+ */
1202
+ /* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
1203
+ devicesReadForSelect(filter, limit, query, sort, start, iapMetadata, callback) {
1204
+ const meth = 'adapter-devicesReadForSelect';
1205
+ const origin = `${this.id}-${meth}`;
1206
+ log.trace(origin);
1207
+
1208
+ if (this.suspended && this.suspendMode === 'error') {
1209
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
1210
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1211
+ return callback(null, errorObj);
1212
+ }
1213
+
1214
+ /* HERE IS WHERE YOU VALIDATE DATA */
1215
+
1216
+ /* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
1217
+ const queryParamsAvailable = { filter, limit, query, sort, start };
1218
+ const queryParams = {};
1219
+ const pathVars = [];
1220
+ const bodyVars = {};
1221
+
1222
+ // loop in template. long callback arg name to avoid identifier conflicts
1223
+ Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
1224
+ if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
1225
+ && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
1226
+ queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
1227
+ }
1228
+ });
1229
+
1230
+ // set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
1231
+ // see adapter code documentation for more information on the request object's fields
1232
+ const reqObj = {
1233
+ payload: bodyVars,
1234
+ uriPathVars: pathVars,
1235
+ uriQuery: queryParams
1236
+ };
1237
+
1238
+ const reqFields = ['payload', 'uriPathVars', 'uriQuery', 'uriOptions', 'addlHeaders', 'authData', 'callProperties', 'filter', 'priority', 'event'];
1239
+
1240
+ // Merge and add new iapMetadata fields in reqObj
1241
+ if (iapMetadata && typeof iapMetadata === 'object') {
1242
+ Object.keys(iapMetadata).forEach((iapField) => {
1243
+ if (reqFields.includes(iapField) && iapMetadata[iapField]) {
1244
+ if (typeof reqObj[iapField] === 'object' && typeof iapMetadata[iapField] === 'object') {
1245
+ reqObj[iapField] = { ...reqObj[iapField], ...iapMetadata[iapField] }; // Merge objects
1246
+ } else if (Array.isArray(reqObj[iapField]) && Array.isArray(iapMetadata[iapField])) {
1247
+ reqObj[iapField] = reqObj[iapField].concat(iapMetadata[iapField]); // Merge arrays
1248
+ } else {
1249
+ // Otherwise, add new iapMetadata fields to reqObj
1250
+ reqObj[iapField] = iapMetadata[iapField];
1251
+ }
1252
+ }
1253
+ });
1254
+ // Add iapMetadata to reqObj for further work
1255
+ reqObj.iapMetadata = iapMetadata;
1256
+ }
1257
+
1258
+ try {
1259
+ // Make the call -
1260
+ // identifyRequest(entity, action, requestObj, returnDataFlag, callback)
1261
+ return this.requestHandlerInst.identifyRequest('Devices', 'devicesReadForSelect', reqObj, true, (irReturnData, irReturnError) => {
1262
+ // if we received an error or their is no response on the results
1263
+ // return an error
1264
+ if (irReturnError) {
1265
+ /* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
1266
+ return callback(null, irReturnError);
1267
+ }
1268
+ if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
1269
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['devicesReadForSelect'], null, null, null);
1270
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1271
+ return callback(null, errorObj);
1272
+ }
1273
+
1274
+ /* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
1275
+ // return the response
1276
+ return callback(irReturnData, null);
1277
+ });
1278
+ } catch (ex) {
1279
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
1280
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1281
+ return callback(null, errorObj);
1282
+ }
1283
+ }
1284
+
1285
+ /**
1286
+ * @function performanceDataGetAll
1287
+ * @pronghornType method
1288
+ * @name performanceDataGetAll
1289
+ * @summary Get all performance data
1290
+ *
1291
+ * @param {string} deviceName - The Device Name
1292
+ * @param {string} metricType - Metric Type
1293
+ * @param {string} instance - The Instance
1294
+ * @param {string} timeRange - Time Range
1295
+ * @param {number} [offset] - Pagination offset
1296
+ * @param {number} [limit] - Pagination limit
1297
+ * @param {string} [sort] - Sort order
1298
+ * @param {object} iapMetadata - IAP Metadata object contains additional info needed for the request: payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, etc.
1299
+ * @param {getCallback} callback - a callback function to return the result
1300
+ * @return {object} results - An object containing the response of the action
1301
+ *
1302
+ * @route {POST} /performanceDataGetAll
1303
+ * @roles admin
1304
+ * @task true
1305
+ */
1306
+ /* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
1307
+ performanceDataGetAll(deviceName, metricType, instance, timeRange, offset, limit, sort, iapMetadata, callback) {
1308
+ const meth = 'adapter-performanceDataGetAll';
1309
+ const origin = `${this.id}-${meth}`;
1310
+ log.trace(origin);
1311
+
1312
+ if (this.suspended && this.suspendMode === 'error') {
1313
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
1314
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1315
+ return callback(null, errorObj);
1316
+ }
1317
+
1318
+ /* HERE IS WHERE YOU VALIDATE DATA */
1319
+ if (deviceName === undefined || deviceName === null || deviceName === '') {
1320
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['deviceName'], null, null, null);
1321
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1322
+ return callback(null, errorObj);
1323
+ }
1324
+ if (metricType === undefined || metricType === null || metricType === '') {
1325
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['metricType'], null, null, null);
1326
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1327
+ return callback(null, errorObj);
1328
+ }
1329
+ if (instance === undefined || instance === null || instance === '') {
1330
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['instance'], null, null, null);
1331
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1332
+ return callback(null, errorObj);
1333
+ }
1334
+ if (timeRange === undefined || timeRange === null || timeRange === '') {
1335
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['timeRange'], null, null, null);
1336
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1337
+ return callback(null, errorObj);
1338
+ }
1339
+
1340
+ /* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
1341
+ const queryParamsAvailable = { deviceName, metricType, instance, timeRange, offset, limit, sort };
1342
+ const queryParams = {};
1343
+ const pathVars = [];
1344
+ const bodyVars = {};
1345
+
1346
+ // loop in template. long callback arg name to avoid identifier conflicts
1347
+ Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
1348
+ if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
1349
+ && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
1350
+ queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
1351
+ }
1352
+ });
1353
+
1354
+ // set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
1355
+ // see adapter code documentation for more information on the request object's fields
1356
+ const reqObj = {
1357
+ payload: bodyVars,
1358
+ uriPathVars: pathVars,
1359
+ uriQuery: queryParams
1360
+ };
1361
+
1362
+ const reqFields = ['payload', 'uriPathVars', 'uriQuery', 'uriOptions', 'addlHeaders', 'authData', 'callProperties', 'filter', 'priority', 'event'];
1363
+
1364
+ // Merge and add new iapMetadata fields in reqObj
1365
+ if (iapMetadata && typeof iapMetadata === 'object') {
1366
+ Object.keys(iapMetadata).forEach((iapField) => {
1367
+ if (reqFields.includes(iapField) && iapMetadata[iapField]) {
1368
+ if (typeof reqObj[iapField] === 'object' && typeof iapMetadata[iapField] === 'object') {
1369
+ reqObj[iapField] = { ...reqObj[iapField], ...iapMetadata[iapField] }; // Merge objects
1370
+ } else if (Array.isArray(reqObj[iapField]) && Array.isArray(iapMetadata[iapField])) {
1371
+ reqObj[iapField] = reqObj[iapField].concat(iapMetadata[iapField]); // Merge arrays
1372
+ } else {
1373
+ // Otherwise, add new iapMetadata fields to reqObj
1374
+ reqObj[iapField] = iapMetadata[iapField];
1375
+ }
1376
+ }
1377
+ });
1378
+ // Add iapMetadata to reqObj for further work
1379
+ reqObj.iapMetadata = iapMetadata;
1380
+ }
1381
+
1382
+ try {
1383
+ // Make the call -
1384
+ // identifyRequest(entity, action, requestObj, returnDataFlag, callback)
1385
+ return this.requestHandlerInst.identifyRequest('PerformanceData', 'performanceDataGetAll', reqObj, true, (irReturnData, irReturnError) => {
1386
+ // if we received an error or their is no response on the results
1387
+ // return an error
1388
+ if (irReturnError) {
1389
+ /* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
1390
+ return callback(null, irReturnError);
1391
+ }
1392
+ if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
1393
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['performanceDataGetAll'], null, null, null);
1394
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1395
+ return callback(null, errorObj);
1396
+ }
1397
+
1398
+ /* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
1399
+ // return the response
1400
+ return callback(irReturnData, null);
1401
+ });
1402
+ } catch (ex) {
1403
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
1404
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1405
+ return callback(null, errorObj);
1406
+ }
1407
+ }
1408
+ }
1409
+
1410
+ module.exports = OracleAssure1;