@itentialopensource/adapter-dna_center 0.5.6 → 0.5.7
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/CHANGELOG.md +8 -0
- package/ENHANCE.md +69 -0
- package/PROPERTIES.md +247 -0
- package/README.md +113 -470
- package/SUMMARY.md +9 -0
- package/TROUBLESHOOT.md +46 -0
- package/adapter.js +856 -57
- package/adapterBase.js +572 -279
- package/entities/.generic/action.json +110 -5
- package/entities/.generic/schema.json +6 -1
- package/entities/Sites/action.json +42 -0
- package/entities/Sites/schema.json +2 -0
- package/error.json +12 -0
- package/package.json +18 -13
- package/pronghorn.json +481 -79
- package/propertiesDecorators.json +14 -0
- package/propertiesSchema.json +382 -0
- package/refs?service=git-upload-pack +0 -0
- package/report/updateReport1651598418513.json +114 -0
- package/sampleProperties.json +4 -1
- package/test/integration/adapterTestBasicGet.js +1 -1
- package/test/integration/adapterTestIntegration.js +67 -2
- package/test/unit/adapterBaseTestUnit.js +33 -27
- package/test/unit/adapterTestUnit.js +776 -11
- package/utils/addAuth.js +94 -0
- package/utils/basicGet.js +1 -14
- package/utils/entitiesToDB.js +224 -0
- package/utils/modify.js +1 -1
- package/utils/packModificationScript.js +1 -1
- package/utils/patches2bundledDeps.js +90 -0
- package/utils/removeHooks.js +20 -0
- package/utils/tbScript.js +14 -8
- package/utils/tbUtils.js +111 -19
- package/utils/troubleshootingAdapter.js +2 -26
package/adapter.js
CHANGED
|
@@ -82,10 +82,10 @@ class DnaCenter extends AdapterBaseCl {
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
/**
|
|
85
|
-
* @
|
|
85
|
+
* @iapGetAdapterWorkflowFunctions
|
|
86
86
|
*/
|
|
87
|
-
|
|
88
|
-
let myIgnore = [];
|
|
87
|
+
iapGetAdapterWorkflowFunctions(inIgnore) {
|
|
88
|
+
let myIgnore = ['hasEntities', 'hasDevices'];
|
|
89
89
|
if (!inIgnore && Array.isArray(inIgnore)) {
|
|
90
90
|
myIgnore = inIgnore;
|
|
91
91
|
} else if (!inIgnore && typeof inIgnore === 'string') {
|
|
@@ -96,15 +96,15 @@ class DnaCenter extends AdapterBaseCl {
|
|
|
96
96
|
// you can add specific methods that you do not want to be workflow functions to ignore like below
|
|
97
97
|
// myIgnore.push('myMethodNotInWorkflow');
|
|
98
98
|
|
|
99
|
-
return super.
|
|
99
|
+
return super.iapGetAdapterWorkflowFunctions(myIgnore);
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
/**
|
|
103
|
-
*
|
|
103
|
+
* iapUpdateAdapterConfiguration is used to update any of the adapter configuration files. This
|
|
104
104
|
* allows customers to make changes to adapter configuration without having to be on the
|
|
105
105
|
* file system.
|
|
106
106
|
*
|
|
107
|
-
* @function
|
|
107
|
+
* @function iapUpdateAdapterConfiguration
|
|
108
108
|
* @param {string} configFile - the name of the file being updated (required)
|
|
109
109
|
* @param {Object} changes - an object containing all of the changes = formatted like the configuration file (required)
|
|
110
110
|
* @param {string} entity - the entity to be changed, if an action, schema or mock data file (optional)
|
|
@@ -112,36 +112,36 @@ class DnaCenter extends AdapterBaseCl {
|
|
|
112
112
|
* @param {string} action - the action to be changed, if an action, schema or mock data file (optional)
|
|
113
113
|
* @param {Callback} callback - The results of the call
|
|
114
114
|
*/
|
|
115
|
-
|
|
116
|
-
const origin = `${this.id}-adapter-
|
|
115
|
+
iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, callback) {
|
|
116
|
+
const origin = `${this.id}-adapter-iapUpdateAdapterConfiguration`;
|
|
117
117
|
log.trace(origin);
|
|
118
|
-
super.
|
|
118
|
+
super.iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, callback);
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
/**
|
|
122
122
|
* See if the API path provided is found in this adapter
|
|
123
123
|
*
|
|
124
|
-
* @function
|
|
124
|
+
* @function iapFindAdapterPath
|
|
125
125
|
* @param {string} apiPath - the api path to check on
|
|
126
126
|
* @param {Callback} callback - The results of the call
|
|
127
127
|
*/
|
|
128
|
-
|
|
129
|
-
const origin = `${this.id}-adapter-
|
|
128
|
+
iapFindAdapterPath(apiPath, callback) {
|
|
129
|
+
const origin = `${this.id}-adapter-iapFindAdapterPath`;
|
|
130
130
|
log.trace(origin);
|
|
131
|
-
super.
|
|
131
|
+
super.iapFindAdapterPath(apiPath, callback);
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
/**
|
|
135
135
|
* @summary Suspends adapter
|
|
136
136
|
*
|
|
137
|
-
* @function
|
|
137
|
+
* @function iapSuspendAdapter
|
|
138
138
|
* @param {Callback} callback - callback function
|
|
139
139
|
*/
|
|
140
|
-
|
|
141
|
-
const origin = `${this.id}-adapter-
|
|
140
|
+
iapSuspendAdapter(mode, callback) {
|
|
141
|
+
const origin = `${this.id}-adapter-iapSuspendAdapter`;
|
|
142
142
|
log.trace(origin);
|
|
143
143
|
try {
|
|
144
|
-
return super.
|
|
144
|
+
return super.iapSuspendAdapter(mode, callback);
|
|
145
145
|
} catch (error) {
|
|
146
146
|
log.error(`${origin}: ${error}`);
|
|
147
147
|
return callback(null, error);
|
|
@@ -151,14 +151,14 @@ class DnaCenter extends AdapterBaseCl {
|
|
|
151
151
|
/**
|
|
152
152
|
* @summary Unsuspends adapter
|
|
153
153
|
*
|
|
154
|
-
* @function
|
|
154
|
+
* @function iapUnsuspendAdapter
|
|
155
155
|
* @param {Callback} callback - callback function
|
|
156
156
|
*/
|
|
157
|
-
|
|
158
|
-
const origin = `${this.id}-adapter-
|
|
157
|
+
iapUnsuspendAdapter(callback) {
|
|
158
|
+
const origin = `${this.id}-adapter-iapUnsuspendAdapter`;
|
|
159
159
|
log.trace(origin);
|
|
160
160
|
try {
|
|
161
|
-
return super.
|
|
161
|
+
return super.iapUnsuspendAdapter(callback);
|
|
162
162
|
} catch (error) {
|
|
163
163
|
log.error(`${origin}: ${error}`);
|
|
164
164
|
return callback(null, error);
|
|
@@ -168,29 +168,29 @@ class DnaCenter extends AdapterBaseCl {
|
|
|
168
168
|
/**
|
|
169
169
|
* @summary Get the Adaoter Queue
|
|
170
170
|
*
|
|
171
|
-
* @function
|
|
171
|
+
* @function iapGetAdapterQueue
|
|
172
172
|
* @param {Callback} callback - callback function
|
|
173
173
|
*/
|
|
174
|
-
|
|
175
|
-
const origin = `${this.id}-adapter-
|
|
174
|
+
iapGetAdapterQueue(callback) {
|
|
175
|
+
const origin = `${this.id}-adapter-iapGetAdapterQueue`;
|
|
176
176
|
log.trace(origin);
|
|
177
|
-
return super.
|
|
177
|
+
return super.iapGetAdapterQueue(callback);
|
|
178
178
|
}
|
|
179
179
|
|
|
180
180
|
/**
|
|
181
181
|
* @summary Runs troubleshoot scripts for adapter
|
|
182
182
|
*
|
|
183
|
-
* @function
|
|
183
|
+
* @function iapTroubleshootAdapter
|
|
184
184
|
* @param {Object} props - the connection, healthcheck and authentication properties
|
|
185
185
|
*
|
|
186
186
|
* @param {boolean} persistFlag - whether the adapter properties should be updated
|
|
187
187
|
* @param {Callback} callback - The results of the call
|
|
188
188
|
*/
|
|
189
|
-
|
|
190
|
-
const origin = `${this.id}-adapter-
|
|
189
|
+
iapTroubleshootAdapter(props, persistFlag, callback) {
|
|
190
|
+
const origin = `${this.id}-adapter-iapTroubleshootAdapter`;
|
|
191
191
|
log.trace(origin);
|
|
192
192
|
try {
|
|
193
|
-
return super.
|
|
193
|
+
return super.iapTroubleshootAdapter(props, persistFlag, this, callback);
|
|
194
194
|
} catch (error) {
|
|
195
195
|
log.error(`${origin}: ${error}`);
|
|
196
196
|
return callback(null, error);
|
|
@@ -200,15 +200,15 @@ class DnaCenter extends AdapterBaseCl {
|
|
|
200
200
|
/**
|
|
201
201
|
* @summary runs healthcheck script for adapter
|
|
202
202
|
*
|
|
203
|
-
* @function
|
|
203
|
+
* @function iapRunAdapterHealthcheck
|
|
204
204
|
* @param {Adapter} adapter - adapter instance to troubleshoot
|
|
205
205
|
* @param {Callback} callback - callback function
|
|
206
206
|
*/
|
|
207
|
-
|
|
208
|
-
const origin = `${this.id}-adapter-
|
|
207
|
+
iapRunAdapterHealthcheck(callback) {
|
|
208
|
+
const origin = `${this.id}-adapter-iapRunAdapterHealthcheck`;
|
|
209
209
|
log.trace(origin);
|
|
210
210
|
try {
|
|
211
|
-
return super.
|
|
211
|
+
return super.iapRunAdapterHealthcheck(this, callback);
|
|
212
212
|
} catch (error) {
|
|
213
213
|
log.error(`${origin}: ${error}`);
|
|
214
214
|
return callback(null, error);
|
|
@@ -218,14 +218,14 @@ class DnaCenter extends AdapterBaseCl {
|
|
|
218
218
|
/**
|
|
219
219
|
* @summary runs connectivity check script for adapter
|
|
220
220
|
*
|
|
221
|
-
* @function
|
|
221
|
+
* @function iapRunAdapterConnectivity
|
|
222
222
|
* @param {Callback} callback - callback function
|
|
223
223
|
*/
|
|
224
|
-
|
|
225
|
-
const origin = `${this.id}-adapter-
|
|
224
|
+
iapRunAdapterConnectivity(callback) {
|
|
225
|
+
const origin = `${this.id}-adapter-iapRunAdapterConnectivity`;
|
|
226
226
|
log.trace(origin);
|
|
227
227
|
try {
|
|
228
|
-
return super.
|
|
228
|
+
return super.iapRunAdapterConnectivity(callback);
|
|
229
229
|
} catch (error) {
|
|
230
230
|
log.error(`${origin}: ${error}`);
|
|
231
231
|
return callback(null, error);
|
|
@@ -235,44 +235,63 @@ class DnaCenter extends AdapterBaseCl {
|
|
|
235
235
|
/**
|
|
236
236
|
* @summary runs basicGet script for adapter
|
|
237
237
|
*
|
|
238
|
-
* @function
|
|
238
|
+
* @function iapRunAdapterBasicGet
|
|
239
239
|
* @param {Callback} callback - callback function
|
|
240
240
|
*/
|
|
241
|
-
|
|
242
|
-
const origin = `${this.id}-adapter-
|
|
241
|
+
iapRunAdapterBasicGet(callback) {
|
|
242
|
+
const origin = `${this.id}-adapter-iapRunAdapterBasicGet`;
|
|
243
243
|
log.trace(origin);
|
|
244
244
|
try {
|
|
245
|
-
return super.
|
|
245
|
+
return super.iapRunAdapterBasicGet(callback);
|
|
246
246
|
} catch (error) {
|
|
247
247
|
log.error(`${origin}: ${error}`);
|
|
248
248
|
return callback(null, error);
|
|
249
249
|
}
|
|
250
250
|
}
|
|
251
251
|
|
|
252
|
+
/**
|
|
253
|
+
* @summary moves entites into Mongo DB
|
|
254
|
+
*
|
|
255
|
+
* @function iapMoveAdapterEntitiesToDB
|
|
256
|
+
* @param {getCallback} callback - a callback function to return the result (Generics)
|
|
257
|
+
* or the error
|
|
258
|
+
*/
|
|
259
|
+
iapMoveAdapterEntitiesToDB(callback) {
|
|
260
|
+
const origin = `${this.id}-adapter-iapMoveAdapterEntitiesToDB`;
|
|
261
|
+
log.trace(origin);
|
|
262
|
+
try {
|
|
263
|
+
return super.iapMoveAdapterEntitiesToDB(callback);
|
|
264
|
+
} catch (err) {
|
|
265
|
+
log.error(`${origin}: ${err}`);
|
|
266
|
+
return callback(null, err);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/* BROKER CALLS */
|
|
252
271
|
/**
|
|
253
272
|
* @summary Determines if this adapter supports the specific entity
|
|
254
273
|
*
|
|
255
|
-
* @function
|
|
274
|
+
* @function iapHasAdapterEntity
|
|
256
275
|
* @param {String} entityType - the entity type to check for
|
|
257
276
|
* @param {String/Array} entityId - the specific entity we are looking for
|
|
258
277
|
*
|
|
259
278
|
* @param {Callback} callback - An array of whether the adapter can has the
|
|
260
279
|
* desired capability or an error
|
|
261
280
|
*/
|
|
262
|
-
|
|
263
|
-
const origin = `${this.id}-adapter-
|
|
281
|
+
iapHasAdapterEntity(entityType, entityId, callback) {
|
|
282
|
+
const origin = `${this.id}-adapter-iapHasAdapterEntity`;
|
|
264
283
|
log.trace(origin);
|
|
265
284
|
|
|
266
285
|
// Make the call -
|
|
267
|
-
//
|
|
268
|
-
return this.
|
|
286
|
+
// iapVerifyAdapterCapability(entityType, actionType, entityId, callback)
|
|
287
|
+
return this.iapVerifyAdapterCapability(entityType, null, entityId, callback);
|
|
269
288
|
}
|
|
270
289
|
|
|
271
290
|
/**
|
|
272
291
|
* @summary Provides a way for the adapter to tell north bound integrations
|
|
273
292
|
* whether the adapter supports type, action and specific entity
|
|
274
293
|
*
|
|
275
|
-
* @function
|
|
294
|
+
* @function iapVerifyAdapterCapability
|
|
276
295
|
* @param {String} entityType - the entity type to check for
|
|
277
296
|
* @param {String} actionType - the action type to check for
|
|
278
297
|
* @param {String/Array} entityId - the specific entity we are looking for
|
|
@@ -280,15 +299,15 @@ class DnaCenter extends AdapterBaseCl {
|
|
|
280
299
|
* @param {Callback} callback - An array of whether the adapter can has the
|
|
281
300
|
* desired capability or an error
|
|
282
301
|
*/
|
|
283
|
-
|
|
284
|
-
const meth = 'adapterBase-
|
|
302
|
+
iapVerifyAdapterCapability(entityType, actionType, entityId, callback) {
|
|
303
|
+
const meth = 'adapterBase-iapVerifyAdapterCapability';
|
|
285
304
|
const origin = `${this.id}-${meth}`;
|
|
286
305
|
log.trace(origin);
|
|
287
306
|
|
|
288
307
|
// if caching
|
|
289
308
|
if (this.caching) {
|
|
290
|
-
// Make the call -
|
|
291
|
-
return this.requestHandlerInst.
|
|
309
|
+
// Make the call - iapVerifyAdapterCapability(entityType, actionType, entityId, callback)
|
|
310
|
+
return this.requestHandlerInst.iapVerifyAdapterCapability(entityType, actionType, entityId, (results, error) => {
|
|
292
311
|
if (error) {
|
|
293
312
|
return callback(null, error);
|
|
294
313
|
}
|
|
@@ -306,7 +325,7 @@ class DnaCenter extends AdapterBaseCl {
|
|
|
306
325
|
}
|
|
307
326
|
|
|
308
327
|
// need to check the cache again since it has been updated
|
|
309
|
-
return this.requestHandlerInst.
|
|
328
|
+
return this.requestHandlerInst.iapVerifyAdapterCapability(entityType, actionType, entityId, (vcapable, verror) => {
|
|
310
329
|
if (verror) {
|
|
311
330
|
return callback(null, verror);
|
|
312
331
|
}
|
|
@@ -339,7 +358,7 @@ class DnaCenter extends AdapterBaseCl {
|
|
|
339
358
|
// if no entity id
|
|
340
359
|
if (!entityId) {
|
|
341
360
|
// need to check the cache again since it has been updated
|
|
342
|
-
return this.requestHandlerInst.
|
|
361
|
+
return this.requestHandlerInst.iapVerifyAdapterCapability(entityType, actionType, null, (vcapable, verror) => {
|
|
343
362
|
if (verror) {
|
|
344
363
|
return callback(null, verror);
|
|
345
364
|
}
|
|
@@ -360,7 +379,7 @@ class DnaCenter extends AdapterBaseCl {
|
|
|
360
379
|
}
|
|
361
380
|
|
|
362
381
|
// need to check the cache again since it has been updated
|
|
363
|
-
return this.requestHandlerInst.
|
|
382
|
+
return this.requestHandlerInst.iapVerifyAdapterCapability(entityType, actionType, null, (vcapable, verror) => {
|
|
364
383
|
if (verror) {
|
|
365
384
|
return callback(null, verror);
|
|
366
385
|
}
|
|
@@ -401,11 +420,11 @@ class DnaCenter extends AdapterBaseCl {
|
|
|
401
420
|
/**
|
|
402
421
|
* @summary Updates the cache for all entities by call the get All entity method
|
|
403
422
|
*
|
|
404
|
-
* @function
|
|
423
|
+
* @function iapUpdateAdapterEntityCache
|
|
405
424
|
*
|
|
406
425
|
*/
|
|
407
|
-
|
|
408
|
-
const origin = `${this.id}-adapter-
|
|
426
|
+
iapUpdateAdapterEntityCache() {
|
|
427
|
+
const origin = `${this.id}-adapter-iapUpdateAdapterEntityCache`;
|
|
409
428
|
log.trace(origin);
|
|
410
429
|
|
|
411
430
|
if (this.caching) {
|
|
@@ -418,6 +437,496 @@ class DnaCenter extends AdapterBaseCl {
|
|
|
418
437
|
}
|
|
419
438
|
}
|
|
420
439
|
|
|
440
|
+
/**
|
|
441
|
+
* @summary Determines if this adapter supports any in a list of entities
|
|
442
|
+
*
|
|
443
|
+
* @function hasEntities
|
|
444
|
+
* @param {String} entityType - the entity type to check for
|
|
445
|
+
* @param {Array} entityList - the list of entities we are looking for
|
|
446
|
+
*
|
|
447
|
+
* @param {Callback} callback - A map where the entity is the key and the
|
|
448
|
+
* value is true or false
|
|
449
|
+
*/
|
|
450
|
+
hasEntities(entityType, entityList, callback) {
|
|
451
|
+
const origin = `${this.id}-adapter-hasEntities`;
|
|
452
|
+
log.trace(origin);
|
|
453
|
+
|
|
454
|
+
switch (entityType) {
|
|
455
|
+
case 'Device':
|
|
456
|
+
return this.hasDevices(entityList, callback);
|
|
457
|
+
default:
|
|
458
|
+
return callback(null, `${this.id} does not support entity ${entityType}`);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* @summary Helper method for hasEntities for the specific device case
|
|
464
|
+
*
|
|
465
|
+
* @param {Array} deviceList - array of unique device identifiers
|
|
466
|
+
* @param {Callback} callback - A map where the device is the key and the
|
|
467
|
+
* value is true or false
|
|
468
|
+
*/
|
|
469
|
+
hasDevices(deviceList, callback) {
|
|
470
|
+
const origin = `${this.id}-adapter-hasDevices`;
|
|
471
|
+
log.trace(origin);
|
|
472
|
+
|
|
473
|
+
const findings = deviceList.reduce((map, device) => {
|
|
474
|
+
// eslint-disable-next-line no-param-reassign
|
|
475
|
+
map[device] = false;
|
|
476
|
+
log.debug(`In reduce: ${JSON.stringify(map)}`);
|
|
477
|
+
return map;
|
|
478
|
+
}, {});
|
|
479
|
+
const apiCalls = deviceList.map((device) => new Promise((resolve) => {
|
|
480
|
+
this.getDevice(device, (result, error) => {
|
|
481
|
+
if (error) {
|
|
482
|
+
log.debug(`In map error: ${JSON.stringify(device)}`);
|
|
483
|
+
return resolve({ name: device, found: false });
|
|
484
|
+
}
|
|
485
|
+
log.debug(`In map: ${JSON.stringify(device)}`);
|
|
486
|
+
return resolve({ name: device, found: true });
|
|
487
|
+
});
|
|
488
|
+
}));
|
|
489
|
+
Promise.all(apiCalls).then((results) => {
|
|
490
|
+
results.forEach((device) => {
|
|
491
|
+
findings[device.name] = device.found;
|
|
492
|
+
});
|
|
493
|
+
log.debug(`FINDINGS: ${JSON.stringify(findings)}`);
|
|
494
|
+
return callback(findings);
|
|
495
|
+
}).catch((errors) => {
|
|
496
|
+
log.error('Unable to do device lookup.');
|
|
497
|
+
return callback(null, { code: 503, message: 'Unable to do device lookup.', error: errors });
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
* @summary Get Appliance that match the deviceName
|
|
503
|
+
*
|
|
504
|
+
* @function getDevice
|
|
505
|
+
* @param {String} deviceName - the deviceName to find (required)
|
|
506
|
+
*
|
|
507
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
508
|
+
* (appliance) or the error
|
|
509
|
+
*/
|
|
510
|
+
getDevice(deviceName, callback) {
|
|
511
|
+
const meth = 'adapter-getDevice';
|
|
512
|
+
const origin = `${this.id}-${meth}`;
|
|
513
|
+
log.trace(origin);
|
|
514
|
+
|
|
515
|
+
// make sure we are set up for device broker getDevice
|
|
516
|
+
if (!this.allProps.devicebroker || !this.allProps.devicebroker.getDevice || this.allProps.devicebroker.getDevice.length === 0 || !this.allProps.devicebroker.getDevice[0].path) {
|
|
517
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Properties', ['devicebroker.getDevice.path'], null, null, null);
|
|
518
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
519
|
+
return callback(null, errorObj);
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
523
|
+
if (deviceName === undefined || deviceName === null || deviceName === '' || deviceName.length === 0) {
|
|
524
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['deviceName'], null, null, null);
|
|
525
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
526
|
+
return callback(null, errorObj);
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
try {
|
|
530
|
+
// need to get the device so we can convert the deviceName to an id
|
|
531
|
+
// !! if we can do a lookup by name the getDevicesFiltered may not be necessary
|
|
532
|
+
const opts = {
|
|
533
|
+
filter: {
|
|
534
|
+
name: deviceName
|
|
535
|
+
}
|
|
536
|
+
};
|
|
537
|
+
return this.getDevicesFiltered(opts, (devs, ferr) => {
|
|
538
|
+
// if we received an error or their is no response on the results return an error
|
|
539
|
+
if (ferr) {
|
|
540
|
+
return callback(null, ferr);
|
|
541
|
+
}
|
|
542
|
+
if (devs.list.length < 1) {
|
|
543
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Did Not Find Device ${deviceName}`, [], null, null, null);
|
|
544
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
545
|
+
return callback(null, errorObj);
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
const callPromises = [];
|
|
549
|
+
for (let i = 0; i < this.allProps.devicebroker.getDevice.length; i += 1) {
|
|
550
|
+
// Perform component calls here.
|
|
551
|
+
callPromises.push(
|
|
552
|
+
new Promise((resolve, reject) => {
|
|
553
|
+
this.iapMakeBrokerCall('getDevice', this.allProps.devicebroker.getDevice[i], devs.list[0], null, (callRet, callErr) => {
|
|
554
|
+
// return an error
|
|
555
|
+
if (callErr) {
|
|
556
|
+
reject(callErr);
|
|
557
|
+
} else {
|
|
558
|
+
// return the data
|
|
559
|
+
resolve(callRet);
|
|
560
|
+
}
|
|
561
|
+
});
|
|
562
|
+
})
|
|
563
|
+
);
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
// return an array of repsonses
|
|
567
|
+
return Promise.all(callPromises).then((results) => {
|
|
568
|
+
let myResult = {};
|
|
569
|
+
results.forEach((result) => {
|
|
570
|
+
myResult = { ...myResult, ...result };
|
|
571
|
+
});
|
|
572
|
+
|
|
573
|
+
return callback(myResult, null);
|
|
574
|
+
})
|
|
575
|
+
.catch((error) => {
|
|
576
|
+
log.debug(`Caught ${JSON.stringify(error)}`);
|
|
577
|
+
return callback(null, error);
|
|
578
|
+
});
|
|
579
|
+
});
|
|
580
|
+
} catch (ex) {
|
|
581
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
582
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
583
|
+
return callback(null, errorObj);
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
/**
|
|
588
|
+
* @summary Get Appliances that match the filter
|
|
589
|
+
*
|
|
590
|
+
* @function getDevicesFiltered
|
|
591
|
+
* @param {Object} options - the data to use to filter the appliances (optional)
|
|
592
|
+
*
|
|
593
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
594
|
+
* (appliances) or the error
|
|
595
|
+
*/
|
|
596
|
+
getDevicesFiltered(options, callback) {
|
|
597
|
+
const meth = 'adapter-getDevicesFiltered';
|
|
598
|
+
const origin = `${this.id}-${meth}`;
|
|
599
|
+
log.trace(origin);
|
|
600
|
+
|
|
601
|
+
// make sure we are set up for device broker getDevicesFiltered
|
|
602
|
+
if (!this.allProps.devicebroker || !this.allProps.devicebroker.getDevicesFiltered || this.allProps.devicebroker.getDevicesFiltered.length === 0 || !this.allProps.devicebroker.getDevicesFiltered[0].path) {
|
|
603
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Properties', ['devicebroker.getDevicesFiltered.path'], null, null, null);
|
|
604
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
605
|
+
return callback(null, errorObj);
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
// verify the required fields have been provided
|
|
609
|
+
if (options === undefined || options === null || options === '' || options.length === 0) {
|
|
610
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['options'], null, null, null);
|
|
611
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
612
|
+
return callback(null, errorObj);
|
|
613
|
+
}
|
|
614
|
+
log.debug(`Device Filter Options: ${JSON.stringify(options)}`);
|
|
615
|
+
|
|
616
|
+
try {
|
|
617
|
+
// TODO - get pagination working
|
|
618
|
+
// const nextToken = options.start;
|
|
619
|
+
// const maxResults = options.limit;
|
|
620
|
+
|
|
621
|
+
// set up the filter of Device Names
|
|
622
|
+
let filterName = [];
|
|
623
|
+
if (options && options.filter && options.filter.name) {
|
|
624
|
+
// when this hack is removed, remove the lint ignore above
|
|
625
|
+
if (Array.isArray(options.filter.name)) {
|
|
626
|
+
// eslint-disable-next-line prefer-destructuring
|
|
627
|
+
filterName = options.filter.name;
|
|
628
|
+
} else {
|
|
629
|
+
filterName = [options.filter.name];
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
// TODO - get sort and order working
|
|
634
|
+
/*
|
|
635
|
+
if (options && options.sort) {
|
|
636
|
+
reqObj.uriOptions.sort = JSON.stringify(options.sort);
|
|
637
|
+
}
|
|
638
|
+
if (options && options.order) {
|
|
639
|
+
reqObj.uriOptions.order = options.order;
|
|
640
|
+
}
|
|
641
|
+
*/
|
|
642
|
+
const callPromises = [];
|
|
643
|
+
for (let i = 0; i < this.allProps.devicebroker.getDevicesFiltered.length; i += 1) {
|
|
644
|
+
// Perform component calls here.
|
|
645
|
+
callPromises.push(
|
|
646
|
+
new Promise((resolve, reject) => {
|
|
647
|
+
this.iapMakeBrokerCall('getDevicesFiltered', this.allProps.devicebroker.getDevicesFiltered[i], {}, filterName, (callRet, callErr) => {
|
|
648
|
+
// return an error
|
|
649
|
+
if (callErr) {
|
|
650
|
+
reject(callErr);
|
|
651
|
+
} else {
|
|
652
|
+
// return the data
|
|
653
|
+
resolve(callRet);
|
|
654
|
+
}
|
|
655
|
+
});
|
|
656
|
+
})
|
|
657
|
+
);
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
// return an array of repsonses
|
|
661
|
+
return Promise.all(callPromises).then((results) => {
|
|
662
|
+
let myResult = [];
|
|
663
|
+
results.forEach((result) => {
|
|
664
|
+
if (Array.isArray(result)) {
|
|
665
|
+
myResult = [...myResult, ...result];
|
|
666
|
+
} else if (Object.keys(result).length > 0) {
|
|
667
|
+
myResult.push(result);
|
|
668
|
+
}
|
|
669
|
+
});
|
|
670
|
+
|
|
671
|
+
log.debug(`${origin}: Found #${myResult.length} devices.`);
|
|
672
|
+
log.debug(`Devices: ${JSON.stringify(myResult)}`);
|
|
673
|
+
return callback({ total: myResult.length, list: myResult });
|
|
674
|
+
})
|
|
675
|
+
.catch((error) => {
|
|
676
|
+
log.debug(`Caught ${JSON.stringify(error)}`);
|
|
677
|
+
return callback(null, error);
|
|
678
|
+
});
|
|
679
|
+
} catch (ex) {
|
|
680
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
681
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
682
|
+
return callback(null, errorObj);
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
/**
|
|
687
|
+
* @summary Gets the status for the provided appliance
|
|
688
|
+
*
|
|
689
|
+
* @function isAlive
|
|
690
|
+
* @param {String} deviceName - the deviceName of the appliance. (required)
|
|
691
|
+
*
|
|
692
|
+
* @param {configCallback} callback - callback function to return the result
|
|
693
|
+
* (appliance isAlive) or the error
|
|
694
|
+
*/
|
|
695
|
+
isAlive(deviceName, callback) {
|
|
696
|
+
const meth = 'adapter-isAlive';
|
|
697
|
+
const origin = `${this.id}-${meth}`;
|
|
698
|
+
log.trace(origin);
|
|
699
|
+
|
|
700
|
+
// make sure we are set up for device broker isAlive
|
|
701
|
+
if (!this.allProps.devicebroker || !this.allProps.devicebroker.isAlive || this.allProps.devicebroker.isAlive.length === 0 || !this.allProps.devicebroker.isAlive[0].path) {
|
|
702
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Properties', ['devicebroker.isAlive.path'], null, null, null);
|
|
703
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
704
|
+
return callback(null, errorObj);
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
// verify the required fields have been provided
|
|
708
|
+
if (deviceName === undefined || deviceName === null || deviceName === '' || deviceName.length === 0) {
|
|
709
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['deviceName'], null, null, null);
|
|
710
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
711
|
+
return callback(null, errorObj);
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
try {
|
|
715
|
+
// need to get the device so we can convert the deviceName to an id
|
|
716
|
+
// !! if we can do a lookup by name the getDevicesFiltered may not be necessary
|
|
717
|
+
const opts = {
|
|
718
|
+
filter: {
|
|
719
|
+
name: deviceName
|
|
720
|
+
}
|
|
721
|
+
};
|
|
722
|
+
return this.getDevicesFiltered(opts, (devs, ferr) => {
|
|
723
|
+
// if we received an error or their is no response on the results return an error
|
|
724
|
+
if (ferr) {
|
|
725
|
+
return callback(null, ferr);
|
|
726
|
+
}
|
|
727
|
+
if (devs.list.length < 1) {
|
|
728
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Did Not Find Device ${deviceName}`, [], null, null, null);
|
|
729
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
730
|
+
return callback(null, errorObj);
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
const callPromises = [];
|
|
734
|
+
for (let i = 0; i < this.allProps.devicebroker.isAlive.length; i += 1) {
|
|
735
|
+
// Perform component calls here.
|
|
736
|
+
callPromises.push(
|
|
737
|
+
new Promise((resolve, reject) => {
|
|
738
|
+
this.iapMakeBrokerCall('isAlive', this.allProps.devicebroker.isAlive[i], devs.list[0], null, (callRet, callErr) => {
|
|
739
|
+
// return an error
|
|
740
|
+
if (callErr) {
|
|
741
|
+
reject(callErr);
|
|
742
|
+
} else {
|
|
743
|
+
// return the data
|
|
744
|
+
resolve(callRet);
|
|
745
|
+
}
|
|
746
|
+
});
|
|
747
|
+
})
|
|
748
|
+
);
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
// return an array of repsonses
|
|
752
|
+
return Promise.all(callPromises).then((results) => {
|
|
753
|
+
let myResult = {};
|
|
754
|
+
results.forEach((result) => {
|
|
755
|
+
myResult = { ...myResult, ...result };
|
|
756
|
+
});
|
|
757
|
+
|
|
758
|
+
let response = true;
|
|
759
|
+
if (myResult.isAlive !== null && myResult.isAlive !== undefined && myResult.isAlive === false) {
|
|
760
|
+
response = false;
|
|
761
|
+
}
|
|
762
|
+
return callback(response);
|
|
763
|
+
})
|
|
764
|
+
.catch((error) => {
|
|
765
|
+
log.debug(`Caught ${JSON.stringify(error)}`);
|
|
766
|
+
return callback(null, error);
|
|
767
|
+
});
|
|
768
|
+
});
|
|
769
|
+
} catch (ex) {
|
|
770
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
771
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
772
|
+
return callback(null, errorObj);
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
/**
|
|
777
|
+
* @summary Gets a config for the provided Appliance
|
|
778
|
+
*
|
|
779
|
+
* @function getConfig
|
|
780
|
+
* @param {String} deviceName - the deviceName of the appliance. (required)
|
|
781
|
+
* @param {String} format - the desired format of the config. (optional)
|
|
782
|
+
*
|
|
783
|
+
* @param {configCallback} callback - callback function to return the result
|
|
784
|
+
* (appliance config) or the error
|
|
785
|
+
*/
|
|
786
|
+
getConfig(deviceName, format, callback) {
|
|
787
|
+
const meth = 'adapter-getConfig';
|
|
788
|
+
const origin = `${this.id}-${meth}`;
|
|
789
|
+
log.trace(origin);
|
|
790
|
+
|
|
791
|
+
// make sure we are set up for device broker getConfig
|
|
792
|
+
if (!this.allProps.devicebroker || !this.allProps.devicebroker.getConfig || this.allProps.devicebroker.getConfig.length === 0 || !this.allProps.devicebroker.getConfig[0].path) {
|
|
793
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Properties', ['devicebroker.getConfig.path'], null, null, null);
|
|
794
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
795
|
+
return callback(null, errorObj);
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
// verify the required fields have been provided
|
|
799
|
+
if (deviceName === undefined || deviceName === null || deviceName === '' || deviceName.length === 0) {
|
|
800
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['deviceName'], null, null, null);
|
|
801
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
802
|
+
return callback(null, errorObj);
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
try {
|
|
806
|
+
// need to get the device so we can convert the deviceName to an id
|
|
807
|
+
// !! if we can do a lookup by name the getDevicesFiltered may not be necessary
|
|
808
|
+
const opts = {
|
|
809
|
+
filter: {
|
|
810
|
+
name: deviceName
|
|
811
|
+
}
|
|
812
|
+
};
|
|
813
|
+
return this.getDevicesFiltered(opts, (devs, ferr) => {
|
|
814
|
+
// if we received an error or their is no response on the results return an error
|
|
815
|
+
if (ferr) {
|
|
816
|
+
return callback(null, ferr);
|
|
817
|
+
}
|
|
818
|
+
if (devs.list.length < 1) {
|
|
819
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Did Not Find Device ${deviceName}`, [], null, null, null);
|
|
820
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
821
|
+
return callback(null, errorObj);
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
const callPromises = [];
|
|
825
|
+
for (let i = 0; i < this.allProps.devicebroker.getConfig.length; i += 1) {
|
|
826
|
+
// Perform component calls here.
|
|
827
|
+
callPromises.push(
|
|
828
|
+
new Promise((resolve, reject) => {
|
|
829
|
+
this.iapMakeBrokerCall('getConfig', this.allProps.devicebroker.getConfig[i], devs.list[0], null, (callRet, callErr) => {
|
|
830
|
+
// return an error
|
|
831
|
+
if (callErr) {
|
|
832
|
+
reject(callErr);
|
|
833
|
+
} else {
|
|
834
|
+
// return the data
|
|
835
|
+
resolve(callRet);
|
|
836
|
+
}
|
|
837
|
+
});
|
|
838
|
+
})
|
|
839
|
+
);
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
// return an array of repsonses
|
|
843
|
+
return Promise.all(callPromises).then((results) => {
|
|
844
|
+
let myResult = {};
|
|
845
|
+
results.forEach((result) => {
|
|
846
|
+
myResult = { ...myResult, ...result };
|
|
847
|
+
});
|
|
848
|
+
|
|
849
|
+
// return the result
|
|
850
|
+
const newResponse = {
|
|
851
|
+
response: JSON.stringify(myResult, null, 2)
|
|
852
|
+
};
|
|
853
|
+
return callback(newResponse, null);
|
|
854
|
+
})
|
|
855
|
+
.catch((error) => {
|
|
856
|
+
log.debug(`Caught ${JSON.stringify(error)}`);
|
|
857
|
+
return callback(null, error);
|
|
858
|
+
});
|
|
859
|
+
});
|
|
860
|
+
} catch (ex) {
|
|
861
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
862
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
863
|
+
return callback(null, errorObj);
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
/**
|
|
868
|
+
* @summary Gets the device count from the system
|
|
869
|
+
*
|
|
870
|
+
* @function iapGetDeviceCount
|
|
871
|
+
*
|
|
872
|
+
* @param {getCallback} callback - callback function to return the result
|
|
873
|
+
* (count) or the error
|
|
874
|
+
*/
|
|
875
|
+
iapGetDeviceCount(callback) {
|
|
876
|
+
const meth = 'adapter-iapGetDeviceCount';
|
|
877
|
+
const origin = `${this.id}-${meth}`;
|
|
878
|
+
log.trace(origin);
|
|
879
|
+
|
|
880
|
+
// make sure we are set up for device broker getCount
|
|
881
|
+
if (!this.allProps.devicebroker || !this.allProps.devicebroker.getCount || this.allProps.devicebroker.getCount.length === 0 || !this.allProps.devicebroker.getCount[0].path) {
|
|
882
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Properties', ['devicebroker.getCount.path'], null, null, null);
|
|
883
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
884
|
+
return callback(null, errorObj);
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
// verify the required fields have been provided
|
|
888
|
+
|
|
889
|
+
try {
|
|
890
|
+
const callPromises = [];
|
|
891
|
+
for (let i = 0; i < this.allProps.devicebroker.getCount.length; i += 1) {
|
|
892
|
+
// Perform component calls here.
|
|
893
|
+
callPromises.push(
|
|
894
|
+
new Promise((resolve, reject) => {
|
|
895
|
+
this.iapMakeBrokerCall('getCount', this.allProps.devicebroker.getCount[i], null, null, (callRet, callErr) => {
|
|
896
|
+
// return an error
|
|
897
|
+
if (callErr) {
|
|
898
|
+
reject(callErr);
|
|
899
|
+
} else {
|
|
900
|
+
// return the data
|
|
901
|
+
resolve(callRet);
|
|
902
|
+
}
|
|
903
|
+
});
|
|
904
|
+
})
|
|
905
|
+
);
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
// return an array of repsonses
|
|
909
|
+
return Promise.all(callPromises).then((results) => {
|
|
910
|
+
let myResult = {};
|
|
911
|
+
results.forEach((result) => {
|
|
912
|
+
myResult = { ...myResult, ...result };
|
|
913
|
+
});
|
|
914
|
+
|
|
915
|
+
// return the result
|
|
916
|
+
return callback({ count: myResult.length });
|
|
917
|
+
})
|
|
918
|
+
.catch((error) => {
|
|
919
|
+
log.debug(`Caught ${JSON.stringify(error)}`);
|
|
920
|
+
return callback(null, error);
|
|
921
|
+
});
|
|
922
|
+
} catch (ex) {
|
|
923
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
924
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
925
|
+
return callback(null, errorObj);
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
/* GENERIC ADAPTER REQUEST - allows extension of adapter without new calls being added */
|
|
421
930
|
/**
|
|
422
931
|
* Makes the requested generic call
|
|
423
932
|
*
|
|
@@ -528,6 +1037,116 @@ class DnaCenter extends AdapterBaseCl {
|
|
|
528
1037
|
}
|
|
529
1038
|
}
|
|
530
1039
|
|
|
1040
|
+
/**
|
|
1041
|
+
* Makes the requested generic call with no base path or version
|
|
1042
|
+
*
|
|
1043
|
+
* @function genericAdapterRequestNoBasePath
|
|
1044
|
+
* @param {String} uriPath - the path of the api call - do not include the host, port, base path or version (required)
|
|
1045
|
+
* @param {String} restMethod - the rest method (GET, POST, PUT, PATCH, DELETE) (required)
|
|
1046
|
+
* @param {Object} queryData - the parameters to be put on the url (optional).
|
|
1047
|
+
* Can be a stringified Object.
|
|
1048
|
+
* @param {Object} requestBody - the body to add to the request (optional).
|
|
1049
|
+
* Can be a stringified Object.
|
|
1050
|
+
* @param {Object} addlHeaders - additional headers to be put on the call (optional).
|
|
1051
|
+
* Can be a stringified Object.
|
|
1052
|
+
* @param {getCallback} callback - a callback function to return the result (Generics)
|
|
1053
|
+
* or the error
|
|
1054
|
+
*/
|
|
1055
|
+
genericAdapterRequestNoBasePath(uriPath, restMethod, queryData, requestBody, addlHeaders, callback) {
|
|
1056
|
+
const meth = 'adapter-genericAdapterRequestNoBasePath';
|
|
1057
|
+
const origin = `${this.id}-${meth}`;
|
|
1058
|
+
log.trace(origin);
|
|
1059
|
+
|
|
1060
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
1061
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
1062
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1063
|
+
return callback(null, errorObj);
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
1067
|
+
if (uriPath === undefined || uriPath === null || uriPath === '') {
|
|
1068
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['uriPath'], null, null, null);
|
|
1069
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1070
|
+
return callback(null, errorObj);
|
|
1071
|
+
}
|
|
1072
|
+
if (restMethod === undefined || restMethod === null || restMethod === '') {
|
|
1073
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['restMethod'], null, null, null);
|
|
1074
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1075
|
+
return callback(null, errorObj);
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
1079
|
+
// remove any leading / and split the uripath into path variables
|
|
1080
|
+
let myPath = uriPath;
|
|
1081
|
+
while (myPath.indexOf('/') === 0) {
|
|
1082
|
+
myPath = myPath.substring(1);
|
|
1083
|
+
}
|
|
1084
|
+
const pathVars = myPath.split('/');
|
|
1085
|
+
const queryParamsAvailable = queryData;
|
|
1086
|
+
const queryParams = {};
|
|
1087
|
+
const bodyVars = requestBody;
|
|
1088
|
+
|
|
1089
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
1090
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
1091
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
1092
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
1093
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
1094
|
+
}
|
|
1095
|
+
});
|
|
1096
|
+
|
|
1097
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders
|
|
1098
|
+
const reqObj = {
|
|
1099
|
+
payload: bodyVars,
|
|
1100
|
+
uriPathVars: pathVars,
|
|
1101
|
+
uriQuery: queryParams,
|
|
1102
|
+
uriOptions: {}
|
|
1103
|
+
};
|
|
1104
|
+
// add headers if provided
|
|
1105
|
+
if (addlHeaders) {
|
|
1106
|
+
reqObj.addlHeaders = addlHeaders;
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
// determine the call and return flag
|
|
1110
|
+
let action = 'getGenericsNoBase';
|
|
1111
|
+
let returnF = true;
|
|
1112
|
+
if (restMethod.toUpperCase() === 'POST') {
|
|
1113
|
+
action = 'createGenericNoBase';
|
|
1114
|
+
} else if (restMethod.toUpperCase() === 'PUT') {
|
|
1115
|
+
action = 'updateGenericNoBase';
|
|
1116
|
+
} else if (restMethod.toUpperCase() === 'PATCH') {
|
|
1117
|
+
action = 'patchGenericNoBase';
|
|
1118
|
+
} else if (restMethod.toUpperCase() === 'DELETE') {
|
|
1119
|
+
action = 'deleteGenericNoBase';
|
|
1120
|
+
returnF = false;
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
try {
|
|
1124
|
+
// Make the call -
|
|
1125
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
1126
|
+
return this.requestHandlerInst.identifyRequest('.generic', action, reqObj, returnF, (irReturnData, irReturnError) => {
|
|
1127
|
+
// if we received an error or their is no response on the results
|
|
1128
|
+
// return an error
|
|
1129
|
+
if (irReturnError) {
|
|
1130
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
1131
|
+
return callback(null, irReturnError);
|
|
1132
|
+
}
|
|
1133
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
1134
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['genericAdapterRequestNoBasePath'], null, null, null);
|
|
1135
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1136
|
+
return callback(null, errorObj);
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
1140
|
+
// return the response
|
|
1141
|
+
return callback(irReturnData, null);
|
|
1142
|
+
});
|
|
1143
|
+
} catch (ex) {
|
|
1144
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
1145
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1146
|
+
return callback(null, errorObj);
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
|
|
531
1150
|
/**
|
|
532
1151
|
* @callback healthCallback
|
|
533
1152
|
* @param {Object} result - the result of the get request (contains an id and a status)
|
|
@@ -10700,6 +11319,186 @@ class DnaCenter extends AdapterBaseCl {
|
|
|
10700
11319
|
}
|
|
10701
11320
|
}
|
|
10702
11321
|
|
|
11322
|
+
/**
|
|
11323
|
+
* @summary Assign Device To Site
|
|
11324
|
+
*
|
|
11325
|
+
* @function postDnasystemapiv1sitesiteIddevice
|
|
11326
|
+
* @param {object} request - request
|
|
11327
|
+
* @param {boolean} Runsync - Enable this parameter to execute the API and return a response synchronously
|
|
11328
|
+
* @param {boolean} Persistbapioutput - Persist bapi sync response
|
|
11329
|
+
* @param {number} Timeout - During synchronous execution, this defines the maximum time to wait for a response, before the API execution is terminated
|
|
11330
|
+
* @param {string} siteId - Site id to which the device is assigned
|
|
11331
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
11332
|
+
*/
|
|
11333
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
11334
|
+
postDnasystemapiv1sitesiteIddevice(request, Runsync, Persistbapioutput, Timeout, siteId, callback) {
|
|
11335
|
+
const meth = 'adapter-postDnasystemapiv1sitesiteIddevice';
|
|
11336
|
+
const origin = `${this.id}-${meth}`;
|
|
11337
|
+
log.trace(origin);
|
|
11338
|
+
|
|
11339
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
11340
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
11341
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
11342
|
+
return callback(null, errorObj);
|
|
11343
|
+
}
|
|
11344
|
+
|
|
11345
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
11346
|
+
if (request === undefined || request === null || request === '') {
|
|
11347
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['request'], null, null, null);
|
|
11348
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
11349
|
+
return callback(null, errorObj);
|
|
11350
|
+
}
|
|
11351
|
+
if (Runsync === undefined || Runsync === null || Runsync === '') {
|
|
11352
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['Runsync'], null, null, null);
|
|
11353
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
11354
|
+
return callback(null, errorObj);
|
|
11355
|
+
}
|
|
11356
|
+
if (Persistbapioutput === undefined || Persistbapioutput === null || Persistbapioutput === '') {
|
|
11357
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['Persistbapioutput'], null, null, null);
|
|
11358
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
11359
|
+
return callback(null, errorObj);
|
|
11360
|
+
}
|
|
11361
|
+
if (siteId === undefined || siteId === null || siteId === '') {
|
|
11362
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['siteId'], null, null, null);
|
|
11363
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
11364
|
+
return callback(null, errorObj);
|
|
11365
|
+
}
|
|
11366
|
+
|
|
11367
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
11368
|
+
const queryParamsAvailable = {};
|
|
11369
|
+
const queryParams = {};
|
|
11370
|
+
const pathVars = [siteId];
|
|
11371
|
+
const bodyVars = request;
|
|
11372
|
+
|
|
11373
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
11374
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
11375
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
11376
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
11377
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
11378
|
+
}
|
|
11379
|
+
});
|
|
11380
|
+
|
|
11381
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders
|
|
11382
|
+
const reqObj = {
|
|
11383
|
+
payload: bodyVars,
|
|
11384
|
+
uriPathVars: pathVars,
|
|
11385
|
+
uriQuery: queryParams
|
|
11386
|
+
};
|
|
11387
|
+
|
|
11388
|
+
try {
|
|
11389
|
+
// Make the call -
|
|
11390
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
11391
|
+
return this.requestHandlerInst.identifyRequest('Sites', 'postDnasystemapiv1sitesiteIddevice', reqObj, true, (irReturnData, irReturnError) => {
|
|
11392
|
+
// if we received an error or their is no response on the results
|
|
11393
|
+
// return an error
|
|
11394
|
+
if (irReturnError) {
|
|
11395
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
11396
|
+
return callback(null, irReturnError);
|
|
11397
|
+
}
|
|
11398
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
11399
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['postDnasystemapiv1sitesiteIddevice'], null, null, null);
|
|
11400
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
11401
|
+
return callback(null, errorObj);
|
|
11402
|
+
}
|
|
11403
|
+
|
|
11404
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
11405
|
+
// return the response
|
|
11406
|
+
return callback(irReturnData, null);
|
|
11407
|
+
});
|
|
11408
|
+
} catch (ex) {
|
|
11409
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
11410
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
11411
|
+
return callback(null, errorObj);
|
|
11412
|
+
}
|
|
11413
|
+
}
|
|
11414
|
+
|
|
11415
|
+
/**
|
|
11416
|
+
* @summary Create Site
|
|
11417
|
+
*
|
|
11418
|
+
* @function postDnaintentapiv1site
|
|
11419
|
+
* @param {object} request - request
|
|
11420
|
+
* @param {boolean} Runsync - Enable this parameter to execute the API and return a response synchronously
|
|
11421
|
+
* @param {number} Timeout - During synchronous execution, this defines the maximum time to wait for a response, before the API execution is terminated
|
|
11422
|
+
* @param {boolean} Persistbapioutput - Persist bapi sync response
|
|
11423
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
11424
|
+
*/
|
|
11425
|
+
/* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
|
|
11426
|
+
postDnaintentapiv1site(request, Runsync, Timeout, Persistbapioutput, callback) {
|
|
11427
|
+
const meth = 'adapter-postDnaintentapiv1site';
|
|
11428
|
+
const origin = `${this.id}-${meth}`;
|
|
11429
|
+
log.trace(origin);
|
|
11430
|
+
|
|
11431
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
11432
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
11433
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
11434
|
+
return callback(null, errorObj);
|
|
11435
|
+
}
|
|
11436
|
+
|
|
11437
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
11438
|
+
if (request === undefined || request === null || request === '') {
|
|
11439
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['request'], null, null, null);
|
|
11440
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
11441
|
+
return callback(null, errorObj);
|
|
11442
|
+
}
|
|
11443
|
+
if (Runsync === undefined || Runsync === null || Runsync === '') {
|
|
11444
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['Runsync'], null, null, null);
|
|
11445
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
11446
|
+
return callback(null, errorObj);
|
|
11447
|
+
}
|
|
11448
|
+
if (Persistbapioutput === undefined || Persistbapioutput === null || Persistbapioutput === '') {
|
|
11449
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['Persistbapioutput'], null, null, null);
|
|
11450
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
11451
|
+
return callback(null, errorObj);
|
|
11452
|
+
}
|
|
11453
|
+
|
|
11454
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
11455
|
+
const queryParamsAvailable = {};
|
|
11456
|
+
const queryParams = {};
|
|
11457
|
+
const pathVars = [];
|
|
11458
|
+
const bodyVars = request;
|
|
11459
|
+
|
|
11460
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
11461
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
11462
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
11463
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
11464
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
11465
|
+
}
|
|
11466
|
+
});
|
|
11467
|
+
|
|
11468
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders
|
|
11469
|
+
const reqObj = {
|
|
11470
|
+
payload: bodyVars,
|
|
11471
|
+
uriPathVars: pathVars,
|
|
11472
|
+
uriQuery: queryParams
|
|
11473
|
+
};
|
|
11474
|
+
|
|
11475
|
+
try {
|
|
11476
|
+
// Make the call -
|
|
11477
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
11478
|
+
return this.requestHandlerInst.identifyRequest('Sites', 'postDnaintentapiv1site', reqObj, true, (irReturnData, irReturnError) => {
|
|
11479
|
+
// if we received an error or their is no response on the results
|
|
11480
|
+
// return an error
|
|
11481
|
+
if (irReturnError) {
|
|
11482
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
11483
|
+
return callback(null, irReturnError);
|
|
11484
|
+
}
|
|
11485
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
11486
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['postDnaintentapiv1site'], null, null, null);
|
|
11487
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
11488
|
+
return callback(null, errorObj);
|
|
11489
|
+
}
|
|
11490
|
+
|
|
11491
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
11492
|
+
// return the response
|
|
11493
|
+
return callback(irReturnData, null);
|
|
11494
|
+
});
|
|
11495
|
+
} catch (ex) {
|
|
11496
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
11497
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
11498
|
+
return callback(null, errorObj);
|
|
11499
|
+
}
|
|
11500
|
+
}
|
|
11501
|
+
|
|
10703
11502
|
/**
|
|
10704
11503
|
* @summary Create Site
|
|
10705
11504
|
*
|