@itentialopensource/adapter-bmc_helix_itsm 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/.eslintignore +6 -0
  2. package/.eslintrc.js +18 -0
  3. package/.gitlab/.gitkeep +0 -0
  4. package/.gitlab/issue_templates/.gitkeep +0 -0
  5. package/.gitlab/issue_templates/Default.md +17 -0
  6. package/.gitlab/issue_templates/bugReportTemplate.md +76 -0
  7. package/.gitlab/issue_templates/featureRequestTemplate.md +14 -0
  8. package/.jshintrc +0 -0
  9. package/AUTH.md +39 -0
  10. package/BROKER.md +199 -0
  11. package/CALLS.md +278 -0
  12. package/CHANGELOG.md +16 -0
  13. package/CODE_OF_CONDUCT.md +43 -0
  14. package/CONTRIBUTING.md +172 -0
  15. package/ENHANCE.md +69 -0
  16. package/LICENSE +201 -0
  17. package/PROPERTIES.md +641 -0
  18. package/README.md +337 -0
  19. package/SUMMARY.md +9 -0
  20. package/SYSTEMINFO.md +11 -0
  21. package/TROUBLESHOOT.md +47 -0
  22. package/adapter.js +2381 -0
  23. package/adapterBase.js +1787 -0
  24. package/entities/.generic/action.json +214 -0
  25. package/entities/.generic/schema.json +28 -0
  26. package/entities/.system/action.json +50 -0
  27. package/entities/.system/mockdatafiles/getToken-default.json +3 -0
  28. package/entities/.system/mockdatafiles/healthcheck-default.json +3 -0
  29. package/entities/.system/schema.json +19 -0
  30. package/entities/.system/schemaTokenReq.json +53 -0
  31. package/entities/.system/schemaTokenResp.json +53 -0
  32. package/entities/Auth/action.json +44 -0
  33. package/entities/Auth/schema.json +31 -0
  34. package/entities/ChangeRequest/action.json +84 -0
  35. package/entities/ChangeRequest/schema.json +22 -0
  36. package/entities/Entry/action.json +146 -0
  37. package/entities/Entry/schema.json +25 -0
  38. package/entities/Event/action.json +24 -0
  39. package/entities/Event/schema.json +19 -0
  40. package/entities/Incident/action.json +84 -0
  41. package/entities/Incident/schema.json +22 -0
  42. package/error.json +190 -0
  43. package/package.json +89 -0
  44. package/pronghorn.json +1403 -0
  45. package/propertiesDecorators.json +14 -0
  46. package/propertiesSchema.json +1248 -0
  47. package/refs?service=git-upload-pack +0 -0
  48. package/report/adapterInfo.json +10 -0
  49. package/report/creationReport.json +272 -0
  50. package/report/helix-itsm-api.json +425 -0
  51. package/sampleProperties.json +195 -0
  52. package/test/integration/adapterTestBasicGet.js +83 -0
  53. package/test/integration/adapterTestConnectivity.js +93 -0
  54. package/test/integration/adapterTestIntegration.js +577 -0
  55. package/test/unit/adapterBaseTestUnit.js +949 -0
  56. package/test/unit/adapterTestUnit.js +1657 -0
  57. package/utils/adapterInfo.js +206 -0
  58. package/utils/addAuth.js +94 -0
  59. package/utils/artifactize.js +146 -0
  60. package/utils/basicGet.js +50 -0
  61. package/utils/checkMigrate.js +63 -0
  62. package/utils/entitiesToDB.js +178 -0
  63. package/utils/findPath.js +74 -0
  64. package/utils/methodDocumentor.js +225 -0
  65. package/utils/modify.js +154 -0
  66. package/utils/packModificationScript.js +35 -0
  67. package/utils/patches2bundledDeps.js +90 -0
  68. package/utils/pre-commit.sh +32 -0
  69. package/utils/removeHooks.js +20 -0
  70. package/utils/setup.js +33 -0
  71. package/utils/tbScript.js +246 -0
  72. package/utils/tbUtils.js +490 -0
  73. package/utils/testRunner.js +298 -0
  74. package/utils/troubleshootingAdapter.js +195 -0
  75. package/workflows/README.md +3 -0
