@itentialopensource/adapter-nokia_altiplano 0.5.0 → 0.5.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.
package/adapter.js CHANGED
@@ -83,7 +83,14 @@ class NokiaAltiplano extends AdapterBaseCl {
83
83
  * @iapGetAdapterWorkflowFunctions
84
84
  */
85
85
  iapGetAdapterWorkflowFunctions(inIgnore) {
86
- let myIgnore = ['hasEntities', 'hasDevices', 'iapMakeBrokerCall'];
86
+ let myIgnore = [
87
+ 'healthCheck',
88
+ 'iapGetAdapterWorkflowFunctions',
89
+ 'iapHasAdapterEntity',
90
+ 'iapVerifyAdapterCapability',
91
+ 'iapUpdateAdapterEntityCache',
92
+ 'hasEntities'
93
+ ];
87
94
  if (!inIgnore && Array.isArray(inIgnore)) {
88
95
  myIgnore = inIgnore;
89
96
  } else if (!inIgnore && typeof inIgnore === 'string') {
@@ -111,8 +118,10 @@ class NokiaAltiplano extends AdapterBaseCl {
111
118
  * @param {Callback} callback - The results of the call
112
119
  */
113
120
  iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, callback) {
114
- const origin = `${this.id}-adapter-iapUpdateAdapterConfiguration`;
121
+ const meth = 'adapter-iapUpdateAdapterConfiguration';
122
+ const origin = `${this.id}-${meth}`;
115
123
  log.trace(origin);
124
+
116
125
  super.iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, callback);
117
126
  }
118
127
 
@@ -124,8 +133,10 @@ class NokiaAltiplano extends AdapterBaseCl {
124
133
  * @param {Callback} callback - The results of the call
125
134
  */
126
135
  iapFindAdapterPath(apiPath, callback) {
127
- const origin = `${this.id}-adapter-iapFindAdapterPath`;
136
+ const meth = 'adapter-iapFindAdapterPath';
137
+ const origin = `${this.id}-${meth}`;
128
138
  log.trace(origin);
139
+
129
140
  super.iapFindAdapterPath(apiPath, callback);
130
141
  }
131
142
 
@@ -136,8 +147,10 @@ class NokiaAltiplano extends AdapterBaseCl {
136
147
  * @param {Callback} callback - callback function
137
148
  */
138
149
  iapSuspendAdapter(mode, callback) {
139
- const origin = `${this.id}-adapter-iapSuspendAdapter`;
150
+ const meth = 'adapter-iapSuspendAdapter';
151
+ const origin = `${this.id}-${meth}`;
140
152
  log.trace(origin);
153
+
141
154
  try {
142
155
  return super.iapSuspendAdapter(mode, callback);
143
156
  } catch (error) {
@@ -153,8 +166,10 @@ class NokiaAltiplano extends AdapterBaseCl {
153
166
  * @param {Callback} callback - callback function
154
167
  */
155
168
  iapUnsuspendAdapter(callback) {
156
- const origin = `${this.id}-adapter-iapUnsuspendAdapter`;
169
+ const meth = 'adapter-iapUnsuspendAdapter';
170
+ const origin = `${this.id}-${meth}`;
157
171
  log.trace(origin);
172
+
158
173
  try {
159
174
  return super.iapUnsuspendAdapter(callback);
160
175
  } catch (error) {
@@ -170,8 +185,10 @@ class NokiaAltiplano extends AdapterBaseCl {
170
185
  * @param {Callback} callback - callback function
171
186
  */
172
187
  iapGetAdapterQueue(callback) {
173
- const origin = `${this.id}-adapter-iapGetAdapterQueue`;
188
+ const meth = 'adapter-iapGetAdapterQueue';
189
+ const origin = `${this.id}-${meth}`;
174
190
  log.trace(origin);
191
+
175
192
  return super.iapGetAdapterQueue(callback);
176
193
  }
177
194
 
@@ -185,8 +202,10 @@ class NokiaAltiplano extends AdapterBaseCl {
185
202
  * @param {Callback} callback - The results of the call
186
203
  */
187
204
  iapTroubleshootAdapter(props, persistFlag, callback) {
188
- const origin = `${this.id}-adapter-iapTroubleshootAdapter`;
205
+ const meth = 'adapter-iapTroubleshootAdapter';
206
+ const origin = `${this.id}-${meth}`;
189
207
  log.trace(origin);
208
+
190
209
  try {
191
210
  return super.iapTroubleshootAdapter(props, persistFlag, this, callback);
192
211
  } catch (error) {
@@ -203,8 +222,10 @@ class NokiaAltiplano extends AdapterBaseCl {
203
222
  * @param {Callback} callback - callback function
204
223
  */
205
224
  iapRunAdapterHealthcheck(callback) {
206
- const origin = `${this.id}-adapter-iapRunAdapterHealthcheck`;
225
+ const meth = 'adapter-iapRunAdapterHealthcheck';
226
+ const origin = `${this.id}-${meth}`;
207
227
  log.trace(origin);
228
+
208
229
  try {
209
230
  return super.iapRunAdapterHealthcheck(this, callback);
210
231
  } catch (error) {
@@ -220,8 +241,10 @@ class NokiaAltiplano extends AdapterBaseCl {
220
241
  * @param {Callback} callback - callback function
221
242
  */
222
243
  iapRunAdapterConnectivity(callback) {
223
- const origin = `${this.id}-adapter-iapRunAdapterConnectivity`;
244
+ const meth = 'adapter-iapRunAdapterConnectivity';
245
+ const origin = `${this.id}-${meth}`;
224
246
  log.trace(origin);
247
+
225
248
  try {
226
249
  return super.iapRunAdapterConnectivity(callback);
227
250
  } catch (error) {
@@ -237,8 +260,10 @@ class NokiaAltiplano extends AdapterBaseCl {
237
260
  * @param {Callback} callback - callback function
238
261
  */
239
262
  iapRunAdapterBasicGet(callback) {
240
- const origin = `${this.id}-adapter-iapRunAdapterBasicGet`;
263
+ const meth = 'adapter-iapRunAdapterBasicGet';
264
+ const origin = `${this.id}-${meth}`;
241
265
  log.trace(origin);
266
+
242
267
  try {
243
268
  return super.iapRunAdapterBasicGet(callback);
244
269
  } catch (error) {
@@ -255,8 +280,10 @@ class NokiaAltiplano extends AdapterBaseCl {
255
280
  * or the error
256
281
  */
257
282
  iapMoveAdapterEntitiesToDB(callback) {
258
- const origin = `${this.id}-adapter-iapMoveAdapterEntitiesToDB`;
283
+ const meth = 'adapter-iapMoveAdapterEntitiesToDB';
284
+ const origin = `${this.id}-${meth}`;
259
285
  log.trace(origin);
286
+
260
287
  try {
261
288
  return super.iapMoveAdapterEntitiesToDB(callback);
262
289
  } catch (err) {
@@ -446,56 +473,18 @@ class NokiaAltiplano extends AdapterBaseCl {
446
473
  * value is true or false
447
474
  */
448
475
  hasEntities(entityType, entityList, callback) {
449
- const origin = `${this.id}-adapter-hasEntities`;
476
+ const meth = 'adapter-hasEntities';
477
+ const origin = `${this.id}-${meth}`;
450
478
  log.trace(origin);
451
479
 
452
- switch (entityType) {
453
- case 'Device':
454
- return this.hasDevices(entityList, callback);
455
- default:
456
- return callback(null, `${this.id} does not support entity ${entityType}`);
480
+ try {
481
+ return super.hasEntities(entityType, entityList, callback);
482
+ } catch (err) {
483
+ log.error(`${origin}: ${err}`);
484
+ return callback(null, err);
457
485
  }
458
486
  }
459
487
 
460
- /**
461
- * @summary Helper method for hasEntities for the specific device case
462
- *
463
- * @param {Array} deviceList - array of unique device identifiers
464
- * @param {Callback} callback - A map where the device is the key and the
465
- * value is true or false
466
- */
467
- hasDevices(deviceList, callback) {
468
- const origin = `${this.id}-adapter-hasDevices`;
469
- log.trace(origin);
470
-
471
- const findings = deviceList.reduce((map, device) => {
472
- // eslint-disable-next-line no-param-reassign
473
- map[device] = false;
474
- log.debug(`In reduce: ${JSON.stringify(map)}`);
475
- return map;
476
- }, {});
477
- const apiCalls = deviceList.map((device) => new Promise((resolve) => {
478
- this.getDevice(device, (result, error) => {
479
- if (error) {
480
- log.debug(`In map error: ${JSON.stringify(device)}`);
481
- return resolve({ name: device, found: false });
482
- }
483
- log.debug(`In map: ${JSON.stringify(device)}`);
484
- return resolve({ name: device, found: true });
485
- });
486
- }));
487
- Promise.all(apiCalls).then((results) => {
488
- results.forEach((device) => {
489
- findings[device.name] = device.found;
490
- });
491
- log.debug(`FINDINGS: ${JSON.stringify(findings)}`);
492
- return callback(findings);
493
- }).catch((errors) => {
494
- log.error('Unable to do device lookup.');
495
- return callback(null, { code: 503, message: 'Unable to do device lookup.', error: errors });
496
- });
497
- }
498
-
499
488
  /**
500
489
  * @summary Get Appliance that match the deviceName
501
490
  *
@@ -510,71 +499,11 @@ class NokiaAltiplano extends AdapterBaseCl {
510
499
  const origin = `${this.id}-${meth}`;
511
500
  log.trace(origin);
512
501
 
513
- // make sure we are set up for device broker getDevice
514
- if (!this.allProps.devicebroker || !this.allProps.devicebroker.getDevice || this.allProps.devicebroker.getDevice.length === 0 || !this.allProps.devicebroker.getDevice[0].path) {
515
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Properties', ['devicebroker.getDevice.path'], null, null, null);
516
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
517
- return callback(null, errorObj);
518
- }
519
-
520
- /* HERE IS WHERE YOU VALIDATE DATA */
521
- if (deviceName === undefined || deviceName === null || deviceName === '' || deviceName.length === 0) {
522
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['deviceName'], null, null, null);
523
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
524
- return callback(null, errorObj);
525
- }
526
-
527
502
  try {
528
- // need to get the device so we can convert the deviceName to an id
529
- // !! if we can do a lookup by name the getDevicesFiltered may not be necessary
530
- const opts = {
531
- filter: {
532
- name: deviceName
533
- }
534
- };
535
- return this.getDevicesFiltered(opts, (devs, ferr) => {
536
- // if we received an error or their is no response on the results return an error
537
- if (ferr) {
538
- return callback(null, ferr);
539
- }
540
- if (devs.list.length < 1) {
541
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Did Not Find Device ${deviceName}`, [], null, null, null);
542
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
543
- return callback(null, errorObj);
544
- }
545
-
546
- const callPromises = [];
547
- for (let i = 0; i < this.allProps.devicebroker.getDevice.length; i += 1) {
548
- // Perform component calls here.
549
- callPromises.push(
550
- new Promise((resolve, reject) => {
551
- this.iapMakeBrokerCall('getDevice', this.allProps.devicebroker.getDevice[i], devs.list[0], null, (callRet, callErr) => {
552
- // return an error
553
- if (callErr) {
554
- reject(callErr);
555
- } else {
556
- // return the data
557
- resolve(callRet);
558
- }
559
- });
560
- })
561
- );
562
- }
563
-
564
- // return an array of repsonses
565
- return Promise.all(callPromises).then((results) => {
566
- let myResult = {};
567
- results.forEach((result) => {
568
- myResult = { ...myResult, ...result };
569
- });
570
-
571
- return callback(myResult, null);
572
- });
573
- });
574
- } catch (ex) {
575
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
576
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
577
- return callback(null, errorObj);
503
+ return super.getDevice(deviceName, callback);
504
+ } catch (err) {
505
+ log.error(`${origin}: ${err}`);
506
+ return callback(null, err);
578
507
  }
579
508
  }
580
509
 
@@ -592,84 +521,11 @@ class NokiaAltiplano extends AdapterBaseCl {
592
521
  const origin = `${this.id}-${meth}`;
593
522
  log.trace(origin);
594
523
 
595
- // make sure we are set up for device broker getDevicesFiltered
596
- if (!this.allProps.devicebroker || !this.allProps.devicebroker.getDevicesFiltered || this.allProps.devicebroker.getDevicesFiltered.length === 0 || !this.allProps.devicebroker.getDevicesFiltered[0].path) {
597
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Properties', ['devicebroker.getDevicesFiltered.path'], null, null, null);
598
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
599
- return callback(null, errorObj);
600
- }
601
-
602
- // verify the required fields have been provided
603
- if (options === undefined || options === null || options === '' || options.length === 0) {
604
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['options'], null, null, null);
605
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
606
- return callback(null, errorObj);
607
- }
608
- log.debug(`Device Filter Options: ${JSON.stringify(options)}`);
609
-
610
524
  try {
611
- // TODO - get pagination working
612
- // const nextToken = options.start;
613
- // const maxResults = options.limit;
614
-
615
- // set up the filter of Device Names
616
- let filterName = [];
617
- if (options && options.filter && options.filter.name) {
618
- // when this hack is removed, remove the lint ignore above
619
- if (Array.isArray(options.filter.name)) {
620
- // eslint-disable-next-line prefer-destructuring
621
- filterName = options.filter.name;
622
- } else {
623
- filterName = [options.filter.name];
624
- }
625
- }
626
-
627
- // TODO - get sort and order working
628
- /*
629
- if (options && options.sort) {
630
- reqObj.uriOptions.sort = JSON.stringify(options.sort);
631
- }
632
- if (options && options.order) {
633
- reqObj.uriOptions.order = options.order;
634
- }
635
- */
636
- const callPromises = [];
637
- for (let i = 0; i < this.allProps.devicebroker.getDevicesFiltered.length; i += 1) {
638
- // Perform component calls here.
639
- callPromises.push(
640
- new Promise((resolve, reject) => {
641
- this.iapMakeBrokerCall('getDevicesFiltered', this.allProps.devicebroker.getDevicesFiltered[i], null, filterName, (callRet, callErr) => {
642
- // return an error
643
- if (callErr) {
644
- reject(callErr);
645
- } else {
646
- // return the data
647
- resolve(callRet);
648
- }
649
- });
650
- })
651
- );
652
- }
653
-
654
- // return an array of repsonses
655
- return Promise.all(callPromises).then((results) => {
656
- let myResult = [];
657
- results.forEach((result) => {
658
- if (Array.isArray(result)) {
659
- myResult = [...myResult, ...result];
660
- } else if (Object.keys(result).length > 0) {
661
- myResult.push(result);
662
- }
663
- });
664
-
665
- log.debug(`${origin}: Found #${myResult.length} devices.`);
666
- log.debug(`Devices: ${JSON.stringify(myResult)}`);
667
- return callback({ total: myResult.length, list: myResult });
668
- });
669
- } catch (ex) {
670
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
671
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
672
- return callback(null, errorObj);
525
+ return super.getDevicesFiltered(options, callback);
526
+ } catch (err) {
527
+ log.error(`${origin}: ${err}`);
528
+ return callback(null, err);
673
529
  }
674
530
  }
675
531
 
@@ -687,75 +543,11 @@ class NokiaAltiplano extends AdapterBaseCl {
687
543
  const origin = `${this.id}-${meth}`;
688
544
  log.trace(origin);
689
545
 
690
- // make sure we are set up for device broker isAlive
691
- if (!this.allProps.devicebroker || !this.allProps.devicebroker.isAlive || this.allProps.devicebroker.isAlive.length === 0 || !this.allProps.devicebroker.isAlive[0].path) {
692
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Properties', ['devicebroker.isAlive.path'], null, null, null);
693
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
694
- return callback(null, errorObj);
695
- }
696
-
697
- // verify the required fields have been provided
698
- if (deviceName === undefined || deviceName === null || deviceName === '' || deviceName.length === 0) {
699
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['deviceName'], null, null, null);
700
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
701
- return callback(null, errorObj);
702
- }
703
-
704
546
  try {
705
- // need to get the device so we can convert the deviceName to an id
706
- // !! if we can do a lookup by name the getDevicesFiltered may not be necessary
707
- const opts = {
708
- filter: {
709
- name: deviceName
710
- }
711
- };
712
- return this.getDevicesFiltered(opts, (devs, ferr) => {
713
- // if we received an error or their is no response on the results return an error
714
- if (ferr) {
715
- return callback(null, ferr);
716
- }
717
- if (devs.list.length < 1) {
718
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Did Not Find Device ${deviceName}`, [], null, null, null);
719
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
720
- return callback(null, errorObj);
721
- }
722
-
723
- const callPromises = [];
724
- for (let i = 0; i < this.allProps.devicebroker.isAlive.length; i += 1) {
725
- // Perform component calls here.
726
- callPromises.push(
727
- new Promise((resolve, reject) => {
728
- this.iapMakeBrokerCall('isAlive', this.allProps.devicebroker.isAlive[i], devs.list[0], null, (callRet, callErr) => {
729
- // return an error
730
- if (callErr) {
731
- reject(callErr);
732
- } else {
733
- // return the data
734
- resolve(callRet);
735
- }
736
- });
737
- })
738
- );
739
- }
740
-
741
- // return an array of repsonses
742
- return Promise.all(callPromises).then((results) => {
743
- let myResult = {};
744
- results.forEach((result) => {
745
- myResult = { ...myResult, ...result };
746
- });
747
-
748
- let response = true;
749
- if (myResult.isAlive !== null && myResult.isAlive !== undefined && myResult.isAlive === false) {
750
- response = false;
751
- }
752
- return callback(response);
753
- });
754
- });
755
- } catch (ex) {
756
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
757
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
758
- return callback(null, errorObj);
547
+ return super.isAlive(deviceName, callback);
548
+ } catch (err) {
549
+ log.error(`${origin}: ${err}`);
550
+ return callback(null, err);
759
551
  }
760
552
  }
761
553
 
@@ -774,75 +566,11 @@ class NokiaAltiplano extends AdapterBaseCl {
774
566
  const origin = `${this.id}-${meth}`;
775
567
  log.trace(origin);
776
568
 
777
- // make sure we are set up for device broker getConfig
778
- if (!this.allProps.devicebroker || !this.allProps.devicebroker.getConfig || this.allProps.devicebroker.getConfig.length === 0 || !this.allProps.devicebroker.getConfig[0].path) {
779
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Properties', ['devicebroker.getConfig.path'], null, null, null);
780
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
781
- return callback(null, errorObj);
782
- }
783
-
784
- // verify the required fields have been provided
785
- if (deviceName === undefined || deviceName === null || deviceName === '' || deviceName.length === 0) {
786
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['deviceName'], null, null, null);
787
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
788
- return callback(null, errorObj);
789
- }
790
-
791
569
  try {
792
- // need to get the device so we can convert the deviceName to an id
793
- // !! if we can do a lookup by name the getDevicesFiltered may not be necessary
794
- const opts = {
795
- filter: {
796
- name: deviceName
797
- }
798
- };
799
- return this.getDevicesFiltered(opts, (devs, ferr) => {
800
- // if we received an error or their is no response on the results return an error
801
- if (ferr) {
802
- return callback(null, ferr);
803
- }
804
- if (devs.list.length < 1) {
805
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Did Not Find Device ${deviceName}`, [], null, null, null);
806
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
807
- return callback(null, errorObj);
808
- }
809
-
810
- const callPromises = [];
811
- for (let i = 0; i < this.allProps.devicebroker.getConfig.length; i += 1) {
812
- // Perform component calls here.
813
- callPromises.push(
814
- new Promise((resolve, reject) => {
815
- this.iapMakeBrokerCall('getConfig', this.allProps.devicebroker.getConfig[i], devs.list[0], null, (callRet, callErr) => {
816
- // return an error
817
- if (callErr) {
818
- reject(callErr);
819
- } else {
820
- // return the data
821
- resolve(callRet);
822
- }
823
- });
824
- })
825
- );
826
- }
827
-
828
- // return an array of repsonses
829
- return Promise.all(callPromises).then((results) => {
830
- let myResult = {};
831
- results.forEach((result) => {
832
- myResult = { ...myResult, ...result };
833
- });
834
-
835
- // return the result
836
- const newResponse = {
837
- response: JSON.stringify(myResult, null, 2)
838
- };
839
- return callback(newResponse, null);
840
- });
841
- });
842
- } catch (ex) {
843
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
844
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
845
- return callback(null, errorObj);
570
+ return super.getConfig(deviceName, format, callback);
571
+ } catch (err) {
572
+ log.error(`${origin}: ${err}`);
573
+ return callback(null, err);
846
574
  }
847
575
  }
848
576
 
@@ -859,43 +587,117 @@ class NokiaAltiplano extends AdapterBaseCl {
859
587
  const origin = `${this.id}-${meth}`;
860
588
  log.trace(origin);
861
589
 
862
- // make sure we are set up for device broker getCount
863
- if (!this.allProps.devicebroker || !this.allProps.devicebroker.getCount || this.allProps.devicebroker.getCount.length === 0 || !this.allProps.devicebroker.getCount[0].path) {
864
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Properties', ['devicebroker.getCount.path'], null, null, null);
590
+ try {
591
+ return super.iapGetDeviceCount(callback);
592
+ } catch (err) {
593
+ log.error(`${origin}: ${err}`);
594
+ return callback(null, err);
595
+ }
596
+ }
597
+
598
+ /* GENERIC ADAPTER REQUEST - allows extension of adapter without new calls being added */
599
+ /**
600
+ * Makes the requested generic call
601
+ *
602
+ * @function genericAdapterRequest
603
+ * @param {String} uriPath - the path of the api call - do not include the host, port, base path or version (required)
604
+ * @param {String} restMethod - the rest method (GET, POST, PUT, PATCH, DELETE) (required)
605
+ * @param {Object} queryData - the parameters to be put on the url (optional).
606
+ * Can be a stringified Object.
607
+ * @param {Object} requestBody - the body to add to the request (optional).
608
+ * Can be a stringified Object.
609
+ * @param {Object} addlHeaders - additional headers to be put on the call (optional).
610
+ * Can be a stringified Object.
611
+ * @param {getCallback} callback - a callback function to return the result (Generics)
612
+ * or the error
613
+ */
614
+ genericAdapterRequest(uriPath, restMethod, queryData, requestBody, addlHeaders, callback) {
615
+ const meth = 'adapter-genericAdapterRequest';
616
+ const origin = `${this.id}-${meth}`;
617
+ log.trace(origin);
618
+
619
+ if (this.suspended && this.suspendMode === 'error') {
620
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
621
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
622
+ return callback(null, errorObj);
623
+ }
624
+
625
+ /* HERE IS WHERE YOU VALIDATE DATA */
626
+ if (uriPath === undefined || uriPath === null || uriPath === '') {
627
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['uriPath'], null, null, null);
628
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
629
+ return callback(null, errorObj);
630
+ }
631
+ if (restMethod === undefined || restMethod === null || restMethod === '') {
632
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['restMethod'], null, null, null);
865
633
  log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
866
634
  return callback(null, errorObj);
867
635
  }
868
636
 
869
- // verify the required fields have been provided
637
+ /* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
638
+ // remove any leading / and split the uripath into path variables
639
+ let myPath = uriPath;
640
+ while (myPath.indexOf('/') === 0) {
641
+ myPath = myPath.substring(1);
642
+ }
643
+ const pathVars = myPath.split('/');
644
+ const queryParamsAvailable = queryData;
645
+ const queryParams = {};
646
+ const bodyVars = requestBody;
870
647
 
871
- try {
872
- const callPromises = [];
873
- for (let i = 0; i < this.allProps.devicebroker.getCount.length; i += 1) {
874
- // Perform component calls here.
875
- callPromises.push(
876
- new Promise((resolve, reject) => {
877
- this.iapMakeBrokerCall('getCount', this.allProps.devicebroker.getCount[i], null, null, (callRet, callErr) => {
878
- // return an error
879
- if (callErr) {
880
- reject(callErr);
881
- } else {
882
- // return the data
883
- resolve(callRet);
884
- }
885
- });
886
- })
887
- );
648
+ // loop in template. long callback arg name to avoid identifier conflicts
649
+ Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
650
+ if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
651
+ && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
652
+ queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
888
653
  }
654
+ });
889
655
 
890
- // return an array of repsonses
891
- return Promise.all(callPromises).then((results) => {
892
- let myResult = {};
893
- results.forEach((result) => {
894
- myResult = { ...myResult, ...result };
895
- });
656
+ // set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders
657
+ const reqObj = {
658
+ payload: bodyVars,
659
+ uriPathVars: pathVars,
660
+ uriQuery: queryParams,
661
+ uriOptions: {}
662
+ };
663
+ // add headers if provided
664
+ if (addlHeaders) {
665
+ reqObj.addlHeaders = addlHeaders;
666
+ }
667
+
668
+ // determine the call and return flag
669
+ let action = 'getGenerics';
670
+ let returnF = true;
671
+ if (restMethod.toUpperCase() === 'POST') {
672
+ action = 'createGeneric';
673
+ } else if (restMethod.toUpperCase() === 'PUT') {
674
+ action = 'updateGeneric';
675
+ } else if (restMethod.toUpperCase() === 'PATCH') {
676
+ action = 'patchGeneric';
677
+ } else if (restMethod.toUpperCase() === 'DELETE') {
678
+ action = 'deleteGeneric';
679
+ returnF = false;
680
+ }
681
+
682
+ try {
683
+ // Make the call -
684
+ // identifyRequest(entity, action, requestObj, returnDataFlag, callback)
685
+ return this.requestHandlerInst.identifyRequest('.generic', action, reqObj, returnF, (irReturnData, irReturnError) => {
686
+ // if we received an error or their is no response on the results
687
+ // return an error
688
+ if (irReturnError) {
689
+ /* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
690
+ return callback(null, irReturnError);
691
+ }
692
+ if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
693
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['genericAdapterRequest'], null, null, null);
694
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
695
+ return callback(null, errorObj);
696
+ }
896
697
 
897
- // return the result
898
- return callback({ count: myResult.length });
698
+ /* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
699
+ // return the response
700
+ return callback(irReturnData, null);
899
701
  });
900
702
  } catch (ex) {
901
703
  const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
@@ -904,11 +706,10 @@ class NokiaAltiplano extends AdapterBaseCl {
904
706
  }
905
707
  }
906
708
 
907
- /* GENERIC ADAPTER REQUEST - allows extension of adapter without new calls being added */
908
709
  /**
909
- * Makes the requested generic call
710
+ * Makes the requested generic call with no base path or version
910
711
  *
911
- * @function genericAdapterRequest
712
+ * @function genericAdapterRequestNoBasePath
912
713
  * @param {String} uriPath - the path of the api call - do not include the host, port, base path or version (required)
913
714
  * @param {String} restMethod - the rest method (GET, POST, PUT, PATCH, DELETE) (required)
914
715
  * @param {Object} queryData - the parameters to be put on the url (optional).
@@ -920,8 +721,8 @@ class NokiaAltiplano extends AdapterBaseCl {
920
721
  * @param {getCallback} callback - a callback function to return the result (Generics)
921
722
  * or the error
922
723
  */
923
- genericAdapterRequest(uriPath, restMethod, queryData, requestBody, addlHeaders, callback) {
924
- const meth = 'adapter-genericAdapterRequest';
724
+ genericAdapterRequestNoBasePath(uriPath, restMethod, queryData, requestBody, addlHeaders, callback) {
725
+ const meth = 'adapter-genericAdapterRequestNoBasePath';
925
726
  const origin = `${this.id}-${meth}`;
926
727
  log.trace(origin);
927
728
 
@@ -975,16 +776,16 @@ class NokiaAltiplano extends AdapterBaseCl {
975
776
  }
976
777
 
977
778
  // determine the call and return flag
978
- let action = 'getGenerics';
779
+ let action = 'getGenericsNoBase';
979
780
  let returnF = true;
980
781
  if (restMethod.toUpperCase() === 'POST') {
981
- action = 'createGeneric';
782
+ action = 'createGenericNoBase';
982
783
  } else if (restMethod.toUpperCase() === 'PUT') {
983
- action = 'updateGeneric';
784
+ action = 'updateGenericNoBase';
984
785
  } else if (restMethod.toUpperCase() === 'PATCH') {
985
- action = 'patchGeneric';
786
+ action = 'patchGenericNoBase';
986
787
  } else if (restMethod.toUpperCase() === 'DELETE') {
987
- action = 'deleteGeneric';
788
+ action = 'deleteGenericNoBase';
988
789
  returnF = false;
989
790
  }
990
791
 
@@ -999,7 +800,7 @@ class NokiaAltiplano extends AdapterBaseCl {
999
800
  return callback(null, irReturnError);
1000
801
  }
1001
802
  if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
1002
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['genericAdapterRequest'], null, null, null);
803
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['genericAdapterRequestNoBasePath'], null, null, null);
1003
804
  log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1004
805
  return callback(null, errorObj);
1005
806
  }
@@ -2543,7 +2344,8 @@ class NokiaAltiplano extends AdapterBaseCl {
2543
2344
  * @name deleteIbnIntent
2544
2345
  * @summary Delete ibn intent
2545
2346
  *
2546
- * @param {string} intent - the intent value, type (MYINTONT1,ont)
2347
+ * @param {string} intentType - the intent type (mcast-user)
2348
+ * @param {string} target - the target intent to delete
2547
2349
  * @param {getCallback} callback - a callback function to return the result
2548
2350
  * @return {object} results - An object containing the response of the action
2549
2351
  *
@@ -2552,7 +2354,7 @@ class NokiaAltiplano extends AdapterBaseCl {
2552
2354
  * @task true
2553
2355
  */
2554
2356
  /* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
2555
- deleteIbnIntent(intent, callback) {
2357
+ deleteIbnIntent(intentType, target, callback) {
2556
2358
  const meth = 'adapter-deleteIbnIntent';
2557
2359
  const origin = `${this.id}-${meth}`;
2558
2360
  log.trace(origin);
@@ -2564,21 +2366,27 @@ class NokiaAltiplano extends AdapterBaseCl {
2564
2366
  }
2565
2367
 
2566
2368
  /* HERE IS WHERE YOU VALIDATE DATA */
2567
- if (intent === undefined || intent === null || intent === '') {
2568
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['intent'], null, null, null);
2369
+ if (intentType === undefined || intentType === null || intentType === '') {
2370
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['intentType'], null, null, null);
2569
2371
  log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
2570
2372
  return callback(null, errorObj);
2571
2373
  }
2572
- let newIntent = intent;
2573
- if (intent.indexOf('intent=') !== 0) {
2574
- newIntent = `intent=${intent}`;
2374
+ if (target === undefined || target === null || target === '') {
2375
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['target'], null, null, null);
2376
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
2377
+ return callback(null, errorObj);
2575
2378
  }
2576
2379
 
2577
2380
  /* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
2578
2381
  const queryParamsAvailable = {};
2579
2382
  const queryParams = {};
2580
- const pathVars = [newIntent];
2581
- const bodyVars = {};
2383
+ const pathVars = [];
2384
+ const bodyVars = {
2385
+ 'ibn:delete-intent-from-network-and-controller': {
2386
+ 'intent-type': intentType,
2387
+ target
2388
+ }
2389
+ };
2582
2390
 
2583
2391
  // loop in template. long callback arg name to avoid identifier conflicts
2584
2392
  Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {