@manyos/smileconnect-api 1.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. package/.github/workflows/nodejs.yml +26 -0
  2. package/CHANGELOG.md +75 -0
  3. package/Dockerfile +21 -0
  4. package/README.md +1 -0
  5. package/app.js +316 -0
  6. package/conf/clients.json +2491 -0
  7. package/conf/mapping.json +1048 -0
  8. package/conf/scripts/p1.js +11 -0
  9. package/conf/scripts/p2.js +1 -0
  10. package/conf/scripts/p3.js +1 -0
  11. package/conf/scripts/p4.js +2 -0
  12. package/conf/scripts/script1.js +2 -0
  13. package/conf/scripts/script2.js +2 -0
  14. package/conf/scripts/script3.js +2 -0
  15. package/controller/cmdbobjectController.js +291 -0
  16. package/controller/eventLogController.js +78 -0
  17. package/controller/orgdataController.js +440 -0
  18. package/controller/relatedObjectsController.js +194 -0
  19. package/controller/scriptController.js +213 -0
  20. package/controller/taskController.js +368 -0
  21. package/controller/templateController.js +97 -0
  22. package/controller/ticketCIRelationController.js +522 -0
  23. package/controller/ticketController.js +329 -0
  24. package/controller/ticketWorkLogController.js +195 -0
  25. package/docs/.gitattributes +48 -0
  26. package/docs/404.html +13 -0
  27. package/docs/CNAME +1 -0
  28. package/docs/Gemfile +7 -0
  29. package/docs/Gemfile.lock +249 -0
  30. package/docs/_config.yml +257 -0
  31. package/docs/_data/SocialNetworks.yml +92 -0
  32. package/docs/_data/ui-text.yml +494 -0
  33. package/docs/_includes/disqus.html +17 -0
  34. package/docs/_includes/ext-css.html +7 -0
  35. package/docs/_includes/ext-js.html +7 -0
  36. package/docs/_includes/fb-comment.html +14 -0
  37. package/docs/_includes/footer-minimal.html +16 -0
  38. package/docs/_includes/footer-scripts.html +32 -0
  39. package/docs/_includes/footer.html +51 -0
  40. package/docs/_includes/google_analytics.html +14 -0
  41. package/docs/_includes/gtag.html +11 -0
  42. package/docs/_includes/gtm_body.html +6 -0
  43. package/docs/_includes/gtm_head.html +9 -0
  44. package/docs/_includes/head.html +131 -0
  45. package/docs/_includes/header.html +76 -0
  46. package/docs/_includes/just_comments.html +4 -0
  47. package/docs/_includes/matomo.html +17 -0
  48. package/docs/_includes/nav.html +57 -0
  49. package/docs/_includes/social-share.html +42 -0
  50. package/docs/_includes/staticman-comment.html +22 -0
  51. package/docs/_includes/staticman-comments.html +81 -0
  52. package/docs/_layouts/base.html +35 -0
  53. package/docs/_layouts/default.html +9 -0
  54. package/docs/_layouts/minimal.html +26 -0
  55. package/docs/_layouts/page.html +26 -0
  56. package/docs/_layouts/post.html +82 -0
  57. package/docs/_posts/2015-02-28-test-markdown.md +77 -0
  58. package/docs/aboutme.md +18 -0
  59. package/docs/css/bootstrap-social.css +147 -0
  60. package/docs/css/bootstrap-theme.css +476 -0
  61. package/docs/css/bootstrap-theme.css.map +1 -0
  62. package/docs/css/bootstrap-theme.min.css +5 -0
  63. package/docs/css/bootstrap.css +6566 -0
  64. package/docs/css/bootstrap.css.map +1 -0
  65. package/docs/css/bootstrap.min.css +5 -0
  66. package/docs/css/main-minimal.css +13 -0
  67. package/docs/css/main.css +788 -0
  68. package/docs/css/normalize.css +427 -0
  69. package/docs/css/pygment_highlights.css +61 -0
  70. package/docs/css/staticman.css +180 -0
  71. package/docs/eventlog/events.md +65 -0
  72. package/docs/feed.xml +24 -0
  73. package/docs/general/architecture.md +10 -0
  74. package/docs/general/config.md +192 -0
  75. package/docs/general/field-management.md +119 -0
  76. package/docs/general/release-notes.md +9 -0
  77. package/docs/getting-started.md +19 -0
  78. package/docs/howto/cmdbobjects.md +339 -0
  79. package/docs/howto/incident-worklogs.md +186 -0
  80. package/docs/howto/incidents.md +244 -0
  81. package/docs/howto/sample-config.md +518 -0
  82. package/docs/howto/token.md +71 -0
  83. package/docs/howto/worklog-attachment.md +113 -0
  84. package/docs/img/404-southpark.jpg +0 -0
  85. package/docs/img/architecture.jpeg +0 -0
  86. package/docs/img/attachment-upload.png +0 -0
  87. package/docs/img/avatar-icon.png +0 -0
  88. package/docs/img/bgimage.png +0 -0
  89. package/docs/img/gb-isapi.jpg +0 -0
  90. package/docs/img/install-steps.gif +0 -0
  91. package/docs/img/workflow.png +0 -0
  92. package/docs/index.md +41 -0
  93. package/docs/installation.md +123 -0
  94. package/docs/js/bootstrap.js +2306 -0
  95. package/docs/js/bootstrap.min.js +7 -0
  96. package/docs/js/jquery-1.11.2.min.js +4 -0
  97. package/docs/js/main.js +140 -0
  98. package/docs/js/staticman.js +54 -0
  99. package/docs/openapi.json +15097 -0
  100. package/docs/postinstall.md +169 -0
  101. package/docs/preinstall.md +19 -0
  102. package/docs/spec/index.html +24 -0
  103. package/docs/staticman.yml +110 -0
  104. package/docs/tags.html +34 -0
  105. package/docs/workflow.md +127 -0
  106. package/nodemon.json +3 -0
  107. package/package.json +46 -0
  108. package/routes/appConfigRoutes.js +352 -0
  109. package/routes/ciRelationRoutes.js +38 -0
  110. package/routes/cmdbObjectRoutes.js +154 -0
  111. package/routes/organisationRoutes.js +121 -0
  112. package/routes/peopleRelationRoutes.js +38 -0
  113. package/routes/personRoutes.js +131 -0
  114. package/routes/supportgroupRoutes.js +122 -0
  115. package/routes/taskRoutes.js +306 -0
  116. package/routes/templateRoutes.js +67 -0
  117. package/routes/ticketRoutes.js +181 -0
  118. package/routes/ticketWorkLogRoutes.js +185 -0
  119. package/screwdriver.yaml +52 -0
  120. package/test/appTest.js +3 -0
  121. package/test/changeTest.js +541 -0
  122. package/test/cmdbobjectTest.js +167 -0
  123. package/test/files/logo.png +0 -0
  124. package/test/incidentTest.js +539 -0
  125. package/test/orgdataTest.js +156 -0
  126. package/test/problemTest.js +512 -0
  127. package/test/templateTest.js +80 -0
  128. package/test/testUtils.js +21 -0
  129. package/test/workorderTest.js +544 -0
  130. package/util/arquery.js +416 -0
  131. package/util/auth.js +37 -0
  132. package/util/cache.service.js +52 -0
  133. package/util/config.js +361 -0
  134. package/util/constants.js +73 -0
  135. package/util/mappingUtil.js +96 -0
  136. package/util/paramHelper.js +43 -0
  137. package/util/relationUtil.js +63 -0
  138. package/util/responsehandler.js +92 -0
  139. package/util/schemas/clientConfigSchema.js +180 -0
  140. package/util/schemas/fieldMappingSchema.js +211 -0
  141. package/util/searchUtil.js +148 -0
