@itentialopensource/adapter-robustel 0.1.1 → 0.3.0

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 (54) hide show
  1. package/AUTH.md +39 -0
  2. package/BROKER.md +199 -0
  3. package/CALLS.md +205 -0
  4. package/CHANGELOG.md +17 -2
  5. package/CODE_OF_CONDUCT.md +12 -17
  6. package/CONTRIBUTING.md +3 -148
  7. package/ENHANCE.md +69 -0
  8. package/PROPERTIES.md +641 -0
  9. package/README.md +235 -576
  10. package/SUMMARY.md +9 -0
  11. package/SYSTEMINFO.md +11 -0
  12. package/TROUBLESHOOT.md +47 -0
  13. package/adapter.js +402 -573
  14. package/adapterBase.js +843 -419
  15. package/changelogs/changelog.md +16 -0
  16. package/entities/.generic/action.json +105 -0
  17. package/entities/.generic/schema.json +6 -1
  18. package/error.json +6 -0
  19. package/metadata.json +47 -0
  20. package/package.json +24 -24
  21. package/pronghorn.json +559 -148
  22. package/propertiesDecorators.json +14 -0
  23. package/propertiesSchema.json +842 -6
  24. package/refs?service=git-upload-pack +0 -0
  25. package/report/adapter-openapi.json +204 -0
  26. package/report/adapter-openapi.yaml +163 -0
  27. package/report/adapterInfo.json +10 -0
  28. package/report/updateReport1653173664637.json +120 -0
  29. package/report/updateReport1691507608338.json +120 -0
  30. package/report/updateReport1692202610637.json +120 -0
  31. package/report/updateReport1694462053440.json +120 -0
  32. package/report/updateReport1698421016757.json +120 -0
  33. package/sampleProperties.json +158 -5
  34. package/test/integration/adapterTestBasicGet.js +3 -5
  35. package/test/integration/adapterTestConnectivity.js +91 -42
  36. package/test/integration/adapterTestIntegration.js +269 -271
  37. package/test/unit/adapterBaseTestUnit.js +388 -308
  38. package/test/unit/adapterTestUnit.js +399 -260
  39. package/utils/adapterInfo.js +206 -0
  40. package/utils/addAuth.js +1 -1
  41. package/utils/artifactize.js +1 -1
  42. package/utils/checkMigrate.js +1 -1
  43. package/utils/entitiesToDB.js +12 -57
  44. package/utils/findPath.js +1 -1
  45. package/utils/methodDocumentor.js +273 -0
  46. package/utils/modify.js +13 -15
  47. package/utils/packModificationScript.js +1 -1
  48. package/utils/pre-commit.sh +5 -0
  49. package/utils/taskMover.js +309 -0
  50. package/utils/tbScript.js +123 -53
  51. package/utils/tbUtils.js +87 -49
  52. package/utils/testRunner.js +17 -17
  53. package/utils/troubleshootingAdapter.js +9 -6
  54. package/workflows/README.md +0 -3
package/adapter.js CHANGED
@@ -82,10 +82,15 @@ class Robustel extends AdapterBaseCl {
82
82
  }
83
83
 
84
84
  /**
85
- * @getWorkflowFunctions
85
+ * @iapGetAdapterWorkflowFunctions
86
86
  */
87
- getWorkflowFunctions(inIgnore) {
88
- let myIgnore = ['getAuthorization', 'hasEntities', 'hasDevices'];
87
+ iapGetAdapterWorkflowFunctions(inIgnore) {
88
+ let myIgnore = [
89
+ 'healthCheck',
90
+ 'iapGetAdapterWorkflowFunctions',
91
+ 'hasEntities',
92
+ 'getAuthorization'
93
+ ];
89
94
  if (!inIgnore && Array.isArray(inIgnore)) {
90
95
  myIgnore = inIgnore;
91
96
  } else if (!inIgnore && typeof inIgnore === 'string') {
@@ -96,52 +101,44 @@ class Robustel extends AdapterBaseCl {
96
101
  // you can add specific methods that you do not want to be workflow functions to ignore like below
97
102
  // myIgnore.push('myMethodNotInWorkflow');
98
103
 
99
- return super.getWorkflowFunctions(myIgnore);
104
+ return super.iapGetAdapterWorkflowFunctions(myIgnore);
100
105
  }
101
106
 
102
107
  /**
103
- * updateAdapterConfiguration is used to update any of the adapter configuration files. This
108
+ * iapUpdateAdapterConfiguration is used to update any of the adapter configuration files. This
104
109
  * allows customers to make changes to adapter configuration without having to be on the
105
110
  * file system.
106
111
  *
107
- * @function updateAdapterConfiguration
112
+ * @function iapUpdateAdapterConfiguration
108
113
  * @param {string} configFile - the name of the file being updated (required)
109
114
  * @param {Object} changes - an object containing all of the changes = formatted like the configuration file (required)
110
115
  * @param {string} entity - the entity to be changed, if an action, schema or mock data file (optional)
111
116
  * @param {string} type - the type of entity file to change, (action, schema, mock) (optional)
112
117
  * @param {string} action - the action to be changed, if an action, schema or mock data file (optional)
118
+ * @param {boolean} replace - true to replace entire mock data, false to merge/append
113
119
  * @param {Callback} callback - The results of the call
114
120
  */
115
- updateAdapterConfiguration(configFile, changes, entity, type, action, callback) {
116
- const origin = `${this.id}-adapter-updateAdapterConfiguration`;
121
+ iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, replace, callback) {
122
+ const meth = 'adapter-iapUpdateAdapterConfiguration';
123
+ const origin = `${this.id}-${meth}`;
117
124
  log.trace(origin);
118
- super.updateAdapterConfiguration(configFile, changes, entity, type, action, callback);
119
- }
120
125
 
121
- /**
122
- * See if the API path provided is found in this adapter
123
- *
124
- * @function findPath
125
- * @param {string} apiPath - the api path to check on
126
- * @param {Callback} callback - The results of the call
127
- */
128
- findPath(apiPath, callback) {
129
- const origin = `${this.id}-adapter-findPath`;
130
- log.trace(origin);
131
- super.findPath(apiPath, callback);
126
+ super.iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, replace, callback);
132
127
  }
133
128
 
134
129
  /**
135
130
  * @summary Suspends adapter
136
131
  *
137
- * @function suspend
132
+ * @function iapSuspendAdapter
138
133
  * @param {Callback} callback - callback function
139
134
  */
140
- suspend(mode, callback) {
141
- const origin = `${this.id}-adapter-suspend`;
135
+ iapSuspendAdapter(mode, callback) {
136
+ const meth = 'adapter-iapSuspendAdapter';
137
+ const origin = `${this.id}-${meth}`;
142
138
  log.trace(origin);
139
+
143
140
  try {
144
- return super.suspend(mode, callback);
141
+ return super.iapSuspendAdapter(mode, callback);
145
142
  } catch (error) {
146
143
  log.error(`${origin}: ${error}`);
147
144
  return callback(null, error);
@@ -151,14 +148,16 @@ class Robustel extends AdapterBaseCl {
151
148
  /**
152
149
  * @summary Unsuspends adapter
153
150
  *
154
- * @function unsuspend
151
+ * @function iapUnsuspendAdapter
155
152
  * @param {Callback} callback - callback function
156
153
  */
157
- unsuspend(callback) {
158
- const origin = `${this.id}-adapter-unsuspend`;
154
+ iapUnsuspendAdapter(callback) {
155
+ const meth = 'adapter-iapUnsuspendAdapter';
156
+ const origin = `${this.id}-${meth}`;
159
157
  log.trace(origin);
158
+
160
159
  try {
161
- return super.unsuspend(callback);
160
+ return super.iapUnsuspendAdapter(callback);
162
161
  } catch (error) {
163
162
  log.error(`${origin}: ${error}`);
164
163
  return callback(null, error);
@@ -166,31 +165,51 @@ class Robustel extends AdapterBaseCl {
166
165
  }
167
166
 
168
167
  /**
169
- * @summary Get the Adaoter Queue
168
+ * @summary Get the Adapter Queue
170
169
  *
171
- * @function getQueue
170
+ * @function iapGetAdapterQueue
172
171
  * @param {Callback} callback - callback function
173
172
  */
174
- getQueue(callback) {
175
- const origin = `${this.id}-adapter-getQueue`;
173
+ iapGetAdapterQueue(callback) {
174
+ const meth = 'adapter-iapGetAdapterQueue';
175
+ const origin = `${this.id}-${meth}`;
176
176
  log.trace(origin);
177
- return super.getQueue(callback);
177
+
178
+ return super.iapGetAdapterQueue(callback);
179
+ }
180
+
181
+ /* SCRIPT CALLS */
182
+ /**
183
+ * See if the API path provided is found in this adapter
184
+ *
185
+ * @function iapFindAdapterPath
186
+ * @param {string} apiPath - the api path to check on
187
+ * @param {Callback} callback - The results of the call
188
+ */
189
+ iapFindAdapterPath(apiPath, callback) {
190
+ const meth = 'adapter-iapFindAdapterPath';
191
+ const origin = `${this.id}-${meth}`;
192
+ log.trace(origin);
193
+
194
+ super.iapFindAdapterPath(apiPath, callback);
178
195
  }
179
196
 
180
197
  /**
181
198
  * @summary Runs troubleshoot scripts for adapter
182
199
  *
183
- * @function troubleshoot
200
+ * @function iapTroubleshootAdapter
184
201
  * @param {Object} props - the connection, healthcheck and authentication properties
185
202
  *
186
203
  * @param {boolean} persistFlag - whether the adapter properties should be updated
187
204
  * @param {Callback} callback - The results of the call
188
205
  */
189
- troubleshoot(props, persistFlag, callback) {
190
- const origin = `${this.id}-adapter-troubleshoot`;
206
+ iapTroubleshootAdapter(props, persistFlag, callback) {
207
+ const meth = 'adapter-iapTroubleshootAdapter';
208
+ const origin = `${this.id}-${meth}`;
191
209
  log.trace(origin);
210
+
192
211
  try {
193
- return super.troubleshoot(props, persistFlag, this, callback);
212
+ return super.iapTroubleshootAdapter(props, persistFlag, this, callback);
194
213
  } catch (error) {
195
214
  log.error(`${origin}: ${error}`);
196
215
  return callback(null, error);
@@ -200,15 +219,17 @@ class Robustel extends AdapterBaseCl {
200
219
  /**
201
220
  * @summary runs healthcheck script for adapter
202
221
  *
203
- * @function runHealthcheck
222
+ * @function iapRunAdapterHealthcheck
204
223
  * @param {Adapter} adapter - adapter instance to troubleshoot
205
224
  * @param {Callback} callback - callback function
206
225
  */
207
- runHealthcheck(callback) {
208
- const origin = `${this.id}-adapter-runHealthcheck`;
226
+ iapRunAdapterHealthcheck(callback) {
227
+ const meth = 'adapter-iapRunAdapterHealthcheck';
228
+ const origin = `${this.id}-${meth}`;
209
229
  log.trace(origin);
230
+
210
231
  try {
211
- return super.runHealthcheck(this, callback);
232
+ return super.iapRunAdapterHealthcheck(this, callback);
212
233
  } catch (error) {
213
234
  log.error(`${origin}: ${error}`);
214
235
  return callback(null, error);
@@ -218,14 +239,16 @@ class Robustel extends AdapterBaseCl {
218
239
  /**
219
240
  * @summary runs connectivity check script for adapter
220
241
  *
221
- * @function runConnectivity
242
+ * @function iapRunAdapterConnectivity
222
243
  * @param {Callback} callback - callback function
223
244
  */
224
- runConnectivity(callback) {
225
- const origin = `${this.id}-adapter-runConnectivity`;
245
+ iapRunAdapterConnectivity(callback) {
246
+ const meth = 'adapter-iapRunAdapterConnectivity';
247
+ const origin = `${this.id}-${meth}`;
226
248
  log.trace(origin);
249
+
227
250
  try {
228
- return super.runConnectivity(callback);
251
+ return super.iapRunAdapterConnectivity(callback);
229
252
  } catch (error) {
230
253
  log.error(`${origin}: ${error}`);
231
254
  return callback(null, error);
@@ -235,14 +258,16 @@ class Robustel extends AdapterBaseCl {
235
258
  /**
236
259
  * @summary runs basicGet script for adapter
237
260
  *
238
- * @function runBasicGet
261
+ * @function iapRunAdapterBasicGet
239
262
  * @param {Callback} callback - callback function
240
263
  */
241
- runBasicGet(callback) {
242
- const origin = `${this.id}-adapter-runBasicGet`;
264
+ iapRunAdapterBasicGet(callback) {
265
+ const meth = 'adapter-iapRunAdapterBasicGet';
266
+ const origin = `${this.id}-${meth}`;
243
267
  log.trace(origin);
268
+
244
269
  try {
245
- return super.runBasicGet(callback);
270
+ return super.iapRunAdapterBasicGet(callback);
246
271
  } catch (error) {
247
272
  log.error(`${origin}: ${error}`);
248
273
  return callback(null, error);
@@ -252,15 +277,17 @@ class Robustel extends AdapterBaseCl {
252
277
  /**
253
278
  * @summary moves entites into Mongo DB
254
279
  *
255
- * @function moveEntitiesToDB
280
+ * @function iapMoveAdapterEntitiesToDB
256
281
  * @param {getCallback} callback - a callback function to return the result (Generics)
257
282
  * or the error
258
283
  */
259
- moveEntitiesToDB(callback) {
260
- const origin = `${this.id}-adapter-moveEntitiesToDB`;
284
+ iapMoveAdapterEntitiesToDB(callback) {
285
+ const meth = 'adapter-iapMoveAdapterEntitiesToDB';
286
+ const origin = `${this.id}-${meth}`;
261
287
  log.trace(origin);
288
+
262
289
  try {
263
- return super.moveEntitiesToDB(callback);
290
+ return super.iapMoveAdapterEntitiesToDB(callback);
264
291
  } catch (err) {
265
292
  log.error(`${origin}: ${err}`);
266
293
  return callback(null, err);
@@ -268,171 +295,255 @@ class Robustel extends AdapterBaseCl {
268
295
  }
269
296
 
270
297
  /**
271
- * @summary Determines if this adapter supports the specific entity
298
+ * @summary Deactivate adapter tasks
272
299
  *
273
- * @function hasEntity
274
- * @param {String} entityType - the entity type to check for
275
- * @param {String/Array} entityId - the specific entity we are looking for
300
+ * @function iapDeactivateTasks
301
+ *
302
+ * @param {Array} tasks - List of tasks to deactivate
303
+ * @param {Callback} callback
304
+ */
305
+ iapDeactivateTasks(tasks, callback) {
306
+ const meth = 'adapter-iapDeactivateTasks';
307
+ const origin = `${this.id}-${meth}`;
308
+ log.trace(origin);
309
+
310
+ try {
311
+ return super.iapDeactivateTasks(tasks, callback);
312
+ } catch (err) {
313
+ log.error(`${origin}: ${err}`);
314
+ return callback(null, err);
315
+ }
316
+ }
317
+
318
+ /**
319
+ * @summary Activate adapter tasks that have previously been deactivated
320
+ *
321
+ * @function iapActivateTasks
322
+ *
323
+ * @param {Array} tasks - List of tasks to activate
324
+ * @param {Callback} callback
325
+ */
326
+ iapActivateTasks(tasks, callback) {
327
+ const meth = 'adapter-iapActivateTasks';
328
+ const origin = `${this.id}-${meth}`;
329
+ log.trace(origin);
330
+
331
+ try {
332
+ return super.iapActivateTasks(tasks, callback);
333
+ } catch (err) {
334
+ log.error(`${origin}: ${err}`);
335
+ return callback(null, err);
336
+ }
337
+ }
338
+
339
+ /* CACHE CALLS */
340
+ /**
341
+ * @summary Populate the cache for the given entities
276
342
  *
277
- * @param {Callback} callback - An array of whether the adapter can has the
278
- * desired capability or an error
343
+ * @function iapPopulateEntityCache
344
+ * @param {String/Array of Strings} entityType - the entity type(s) to populate
345
+ * @param {Callback} callback - whether the cache was updated or not for each entity type
346
+ *
347
+ * @returns status of the populate
279
348
  */
280
- hasEntity(entityType, entityId, callback) {
281
- const origin = `${this.id}-adapter-hasEntity`;
349
+ iapPopulateEntityCache(entityTypes, callback) {
350
+ const meth = 'adapter-iapPopulateEntityCache';
351
+ const origin = `${this.id}-${meth}`;
282
352
  log.trace(origin);
283
353
 
284
- // Make the call -
285
- // verifyCapability(entityType, actionType, entityId, callback)
286
- return this.verifyCapability(entityType, null, entityId, callback);
354
+ try {
355
+ return super.iapPopulateEntityCache(entityTypes, callback);
356
+ } catch (err) {
357
+ log.error(`${origin}: ${err}`);
358
+ return callback(null, err);
359
+ }
287
360
  }
288
361
 
289
362
  /**
290
- * @summary Provides a way for the adapter to tell north bound integrations
291
- * whether the adapter supports type, action and specific entity
363
+ * @summary Retrieves data from cache for specified entity type
292
364
  *
293
- * @function verifyCapability
365
+ * @function iapRetrieveEntitiesCache
366
+ * @param {String} entityType - entity of which to retrieve
367
+ * @param {Object} options - settings of which data to return and how to return it
368
+ * @param {Callback} callback - the data if it was retrieved
369
+ */
370
+ iapRetrieveEntitiesCache(entityType, options, callback) {
371
+ const meth = 'adapter-iapCheckEiapRetrieveEntitiesCachentityCached';
372
+ const origin = `${this.id}-${meth}`;
373
+ log.trace(origin);
374
+
375
+ try {
376
+ return super.iapRetrieveEntitiesCache(entityType, options, callback);
377
+ } catch (err) {
378
+ log.error(`${origin}: ${err}`);
379
+ return callback(null, err);
380
+ }
381
+ }
382
+
383
+ /* BROKER CALLS */
384
+ /**
385
+ * @summary Determines if this adapter supports any in a list of entities
386
+ *
387
+ * @function hasEntities
294
388
  * @param {String} entityType - the entity type to check for
295
- * @param {String} actionType - the action type to check for
296
- * @param {String/Array} entityId - the specific entity we are looking for
389
+ * @param {Array} entityList - the list of entities we are looking for
297
390
  *
298
- * @param {Callback} callback - An array of whether the adapter can has the
299
- * desired capability or an error
391
+ * @param {Callback} callback - A map where the entity is the key and the
392
+ * value is true or false
300
393
  */
301
- verifyCapability(entityType, actionType, entityId, callback) {
302
- const meth = 'adapterBase-verifyCapability';
394
+ hasEntities(entityType, entityList, callback) {
395
+ const meth = 'adapter-hasEntities';
303
396
  const origin = `${this.id}-${meth}`;
304
397
  log.trace(origin);
305
398
 
306
- // if caching
307
- if (this.caching) {
308
- // Make the call - verifyCapability(entityType, actionType, entityId, callback)
309
- return this.requestHandlerInst.verifyCapability(entityType, actionType, entityId, (results, error) => {
310
- if (error) {
311
- return callback(null, error);
312
- }
399
+ try {
400
+ return super.hasEntities(entityType, entityList, callback);
401
+ } catch (err) {
402
+ log.error(`${origin}: ${err}`);
403
+ return callback(null, err);
404
+ }
405
+ }
313
406
 
314
- // if the cache needs to be updated, update and try again
315
- if (results && results[0] === 'needupdate') {
316
- switch (entityType) {
317
- case 'template_entity': {
318
- // if the cache is invalid, update the cache
319
- return this.getEntities(null, null, null, null, (data, err) => {
320
- if (err) {
321
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Could not update entity: $VARIABLE$, cache', [entityType], null, null, null);
322
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
323
- return callback(null, errorObj);
324
- }
325
-
326
- // need to check the cache again since it has been updated
327
- return this.requestHandlerInst.verifyCapability(entityType, actionType, entityId, (vcapable, verror) => {
328
- if (verror) {
329
- return callback(null, verror);
330
- }
331
-
332
- return this.capabilityResults(vcapable, callback);
333
- });
334
- });
335
- }
336
- default: {
337
- // unsupported entity type
338
- const result = [false];
339
-
340
- // put false in array for all entities
341
- if (Array.isArray(entityId)) {
342
- for (let e = 1; e < entityId.length; e += 1) {
343
- result.push(false);
344
- }
345
- }
346
-
347
- return callback(result);
348
- }
349
- }
350
- }
407
+ /**
408
+ * @summary Get Appliance that match the deviceName
409
+ *
410
+ * @function getDevice
411
+ * @param {String} deviceName - the deviceName to find (required)
412
+ *
413
+ * @param {getCallback} callback - a callback function to return the result
414
+ * (appliance) or the error
415
+ */
416
+ getDevice(deviceName, callback) {
417
+ const meth = 'adapter-getDevice';
418
+ const origin = `${this.id}-${meth}`;
419
+ log.trace(origin);
351
420
 
352
- // return the results
353
- return this.capabilityResults(results, callback);
354
- });
421
+ try {
422
+ return super.getDevice(deviceName, callback);
423
+ } catch (err) {
424
+ log.error(`${origin}: ${err}`);
425
+ return callback(null, err);
355
426
  }
427
+ }
356
428
 
357
- // if no entity id
358
- if (!entityId) {
359
- // need to check the cache again since it has been updated
360
- return this.requestHandlerInst.verifyCapability(entityType, actionType, null, (vcapable, verror) => {
361
- if (verror) {
362
- return callback(null, verror);
363
- }
429
+ /**
430
+ * @summary Get Appliances that match the filter
431
+ *
432
+ * @function getDevicesFiltered
433
+ * @param {Object} options - the data to use to filter the appliances (optional)
434
+ *
435
+ * @param {getCallback} callback - a callback function to return the result
436
+ * (appliances) or the error
437
+ */
438
+ getDevicesFiltered(options, callback) {
439
+ const meth = 'adapter-getDevicesFiltered';
440
+ const origin = `${this.id}-${meth}`;
441
+ log.trace(origin);
364
442
 
365
- return this.capabilityResults(vcapable, callback);
366
- });
443
+ try {
444
+ return super.getDevicesFiltered(options, callback);
445
+ } catch (err) {
446
+ log.error(`${origin}: ${err}`);
447
+ return callback(null, err);
367
448
  }
449
+ }
368
450
 
369
- // if not caching
370
- switch (entityType) {
371
- case 'template_entity': {
372
- // need to get the entities to check
373
- return this.getEntities(null, null, null, null, (data, err) => {
374
- if (err) {
375
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Could not update entity: $VARIABLE$, cache', [entityType], null, null, null);
376
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
377
- return callback(null, errorObj);
378
- }
379
-
380
- // need to check the cache again since it has been updated
381
- return this.requestHandlerInst.verifyCapability(entityType, actionType, null, (vcapable, verror) => {
382
- if (verror) {
383
- return callback(null, verror);
384
- }
385
-
386
- // is the entity in the list?
387
- const isEntity = this.entityInList(entityId, data.response, callback);
388
- const res = [];
389
-
390
- // not found
391
- for (let i = 0; i < isEntity.length; i += 1) {
392
- if (vcapable) {
393
- res.push(isEntity[i]);
394
- } else {
395
- res.push(false);
396
- }
397
- }
398
-
399
- return callback(res);
400
- });
401
- });
402
- }
403
- default: {
404
- // unsupported entity type
405
- const result = [false];
406
-
407
- // put false in array for all entities
408
- if (Array.isArray(entityId)) {
409
- for (let e = 1; e < entityId.length; e += 1) {
410
- result.push(false);
411
- }
412
- }
451
+ /**
452
+ * @summary Gets the status for the provided appliance
453
+ *
454
+ * @function isAlive
455
+ * @param {String} deviceName - the deviceName of the appliance. (required)
456
+ *
457
+ * @param {configCallback} callback - callback function to return the result
458
+ * (appliance isAlive) or the error
459
+ */
460
+ isAlive(deviceName, callback) {
461
+ const meth = 'adapter-isAlive';
462
+ const origin = `${this.id}-${meth}`;
463
+ log.trace(origin);
413
464
 
414
- return callback(result);
415
- }
465
+ try {
466
+ return super.isAlive(deviceName, callback);
467
+ } catch (err) {
468
+ log.error(`${origin}: ${err}`);
469
+ return callback(null, err);
470
+ }
471
+ }
472
+
473
+ /**
474
+ * @summary Gets a config for the provided Appliance
475
+ *
476
+ * @function getConfig
477
+ * @param {String} deviceName - the deviceName of the appliance. (required)
478
+ * @param {String} format - the desired format of the config. (optional)
479
+ *
480
+ * @param {configCallback} callback - callback function to return the result
481
+ * (appliance config) or the error
482
+ */
483
+ getConfig(deviceName, format, callback) {
484
+ const meth = 'adapter-getConfig';
485
+ const origin = `${this.id}-${meth}`;
486
+ log.trace(origin);
487
+
488
+ try {
489
+ return super.getConfig(deviceName, format, callback);
490
+ } catch (err) {
491
+ log.error(`${origin}: ${err}`);
492
+ return callback(null, err);
416
493
  }
417
494
  }
418
495
 
419
496
  /**
420
- * @summary Updates the cache for all entities by call the get All entity method
497
+ * @summary Gets the device count from the system
421
498
  *
422
- * @function updateEntityCache
499
+ * @function iapGetDeviceCount
423
500
  *
501
+ * @param {getCallback} callback - callback function to return the result
502
+ * (count) or the error
424
503
  */
425
- updateEntityCache() {
426
- const origin = `${this.id}-adapter-updateEntityCache`;
504
+ iapGetDeviceCount(callback) {
505
+ const meth = 'adapter-iapGetDeviceCount';
506
+ const origin = `${this.id}-${meth}`;
427
507
  log.trace(origin);
428
508
 
429
- if (this.caching) {
430
- // if the cache is invalid, update the cache
431
- this.getEntities(null, null, null, null, (data, err) => {
432
- if (err) {
433
- log.trace(`${origin}: Could not load template_entity into cache - ${err}`);
434
- }
435
- });
509
+ try {
510
+ return super.iapGetDeviceCount(callback);
511
+ } catch (err) {
512
+ log.error(`${origin}: ${err}`);
513
+ return callback(null, err);
514
+ }
515
+ }
516
+
517
+ /* GENERIC ADAPTER REQUEST - allows extension of adapter without new calls being added */
518
+ /**
519
+ * Makes the requested generic call
520
+ *
521
+ * @function iapExpandedGenericAdapterRequest
522
+ * @param {Object} metadata - metadata for the call (optional).
523
+ * Can be a stringified Object.
524
+ * @param {String} uriPath - the path of the api call - do not include the host, port, base path or version (optional)
525
+ * @param {String} restMethod - the rest method (GET, POST, PUT, PATCH, DELETE) (optional)
526
+ * @param {Object} pathVars - the parameters to be put within the url path (optional).
527
+ * Can be a stringified Object.
528
+ * @param {Object} queryData - the parameters to be put on the url (optional).
529
+ * Can be a stringified Object.
530
+ * @param {Object} requestBody - the body to add to the request (optional).
531
+ * Can be a stringified Object.
532
+ * @param {Object} addlHeaders - additional headers to be put on the call (optional).
533
+ * Can be a stringified Object.
534
+ * @param {getCallback} callback - a callback function to return the result (Generics)
535
+ * or the error
536
+ */
537
+ iapExpandedGenericAdapterRequest(metadata, uriPath, restMethod, pathVars, queryData, requestBody, addlHeaders, callback) {
538
+ const meth = 'adapter-iapExpandedGenericAdapterRequest';
539
+ const origin = `${this.id}-${meth}`;
540
+ log.trace(origin);
541
+
542
+ try {
543
+ return super.iapExpandedGenericAdapterRequest(metadata, uriPath, restMethod, pathVars, queryData, requestBody, addlHeaders, callback);
544
+ } catch (err) {
545
+ log.error(`${origin}: ${err}`);
546
+ return callback(null, err);
436
547
  }
437
548
  }
438
549
 
@@ -560,79 +671,23 @@ class Robustel extends AdapterBaseCl {
560
671
  }
561
672
  }
562
673
 
563
- /* BROKER CALLS */
564
674
  /**
565
- * @summary Determines if this adapter supports any in a list of entities
566
- *
567
- * @function hasEntities
568
- * @param {String} entityType - the entity type to check for
569
- * @param {Array} entityList - the list of entities we are looking for
675
+ * Makes the requested generic call with no base path or version
570
676
  *
571
- * @param {Callback} callback - A map where the entity is the key and the
572
- * value is true or false
573
- */
574
- hasEntities(entityType, entityList, callback) {
575
- const origin = `${this.id}-adapter-hasEntities`;
576
- log.trace(origin);
577
-
578
- switch (entityType) {
579
- case 'Device':
580
- return this.hasDevices(entityList, callback);
581
- default:
582
- return callback(null, `${this.id} does not support entity ${entityType}`);
583
- }
584
- }
585
-
586
- /**
587
- * @summary Helper method for hasEntities for the specific device case
588
- *
589
- * @param {Array} deviceList - array of unique device identifiers
590
- * @param {Callback} callback - A map where the device is the key and the
591
- * value is true or false
592
- */
593
- hasDevices(deviceList, callback) {
594
- const origin = `${this.id}-adapter-hasDevices`;
595
- log.trace(origin);
596
-
597
- const findings = deviceList.reduce((map, device) => {
598
- // eslint-disable-next-line no-param-reassign
599
- map[device] = false;
600
- log.debug(`In reduce: ${JSON.stringify(map)}`);
601
- return map;
602
- }, {});
603
- const apiCalls = deviceList.map((device) => new Promise((resolve) => {
604
- this.getDevice(device, (result, error) => {
605
- if (error) {
606
- log.debug(`In map error: ${JSON.stringify(device)}`);
607
- return resolve({ name: device, found: false });
608
- }
609
- log.debug(`In map: ${JSON.stringify(device)}`);
610
- return resolve({ name: device, found: true });
611
- });
612
- }));
613
- Promise.all(apiCalls).then((results) => {
614
- results.forEach((device) => {
615
- findings[device.name] = device.found;
616
- });
617
- log.debug(`FINDINGS: ${JSON.stringify(findings)}`);
618
- return callback(findings);
619
- }).catch((errors) => {
620
- log.error('Unable to do device lookup.');
621
- return callback(null, { code: 503, message: 'Unable to do device lookup.', error: errors });
622
- });
623
- }
624
-
625
- /**
626
- * @summary Get Appliance that match the deviceName
627
- *
628
- * @function getDevice
629
- * @param {String} deviceName - the deviceName to find (required)
630
- *
631
- * @param {getCallback} callback - a callback function to return the result
632
- * (appliance) or the error
677
+ * @function genericAdapterRequestNoBasePath
678
+ * @param {String} uriPath - the path of the api call - do not include the host, port, base path or version (required)
679
+ * @param {String} restMethod - the rest method (GET, POST, PUT, PATCH, DELETE) (required)
680
+ * @param {Object} queryData - the parameters to be put on the url (optional).
681
+ * Can be a stringified Object.
682
+ * @param {Object} requestBody - the body to add to the request (optional).
683
+ * Can be a stringified Object.
684
+ * @param {Object} addlHeaders - additional headers to be put on the call (optional).
685
+ * Can be a stringified Object.
686
+ * @param {getCallback} callback - a callback function to return the result (Generics)
687
+ * or the error
633
688
  */
634
- getDevice(deviceName, callback) {
635
- const meth = 'adapter-getDevice';
689
+ genericAdapterRequestNoBasePath(uriPath, restMethod, queryData, requestBody, addlHeaders, callback) {
690
+ const meth = 'adapter-genericAdapterRequestNoBasePath';
636
691
  const origin = `${this.id}-${meth}`;
637
692
  log.trace(origin);
638
693
 
@@ -643,196 +698,95 @@ class Robustel extends AdapterBaseCl {
643
698
  }
644
699
 
645
700
  /* HERE IS WHERE YOU VALIDATE DATA */
646
- if (deviceName === undefined || deviceName === null || deviceName === '' || deviceName.length === 0) {
647
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['deviceName'], null, null, null);
701
+ if (uriPath === undefined || uriPath === null || uriPath === '') {
702
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['uriPath'], null, null, null);
648
703
  log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
649
704
  return callback(null, errorObj);
650
705
  }
651
-
652
- try {
653
- // need to get the device so we can convert the deviceName to an id
654
- // !! if we can do a lookup by name the getDevicesFiltered may not be necessary
655
- const opts = {
656
- filter: {
657
- name: deviceName
658
- }
659
- };
660
- return this.getDevicesFiltered(opts, (devs, ferr) => {
661
- // if we received an error or their is no response on the results return an error
662
- if (ferr) {
663
- return callback(null, ferr);
664
- }
665
- if (devs.list.length < 1) {
666
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Did Not Find Device ${deviceName}`, [], null, null, null);
667
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
668
- return callback(null, errorObj);
669
- }
670
- // get the uuid from the device
671
- const { uuid } = devs.list[0];
672
-
673
- // !! using Generic makes it easier on the Adapter Builder (just need to change the path)
674
- // !! you can also replace with a specific call if that is easier
675
- const uriPath = `/call/toget/device/${uuid}`;
676
- return this.genericAdapterRequest(uriPath, 'GET', {}, {}, {}, (result, error) => {
677
- // if we received an error or their is no response on the results return an error
678
- if (error) {
679
- return callback(null, error);
680
- }
681
- if (!result.response || !result.response.applianceMo) {
682
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getDevice'], null, null, null);
683
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
684
- return callback(null, errorObj);
685
- }
686
-
687
- // return the response
688
- // !! format the data we send back
689
- // !! these fields are config manager fields you need to map to the data we receive
690
- const thisDevice = result.response;
691
- thisDevice.name = thisDevice.systemName;
692
- thisDevice.ostype = `System-${thisDevice.systemType}`;
693
- thisDevice.port = thisDevice.systemPort;
694
- thisDevice.ipaddress = thisDevice.systemIP;
695
- return callback(thisDevice);
696
- });
697
- });
698
- } catch (ex) {
699
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
706
+ if (restMethod === undefined || restMethod === null || restMethod === '') {
707
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['restMethod'], null, null, null);
700
708
  log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
701
709
  return callback(null, errorObj);
702
710
  }
703
- }
704
711
 
705
- /**
706
- * @summary Get Appliances that match the filter
707
- *
708
- * @function getDevicesFiltered
709
- * @param {Object} options - the data to use to filter the appliances (optional)
710
- *
711
- * @param {getCallback} callback - a callback function to return the result
712
- * (appliances) or the error
713
- */
714
- getDevicesFiltered(options, callback) {
715
- const meth = 'adapter-getDevicesFiltered';
716
- const origin = `${this.id}-${meth}`;
717
- log.trace(origin);
712
+ /* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
713
+ // remove any leading / and split the uripath into path variables
714
+ let myPath = uriPath;
715
+ while (myPath.indexOf('/') === 0) {
716
+ myPath = myPath.substring(1);
717
+ }
718
+ const pathVars = myPath.split('/');
719
+ const queryParamsAvailable = queryData;
720
+ const queryParams = {};
721
+ const bodyVars = requestBody;
722
+
723
+ // loop in template. long callback arg name to avoid identifier conflicts
724
+ Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
725
+ if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
726
+ && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
727
+ queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
728
+ }
729
+ });
718
730
 
719
- // verify the required fields have been provided
720
- if (options === undefined || options === null || options === '' || options.length === 0) {
721
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['options'], null, null, null);
731
+ let usePath = uriPath;
732
+ if (queryParams && Object.keys(queryParams).length > 0) {
733
+ usePath = `${uriPath}?${querystring(queryData)}`;
734
+ }
735
+ const callSign = this.getAuthorization(restMethod, usePath, bodyVars);
736
+
737
+ // if the callAuth was unsuccessful
738
+ if (callSign === -1) {
739
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['call signature'], null, null, null);
722
740
  log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
723
741
  return callback(null, errorObj);
724
742
  }
725
- log.debug(`Device Filter Options: ${JSON.stringify(options)}`);
726
-
727
- // TODO - get pagination working
728
- // const nextToken = options.start;
729
- // const maxResults = options.limit;
730
-
731
- // set up the filter of Device Names
732
- let filterName = [];
733
- if (options && options.filter && options.filter.name) {
734
- // when this hack is removed, remove the lint ignore above
735
- if (Array.isArray(options.filter.name)) {
736
- // eslint-disable-next-line prefer-destructuring
737
- filterName = options.filter.name;
738
- } else {
739
- filterName = [options.filter.name];
740
- }
741
- }
742
743
 
743
- // TODO - get sort and order working
744
- /*
745
- if (options && options.sort) {
746
- reqObj.uriOptions.sort = JSON.stringify(options.sort);
744
+ // set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders
745
+ const reqObj = {
746
+ payload: bodyVars,
747
+ uriPathVars: pathVars,
748
+ uriQuery: queryParams,
749
+ uriOptions: {},
750
+ addlHeaders: callSign
751
+ };
752
+ // add headers if provided
753
+ if (addlHeaders) {
754
+ reqObj.addlHeaders = addlHeaders;
747
755
  }
748
- if (options && options.order) {
749
- reqObj.uriOptions.order = options.order;
756
+
757
+ // determine the call and return flag
758
+ let action = 'getGenericsNoBase';
759
+ let returnF = true;
760
+ if (restMethod.toUpperCase() === 'POST') {
761
+ action = 'createGenericNoBase';
762
+ } else if (restMethod.toUpperCase() === 'PUT') {
763
+ action = 'updateGenericNoBase';
764
+ } else if (restMethod.toUpperCase() === 'PATCH') {
765
+ action = 'patchGenericNoBase';
766
+ } else if (restMethod.toUpperCase() === 'DELETE') {
767
+ action = 'deleteGenericNoBase';
768
+ returnF = false;
750
769
  }
751
- */
770
+
752
771
  try {
753
- // !! using Generic makes it easier on the Adapter Builder (just need to change the path)
754
- // !! you can also replace with a specific call if that is easier
755
- const uriPath = '/call/toget/devices';
756
- return this.genericAdapterRequest(uriPath, 'GET', {}, {}, {}, (result, error) => {
757
- // if we received an error or their is no response on the results return an error
758
- if (error) {
759
- return callback(null, error);
772
+ // Make the call -
773
+ // identifyRequest(entity, action, requestObj, returnDataFlag, callback)
774
+ return this.requestHandlerInst.identifyRequest('.generic', action, reqObj, returnF, (irReturnData, irReturnError) => {
775
+ // if we received an error or their is no response on the results
776
+ // return an error
777
+ if (irReturnError) {
778
+ /* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
779
+ return callback(null, irReturnError);
760
780
  }
761
- if (!result.response) {
762
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getDevicesFiltered'], null, null, null);
781
+ if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
782
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['genericAdapterRequestNoBasePath'], null, null, null);
763
783
  log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
764
784
  return callback(null, errorObj);
765
785
  }
766
786
 
767
- // !! go through the response - may have to look for sub object
768
- // handle an array of devices
769
- if (Array.isArray(result.response)) {
770
- const myDevices = [];
771
-
772
- for (let d = 0; d < result.response.length; d += 1) {
773
- // !! format the data we send back
774
- // !! these fields are config manager fields you need to map to the data we receive
775
- const thisDevice = result.response;
776
- thisDevice.name = thisDevice.systemName;
777
- thisDevice.ostype = `System-${thisDevice.systemType}`;
778
- thisDevice.port = thisDevice.systemPort;
779
- thisDevice.ipaddress = thisDevice.systemIP;
780
-
781
- // if there is no filter - return the device
782
- if (filterName.length === 0) {
783
- myDevices.push(thisDevice);
784
- } else {
785
- // if we have to match a filter
786
- let found = false;
787
- for (let f = 0; f < filterName.length; f += 1) {
788
- if (thisDevice.name.indexOf(filterName[f]) >= 0) {
789
- found = true;
790
- break;
791
- }
792
- }
793
- // matching device
794
- if (found) {
795
- myDevices.push(thisDevice);
796
- }
797
- }
798
- }
799
- log.debug(`${origin}: Found #${myDevices.length} devices.`);
800
- log.debug(`Devices: ${JSON.stringify(myDevices)}`);
801
- return callback({ total: myDevices.length, list: myDevices });
802
- }
803
- // handle a single device response
804
- // !! format the data we send back
805
- // !! these fields are config manager fields you need to map to the data we receive
806
- const thisDevice = result.response;
807
- thisDevice.name = thisDevice.systemName;
808
- thisDevice.ostype = `System-${thisDevice.systemType}`;
809
- thisDevice.port = thisDevice.systemPort;
810
- thisDevice.ipaddress = thisDevice.systemIP;
811
-
812
- // if there is no filter - return the device
813
- if (filterName.length === 0) {
814
- log.debug(`${origin}: Found #1 device.`);
815
- log.debug(`Device: ${JSON.stringify(thisDevice)}`);
816
- return callback({ total: 1, list: [thisDevice] });
817
- }
818
-
819
- // if there is a filter need to check for matching device
820
- let found = false;
821
- for (let f = 0; f < filterName.length; f += 1) {
822
- if (thisDevice.name.indexOf(filterName[f]) >= 0) {
823
- found = true;
824
- break;
825
- }
826
- }
827
- // matching device
828
- if (found) {
829
- log.debug(`${origin}: Found #1 device.`);
830
- log.debug(`Device Found: ${JSON.stringify(thisDevice)}`);
831
- return callback({ total: 1, list: [thisDevice] });
832
- }
833
- // not a matching device
834
- log.debug(`${origin}: No matching device found.`);
835
- return callback({ total: 0, list: [] });
787
+ /* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
788
+ // return the response
789
+ return callback(irReturnData, null);
836
790
  });
837
791
  } catch (ex) {
838
792
  const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
@@ -841,173 +795,48 @@ class Robustel extends AdapterBaseCl {
841
795
  }
842
796
  }
843
797
 
798
+ /* INVENTORY CALLS */
844
799
  /**
845
- * @summary Gets the status for the provided appliance
800
+ * @summary run the adapter lint script to return the results.
846
801
  *
847
- * @function isAlive
848
- * @param {String} deviceName - the deviceName of the appliance. (required)
849
- *
850
- * @param {configCallback} callback - callback function to return the result
851
- * (appliance isAlive) or the error
802
+ * @function iapRunAdapterLint
803
+ * @param {Callback} callback - callback function
852
804
  */
853
- isAlive(deviceName, callback) {
854
- const meth = 'adapter-isAlive';
805
+ iapRunAdapterLint(callback) {
806
+ const meth = 'adapter-iapRunAdapterLint';
855
807
  const origin = `${this.id}-${meth}`;
856
808
  log.trace(origin);
857
809
 
858
- // verify the required fields have been provided
859
- if (deviceName === undefined || deviceName === null || deviceName === '' || deviceName.length === 0) {
860
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['deviceName'], null, null, null);
861
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
862
- return callback(null, errorObj);
863
- }
864
-
865
- try {
866
- // need to get the device so we can convert the deviceName to an id
867
- // !! if we can do a lookup by name the getDevicesFiltered may not be necessary
868
- const opts = {
869
- filter: {
870
- name: deviceName
871
- }
872
- };
873
- return this.getDevicesFiltered(opts, (devs, ferr) => {
874
- // if we received an error or their is no response on the results return an error
875
- if (ferr) {
876
- return callback(null, ferr);
877
- }
878
- if (devs.list.length < 1) {
879
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Did Not Find Device ${deviceName}`, [], null, null, null);
880
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
881
- return callback(null, errorObj);
882
- }
883
- // get the uuid from the device
884
- const { uuid } = devs.list[0];
885
-
886
- // !! using Generic makes it easier on the Adapter Builder (just need to change the path)
887
- // !! you can also replace with a specific call if that is easier
888
- const uriPath = `/call/toget/status/${uuid}`;
889
- return this.genericAdapterRequest(uriPath, 'GET', {}, {}, {}, (result, error) => {
890
- // if we received an error or their is no response on the results return an error
891
- if (error) {
892
- return callback(null, error);
893
- }
894
- // !! should update this to make sure we are checking for the appropriate object/field
895
- if (!result.response || !result.response.returnObj || !Object.hasOwnProperty.call(result.response.returnObj, 'statusField')) {
896
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['isAlive'], null, null, null);
897
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
898
- return callback(null, errorObj);
899
- }
900
-
901
- // !! return the response - Update to the appropriate object/field
902
- return callback(!result.response.returnObj.statusField);
903
- });
904
- });
905
- } catch (ex) {
906
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
907
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
908
- return callback(null, errorObj);
909
- }
810
+ return super.iapRunAdapterLint(callback);
910
811
  }
911
812
 
912
813
  /**
913
- * @summary Gets a config for the provided Appliance
914
- *
915
- * @function getConfig
916
- * @param {String} deviceName - the deviceName of the appliance. (required)
917
- * @param {String} format - the desired format of the config. (optional)
814
+ * @summary run the adapter test scripts (baseunit and unit) to return the results.
815
+ * can not run integration as there can be implications with that.
918
816
  *
919
- * @param {configCallback} callback - callback function to return the result
920
- * (appliance config) or the error
817
+ * @function iapRunAdapterTests
818
+ * @param {Callback} callback - callback function
921
819
  */
922
- getConfig(deviceName, format, callback) {
923
- const meth = 'adapter-getConfig';
820
+ iapRunAdapterTests(callback) {
821
+ const meth = 'adapter-iapRunAdapterTests';
924
822
  const origin = `${this.id}-${meth}`;
925
823
  log.trace(origin);
926
824
 
927
- // verify the required fields have been provided
928
- if (deviceName === undefined || deviceName === null || deviceName === '' || deviceName.length === 0) {
929
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['deviceName'], null, null, null);
930
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
931
- return callback(null, errorObj);
932
- }
933
-
934
- try {
935
- // need to get the device so we can convert the deviceName to an id
936
- // !! if we can do a lookup by name the getDevicesFiltered may not be necessary
937
- const opts = {
938
- filter: {
939
- name: deviceName
940
- }
941
- };
942
- return this.getDevicesFiltered(opts, (devs, ferr) => {
943
- // if we received an error or their is no response on the results return an error
944
- if (ferr) {
945
- return callback(null, ferr);
946
- }
947
- if (devs.list.length < 1) {
948
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Did Not Find Device ${deviceName}`, [], null, null, null);
949
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
950
- return callback(null, errorObj);
951
- }
952
- // get the uuid from the device
953
- const { uuid } = devs.list[0];
954
-
955
- // !! using Generic makes it easier on the Adapter Builder (just need to change the path)
956
- // !! you can also replace with a specific call if that is easier
957
- const uriPath = `/call/toget/config/${uuid}`;
958
- return this.genericAdapterRequest(uriPath, 'GET', {}, {}, {}, (result, error) => {
959
- // if we received an error or their is no response on the results return an error
960
- if (error) {
961
- return callback(null, error);
962
- }
963
-
964
- // return the result
965
- const newResponse = {
966
- response: JSON.stringify(result.response, null, 2)
967
- };
968
- return callback(newResponse);
969
- });
970
- });
971
- } catch (ex) {
972
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
973
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
974
- return callback(null, errorObj);
975
- }
825
+ return super.iapRunAdapterTests(callback);
976
826
  }
977
827
 
978
828
  /**
979
- * @summary Gets the device count from the system
980
- *
981
- * @function getCount
829
+ * @summary provide inventory information abbout the adapter
982
830
  *
983
- * @param {getCallback} callback - callback function to return the result
984
- * (count) or the error
831
+ * @function iapGetAdapterInventory
832
+ * @param {Callback} callback - callback function
985
833
  */
986
- getCount(callback) {
987
- const meth = 'adapter-getCount';
834
+ iapGetAdapterInventory(callback) {
835
+ const meth = 'adapter-iapGetAdapterInventory';
988
836
  const origin = `${this.id}-${meth}`;
989
837
  log.trace(origin);
990
838
 
991
- // verify the required fields have been provided
992
-
993
- try {
994
- // !! using Generic makes it easier on the Adapter Builder (just need to change the path)
995
- // !! you can also replace with a specific call if that is easier
996
- const uriPath = '/call/toget/count';
997
- return this.genericAdapterRequest(uriPath, 'GET', {}, {}, {}, (result, error) => {
998
- // if we received an error or their is no response on the results return an error
999
- if (error) {
1000
- return callback(null, error);
1001
- }
1002
-
1003
- // return the result
1004
- return callback({ count: result.response });
1005
- });
1006
- } catch (ex) {
1007
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
1008
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1009
- return callback(null, errorObj);
1010
- }
839
+ return super.iapGetAdapterInventory(callback);
1011
840
  }
1012
841
 
1013
842
  /**
@@ -1474,7 +1303,7 @@ class Robustel extends AdapterBaseCl {
1474
1303
  * @name runCommandOnDevice
1475
1304
  * @summary Run Command on Device
1476
1305
  *
1477
- * @param {} serialNumber - device serial number
1306
+ * @param {string} serialNumber - device serial number
1478
1307
  * @param {object} body - { commandType: , softwareVersionId: }
1479
1308
  * @param {getCallback} callback - a callback function to return the result
1480
1309
  * @return {object} results - An object containing the response of the action