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