package/util/config.js ADDED
@@ -0,0 +1,361 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const log = require('@manyos/logger').setupLog('SMILEconnect_' + path.basename(__filename));
4
+
5
+ const clientConfigFile = 'conf/clients.json';
6
+ const arquery = require('../util/arquery');
7
+ const CacheService = require ('../util/cache.service');
8
+
9
+ const CONSTANTS = require('./constants');
10
+
11
+ const configCache = new CacheService(process.env.CACHETTL_CONFIG || 3600); // Create a new cache service instance
12
+
13
+ const clientConfigItemTemplate = {
14
+ "basequery": "1=2",
15
+ "fields": [],
16
+ "constants": []
17
+ };
18
+
19
+ function getClients() {
20
+ log.debug('start to read config from file', clientConfigFile);
21
+ let rawdata = fs.readFileSync(clientConfigFile);
22
+ return JSON.parse(rawdata);
23
+ }
24
+
25
+ function getClientConfig(clientName) {
26
+ log.debug('get clientconfig for', clientName);
27
+ const config = getClients();
28
+ const client = config.find(function(element) {
29
+ return element.name === clientName;
30
+ });
31
+ if (client !== null && client !== undefined) {
32
+ return client.config;
33
+ } else {
34
+ return {}
35
+ //TODO implement only for NON-Admin
36
+ //throw ('Client ' + clientName + ' not found in configuration.');
37
+ }
38
+ }
39
+
40
+ function getClient(client) {
41
+ log.debug('get clientconfig for', client);
42
+ const config = getClients();
43
+ return config.find(function(element) {
44
+ return element.name === client;
45
+ });
46
+ }
47
+
48
+ function getMapping(objectType) {
49
+ const configFile = 'conf/mapping.json';
50
+ log.debug('start to read config from file', configFile);
51
+ let rawdata = fs.readFileSync(configFile);
52
+ return JSON.parse(rawdata)[objectType] || [];
53
+ }
54
+
55
+ function getMappings() {
56
+ const configFile = 'conf/mapping.json';
57
+ log.debug('start to read config from file', configFile);
58
+ let rawdata = fs.readFileSync(configFile);
59
+ return JSON.parse(rawdata) || {};
60
+ }
61
+
62
+ function setMapping(objectType, mapping) {
63
+ const configFile = 'conf/mapping.json';
64
+ log.debug('start to update config from file', configFile);
65
+ log.debug('set mapping data', objectType, mapping);
66
+ const data = JSON.parse(fs.readFileSync(configFile)) || {};
67
+ data[objectType] = mapping;
68
+ fs.writeFileSync(configFile, JSON.stringify(data, null, 2));
69
+ return true
70
+ }
71
+
72
+ function setMappings(mapping) {
73
+ const configFile = 'conf/mapping.json';
74
+ log.debug('start to update config from file', configFile);
75
+ log.debug('set mapping data', mapping);
76
+ fs.writeFileSync(configFile, JSON.stringify(mapping, null, 2));
77
+ return true
78
+ }
79
+
80
+ function setClient(clientName, clientConfig) {
81
+ log.debug('start to update config in file', clientConfigFile);
82
+ log.debug('set client data', clientName, clientConfig);
83
+ let config = JSON.parse(fs.readFileSync(clientConfigFile)) || {};
84
+ config = config.filter(function( obj ) {
85
+ return obj.name !== clientName;
86
+ });
87
+ config.push(clientConfig)
88
+ log.debug('new config', config);
89
+ fs.writeFileSync(clientConfigFile, JSON.stringify(config, null, 2));
90
+ return true
91
+ }
92
+
93
+ function deleteClient(clientName) {
94
+ log.debug('start to update config in file', clientConfigFile);
95
+ log.debug('delete client data', clientName);
96
+ let config = JSON.parse(fs.readFileSync(clientConfigFile)) || {};
97
+ config = config.filter(function( obj ) {
98
+ return obj.name !== clientName;
99
+ });
100
+ log.debug('new config', config);
101
+ fs.writeFileSync(clientConfigFile, JSON.stringify(config, null, 2));
102
+ return true
103
+ }
104
+
105
+ function getConstants(objectType) {
106
+ const configFile = 'conf/mapping.json';
107
+ log.debug('start to read config from file', configFile);
108
+ try {
109
+ let rawdata = fs.readFileSync(configFile);
110
+ return JSON.parse(rawdata)[objectType] || [];
111
+ } catch (e) {
112
+ log.error (e);
113
+ return []
114
+ }
115
+ }
116
+
117
+ function checkMapping() {
118
+ log.info('check mapping');
119
+ const mappingDefs = [
120
+ 'cmdbobject',
121
+ 'change',
122
+ 'newChange',
123
+ 'changeWorklog',
124
+ 'changeTemplate',
125
+ 'incident',
126
+ 'newIncident',
127
+ 'incidentWorklog',
128
+ 'incidentTemplate',
129
+ 'person',
130
+ 'problem',
131
+ 'newProblem',
132
+ 'problemTemplate',
133
+ 'problemWorklog',
134
+ 'supportGroup',
135
+ 'organisation',
136
+ 'workOrder',
137
+ 'newWorkOrder',
138
+ 'workOrderWorklog',
139
+ 'workOrderTemplate',
140
+ 'task',
141
+ 'newTask',
142
+ 'taskWorklog',
143
+ 'taskTemplate',
144
+ 'flowBuilder'
145
+ ];
146
+ const mappings = getMappings() || {};
147
+ const mappingKeys = Object.keys(mappings);
148
+ //delete too many
149
+ mappingKeys.forEach(key=>{
150
+ if (!mappingDefs.includes(key) && !key.startsWith('cmdbobject_')) {
151
+ log.info('delete from mapping', key);
152
+ delete mappings[key];
153
+ }
154
+ });
155
+ //add too less
156
+ mappingDefs.forEach(mappingDef => {
157
+ if (!mappingKeys.includes(mappingDef)) {
158
+ log.info('add to mapping', mappingDef);
159
+ mappings[mappingDef] = [];
160
+ }
161
+ });
162
+ //save
163
+ setMappings(mappings);
164
+ log.info('check mapping done');
165
+ }
166
+
167
+ function checkClientConfig(client) {
168
+ const clientKeys = [
169
+ 'cmdbobject',
170
+ 'change',
171
+ 'changeWorklog',
172
+ 'changeTemplate',
173
+ 'incident',
174
+ 'incidentWorklog',
175
+ 'incidentTemplate',
176
+ 'person',
177
+ 'problem',
178
+ 'problemWorklog',
179
+ 'problemTemplate',
180
+ 'supportGroup',
181
+ 'organisation',
182
+ 'workOrder',
183
+ 'workOrderWorklog',
184
+ 'workOrderTemplate',
185
+ 'task',
186
+ 'taskWorklog',
187
+ 'taskTemplate',
188
+ 'flowBuilder'
189
+ ];
190
+ log.info('check config for client', client.name);
191
+ const clientConfig = client.config || {};
192
+ const clientConfigKeys = Object.keys(clientConfig);
193
+ //delete too many
194
+ clientConfigKeys.forEach(key=>{
195
+ if (!clientKeys.includes(key) && !(key === 'options')) {
196
+ log.info('delete from clientconfig', key);
197
+ delete clientConfig[key];
198
+ } else if (clientKeys.includes(key) && !(key === 'options')) {
199
+ if (!clientConfig[key].basequery) {
200
+ clientConfig[key].basequery = '';
201
+ log.info('add basequery', key);
202
+ }
203
+ if (!clientConfig[key].fields) {
204
+ clientConfig[key].fields = [];
205
+ log.info('add fields', key);
206
+ }
207
+ if (!clientConfig[key].constants) {
208
+ clientConfig[key].constants = [];
209
+ log.info('add constants', key);
210
+ }
211
+ if (!clientConfig[key].scripts) {
212
+ clientConfig[key].scripts = {};
213
+ log.info('add scripts', key);
214
+ }
215
+ }
216
+ });
217
+ //add too less
218
+ clientKeys.forEach(clientKey => {
219
+ if (!clientConfigKeys.includes(clientKey)) {
220
+ log.info('add to mapping', clientKey);
221
+ clientConfig[clientKey] = clientConfigItemTemplate;
222
+ }
223
+ });
224
+ client.config = clientConfig;
225
+ //save
226
+ setClient(client.name, client);
227
+ log.info('check config for client done', client.name);
228
+ }
229
+
230
+ function checkClientConfigs() {
231
+ log.info('check client configs');
232
+ const clientConfigs = getClients();
233
+ clientConfigs.forEach(clientConfig => {
234
+ checkClientConfig(clientConfig);
235
+ });
236
+ log.info('check client configs done');
237
+ }
238
+
239
+ function checkConfig() {
240
+ log.info('check config');
241
+ checkMapping();
242
+ checkClientConfigs();
243
+ log.info('check config done');
244
+ }
245
+
246
+ function getForms() {
247
+ log.debug('get forms');
248
+ const key = 'forms';
249
+ return configCache.get(key, async function () {
250
+ const result = await arquery.getMetaData();
251
+ return result;
252
+ });
253
+ }
254
+
255
+ function getFields(form) {
256
+ log.debug('get fields for', form);
257
+ const key = 'fields/' + form;
258
+ return configCache.get(key, async function () {
259
+ const result = await arquery.getMetaData(form);
260
+ return result;
261
+ });
262
+ }
263
+
264
+ const ticketConfig = {
265
+ "workorders": {
266
+ "forms": {
267
+ "regular": CONSTANTS.FORM_WORKORDER,
268
+ "new": CONSTANTS.FORM_WORKORDER_CREATE,
269
+ "workLog": CONSTANTS.FORM_WORKORDER_WORKLOG,
270
+ "assoc": CONSTANTS.FORM_WORKORDER_ASSOC,
271
+ "template": CONSTANTS.FORM_WORKORDER_TEMPLATE
272
+ },
273
+ "requestIdField": "Request ID",
274
+ "requestType": "workOrder",
275
+ "ticketIdField": "WorkOrder_ID",
276
+ "requestTypeWorkLog": "workOrderWorklog",
277
+ "requestTemplate": "workOrderTemplate",
278
+ "baseURI": "/v1/workorders",
279
+ "assocTicketKeyword": "MAINWORKORDER",
280
+ "assocTicketType": "Work Order",
281
+ "templateRequestId": "Request ID"
282
+ },
283
+ "incidents": {
284
+ "forms": {
285
+ "regular": CONSTANTS.FORM_INCIDENT,
286
+ "new": CONSTANTS.FORM_INCIDENT_CREATE,
287
+ "workLog": CONSTANTS.FORM_INCIDENT_WORKLOG,
288
+ "assoc": CONSTANTS.FORM_INCIDENT_ASSOC,
289
+ "template": CONSTANTS.FORM_INCIDENT_TEMPLATE
290
+ },
291
+ "requestIdField": "Entry ID",
292
+ "requestType": "incident",
293
+ "ticketIdField": "Incident Number",
294
+ "requestTypeWorkLog": "incidentWorklog",
295
+ "requestTemplate": "incidentTemplate",
296
+ "baseURI": "/v1/incidents",
297
+ "assocTicketKeyword": "MAINHELPDESK",
298
+ "assocTicketType":"Incident",
299
+ "templateRequestId": "HPD Template ID"
300
+ },
301
+ "changes": {
302
+ "forms": {
303
+ "regular": CONSTANTS.FORM_CHANGE,
304
+ "new": CONSTANTS.FORM_CHANGE_CREATE,
305
+ "workLog": CONSTANTS.FORM_CHANGE_WORKLOG,
306
+ "assoc": CONSTANTS.FORM_CHANGE_ASSOC,
307
+ "template": CONSTANTS.FORM_CHANGE_TEMPLATE
308
+ },
309
+ "requestIdField": "Request ID",
310
+ "requestType": "change",
311
+ "ticketIdField": "Infrastructure Change Id",
312
+ "requestTypeWorkLog": "changeWorklog",
313
+ "requestTemplate": "changeTemplate",
314
+ "baseURI": "/v1/changes",
315
+ "assocTicketKeyword": "MAINCHANGE",
316
+ "assocTicketType": "Infrastructure Change",
317
+ "templateRequestId": "CHG Template ID"
318
+ },
319
+ "problems": {
320
+ "forms": {
321
+ "regular": CONSTANTS.FORM_PROBLEM,
322
+ "new": CONSTANTS.FORM_PROBLEM_CREATE,
323
+ "workLog": CONSTANTS.FORM_PROBLEM_WORKLOG,
324
+ "assoc": CONSTANTS.FORM_PROBLEM_ASSOC,
325
+ "template": CONSTANTS.FORM_PROBLEM_TEMPLATE
326
+ },
327
+ "requestIdField": "Sys-Problem Investigation ID",
328
+ "requestType": "problem",
329
+ "ticketIdField": "Problem Investigation ID",
330
+ "requestTypeWorkLog": "problemWorklog",
331
+ "requestTemplate": "problemTemplate",
332
+ "baseURI": "/v1/problems",
333
+ "assocTicketKeyword": "MAINPROBLEM",
334
+ "assocTicketType": "Problem Investigation",
335
+ "templateRequestId": "PBM Template ID"
336
+ },
337
+ "tasks": {
338
+ "forms": {
339
+ "template": CONSTANTS.FORM_TASK_TEMPLATE
340
+ },
341
+ "requestTemplate": "taskTemplate",
342
+ "templateRequestId": "Template ID"
343
+ }
344
+
345
+ };
346
+
347
+ module.exports = {
348
+ getClientConfig,
349
+ getMapping,
350
+ getClient,
351
+ getClients,
352
+ setMapping,
353
+ getMappings,
354
+ setClient,
355
+ deleteClient,
356
+ setMappings,
357
+ checkConfig,
358
+ getForms,
359
+ getFields,
360
+ ticketConfig
361
+ };
@@ -0,0 +1,73 @@
1
+ module.exports = {
2
+ FORM_INCIDENT: "HPD:Help Desk",
3
+ FORM_INCIDENT_CREATE: "HPD:IncidentInterface_Create",
4
+ FORM_INCIDENT_WORKLOG: "HPD:WorkLog",
5
+ FORM_INCIDENT_ASSOC: "HPD:Associations",
6
+ FORM_INCIDENT_TEMPLATE: "HPD:Template",
7
+ FORM_CHANGE: "CHG:Infrastructure Change",
8
+ FORM_CHANGE_CREATE: "CHG:ChangeInterface_Create",
9
+ FORM_CHANGE_WORKLOG: "CHG:WorkLog",
10
+ FORM_CHANGE_ASSOC: "CHG:Associations",
11
+ FORM_CHANGE_TEMPLATE: "CHG:Template",
12
+ FORM_ASSET: "AST:BaseElement",
13
+ FORM_ASSET_TICKET_ASSOC: "AST:CMDB Associations",
14
+ FORM_TASK: "TMS:Task",
15
+ FORM_TASK_WORKLOG: "TMS:WorkInfo",
16
+ FORM_TASK_TEMPLATE: "TMS:TaskTemplate",
17
+ FORM_WORKORDER: "WOI:WorkOrder",
18
+ FORM_WORKORDER_CREATE: "WOI:WorkOrderInterface_Create",
19
+ FORM_WORKORDER_ASSOC: "WOI:Associations",
20
+ FORM_WORKORDER_WORKLOG: "WOI:WorkInfo",
21
+ FORM_WORKORDER_TEMPLATE: "WOI:Template",
22
+ FORM_APC_CLIENTS: "ClientConfig",
23
+ FORM_APC_MAPPING_FIELDS: "MappingFields",
24
+ FORM_APC_WEBHOOK: "Webhooks",
25
+ FORM_APC_FORMS_FIELDS: "FormFields",
26
+ FORM_APC_FORMS: "Forms",
27
+ FORM_APC_FORMS_META: "Metadata",
28
+
29
+ FORM_PEOPLE: "CTM:People",
30
+ FORM_SUPPORTGROUP: "CTM:Support Group",
31
+ FORM_ORGANISATION: "CTM:People Organization",
32
+
33
+ FORM_PROBLEM: "PBM:Problem Investigation",
34
+ FORM_PROBLEM_ASSOC: "PBM:Investigation Associations",
35
+ FORM_PROBLEM_CREATE: "PBM:ProblemInterface_Create",
36
+ FORM_PROBLEM_WORKLOG: "PBM:Investigation WorkLog",
37
+ FORM_PROBLEM_TEMPLATE: "PBM:Template",
38
+ FORM_SCHEMA_NAMES: "SHR:SchemaNames",
39
+ FORM_CMDB_CI_BASE: "BMC.CORE:BMC_BaseElement",
40
+ FORM_CMDB_AST_BASE: "AST:BaseElement",
41
+
42
+ FORM_SYS_ASSOCIATION_TYPES_OPPO: "SYS:AssocTypeOpposite",
43
+ FORM_SYS_ASSOCIATION_TYPES_LOOKUP: "SYS:AssociationTypeAssocLookUp",
44
+
45
+ EVENT_BASE_AST: "AST",
46
+
47
+ EVENT_BASE_APC: "APC",
48
+
49
+ EVENT_BASE_INC: "INC",
50
+ EVENT_BASE_INC_WORKLOG: "INC_Worklog",
51
+ EVENT_BASE_INC_WORKLOG_ATTACHTMENT: "INC_Worklog_Attachment",
52
+
53
+ EVENT_BASE_CHG: "CHG",
54
+ EVENT_BASE_CHG_WORKLOG: "CHG_Worklog",
55
+ EVENT_BASE_CHG_WORKLOG_ATTACHTMENT: "CHG_Worklog_Attachment",
56
+
57
+ EVENT_BASE_PBM: "PBM",
58
+ EVENT_BASE_PBM_WORKLOG: "PBM_Worklog",
59
+ EVENT_BASE_PBM_WORKLOG_ATTACHTMENT: "PBM_Worklog_Attachment",
60
+
61
+ EVENT_BASE_WOI: "WOI",
62
+
63
+ EVENT_ACTION_QUERY: 'Query',
64
+ EVENT_ACTION_CREATE: 'Create',
65
+ EVENT_ACTION_MODIFY: 'Modify',
66
+ EVENT_ACTION_SEARCH: 'Search',
67
+
68
+ EVENT_BASE_ORG_PEOPLE: "ORG_People",
69
+ EVENT_BASE_ORG_SUPPORTGROUP: "ORG_SupportGroup",
70
+ EVENT_BASE_ORG_ORGANISATION: "ORG_Organisation",
71
+
72
+ TEXT_CREATED_BY: "created by SMILEconnect."
73
+ }
@@ -0,0 +1,96 @@
1
+ const path = require('path');
2
+ const log = require('@manyos/logger').setupLog('SMILEconnect_' + path.basename(__filename));
3
+
4
+ function applyMapping2Remedy(entryData, mapping, constants, fields) {
5
+
6
+ //todo add array handling
7
+ if (!Array.isArray(entryData)) {
8
+ return applyMappingInternal(entryData, mapping, constants, fields);
9
+ } else {
10
+ const entries = [];
11
+ entryData.forEach(entry => {
12
+ const myMappedEntry = applyMappingInternal(entry, mapping, constants, fields);
13
+ entries.push(myMappedEntry);
14
+ })
15
+ return entries;
16
+ }
17
+ }
18
+
19
+ function applyMappingInternal(entryData, mapping, constants, fields) {
20
+ Object.keys(entryData).forEach(function (objectKey) {
21
+ const found = mapping.find(function(element) {
22
+ return element.newName === objectKey;
23
+ });
24
+
25
+ if (found == null || found=== undefined) {
26
+ log.debug('delete', objectKey)
27
+ delete entryData[objectKey];
28
+ }
29
+ });
30
+
31
+ mapping.forEach(function (mappingEntry) {
32
+ try {
33
+ Object.defineProperty(entryData, mappingEntry.oldName, Object.getOwnPropertyDescriptor(entryData, mappingEntry.newName));
34
+ //delete mapping only if no self mapping
35
+ if (!(mappingEntry.newName == mappingEntry.oldName)) {
36
+ delete entryData[mappingEntry.newName];
37
+ }
38
+ } catch (e) {
39
+ //ignore missing mapping
40
+ }
41
+ });
42
+ //remove fields if no access
43
+ log.debug('Check for fields in', fields);
44
+ if (fields && Array.isArray(fields)) {
45
+ Object.keys(entryData).forEach(function (objectKey) {
46
+ const found = fields.find(function(element) {
47
+ return element === objectKey;
48
+ });
49
+ log.debug(`Found ${objectKey} in fields:`, found)
50
+
51
+ if (found == null || found=== undefined) {
52
+ log.debug('delete not accessible field', objectKey)
53
+ delete entryData[objectKey];
54
+ }
55
+ });
56
+ }
57
+
58
+ //add constant values (defaults)
59
+ if (constants && Array.isArray(constants) && constants.length) {
60
+
61
+ constants.forEach(function (element) {
62
+ log.debug('add constant', element);
63
+ try {
64
+ entryData[element.name] = element.value;
65
+ } catch (e) {
66
+ log.error(e);
67
+ }
68
+ });
69
+ }
70
+ return entryData;
71
+ }
72
+
73
+ //get the allowed fields for a POST Action based on a PUT/GET Action
74
+ function getFieldsForCreate(mapping, mappingNew, clientFields) {
75
+ const targetList = [];
76
+ clientFields.forEach(field => {
77
+ //find field in normal mapping
78
+ const mapped = mapping.find(element => {
79
+ return element.oldName === field;
80
+ });
81
+ if (mapped) {
82
+ const mappedNew = mappingNew.find(element => {
83
+ return element.newName === mapped.newName;
84
+ });
85
+ if (mappedNew) {
86
+ targetList.push(mappedNew.oldName)
87
+ }
88
+ }
89
+ });
90
+
91
+ return targetList;
92
+ }
93
+
94
+ module.exports = {
95
+ applyMapping2Remedy, getFieldsForCreate
96
+ }
@@ -0,0 +1,43 @@
1
+ const path = require('path');
2
+ const log = require('@manyos/logger').setupLog('SMILEconnect_' + path.basename(__filename));
3
+
4
+ function getIncludeArray(includeString) {
5
+ log.debug('transform includeString', includeString);
6
+ let includeArray = [];
7
+ if (includeString !== null && includeString !== undefined) {
8
+ includeArray = includeString.split(',');
9
+ includeArray = includeArray.map(item => {
10
+ return item.trim()
11
+ });
12
+ }
13
+ log.debug('includeArray', includeArray);
14
+ return includeArray;
15
+ }
16
+
17
+ function getLinkCI(ciId) {
18
+ const baseUrl = process.env.BASEURL_LINKS;
19
+ if (ciId !== null && ciId !== undefined && baseUrl !== null && baseUrl !== undefined) {
20
+ return baseUrl + '/v1/cmdbobjects/' + ciId;
21
+ } else {
22
+ return null;
23
+ }
24
+ }
25
+
26
+ function applyMapping(object, mapping, requestIdField) {
27
+ //Apply mapping
28
+ mapping.forEach(function (mappingEntry) {
29
+ try {
30
+ Object.defineProperty(object, mappingEntry.newName, Object.getOwnPropertyDescriptor(object, mappingEntry.oldName));
31
+ delete object[mappingEntry.oldName];
32
+ } catch (e) {
33
+ //ignore missing mapping
34
+ }
35
+ });
36
+ if (requestIdField) {
37
+ log.debug('Delete requestIdField', requestIdField);
38
+ delete object[requestIdField];
39
+ }
40
+ }
41
+ module.exports = {
42
+ getIncludeArray, getLinkCI, applyMapping
43
+ };
@@ -0,0 +1,63 @@
1
+ const path = require('path');
2
+ const log = require('@manyos/logger').setupLog('SMILEconnect_' + path.basename(__filename));
3
+
4
+ const CONSTANTS = require('../util/constants');
5
+
6
+ function prepareGlobalRelationObject() {
7
+ const globalRelationObjects = {
8
+ "persons":new Set(),
9
+ "organisations":new Set(),
10
+ "supportgroups":new Set(),
11
+ "cmdbObjects":new Set(),
12
+ "incidents":new Set(),
13
+ "changes":new Set(),
14
+ "problems":new Set(),
15
+ "workOrders":new Set()
16
+ };
17
+ return globalRelationObjects;
18
+ }
19
+
20
+ function getRelatedObjectList(cmdbObject, includeArray, globalRelationObjects) {
21
+ if (cmdbObject.relations) {
22
+ if (cmdbObject.relations.personRelations) {
23
+ cmdbObject.relations.personRelations.forEach(personRelation => {
24
+ globalRelationObjects.persons.add(personRelation.id);
25
+ });
26
+ }
27
+ if (cmdbObject.relations.supportGroupRelations) {
28
+ cmdbObject.relations.supportGroupRelations.forEach(personRelation => {
29
+ globalRelationObjects.supportgroups.add(personRelation.id);
30
+ });
31
+ }
32
+ if (cmdbObject.relations.organisationRelations) {
33
+ cmdbObject.relations.organisationRelations.forEach(orgRelation => {
34
+ globalRelationObjects.organisations.add(orgRelation.id);
35
+ });
36
+ }
37
+ if (cmdbObject.relations.ciRelations) {
38
+ cmdbObject.relations.ciRelations.forEach(ciRelation => {
39
+ globalRelationObjects.cmdbObjects.add(ciRelation.ciId);
40
+ });
41
+ }
42
+ if (cmdbObject.relations.ticketRelations) {
43
+ cmdbObject.relations.ticketRelations.forEach(ticketRelation => {
44
+ if (ticketRelation.ticketType === 'Incident') {
45
+ globalRelationObjects.incidents.add(ticketRelation.ticketId);
46
+ } else if (ticketRelation.ticketType === 'Work Order') {
47
+ globalRelationObjects.workOrders.add(ticketRelation.ticketId);
48
+ } else if (ticketRelation.ticketType === 'Infrastructure Change') {
49
+ globalRelationObjects.changes.add(ticketRelation.ticketId);
50
+ } else if (ticketRelation.ticketType === 'Problem Investigation') {
51
+ globalRelationObjects.problems.add(ticketRelation.ticketId);
52
+ }
53
+ });
54
+ }
55
+
56
+ }
57
+ }
58
+
59
+
60
+ module.exports = {
61
+ prepareGlobalRelationObject,
62
+ getRelatedObjectList
63
+ };