package/adapter.js ADDED
@@ -0,0 +1,2381 @@
1
+ /* @copyright Itential, LLC 2019 (pre-modifications) */
2
+
3
+ /* eslint import/no-dynamic-require: warn */
4
+ /* eslint object-curly-newline: warn */
5
+
6
+ // Set globals
7
+ /* global log */
8
+
9
+ /* Required libraries. */
10
+ const path = require('path');
11
+
12
+ /* Fetch in the other needed components for the this Adaptor */
13
+ const AdapterBaseCl = require(path.join(__dirname, 'adapterBase.js'));
14
+
15
+ /**
16
+ * This is the adapter/interface into Bmc_helix_itsm
17
+ */
18
+
19
+ /* GENERAL ADAPTER FUNCTIONS */
20
+ class BmcHelixItsm extends AdapterBaseCl {
21
+ /**
22
+ * BmcHelixItsm Adapter
23
+ * @constructor
24
+ */
25
+ /* Working on changing the way we do Emit methods due to size and time constrainsts
26
+ constructor(prongid, properties) {
27
+ // Instantiate the AdapterBase super class
28
+ super(prongid, properties);
29
+
30
+ const restFunctionNames = this.iapGetAdapterWorkflowFunctions();
31
+
32
+ // Dynamically bind emit functions
33
+ for (let i = 0; i < restFunctionNames.length; i += 1) {
34
+ // Bind function to have name fnNameEmit for fnName
35
+ const version = restFunctionNames[i].match(/__v[0-9]+/);
36
+ const baseFnName = restFunctionNames[i].replace(/__v[0-9]+/, '');
37
+ const fnNameEmit = version ? `${baseFnName}Emit${version}` : `${baseFnName}Emit`;
38
+ this[fnNameEmit] = function (...args) {
39
+ // extract the callback
40
+ const callback = args[args.length - 1];
41
+ // slice the callback from args so we can insert our own
42
+ const functionArgs = args.slice(0, args.length - 1);
43
+ // create a random name for the listener
44
+ const eventName = `${restFunctionNames[i]}:${Math.random().toString(36)}`;
45
+ // tell the calling class to start listening
46
+ callback({ event: eventName, status: 'received' });
47
+ // store parent for use of this context later
48
+ const parent = this;
49
+ // store emission function
50
+ const func = function (val, err) {
51
+ parent.removeListener(eventName, func);
52
+ parent.emit(eventName, val, err);
53
+ };
54
+ // Use apply to call the function in a specific context
55
+ this[restFunctionNames[i]].apply(this, functionArgs.concat([func])); // eslint-disable-line prefer-spread
56
+ };
57
+ }
58
+
59
+ // Uncomment if you have things to add to the constructor like using your own properties.
60
+ // Otherwise the constructor in the adapterBase will be used.
61
+ // Capture my own properties - they need to be defined in propertiesSchema.json
62
+ // if (this.allProps && this.allProps.myownproperty) {
63
+ // mypropvariable = this.allProps.myownproperty;
64
+ // }
65
+ }
66
+ */
67
+
68
+ /**
69
+ * @callback healthCallback
70
+ * @param {Object} reqObj - the request to send into the healthcheck
71
+ * @param {Callback} callback - The results of the call
72
+ */
73
+ healthCheck(reqObj, callback) {
74
+ // you can modify what is passed into the healthcheck by changing things in the newReq
75
+ let newReq = null;
76
+ if (reqObj) {
77
+ newReq = Object.assign(...reqObj);
78
+ }
79
+ super.healthCheck(newReq, callback);
80
+ }
81
+
82
+ /**
83
+ * @iapGetAdapterWorkflowFunctions
84
+ */
85
+ iapGetAdapterWorkflowFunctions(inIgnore) {
86
+ let myIgnore = [
87
+ 'healthCheck',
88
+ 'iapGetAdapterWorkflowFunctions',
89
+ 'iapHasAdapterEntity',
90
+ 'iapVerifyAdapterCapability',
91
+ 'iapUpdateAdapterEntityCache',
92
+ 'hasEntities'
93
+ ];
94
+ if (!inIgnore && Array.isArray(inIgnore)) {
95
+ myIgnore = inIgnore;
96
+ } else if (!inIgnore && typeof inIgnore === 'string') {
97
+ myIgnore = [inIgnore];
98
+ }
99
+
100
+ // The generic adapter functions should already be ignored (e.g. healthCheck)
101
+ // you can add specific methods that you do not want to be workflow functions to ignore like below
102
+ // myIgnore.push('myMethodNotInWorkflow');
103
+
104
+ return super.iapGetAdapterWorkflowFunctions(myIgnore);
105
+ }
106
+
107
+ /**
108
+ * iapUpdateAdapterConfiguration is used to update any of the adapter configuration files. This
109
+ * allows customers to make changes to adapter configuration without having to be on the
110
+ * file system.
111
+ *
112
+ * @function iapUpdateAdapterConfiguration
113
+ * @param {string} configFile - the name of the file being updated (required)
114
+ * @param {Object} changes - an object containing all of the changes = formatted like the configuration file (required)
115
+ * @param {string} entity - the entity to be changed, if an action, schema or mock data file (optional)
116
+ * @param {string} type - the type of entity file to change, (action, schema, mock) (optional)
117
+ * @param {string} action - the action to be changed, if an action, schema or mock data file (optional)
118
+ * @param {Callback} callback - The results of the call
119
+ */
120
+ iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, callback) {
121
+ const meth = 'adapter-iapUpdateAdapterConfiguration';
122
+ const origin = `${this.id}-${meth}`;
123
+ log.trace(origin);
124
+
125
+ super.iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, callback);
126
+ }
127
+
128
+ /**
129
+ * See if the API path provided is found in this adapter
130
+ *
131
+ * @function iapFindAdapterPath
132
+ * @param {string} apiPath - the api path to check on
133
+ * @param {Callback} callback - The results of the call
134
+ */
135
+ iapFindAdapterPath(apiPath, callback) {
136
+ const meth = 'adapter-iapFindAdapterPath';
137
+ const origin = `${this.id}-${meth}`;
138
+ log.trace(origin);
139
+
140
+ super.iapFindAdapterPath(apiPath, callback);
141
+ }
142
+
143
+ /**
144
+ * @summary Suspends adapter
145
+ *
146
+ * @function iapSuspendAdapter
147
+ * @param {Callback} callback - callback function
148
+ */
149
+ iapSuspendAdapter(mode, callback) {
150
+ const meth = 'adapter-iapSuspendAdapter';
151
+ const origin = `${this.id}-${meth}`;
152
+ log.trace(origin);
153
+
154
+ try {
155
+ return super.iapSuspendAdapter(mode, callback);
156
+ } catch (error) {
157
+ log.error(`${origin}: ${error}`);
158
+ return callback(null, error);
159
+ }
160
+ }
161
+
162
+ /**
163
+ * @summary Unsuspends adapter
164
+ *
165
+ * @function iapUnsuspendAdapter
166
+ * @param {Callback} callback - callback function
167
+ */
168
+ iapUnsuspendAdapter(callback) {
169
+ const meth = 'adapter-iapUnsuspendAdapter';
170
+ const origin = `${this.id}-${meth}`;
171
+ log.trace(origin);
172
+
173
+ try {
174
+ return super.iapUnsuspendAdapter(callback);
175
+ } catch (error) {
176
+ log.error(`${origin}: ${error}`);
177
+ return callback(null, error);
178
+ }
179
+ }
180
+
181
+ /**
182
+ * @summary Get the Adaoter Queue
183
+ *
184
+ * @function iapGetAdapterQueue
185
+ * @param {Callback} callback - callback function
186
+ */
187
+ iapGetAdapterQueue(callback) {
188
+ const meth = 'adapter-iapGetAdapterQueue';
189
+ const origin = `${this.id}-${meth}`;
190
+ log.trace(origin);
191
+
192
+ return super.iapGetAdapterQueue(callback);
193
+ }
194
+
195
+ /**
196
+ * @summary Runs troubleshoot scripts for adapter
197
+ *
198
+ * @function iapTroubleshootAdapter
199
+ * @param {Object} props - the connection, healthcheck and authentication properties
200
+ *
201
+ * @param {boolean} persistFlag - whether the adapter properties should be updated
202
+ * @param {Callback} callback - The results of the call
203
+ */
204
+ iapTroubleshootAdapter(props, persistFlag, callback) {
205
+ const meth = 'adapter-iapTroubleshootAdapter';
206
+ const origin = `${this.id}-${meth}`;
207
+ log.trace(origin);
208
+
209
+ try {
210
+ return super.iapTroubleshootAdapter(props, persistFlag, this, callback);
211
+ } catch (error) {
212
+ log.error(`${origin}: ${error}`);
213
+ return callback(null, error);
214
+ }
215
+ }
216
+
217
+ /**
218
+ * @summary runs healthcheck script for adapter
219
+ *
220
+ * @function iapRunAdapterHealthcheck
221
+ * @param {Adapter} adapter - adapter instance to troubleshoot
222
+ * @param {Callback} callback - callback function
223
+ */
224
+ iapRunAdapterHealthcheck(callback) {
225
+ const meth = 'adapter-iapRunAdapterHealthcheck';
226
+ const origin = `${this.id}-${meth}`;
227
+ log.trace(origin);
228
+
229
+ try {
230
+ return super.iapRunAdapterHealthcheck(this, callback);
231
+ } catch (error) {
232
+ log.error(`${origin}: ${error}`);
233
+ return callback(null, error);
234
+ }
235
+ }
236
+
237
+ /**
238
+ * @summary runs connectivity check script for adapter
239
+ *
240
+ * @function iapRunAdapterConnectivity
241
+ * @param {Callback} callback - callback function
242
+ */
243
+ iapRunAdapterConnectivity(callback) {
244
+ const meth = 'adapter-iapRunAdapterConnectivity';
245
+ const origin = `${this.id}-${meth}`;
246
+ log.trace(origin);
247
+
248
+ try {
249
+ return super.iapRunAdapterConnectivity(callback);
250
+ } catch (error) {
251
+ log.error(`${origin}: ${error}`);
252
+ return callback(null, error);
253
+ }
254
+ }
255
+
256
+ /**
257
+ * @summary runs basicGet script for adapter
258
+ *
259
+ * @function iapRunAdapterBasicGet
260
+ * @param {Callback} callback - callback function
261
+ */
262
+ iapRunAdapterBasicGet(callback) {
263
+ const meth = 'adapter-iapRunAdapterBasicGet';
264
+ const origin = `${this.id}-${meth}`;
265
+ log.trace(origin);
266
+
267
+ try {
268
+ return super.iapRunAdapterBasicGet(callback);
269
+ } catch (error) {
270
+ log.error(`${origin}: ${error}`);
271
+ return callback(null, error);
272
+ }
273
+ }
274
+
275
+ /**
276
+ * @summary moves entites into Mongo DB
277
+ *
278
+ * @function iapMoveAdapterEntitiesToDB
279
+ * @param {getCallback} callback - a callback function to return the result (Generics)
280
+ * or the error
281
+ */
282
+ iapMoveAdapterEntitiesToDB(callback) {
283
+ const meth = 'adapter-iapMoveAdapterEntitiesToDB';
284
+ const origin = `${this.id}-${meth}`;
285
+ log.trace(origin);
286
+
287
+ try {
288
+ return super.iapMoveAdapterEntitiesToDB(callback);
289
+ } catch (err) {
290
+ log.error(`${origin}: ${err}`);
291
+ return callback(null, err);
292
+ }
293
+ }
294
+
295
+ /* BROKER CALLS */
296
+ /**
297
+ * @summary Determines if this adapter supports the specific entity
298
+ *
299
+ * @function iapHasAdapterEntity
300
+ * @param {String} entityType - the entity type to check for
301
+ * @param {String/Array} entityId - the specific entity we are looking for
302
+ *
303
+ * @param {Callback} callback - An array of whether the adapter can has the
304
+ * desired capability or an error
305
+ */
306
+ iapHasAdapterEntity(entityType, entityId, callback) {
307
+ const origin = `${this.id}-adapter-iapHasAdapterEntity`;
308
+ log.trace(origin);
309
+
310
+ // Make the call -
311
+ // iapVerifyAdapterCapability(entityType, actionType, entityId, callback)
312
+ return this.iapVerifyAdapterCapability(entityType, null, entityId, callback);
313
+ }
314
+
315
+ /**
316
+ * @summary Provides a way for the adapter to tell north bound integrations
317
+ * whether the adapter supports type, action and specific entity
318
+ *
319
+ * @function iapVerifyAdapterCapability
320
+ * @param {String} entityType - the entity type to check for
321
+ * @param {String} actionType - the action type to check for
322
+ * @param {String/Array} entityId - the specific entity we are looking for
323
+ *
324
+ * @param {Callback} callback - An array of whether the adapter can has the
325
+ * desired capability or an error
326
+ */
327
+ iapVerifyAdapterCapability(entityType, actionType, entityId, callback) {
328
+ const meth = 'adapterBase-iapVerifyAdapterCapability';
329
+ const origin = `${this.id}-${meth}`;
330
+ log.trace(origin);
331
+
332
+ // if caching
333
+ if (this.caching) {
334
+ // Make the call - iapVerifyAdapterCapability(entityType, actionType, entityId, callback)
335
+ return this.requestHandlerInst.iapVerifyAdapterCapability(entityType, actionType, entityId, (results, error) => {
336
+ if (error) {
337
+ return callback(null, error);
338
+ }
339
+
340
+ // if the cache needs to be updated, update and try again
341
+ if (results && results[0] === 'needupdate') {
342
+ switch (entityType) {
343
+ case 'template_entity': {
344
+ // if the cache is invalid, update the cache
345
+ return this.getEntities(null, null, null, null, (data, err) => {
346
+ if (err) {
347
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Could not update entity: $VARIABLE$, cache', [entityType], null, null, null);
348
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
349
+ return callback(null, errorObj);
350
+ }
351
+
352
+ // need to check the cache again since it has been updated
353
+ return this.requestHandlerInst.iapVerifyAdapterCapability(entityType, actionType, entityId, (vcapable, verror) => {
354
+ if (verror) {
355
+ return callback(null, verror);
356
+ }
357
+
358
+ return this.capabilityResults(vcapable, callback);
359
+ });
360
+ });
361
+ }
362
+ default: {
363
+ // unsupported entity type
364
+ const result = [false];
365
+
366
+ // put false in array for all entities
367
+ if (Array.isArray(entityId)) {
368
+ for (let e = 1; e < entityId.length; e += 1) {
369
+ result.push(false);
370
+ }
371
+ }
372
+
373
+ return callback(result);
374
+ }
375
+ }
376
+ }
377
+
378
+ // return the results
379
+ return this.capabilityResults(results, callback);
380
+ });
381
+ }
382
+
383
+ // if no entity id
384
+ if (!entityId) {
385
+ // need to check the cache again since it has been updated
386
+ return this.requestHandlerInst.iapVerifyAdapterCapability(entityType, actionType, null, (vcapable, verror) => {
387
+ if (verror) {
388
+ return callback(null, verror);
389
+ }
390
+
391
+ return this.capabilityResults(vcapable, callback);
392
+ });
393
+ }
394
+
395
+ // if not caching
396
+ switch (entityType) {
397
+ case 'template_entity': {
398
+ // need to get the entities to check
399
+ return this.getEntities(null, null, null, null, (data, err) => {
400
+ if (err) {
401
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Could not update entity: $VARIABLE$, cache', [entityType], null, null, null);
402
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
403
+ return callback(null, errorObj);
404
+ }
405
+
406
+ // need to check the cache again since it has been updated
407
+ return this.requestHandlerInst.iapVerifyAdapterCapability(entityType, actionType, null, (vcapable, verror) => {
408
+ if (verror) {
409
+ return callback(null, verror);
410
+ }
411
+
412
+ // is the entity in the list?
413
+ const isEntity = this.entityInList(entityId, data.response, callback);
414
+ const res = [];
415
+
416
+ // not found
417
+ for (let i = 0; i < isEntity.length; i += 1) {
418
+ if (vcapable) {
419
+ res.push(isEntity[i]);
420
+ } else {
421
+ res.push(false);
422
+ }
423
+ }
424
+
425
+ return callback(res);
426
+ });
427
+ });
428
+ }
429
+ default: {
430
+ // unsupported entity type
431
+ const result = [false];
432
+
433
+ // put false in array for all entities
434
+ if (Array.isArray(entityId)) {
435
+ for (let e = 1; e < entityId.length; e += 1) {
436
+ result.push(false);
437
+ }
438
+ }
439
+
440
+ return callback(result);
441
+ }
442
+ }
443
+ }
444
+
445
+ /**
446
+ * @summary Updates the cache for all entities by call the get All entity method
447
+ *
448
+ * @function iapUpdateAdapterEntityCache
449
+ *
450
+ */
451
+ iapUpdateAdapterEntityCache() {
452
+ const origin = `${this.id}-adapter-iapUpdateAdapterEntityCache`;
453
+ log.trace(origin);
454
+
455
+ if (this.caching) {
456
+ // if the cache is invalid, update the cache
457
+ this.getEntities(null, null, null, null, (data, err) => {
458
+ if (err) {
459
+ log.trace(`${origin}: Could not load template_entity into cache - ${err}`);
460
+ }
461
+ });
462
+ }
463
+ }
464
+
465
+ /**
466
+ * @summary Determines if this adapter supports any in a list of entities
467
+ *
468
+ * @function hasEntities
469
+ * @param {String} entityType - the entity type to check for
470
+ * @param {Array} entityList - the list of entities we are looking for
471
+ *
472
+ * @param {Callback} callback - A map where the entity is the key and the
473
+ * value is true or false
474
+ */
475
+ hasEntities(entityType, entityList, callback) {
476
+ const meth = 'adapter-hasEntities';
477
+ const origin = `${this.id}-${meth}`;
478
+ log.trace(origin);
479
+
480
+ try {
481
+ return super.hasEntities(entityType, entityList, callback);
482
+ } catch (err) {
483
+ log.error(`${origin}: ${err}`);
484
+ return callback(null, err);
485
+ }
486
+ }
487
+
488
+ /**
489
+ * @summary Get Appliance that match the deviceName
490
+ *
491
+ * @function getDevice
492
+ * @param {String} deviceName - the deviceName to find (required)
493
+ *
494
+ * @param {getCallback} callback - a callback function to return the result
495
+ * (appliance) or the error
496
+ */
497
+ getDevice(deviceName, callback) {
498
+ const meth = 'adapter-getDevice';
499
+ const origin = `${this.id}-${meth}`;
500
+ log.trace(origin);
501
+
502
+ try {
503
+ return super.getDevice(deviceName, callback);
504
+ } catch (err) {
505
+ log.error(`${origin}: ${err}`);
506
+ return callback(null, err);
507
+ }
508
+ }
509
+
510
+ /**
511
+ * @summary Get Appliances that match the filter
512
+ *
513
+ * @function getDevicesFiltered
514
+ * @param {Object} options - the data to use to filter the appliances (optional)
515
+ *
516
+ * @param {getCallback} callback - a callback function to return the result
517
+ * (appliances) or the error
518
+ */
519
+ getDevicesFiltered(options, callback) {
520
+ const meth = 'adapter-getDevicesFiltered';
521
+ const origin = `${this.id}-${meth}`;
522
+ log.trace(origin);
523
+
524
+ try {
525
+ return super.getDevicesFiltered(options, callback);
526
+ } catch (err) {
527
+ log.error(`${origin}: ${err}`);
528
+ return callback(null, err);
529
+ }
530
+ }
531
+
532
+ /**
533
+ * @summary Gets the status for the provided appliance
534
+ *
535
+ * @function isAlive
536
+ * @param {String} deviceName - the deviceName of the appliance. (required)
537
+ *
538
+ * @param {configCallback} callback - callback function to return the result
539
+ * (appliance isAlive) or the error
540
+ */
541
+ isAlive(deviceName, callback) {
542
+ const meth = 'adapter-isAlive';
543
+ const origin = `${this.id}-${meth}`;
544
+ log.trace(origin);
545
+
546
+ try {
547
+ return super.isAlive(deviceName, callback);
548
+ } catch (err) {
549
+ log.error(`${origin}: ${err}`);
550
+ return callback(null, err);
551
+ }
552
+ }
553
+
554
+ /**
555
+ * @summary Gets a config for the provided Appliance
556
+ *
557
+ * @function getConfig
558
+ * @param {String} deviceName - the deviceName of the appliance. (required)
559
+ * @param {String} format - the desired format of the config. (optional)
560
+ *
561
+ * @param {configCallback} callback - callback function to return the result
562
+ * (appliance config) or the error
563
+ */
564
+ getConfig(deviceName, format, callback) {
565
+ const meth = 'adapter-getConfig';
566
+ const origin = `${this.id}-${meth}`;
567
+ log.trace(origin);
568
+
569
+ try {
570
+ return super.getConfig(deviceName, format, callback);
571
+ } catch (err) {
572
+ log.error(`${origin}: ${err}`);
573
+ return callback(null, err);
574
+ }
575
+ }
576
+
577
+ /**
578
+ * @summary Gets the device count from the system
579
+ *
580
+ * @function iapGetDeviceCount
581
+ *
582
+ * @param {getCallback} callback - callback function to return the result
583
+ * (count) or the error
584
+ */
585
+ iapGetDeviceCount(callback) {
586
+ const meth = 'adapter-iapGetDeviceCount';
587
+ const origin = `${this.id}-${meth}`;
588
+ log.trace(origin);
589
+
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);
633
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
634
+ return callback(null, errorObj);
635
+ }
636
+
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;
647
+
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];
653
+ }
654
+ });
655
+
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
+ }
697
+
698
+ /* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
699
+ // return the response
700
+ return callback(irReturnData, null);
701
+ });
702
+ } catch (ex) {
703
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
704
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
705
+ return callback(null, errorObj);
706
+ }
707
+ }
708
+
709
+ /**
710
+ * Makes the requested generic call with no base path or version
711
+ *
712
+ * @function genericAdapterRequestNoBasePath
713
+ * @param {String} uriPath - the path of the api call - do not include the host, port, base path or version (required)
714
+ * @param {String} restMethod - the rest method (GET, POST, PUT, PATCH, DELETE) (required)
715
+ * @param {Object} queryData - the parameters to be put on the url (optional).
716
+ * Can be a stringified Object.
717
+ * @param {Object} requestBody - the body to add to the request (optional).
718
+ * Can be a stringified Object.
719
+ * @param {Object} addlHeaders - additional headers to be put on the call (optional).
720
+ * Can be a stringified Object.
721
+ * @param {getCallback} callback - a callback function to return the result (Generics)
722
+ * or the error
723
+ */
724
+ genericAdapterRequestNoBasePath(uriPath, restMethod, queryData, requestBody, addlHeaders, callback) {
725
+ const meth = 'adapter-genericAdapterRequestNoBasePath';
726
+ const origin = `${this.id}-${meth}`;
727
+ log.trace(origin);
728
+
729
+ if (this.suspended && this.suspendMode === 'error') {
730
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
731
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
732
+ return callback(null, errorObj);
733
+ }
734
+
735
+ /* HERE IS WHERE YOU VALIDATE DATA */
736
+ if (uriPath === undefined || uriPath === null || uriPath === '') {
737
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['uriPath'], null, null, null);
738
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
739
+ return callback(null, errorObj);
740
+ }
741
+ if (restMethod === undefined || restMethod === null || restMethod === '') {
742
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['restMethod'], null, null, null);
743
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
744
+ return callback(null, errorObj);
745
+ }
746
+
747
+ /* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
748
+ // remove any leading / and split the uripath into path variables
749
+ let myPath = uriPath;
750
+ while (myPath.indexOf('/') === 0) {
751
+ myPath = myPath.substring(1);
752
+ }
753
+ const pathVars = myPath.split('/');
754
+ const queryParamsAvailable = queryData;
755
+ const queryParams = {};
756
+ const bodyVars = requestBody;
757
+
758
+ // loop in template. long callback arg name to avoid identifier conflicts
759
+ Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
760
+ if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
761
+ && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
762
+ queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
763
+ }
764
+ });
765
+
766
+ // set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders
767
+ const reqObj = {
768
+ payload: bodyVars,
769
+ uriPathVars: pathVars,
770
+ uriQuery: queryParams,
771
+ uriOptions: {}
772
+ };
773
+ // add headers if provided
774
+ if (addlHeaders) {
775
+ reqObj.addlHeaders = addlHeaders;
776
+ }
777
+
778
+ // determine the call and return flag
779
+ let action = 'getGenericsNoBase';
780
+ let returnF = true;
781
+ if (restMethod.toUpperCase() === 'POST') {
782
+ action = 'createGenericNoBase';
783
+ } else if (restMethod.toUpperCase() === 'PUT') {
784
+ action = 'updateGenericNoBase';
785
+ } else if (restMethod.toUpperCase() === 'PATCH') {
786
+ action = 'patchGenericNoBase';
787
+ } else if (restMethod.toUpperCase() === 'DELETE') {
788
+ action = 'deleteGenericNoBase';
789
+ returnF = false;
790
+ }
791
+
792
+ try {
793
+ // Make the call -
794
+ // identifyRequest(entity, action, requestObj, returnDataFlag, callback)
795
+ return this.requestHandlerInst.identifyRequest('.generic', action, reqObj, returnF, (irReturnData, irReturnError) => {
796
+ // if we received an error or their is no response on the results
797
+ // return an error
798
+ if (irReturnError) {
799
+ /* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
800
+ return callback(null, irReturnError);
801
+ }
802
+ if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
803
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['genericAdapterRequestNoBasePath'], null, null, null);
804
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
805
+ return callback(null, errorObj);
806
+ }
807
+
808
+ /* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
809
+ // return the response
810
+ return callback(irReturnData, null);
811
+ });
812
+ } catch (ex) {
813
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
814
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
815
+ return callback(null, errorObj);
816
+ }
817
+ }
818
+
819
+ /**
820
+ * @callback healthCallback
821
+ * @param {Object} result - the result of the get request (contains an id and a status)
822
+ */
823
+ /**
824
+ * @callback getCallback
825
+ * @param {Object} result - the result of the get request (entity/ies)
826
+ * @param {String} error - any error that occurred
827
+ */
828
+ /**
829
+ * @callback createCallback
830
+ * @param {Object} item - the newly created entity
831
+ * @param {String} error - any error that occurred
832
+ */
833
+ /**
834
+ * @callback updateCallback
835
+ * @param {String} status - the status of the update action
836
+ * @param {String} error - any error that occurred
837
+ */
838
+ /**
839
+ * @callback deleteCallback
840
+ * @param {String} status - the status of the delete action
841
+ * @param {String} error - any error that occurred
842
+ */
843
+
844
+ /**
845
+ * @function createEntry
846
+ * @pronghornType method
847
+ * @name createEntry
848
+ * @summary Create Entry
849
+ *
850
+ * @param {string} formName - the form name
851
+ * @param {object} [query] - object of query/option data - fields, etc
852
+ * @param {object} body - body param
853
+ * @param {getCallback} callback - a callback function to return the result
854
+ * @return {object} results - An object containing the response of the action
855
+ *
856
+ * @route {POST} /createEntry
857
+ * @roles admin
858
+ * @task true
859
+ */
860
+ /* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
861
+ createEntry(formName, query, body, callback) {
862
+ const meth = 'adapter-createEntry';
863
+ const origin = `${this.id}-${meth}`;
864
+ log.trace(origin);
865
+
866
+ if (this.suspended && this.suspendMode === 'error') {
867
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
868
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
869
+ return callback(null, errorObj);
870
+ }
871
+
872
+ /* HERE IS WHERE YOU VALIDATE DATA */
873
+ if (formName === undefined || formName === null || formName === '') {
874
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['formName'], null, null, null);
875
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
876
+ return callback(null, errorObj);
877
+ }
878
+ if (body === undefined || body === null || body === '') {
879
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['body'], null, null, null);
880
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
881
+ return callback(null, errorObj);
882
+ }
883
+
884
+ /* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
885
+ const queryParamsAvailable = { query };
886
+ const queryParams = {};
887
+ const pathVars = [formName];
888
+ const bodyVars = body;
889
+
890
+ // loop in template. long callback arg name to avoid identifier conflicts
891
+ Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
892
+ if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
893
+ && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
894
+ queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
895
+ }
896
+ });
897
+
898
+ // set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
899
+ // see adapter code documentation for more information on the request object's fields
900
+ const reqObj = {
901
+ payload: bodyVars,
902
+ uriPathVars: pathVars,
903
+ uriQuery: queryParams
904
+ };
905
+
906
+ try {
907
+ // Make the call -
908
+ // identifyRequest(entity, action, requestObj, returnDataFlag, callback)
909
+ return this.requestHandlerInst.identifyRequest('Entry', 'createEntry', reqObj, true, (irReturnData, irReturnError) => {
910
+ // if we received an error or their is no response on the results
911
+ // return an error
912
+ if (irReturnError) {
913
+ /* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
914
+ return callback(null, irReturnError);
915
+ }
916
+ if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
917
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['createEntry'], null, null, null);
918
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
919
+ return callback(null, errorObj);
920
+ }
921
+
922
+ /* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
923
+ // return the response
924
+ return callback(irReturnData, null);
925
+ });
926
+ } catch (ex) {
927
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
928
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
929
+ return callback(null, errorObj);
930
+ }
931
+ }
932
+
933
+ /**
934
+ * @function getMultipleEntries
935
+ * @pronghornType method
936
+ * @name getMultipleEntries
937
+ * @summary Get Multiple Entries
938
+ *
939
+ * @param {string} formName - the form name
940
+ * @param {object} [query] - object of query/option data - fields, sort, limit, offset, etc
941
+ * @param {getCallback} callback - a callback function to return the result
942
+ * @return {object} results - An object containing the response of the action
943
+ *
944
+ * @route {POST} /getMultipleEntries
945
+ * @roles admin
946
+ * @task true
947
+ */
948
+ /* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
949
+ getMultipleEntries(formName, query, callback) {
950
+ const meth = 'adapter-getMultipleEntries';
951
+ const origin = `${this.id}-${meth}`;
952
+ log.trace(origin);
953
+
954
+ if (this.suspended && this.suspendMode === 'error') {
955
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
956
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
957
+ return callback(null, errorObj);
958
+ }
959
+
960
+ /* HERE IS WHERE YOU VALIDATE DATA */
961
+ if (formName === undefined || formName === null || formName === '') {
962
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['formName'], null, null, null);
963
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
964
+ return callback(null, errorObj);
965
+ }
966
+
967
+ /* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
968
+ const queryParamsAvailable = { query };
969
+ const queryParams = {};
970
+ const pathVars = [formName];
971
+ const bodyVars = {};
972
+
973
+ // loop in template. long callback arg name to avoid identifier conflicts
974
+ Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
975
+ if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
976
+ && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
977
+ queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
978
+ }
979
+ });
980
+
981
+ // set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
982
+ // see adapter code documentation for more information on the request object's fields
983
+ const reqObj = {
984
+ payload: bodyVars,
985
+ uriPathVars: pathVars,
986
+ uriQuery: queryParams
987
+ };
988
+
989
+ try {
990
+ // Make the call -
991
+ // identifyRequest(entity, action, requestObj, returnDataFlag, callback)
992
+ return this.requestHandlerInst.identifyRequest('Entry', 'getMultipleEntries', reqObj, true, (irReturnData, irReturnError) => {
993
+ // if we received an error or their is no response on the results
994
+ // return an error
995
+ if (irReturnError) {
996
+ /* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
997
+ return callback(null, irReturnError);
998
+ }
999
+ if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
1000
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getMultipleEntries'], null, null, null);
1001
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1002
+ return callback(null, errorObj);
1003
+ }
1004
+
1005
+ /* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
1006
+ // return the response
1007
+ return callback(irReturnData, null);
1008
+ });
1009
+ } catch (ex) {
1010
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
1011
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1012
+ return callback(null, errorObj);
1013
+ }
1014
+ }
1015
+
1016
+ /**
1017
+ * @function getFormSchemaOptions
1018
+ * @pronghornType method
1019
+ * @name getFormSchemaOptions
1020
+ * @summary Get Options of Form Schema
1021
+ *
1022
+ * @param {string} formName - the form name
1023
+ * @param {object} [query] - object of query/option data - fields, etc
1024
+ * @param {getCallback} callback - a callback function to return the result
1025
+ * @return {object} results - An object containing the response of the action
1026
+ *
1027
+ * @route {POST} /getFormSchemaOptions
1028
+ * @roles admin
1029
+ * @task true
1030
+ */
1031
+ /* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
1032
+ getFormSchemaOptions(formName, query, callback) {
1033
+ const meth = 'adapter-getFormSchemaOptions';
1034
+ const origin = `${this.id}-${meth}`;
1035
+ log.trace(origin);
1036
+
1037
+ if (this.suspended && this.suspendMode === 'error') {
1038
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
1039
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1040
+ return callback(null, errorObj);
1041
+ }
1042
+
1043
+ /* HERE IS WHERE YOU VALIDATE DATA */
1044
+ if (formName === undefined || formName === null || formName === '') {
1045
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['formName'], null, null, null);
1046
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1047
+ return callback(null, errorObj);
1048
+ }
1049
+
1050
+ /* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
1051
+ const queryParamsAvailable = { query };
1052
+ const queryParams = {};
1053
+ const pathVars = [formName];
1054
+ const bodyVars = {};
1055
+
1056
+ // loop in template. long callback arg name to avoid identifier conflicts
1057
+ Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
1058
+ if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
1059
+ && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
1060
+ queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
1061
+ }
1062
+ });
1063
+
1064
+ // set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
1065
+ // see adapter code documentation for more information on the request object's fields
1066
+ const reqObj = {
1067
+ payload: bodyVars,
1068
+ uriPathVars: pathVars,
1069
+ uriQuery: queryParams
1070
+ };
1071
+
1072
+ try {
1073
+ // Make the call -
1074
+ // identifyRequest(entity, action, requestObj, returnDataFlag, callback)
1075
+ return this.requestHandlerInst.identifyRequest('Entry', 'getFormSchemaOptions', reqObj, true, (irReturnData, irReturnError) => {
1076
+ // if we received an error or their is no response on the results
1077
+ // return an error
1078
+ if (irReturnError) {
1079
+ /* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
1080
+ return callback(null, irReturnError);
1081
+ }
1082
+ if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
1083
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getFormSchemaOptions'], null, null, null);
1084
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1085
+ return callback(null, errorObj);
1086
+ }
1087
+
1088
+ /* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
1089
+ // return the response
1090
+ return callback(irReturnData, null);
1091
+ });
1092
+ } catch (ex) {
1093
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
1094
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1095
+ return callback(null, errorObj);
1096
+ }
1097
+ }
1098
+
1099
+ /**
1100
+ * @function updateEntry
1101
+ * @pronghornType method
1102
+ * @name updateEntry
1103
+ * @summary Update Entry
1104
+ *
1105
+ * @param {string} formName - the form name
1106
+ * @param {string} entryId - the entry id
1107
+ * @param {object} body - body param
1108
+ * @param {getCallback} callback - a callback function to return the result
1109
+ * @return {object} results - An object containing the response of the action
1110
+ *
1111
+ * @route {POST} /updateEntry
1112
+ * @roles admin
1113
+ * @task true
1114
+ */
1115
+ /* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
1116
+ updateEntry(formName, entryId, body, callback) {
1117
+ const meth = 'adapter-updateEntry';
1118
+ const origin = `${this.id}-${meth}`;
1119
+ log.trace(origin);
1120
+
1121
+ if (this.suspended && this.suspendMode === 'error') {
1122
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
1123
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1124
+ return callback(null, errorObj);
1125
+ }
1126
+
1127
+ /* HERE IS WHERE YOU VALIDATE DATA */
1128
+ if (formName === undefined || formName === null || formName === '') {
1129
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['formName'], null, null, null);
1130
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1131
+ return callback(null, errorObj);
1132
+ }
1133
+ if (entryId === undefined || entryId === null || entryId === '') {
1134
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['entryId'], null, null, null);
1135
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1136
+ return callback(null, errorObj);
1137
+ }
1138
+ if (body === undefined || body === null || body === '') {
1139
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['body'], null, null, null);
1140
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1141
+ return callback(null, errorObj);
1142
+ }
1143
+
1144
+ /* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
1145
+ const queryParamsAvailable = {};
1146
+ const queryParams = {};
1147
+ const pathVars = [formName, entryId];
1148
+ const bodyVars = body;
1149
+
1150
+ // loop in template. long callback arg name to avoid identifier conflicts
1151
+ Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
1152
+ if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
1153
+ && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
1154
+ queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
1155
+ }
1156
+ });
1157
+
1158
+ // set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
1159
+ // see adapter code documentation for more information on the request object's fields
1160
+ const reqObj = {
1161
+ payload: bodyVars,
1162
+ uriPathVars: pathVars,
1163
+ uriQuery: queryParams
1164
+ };
1165
+
1166
+ try {
1167
+ // Make the call -
1168
+ // identifyRequest(entity, action, requestObj, returnDataFlag, callback)
1169
+ return this.requestHandlerInst.identifyRequest('Entry', 'updateEntry', reqObj, false, (irReturnData, irReturnError) => {
1170
+ // if we received an error or their is no response on the results
1171
+ // return an error
1172
+ if (irReturnError) {
1173
+ /* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
1174
+ return callback(null, irReturnError);
1175
+ }
1176
+ if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
1177
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['updateEntry'], null, null, null);
1178
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1179
+ return callback(null, errorObj);
1180
+ }
1181
+
1182
+ /* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
1183
+ // return the response
1184
+ return callback(irReturnData, null);
1185
+ });
1186
+ } catch (ex) {
1187
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
1188
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1189
+ return callback(null, errorObj);
1190
+ }
1191
+ }
1192
+
1193
+ /**
1194
+ * @function getEntryById
1195
+ * @pronghornType method
1196
+ * @name getEntryById
1197
+ * @summary Get Entry
1198
+ *
1199
+ * @param {string} formName - the form name
1200
+ * @param {string} entryId - the entry id
1201
+ * @param {object} [query] - object of query/option data - fields, etc
1202
+ * @param {getCallback} callback - a callback function to return the result
1203
+ * @return {object} results - An object containing the response of the action
1204
+ *
1205
+ * @route {POST} /getEntryById
1206
+ * @roles admin
1207
+ * @task true
1208
+ */
1209
+ /* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
1210
+ getEntryById(formName, entryId, query, callback) {
1211
+ const meth = 'adapter-getEntryById';
1212
+ const origin = `${this.id}-${meth}`;
1213
+ log.trace(origin);
1214
+
1215
+ if (this.suspended && this.suspendMode === 'error') {
1216
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
1217
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1218
+ return callback(null, errorObj);
1219
+ }
1220
+
1221
+ /* HERE IS WHERE YOU VALIDATE DATA */
1222
+ if (formName === undefined || formName === null || formName === '') {
1223
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['formName'], null, null, null);
1224
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1225
+ return callback(null, errorObj);
1226
+ }
1227
+ if (entryId === undefined || entryId === null || entryId === '') {
1228
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['entryId'], null, null, null);
1229
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1230
+ return callback(null, errorObj);
1231
+ }
1232
+
1233
+ /* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
1234
+ const queryParamsAvailable = { query };
1235
+ const queryParams = {};
1236
+ const pathVars = [formName, entryId];
1237
+ const bodyVars = {};
1238
+
1239
+ // loop in template. long callback arg name to avoid identifier conflicts
1240
+ Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
1241
+ if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
1242
+ && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
1243
+ queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
1244
+ }
1245
+ });
1246
+
1247
+ // set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
1248
+ // see adapter code documentation for more information on the request object's fields
1249
+ const reqObj = {
1250
+ payload: bodyVars,
1251
+ uriPathVars: pathVars,
1252
+ uriQuery: queryParams
1253
+ };
1254
+
1255
+ try {
1256
+ // Make the call -
1257
+ // identifyRequest(entity, action, requestObj, returnDataFlag, callback)
1258
+ return this.requestHandlerInst.identifyRequest('Entry', 'getEntryById', reqObj, true, (irReturnData, irReturnError) => {
1259
+ // if we received an error or their is no response on the results
1260
+ // return an error
1261
+ if (irReturnError) {
1262
+ /* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
1263
+ return callback(null, irReturnError);
1264
+ }
1265
+ if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
1266
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getEntryById'], null, null, null);
1267
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1268
+ return callback(null, errorObj);
1269
+ }
1270
+
1271
+ /* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
1272
+ // return the response
1273
+ return callback(irReturnData, null);
1274
+ });
1275
+ } catch (ex) {
1276
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
1277
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1278
+ return callback(null, errorObj);
1279
+ }
1280
+ }
1281
+
1282
+ /**
1283
+ * @function deleteEntryById
1284
+ * @pronghornType method
1285
+ * @name deleteEntryById
1286
+ * @summary Delete Entry
1287
+ *
1288
+ * @param {string} formName - the form name
1289
+ * @param {string} entryId - the entry id
1290
+ * @param {object} [options] - delete options
1291
+ * @param {getCallback} callback - a callback function to return the result
1292
+ * @return {object} results - An object containing the response of the action
1293
+ *
1294
+ * @route {POST} /deleteEntryById
1295
+ * @roles admin
1296
+ * @task true
1297
+ */
1298
+ /* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
1299
+ deleteEntryById(formName, entryId, options, callback) {
1300
+ const meth = 'adapter-deleteEntryById';
1301
+ const origin = `${this.id}-${meth}`;
1302
+ log.trace(origin);
1303
+
1304
+ if (this.suspended && this.suspendMode === 'error') {
1305
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
1306
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1307
+ return callback(null, errorObj);
1308
+ }
1309
+
1310
+ /* HERE IS WHERE YOU VALIDATE DATA */
1311
+ if (formName === undefined || formName === null || formName === '') {
1312
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['formName'], null, null, null);
1313
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1314
+ return callback(null, errorObj);
1315
+ }
1316
+ if (entryId === undefined || entryId === null || entryId === '') {
1317
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['entryId'], null, null, null);
1318
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1319
+ return callback(null, errorObj);
1320
+ }
1321
+
1322
+ /* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
1323
+ const queryParamsAvailable = { options };
1324
+ const queryParams = {};
1325
+ const pathVars = [formName, entryId];
1326
+ const bodyVars = {};
1327
+
1328
+ // loop in template. long callback arg name to avoid identifier conflicts
1329
+ Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
1330
+ if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
1331
+ && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
1332
+ queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
1333
+ }
1334
+ });
1335
+
1336
+ // set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
1337
+ // see adapter code documentation for more information on the request object's fields
1338
+ const reqObj = {
1339
+ payload: bodyVars,
1340
+ uriPathVars: pathVars,
1341
+ uriQuery: queryParams
1342
+ };
1343
+
1344
+ try {
1345
+ // Make the call -
1346
+ // identifyRequest(entity, action, requestObj, returnDataFlag, callback)
1347
+ return this.requestHandlerInst.identifyRequest('Entry', 'deleteEntryById', reqObj, false, (irReturnData, irReturnError) => {
1348
+ // if we received an error or their is no response on the results
1349
+ // return an error
1350
+ if (irReturnError) {
1351
+ /* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
1352
+ return callback(null, irReturnError);
1353
+ }
1354
+ if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
1355
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['deleteEntryById'], null, null, null);
1356
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1357
+ return callback(null, errorObj);
1358
+ }
1359
+
1360
+ /* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
1361
+ // return the response
1362
+ return callback(irReturnData, null);
1363
+ });
1364
+ } catch (ex) {
1365
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
1366
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1367
+ return callback(null, errorObj);
1368
+ }
1369
+ }
1370
+
1371
+ /**
1372
+ * @function getEntryFormSchemaOptions
1373
+ * @pronghornType method
1374
+ * @name getEntryFormSchemaOptions
1375
+ * @summary Get Options of Entry Form Schema
1376
+ *
1377
+ * @param {string} formName - the form name
1378
+ * @param {string} entryId - the entry id
1379
+ * @param {object} [query] - object of query/option data - fields, etc
1380
+ * @param {getCallback} callback - a callback function to return the result
1381
+ * @return {object} results - An object containing the response of the action
1382
+ *
1383
+ * @route {POST} /getEntryFormSchemaOptions
1384
+ * @roles admin
1385
+ * @task true
1386
+ */
1387
+ /* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
1388
+ getEntryFormSchemaOptions(formName, entryId, query, callback) {
1389
+ const meth = 'adapter-getEntryFormSchemaOptions';
1390
+ const origin = `${this.id}-${meth}`;
1391
+ log.trace(origin);
1392
+
1393
+ if (this.suspended && this.suspendMode === 'error') {
1394
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
1395
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1396
+ return callback(null, errorObj);
1397
+ }
1398
+
1399
+ /* HERE IS WHERE YOU VALIDATE DATA */
1400
+ if (formName === undefined || formName === null || formName === '') {
1401
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['formName'], null, null, null);
1402
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1403
+ return callback(null, errorObj);
1404
+ }
1405
+ if (entryId === undefined || entryId === null || entryId === '') {
1406
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['entryId'], null, null, null);
1407
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1408
+ return callback(null, errorObj);
1409
+ }
1410
+
1411
+ /* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
1412
+ const queryParamsAvailable = { query };
1413
+ const queryParams = {};
1414
+ const pathVars = [formName, entryId];
1415
+ const bodyVars = {};
1416
+
1417
+ // loop in template. long callback arg name to avoid identifier conflicts
1418
+ Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
1419
+ if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
1420
+ && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
1421
+ queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
1422
+ }
1423
+ });
1424
+
1425
+ // set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
1426
+ // see adapter code documentation for more information on the request object's fields
1427
+ const reqObj = {
1428
+ payload: bodyVars,
1429
+ uriPathVars: pathVars,
1430
+ uriQuery: queryParams
1431
+ };
1432
+
1433
+ try {
1434
+ // Make the call -
1435
+ // identifyRequest(entity, action, requestObj, returnDataFlag, callback)
1436
+ return this.requestHandlerInst.identifyRequest('Entry', 'getEntryFormSchemaOptions', reqObj, true, (irReturnData, irReturnError) => {
1437
+ // if we received an error or their is no response on the results
1438
+ // return an error
1439
+ if (irReturnError) {
1440
+ /* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
1441
+ return callback(null, irReturnError);
1442
+ }
1443
+ if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
1444
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getEntryFormSchemaOptions'], null, null, null);
1445
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1446
+ return callback(null, errorObj);
1447
+ }
1448
+
1449
+ /* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
1450
+ // return the response
1451
+ return callback(irReturnData, null);
1452
+ });
1453
+ } catch (ex) {
1454
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
1455
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1456
+ return callback(null, errorObj);
1457
+ }
1458
+ }
1459
+
1460
+ /**
1461
+ * @function login
1462
+ * @pronghornType method
1463
+ * @name login
1464
+ * @summary Login
1465
+ *
1466
+ * @param {object} bodyFormData - bodyFormData param
1467
+ * @param {getCallback} callback - a callback function to return the result
1468
+ * @return {object} results - An object containing the response of the action
1469
+ *
1470
+ * @route {POST} /login
1471
+ * @roles admin
1472
+ * @task true
1473
+ */
1474
+ /* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
1475
+ login(bodyFormData, callback) {
1476
+ const meth = 'adapter-login';
1477
+ const origin = `${this.id}-${meth}`;
1478
+ log.trace(origin);
1479
+
1480
+ if (this.suspended && this.suspendMode === 'error') {
1481
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
1482
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1483
+ return callback(null, errorObj);
1484
+ }
1485
+
1486
+ /* HERE IS WHERE YOU VALIDATE DATA */
1487
+ if (bodyFormData === undefined || bodyFormData === null || bodyFormData === '') {
1488
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['bodyFormData'], null, null, null);
1489
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1490
+ return callback(null, errorObj);
1491
+ }
1492
+
1493
+ /* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
1494
+ const queryParamsAvailable = {};
1495
+ const queryParams = {};
1496
+ const pathVars = [];
1497
+ const bodyVars = {};
1498
+
1499
+ // loop in template. long callback arg name to avoid identifier conflicts
1500
+ Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
1501
+ if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
1502
+ && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
1503
+ queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
1504
+ }
1505
+ });
1506
+
1507
+ // set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
1508
+ // see adapter code documentation for more information on the request object's fields
1509
+ const reqObj = {
1510
+ payload: bodyVars,
1511
+ uriPathVars: pathVars,
1512
+ uriQuery: queryParams
1513
+ };
1514
+
1515
+ try {
1516
+ // Make the call -
1517
+ // identifyRequest(entity, action, requestObj, returnDataFlag, callback)
1518
+ return this.requestHandlerInst.identifyRequest('Auth', 'login', reqObj, true, (irReturnData, irReturnError) => {
1519
+ // if we received an error or their is no response on the results
1520
+ // return an error
1521
+ if (irReturnError) {
1522
+ /* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
1523
+ return callback(null, irReturnError);
1524
+ }
1525
+ if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
1526
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['login'], null, null, null);
1527
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1528
+ return callback(null, errorObj);
1529
+ }
1530
+
1531
+ /* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
1532
+ // return the response
1533
+ return callback(irReturnData, null);
1534
+ });
1535
+ } catch (ex) {
1536
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
1537
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1538
+ return callback(null, errorObj);
1539
+ }
1540
+ }
1541
+
1542
+ /**
1543
+ * @function logout
1544
+ * @pronghornType method
1545
+ * @name logout
1546
+ * @summary Logout
1547
+ *
1548
+ * @param {getCallback} callback - a callback function to return the result
1549
+ * @return {object} results - An object containing the response of the action
1550
+ *
1551
+ * @route {GET} /logout
1552
+ * @roles admin
1553
+ * @task true
1554
+ */
1555
+ /* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
1556
+ logout(callback) {
1557
+ const meth = 'adapter-logout';
1558
+ const origin = `${this.id}-${meth}`;
1559
+ log.trace(origin);
1560
+
1561
+ if (this.suspended && this.suspendMode === 'error') {
1562
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
1563
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1564
+ return callback(null, errorObj);
1565
+ }
1566
+
1567
+ /* HERE IS WHERE YOU VALIDATE DATA */
1568
+
1569
+ /* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
1570
+ const queryParamsAvailable = {};
1571
+ const queryParams = {};
1572
+ const pathVars = [];
1573
+ const bodyVars = {};
1574
+
1575
+ // loop in template. long callback arg name to avoid identifier conflicts
1576
+ Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
1577
+ if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
1578
+ && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
1579
+ queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
1580
+ }
1581
+ });
1582
+
1583
+ // set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
1584
+ // see adapter code documentation for more information on the request object's fields
1585
+ const reqObj = {
1586
+ payload: bodyVars,
1587
+ uriPathVars: pathVars,
1588
+ uriQuery: queryParams
1589
+ };
1590
+
1591
+ try {
1592
+ // Make the call -
1593
+ // identifyRequest(entity, action, requestObj, returnDataFlag, callback)
1594
+ return this.requestHandlerInst.identifyRequest('Auth', 'logout', reqObj, true, (irReturnData, irReturnError) => {
1595
+ // if we received an error or their is no response on the results
1596
+ // return an error
1597
+ if (irReturnError) {
1598
+ /* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
1599
+ return callback(null, irReturnError);
1600
+ }
1601
+ if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
1602
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['logout'], null, null, null);
1603
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1604
+ return callback(null, errorObj);
1605
+ }
1606
+
1607
+ /* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
1608
+ // return the response
1609
+ return callback(irReturnData, null);
1610
+ });
1611
+ } catch (ex) {
1612
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
1613
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1614
+ return callback(null, errorObj);
1615
+ }
1616
+ }
1617
+
1618
+ /**
1619
+ * @function processEvent
1620
+ * @pronghornType method
1621
+ * @name processEvent
1622
+ * @summary Receive Event
1623
+ *
1624
+ * @param {object} values - Values object to be created with record
1625
+ * @param {getCallback} callback - a callback function to return the result
1626
+ * @return {object} results - An object containing the response of the action
1627
+ *
1628
+ * @route {POST} /processEvent
1629
+ * @roles admin
1630
+ * @task true
1631
+ */
1632
+ /* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
1633
+ processEvent(values, callback) {
1634
+ const meth = 'adapter-processEvent';
1635
+ const origin = `${this.id}-${meth}`;
1636
+ log.trace(origin);
1637
+
1638
+ if (this.suspended && this.suspendMode === 'error') {
1639
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
1640
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1641
+ return callback(null, errorObj);
1642
+ }
1643
+
1644
+ /* HERE IS WHERE YOU VALIDATE DATA */
1645
+ if (values === undefined || values === null || values === '') {
1646
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['values'], null, null, null);
1647
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1648
+ return callback(null, errorObj);
1649
+ }
1650
+
1651
+ /* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
1652
+ const queryParamsAvailable = { };
1653
+ const queryParams = {
1654
+ fields: 'values(Incident Number,InstanceId)'
1655
+ };
1656
+ const pathVars = [];
1657
+ const bodyVars = { values };
1658
+
1659
+ // loop in template. long callback arg name to avoid identifier conflicts
1660
+ Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
1661
+ if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
1662
+ && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
1663
+ queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
1664
+ }
1665
+ });
1666
+
1667
+ // set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
1668
+ // see adapter code documentation for more information on the request object's fields
1669
+ const reqObj = {
1670
+ payload: bodyVars,
1671
+ uriPathVars: pathVars,
1672
+ uriQuery: queryParams
1673
+ };
1674
+
1675
+ try {
1676
+ // Make the call -
1677
+ // identifyRequest(entity, action, requestObj, returnDataFlag, callback)
1678
+ return this.requestHandlerInst.identifyRequest('Event', 'processEvent', reqObj, true, (irReturnData, irReturnError) => {
1679
+ // if we received an error or their is no response on the results
1680
+ // return an error
1681
+ if (irReturnError) {
1682
+ /* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
1683
+ return callback(null, irReturnError);
1684
+ }
1685
+ if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
1686
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['processEvent'], null, null, null);
1687
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1688
+ return callback(null, errorObj);
1689
+ }
1690
+
1691
+ /* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
1692
+ // return the response
1693
+ return callback(irReturnData, null);
1694
+ });
1695
+ } catch (ex) {
1696
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
1697
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1698
+ return callback(null, errorObj);
1699
+ }
1700
+ }
1701
+
1702
+ /**
1703
+ * @function createIncident
1704
+ * @pronghornType method
1705
+ * @name createIncident
1706
+ * @summary Create Incident
1707
+ *
1708
+ * @param {object} values - Values object to be created with record
1709
+ * @param {getCallback} callback - a callback function to return the result
1710
+ * @return {object} results - An object containing the response of the action
1711
+ *
1712
+ * @route {POST} /createIncident
1713
+ * @roles admin
1714
+ * @task true
1715
+ */
1716
+ /* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
1717
+ createIncident(values, callback) {
1718
+ const meth = 'adapter-createIncident';
1719
+ const origin = `${this.id}-${meth}`;
1720
+ log.trace(origin);
1721
+
1722
+ if (this.suspended && this.suspendMode === 'error') {
1723
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
1724
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1725
+ return callback(null, errorObj);
1726
+ }
1727
+
1728
+ /* HERE IS WHERE YOU VALIDATE DATA */
1729
+ if (values === undefined || values === null || values === '') {
1730
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['values'], null, null, null);
1731
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1732
+ return callback(null, errorObj);
1733
+ }
1734
+
1735
+ /* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
1736
+ const queryParamsAvailable = { };
1737
+ const queryParams = {
1738
+ fields: 'values(Incident Number,InstanceId)'
1739
+ };
1740
+ const pathVars = [];
1741
+ const bodyVars = { values };
1742
+
1743
+ // loop in template. long callback arg name to avoid identifier conflicts
1744
+ Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
1745
+ if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
1746
+ && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
1747
+ queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
1748
+ }
1749
+ });
1750
+
1751
+ // set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
1752
+ // see adapter code documentation for more information on the request object's fields
1753
+ const reqObj = {
1754
+ payload: bodyVars,
1755
+ uriPathVars: pathVars,
1756
+ uriQuery: queryParams
1757
+ };
1758
+
1759
+ try {
1760
+ // Make the call -
1761
+ // identifyRequest(entity, action, requestObj, returnDataFlag, callback)
1762
+ return this.requestHandlerInst.identifyRequest('Incident', 'createIncident', reqObj, true, (irReturnData, irReturnError) => {
1763
+ // if we received an error or their is no response on the results
1764
+ // return an error
1765
+ if (irReturnError) {
1766
+ /* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
1767
+ return callback(null, irReturnError);
1768
+ }
1769
+ if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
1770
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['createIncident'], null, null, null);
1771
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1772
+ return callback(null, errorObj);
1773
+ }
1774
+
1775
+ /* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
1776
+ // return the response
1777
+ return callback(irReturnData, null);
1778
+ });
1779
+ } catch (ex) {
1780
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
1781
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1782
+ return callback(null, errorObj);
1783
+ }
1784
+ }
1785
+
1786
+ /**
1787
+ * @function updateIncident
1788
+ * @pronghornType method
1789
+ * @name updateIncident
1790
+ * @summary Update Incident
1791
+ *
1792
+ * @param {string} requestId - Request ID for Incident
1793
+ * @param {object} values - Values object for updating the incident
1794
+ * @param {getCallback} callback - a callback function to return the result
1795
+ * @return {object} results - An object containing the response of the action
1796
+ *
1797
+ * @route {POST} /updateIncident
1798
+ * @roles admin
1799
+ * @task true
1800
+ */
1801
+ /* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
1802
+ updateIncident(requestId, values, callback) {
1803
+ const meth = 'adapter-updateIncident';
1804
+ const origin = `${this.id}-${meth}`;
1805
+ log.trace(origin);
1806
+
1807
+ if (this.suspended && this.suspendMode === 'error') {
1808
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
1809
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1810
+ return callback(null, errorObj);
1811
+ }
1812
+
1813
+ /* HERE IS WHERE YOU VALIDATE DATA */
1814
+ if (requestId === undefined || requestId === null || requestId === '') {
1815
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['requestId'], null, null, null);
1816
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1817
+ return callback(null, errorObj);
1818
+ }
1819
+
1820
+ if (values === undefined || values === null || values === '') {
1821
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['values'], null, null, null);
1822
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1823
+ return callback(null, errorObj);
1824
+ }
1825
+
1826
+ /* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
1827
+ const queryParamsAvailable = { };
1828
+ const queryParams = {
1829
+ fields: 'values(Incident Number)'
1830
+ };
1831
+ const pathVars = [`${requestId}`];
1832
+ const bodyVars = { values };
1833
+
1834
+ // loop in template. long callback arg name to avoid identifier conflicts
1835
+ Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
1836
+ if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
1837
+ && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
1838
+ queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
1839
+ }
1840
+ });
1841
+
1842
+ // set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
1843
+ // see adapter code documentation for more information on the request object's fields
1844
+ const reqObj = {
1845
+ payload: bodyVars,
1846
+ uriPathVars: pathVars,
1847
+ uriQuery: queryParams
1848
+ };
1849
+
1850
+ try {
1851
+ // Make the call -
1852
+ // identifyRequest(entity, action, requestObj, returnDataFlag, callback)
1853
+ return this.requestHandlerInst.identifyRequest('Incident', 'updateIncident', reqObj, true, (irReturnData, irReturnError) => {
1854
+ // if we received an error or their is no response on the results
1855
+ // return an error
1856
+ if (irReturnError) {
1857
+ /* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
1858
+ return callback(null, irReturnError);
1859
+ }
1860
+ if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
1861
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['updateIncident'], null, null, null);
1862
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1863
+ return callback(null, errorObj);
1864
+ }
1865
+
1866
+ /* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
1867
+ // return the response
1868
+ return callback(irReturnData, null);
1869
+ });
1870
+ } catch (ex) {
1871
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
1872
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1873
+ return callback(null, errorObj);
1874
+ }
1875
+ }
1876
+
1877
+ /**
1878
+ * @function getIncident
1879
+ * @pronghornType method
1880
+ * @name getIncident
1881
+ * @summary Get Incident
1882
+ *
1883
+ * @param {string} instanceId - instanceId from the createIncident response
1884
+ * @param {getCallback} callback - a callback function to return the result
1885
+ * @return {object} results - An object containing the response of the action
1886
+ *
1887
+ * @route {POST} /getIncident
1888
+ * @roles admin
1889
+ * @task true
1890
+ */
1891
+ /* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
1892
+ getIncident(instanceId, callback) {
1893
+ const meth = 'adapter-getIncident';
1894
+ const origin = `${this.id}-${meth}`;
1895
+ log.trace(origin);
1896
+
1897
+ if (this.suspended && this.suspendMode === 'error') {
1898
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
1899
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1900
+ return callback(null, errorObj);
1901
+ }
1902
+
1903
+ /* HERE IS WHERE YOU VALIDATE DATA */
1904
+ if (instanceId === undefined || instanceId === null || instanceId === '') {
1905
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['instanceId'], null, null, null);
1906
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1907
+ return callback(null, errorObj);
1908
+ }
1909
+
1910
+ /* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
1911
+ const queryParamsAvailable = { q: `('InstanceId'="${instanceId}") ` };
1912
+ const queryParams = {};
1913
+ const pathVars = [];
1914
+ const bodyVars = { };
1915
+
1916
+ // loop in template. long callback arg name to avoid identifier conflicts
1917
+ Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
1918
+ if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
1919
+ && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
1920
+ queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
1921
+ }
1922
+ });
1923
+
1924
+ // set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
1925
+ // see adapter code documentation for more information on the request object's fields
1926
+ const reqObj = {
1927
+ payload: bodyVars,
1928
+ uriPathVars: pathVars,
1929
+ uriQuery: queryParams
1930
+ };
1931
+
1932
+ try {
1933
+ // Make the call -
1934
+ // identifyRequest(entity, action, requestObj, returnDataFlag, callback)
1935
+ return this.requestHandlerInst.identifyRequest('Incident', 'getIncident', reqObj, true, (irReturnData, irReturnError) => {
1936
+ // if we received an error or their is no response on the results
1937
+ // return an error
1938
+ if (irReturnError) {
1939
+ /* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
1940
+ return callback(null, irReturnError);
1941
+ }
1942
+ if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
1943
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getIncident'], null, null, null);
1944
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1945
+ return callback(null, errorObj);
1946
+ }
1947
+
1948
+ /* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
1949
+ // return the response
1950
+ return callback(irReturnData, null);
1951
+ });
1952
+ } catch (ex) {
1953
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
1954
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1955
+ return callback(null, errorObj);
1956
+ }
1957
+ }
1958
+
1959
+ /**
1960
+ * @function getIncidents
1961
+ * @pronghornType method
1962
+ * @name getIncidents
1963
+ * @summary Get Incidents
1964
+ *
1965
+ * @param {string} query - Query string for incidents
1966
+ * @param {getCallback} callback - a callback function to return the result
1967
+ * @return {object} results - An object containing the response of the action
1968
+ *
1969
+ * @route {POST} /getIncidents
1970
+ * @roles admin
1971
+ * @task true
1972
+ */
1973
+ /* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
1974
+ getIncidents(query, callback) {
1975
+ const meth = 'adapter-getIncidents';
1976
+ const origin = `${this.id}-${meth}`;
1977
+ log.trace(origin);
1978
+
1979
+ if (this.suspended && this.suspendMode === 'error') {
1980
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
1981
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1982
+ return callback(null, errorObj);
1983
+ }
1984
+
1985
+ /* HERE IS WHERE YOU VALIDATE DATA */
1986
+ if (query === undefined || query === null || query === '') {
1987
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['query'], null, null, null);
1988
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1989
+ return callback(null, errorObj);
1990
+ }
1991
+
1992
+ /* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
1993
+ const queryParamsAvailable = { q: query };
1994
+ const queryParams = { };
1995
+ const pathVars = [];
1996
+ const bodyVars = { };
1997
+
1998
+ // loop in template. long callback arg name to avoid identifier conflicts
1999
+ Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
2000
+ if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
2001
+ && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
2002
+ queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
2003
+ }
2004
+ });
2005
+
2006
+ // set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
2007
+ // see adapter code documentation for more information on the request object's fields
2008
+ const reqObj = {
2009
+ payload: bodyVars,
2010
+ uriPathVars: pathVars,
2011
+ uriQuery: queryParams
2012
+ };
2013
+
2014
+ try {
2015
+ // Make the call -
2016
+ // identifyRequest(entity, action, requestObj, returnDataFlag, callback)
2017
+ return this.requestHandlerInst.identifyRequest('Incident', 'getIncidents', reqObj, true, (irReturnData, irReturnError) => {
2018
+ // if we received an error or their is no response on the results
2019
+ // return an error
2020
+ if (irReturnError) {
2021
+ /* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
2022
+ return callback(null, irReturnError);
2023
+ }
2024
+ if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
2025
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getIncidents'], null, null, null);
2026
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
2027
+ return callback(null, errorObj);
2028
+ }
2029
+
2030
+ /* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
2031
+ // return the response
2032
+ return callback(irReturnData, null);
2033
+ });
2034
+ } catch (ex) {
2035
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
2036
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
2037
+ return callback(null, errorObj);
2038
+ }
2039
+ }
2040
+
2041
+ /**
2042
+ * @function createChangeRequest
2043
+ * @pronghornType method
2044
+ * @name createChangeRequest
2045
+ * @summary Create Change Request
2046
+ *
2047
+ * @param {object} values - Values object to be created with record
2048
+ * @param {getCallback} callback - a callback function to return the result
2049
+ * @return {object} results - An object containing the response of the action
2050
+ *
2051
+ * @route {POST} /createChangeRequest
2052
+ * @roles admin
2053
+ * @task true
2054
+ */
2055
+ /* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
2056
+ createChangeRequest(values, callback) {
2057
+ const meth = 'adapter-createChangeRequest';
2058
+ const origin = `${this.id}-${meth}`;
2059
+ log.trace(origin);
2060
+
2061
+ if (this.suspended && this.suspendMode === 'error') {
2062
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
2063
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
2064
+ return callback(null, errorObj);
2065
+ }
2066
+
2067
+ /* HERE IS WHERE YOU VALIDATE DATA */
2068
+ if (values === undefined || values === null || values === '') {
2069
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['values'], null, null, null);
2070
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
2071
+ return callback(null, errorObj);
2072
+ }
2073
+
2074
+ /* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
2075
+ const queryParamsAvailable = { };
2076
+ const queryParams = {
2077
+ fields: 'values(Infrastructure Change Id,InstanceId)'
2078
+ };
2079
+ const pathVars = [];
2080
+ const bodyVars = { values };
2081
+
2082
+ // loop in template. long callback arg name to avoid identifier conflicts
2083
+ Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
2084
+ if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
2085
+ && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
2086
+ queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
2087
+ }
2088
+ });
2089
+
2090
+ // set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
2091
+ // see adapter code documentation for more information on the request object's fields
2092
+ const reqObj = {
2093
+ payload: bodyVars,
2094
+ uriPathVars: pathVars,
2095
+ uriQuery: queryParams
2096
+ };
2097
+
2098
+ try {
2099
+ // Make the call -
2100
+ // identifyRequest(entity, action, requestObj, returnDataFlag, callback)
2101
+ return this.requestHandlerInst.identifyRequest('ChangeRequest', 'createChangeRequest', reqObj, true, (irReturnData, irReturnError) => {
2102
+ // if we received an error or their is no response on the results
2103
+ // return an error
2104
+ if (irReturnError) {
2105
+ /* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
2106
+ return callback(null, irReturnError);
2107
+ }
2108
+ if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
2109
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['createChangeRequest'], null, null, null);
2110
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
2111
+ return callback(null, errorObj);
2112
+ }
2113
+
2114
+ /* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
2115
+ // return the response
2116
+ return callback(irReturnData, null);
2117
+ });
2118
+ } catch (ex) {
2119
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
2120
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
2121
+ return callback(null, errorObj);
2122
+ }
2123
+ }
2124
+
2125
+ /**
2126
+ * @function updateChangeRequest
2127
+ * @pronghornType method
2128
+ * @name updateChangeRequest
2129
+ * @summary Update ChangeRequest
2130
+ *
2131
+ * @param {string} requestId - Request Id of Change Request
2132
+ * @param {object} values - Values object for updating the Change Request
2133
+ * @param {getCallback} callback - a callback function to return the result
2134
+ * @return {object} results - An object containing the response of the action
2135
+ *
2136
+ * @route {POST} /updateChangeRequest
2137
+ * @roles admin
2138
+ * @task true
2139
+ */
2140
+ /* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
2141
+ updateChangeRequest(requestId, values, callback) {
2142
+ const meth = 'adapter-updateChangeRequest';
2143
+ const origin = `${this.id}-${meth}`;
2144
+ log.trace(origin);
2145
+
2146
+ if (this.suspended && this.suspendMode === 'error') {
2147
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
2148
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
2149
+ return callback(null, errorObj);
2150
+ }
2151
+
2152
+ /* HERE IS WHERE YOU VALIDATE DATA */
2153
+ if (requestId === undefined || requestId === null || requestId === '') {
2154
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['requestId'], null, null, null);
2155
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
2156
+ return callback(null, errorObj);
2157
+ }
2158
+
2159
+ if (values === undefined || values === null || values === '') {
2160
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['values'], null, null, null);
2161
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
2162
+ return callback(null, errorObj);
2163
+ }
2164
+
2165
+ /* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
2166
+ const queryParamsAvailable = { };
2167
+ const queryParams = {
2168
+ fields: 'values(Infrastructure Change Id)'
2169
+ };
2170
+ const pathVars = [`${requestId}`];
2171
+ const bodyVars = { values };
2172
+
2173
+ // loop in template. long callback arg name to avoid identifier conflicts
2174
+ Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
2175
+ if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
2176
+ && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
2177
+ queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
2178
+ }
2179
+ });
2180
+
2181
+ // set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
2182
+ // see adapter code documentation for more information on the request object's fields
2183
+ const reqObj = {
2184
+ payload: bodyVars,
2185
+ uriPathVars: pathVars,
2186
+ uriQuery: queryParams
2187
+ };
2188
+
2189
+ try {
2190
+ // Make the call -
2191
+ // identifyRequest(entity, action, requestObj, returnDataFlag, callback)
2192
+ return this.requestHandlerInst.identifyRequest('ChangeRequest', 'updateChangeRequest', reqObj, true, (irReturnData, irReturnError) => {
2193
+ // if we received an error or their is no response on the results
2194
+ // return an error
2195
+ if (irReturnError) {
2196
+ /* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
2197
+ return callback(null, irReturnError);
2198
+ }
2199
+ if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
2200
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['updateChangeRequest'], null, null, null);
2201
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
2202
+ return callback(null, errorObj);
2203
+ }
2204
+
2205
+ /* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
2206
+ // return the response
2207
+ return callback(irReturnData, null);
2208
+ });
2209
+ } catch (ex) {
2210
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
2211
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
2212
+ return callback(null, errorObj);
2213
+ }
2214
+ }
2215
+
2216
+ /**
2217
+ * @function getChangeRequest
2218
+ * @pronghornType method
2219
+ * @name getChangeRequest
2220
+ * @summary Get ChangeRequest
2221
+ *
2222
+ * @param {string} instanceId - instanceId from the createChangeRequest response
2223
+ * @param {getCallback} callback - a callback function to return the result
2224
+ * @return {object} results - An object containing the response of the action
2225
+ *
2226
+ * @route {POST} /getChangeRequest
2227
+ * @roles admin
2228
+ * @task true
2229
+ */
2230
+ /* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
2231
+ getChangeRequest(instanceId, callback) {
2232
+ const meth = 'adapter-getChangeRequest';
2233
+ const origin = `${this.id}-${meth}`;
2234
+ log.trace(origin);
2235
+
2236
+ if (this.suspended && this.suspendMode === 'error') {
2237
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
2238
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
2239
+ return callback(null, errorObj);
2240
+ }
2241
+
2242
+ /* HERE IS WHERE YOU VALIDATE DATA */
2243
+ if (instanceId === undefined || instanceId === null || instanceId === '') {
2244
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['instanceId'], null, null, null);
2245
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
2246
+ return callback(null, errorObj);
2247
+ }
2248
+
2249
+ /* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
2250
+ const queryParamsAvailable = { q: `('InstanceId'="${instanceId}") ` };
2251
+ const queryParams = {};
2252
+ const pathVars = [];
2253
+ const bodyVars = { };
2254
+
2255
+ // loop in template. long callback arg name to avoid identifier conflicts
2256
+ Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
2257
+ if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
2258
+ && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
2259
+ queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
2260
+ }
2261
+ });
2262
+
2263
+ // set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
2264
+ // see adapter code documentation for more information on the request object's fields
2265
+ const reqObj = {
2266
+ payload: bodyVars,
2267
+ uriPathVars: pathVars,
2268
+ uriQuery: queryParams
2269
+ };
2270
+
2271
+ try {
2272
+ // Make the call -
2273
+ // identifyRequest(entity, action, requestObj, returnDataFlag, callback)
2274
+ return this.requestHandlerInst.identifyRequest('ChangeRequest', 'getChangeRequest', reqObj, true, (irReturnData, irReturnError) => {
2275
+ // if we received an error or their is no response on the results
2276
+ // return an error
2277
+ if (irReturnError) {
2278
+ /* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
2279
+ return callback(null, irReturnError);
2280
+ }
2281
+ if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
2282
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getChangeRequest'], null, null, null);
2283
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
2284
+ return callback(null, errorObj);
2285
+ }
2286
+
2287
+ /* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
2288
+ // return the response
2289
+ return callback(irReturnData, null);
2290
+ });
2291
+ } catch (ex) {
2292
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
2293
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
2294
+ return callback(null, errorObj);
2295
+ }
2296
+ }
2297
+
2298
+ /**
2299
+ * @function getChangeRequests
2300
+ * @pronghornType method
2301
+ * @name getChangeRequests
2302
+ * @summary Get ChangeRequests
2303
+ *
2304
+ * @param {string} query - Query string for Change Requests
2305
+ * @param {getCallback} callback - a callback function to return the result
2306
+ * @return {object} results - An object containing the response of the action
2307
+ *
2308
+ * @route {POST} /getChangeRequests
2309
+ * @roles admin
2310
+ * @task true
2311
+ */
2312
+ /* YOU CAN CHANGE THE PARAMETERS YOU TAKE IN HERE AND IN THE pronghorn.json FILE */
2313
+ getChangeRequests(query, callback) {
2314
+ const meth = 'adapter-getChangeRequests';
2315
+ const origin = `${this.id}-${meth}`;
2316
+ log.trace(origin);
2317
+
2318
+ if (this.suspended && this.suspendMode === 'error') {
2319
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
2320
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
2321
+ return callback(null, errorObj);
2322
+ }
2323
+
2324
+ /* HERE IS WHERE YOU VALIDATE DATA */
2325
+ if (query === undefined || query === null || query === '') {
2326
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['query'], null, null, null);
2327
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
2328
+ return callback(null, errorObj);
2329
+ }
2330
+
2331
+ /* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
2332
+ const queryParamsAvailable = { q: query };
2333
+ const queryParams = { };
2334
+ const pathVars = [];
2335
+ const bodyVars = { };
2336
+
2337
+ // loop in template. long callback arg name to avoid identifier conflicts
2338
+ Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
2339
+ if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
2340
+ && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
2341
+ queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
2342
+ }
2343
+ });
2344
+
2345
+ // set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders, authData, callProperties, filter, priority, event
2346
+ // see adapter code documentation for more information on the request object's fields
2347
+ const reqObj = {
2348
+ payload: bodyVars,
2349
+ uriPathVars: pathVars,
2350
+ uriQuery: queryParams
2351
+ };
2352
+
2353
+ try {
2354
+ // Make the call -
2355
+ // identifyRequest(entity, action, requestObj, returnDataFlag, callback)
2356
+ return this.requestHandlerInst.identifyRequest('ChangeRequest', 'getChangeRequests', reqObj, true, (irReturnData, irReturnError) => {
2357
+ // if we received an error or their is no response on the results
2358
+ // return an error
2359
+ if (irReturnError) {
2360
+ /* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
2361
+ return callback(null, irReturnError);
2362
+ }
2363
+ if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
2364
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getChangeRequests'], null, null, null);
2365
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
2366
+ return callback(null, errorObj);
2367
+ }
2368
+
2369
+ /* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
2370
+ // return the response
2371
+ return callback(irReturnData, null);
2372
+ });
2373
+ } catch (ex) {
2374
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
2375
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
2376
+ return callback(null, errorObj);
2377
+ }
2378
+ }
2379
+ }
2380
+
2381
+ module.exports = BmcHelixItsm;