@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.
- package/.github/workflows/nodejs.yml +26 -0
- package/CHANGELOG.md +75 -0
- package/Dockerfile +21 -0
- package/README.md +1 -0
- package/app.js +316 -0
- package/conf/clients.json +2491 -0
- package/conf/mapping.json +1048 -0
- package/conf/scripts/p1.js +11 -0
- package/conf/scripts/p2.js +1 -0
- package/conf/scripts/p3.js +1 -0
- package/conf/scripts/p4.js +2 -0
- package/conf/scripts/script1.js +2 -0
- package/conf/scripts/script2.js +2 -0
- package/conf/scripts/script3.js +2 -0
- package/controller/cmdbobjectController.js +291 -0
- package/controller/eventLogController.js +78 -0
- package/controller/orgdataController.js +440 -0
- package/controller/relatedObjectsController.js +194 -0
- package/controller/scriptController.js +213 -0
- package/controller/taskController.js +368 -0
- package/controller/templateController.js +97 -0
- package/controller/ticketCIRelationController.js +522 -0
- package/controller/ticketController.js +329 -0
- package/controller/ticketWorkLogController.js +195 -0
- package/docs/.gitattributes +48 -0
- package/docs/404.html +13 -0
- package/docs/CNAME +1 -0
- package/docs/Gemfile +7 -0
- package/docs/Gemfile.lock +249 -0
- package/docs/_config.yml +257 -0
- package/docs/_data/SocialNetworks.yml +92 -0
- package/docs/_data/ui-text.yml +494 -0
- package/docs/_includes/disqus.html +17 -0
- package/docs/_includes/ext-css.html +7 -0
- package/docs/_includes/ext-js.html +7 -0
- package/docs/_includes/fb-comment.html +14 -0
- package/docs/_includes/footer-minimal.html +16 -0
- package/docs/_includes/footer-scripts.html +32 -0
- package/docs/_includes/footer.html +51 -0
- package/docs/_includes/google_analytics.html +14 -0
- package/docs/_includes/gtag.html +11 -0
- package/docs/_includes/gtm_body.html +6 -0
- package/docs/_includes/gtm_head.html +9 -0
- package/docs/_includes/head.html +131 -0
- package/docs/_includes/header.html +76 -0
- package/docs/_includes/just_comments.html +4 -0
- package/docs/_includes/matomo.html +17 -0
- package/docs/_includes/nav.html +57 -0
- package/docs/_includes/social-share.html +42 -0
- package/docs/_includes/staticman-comment.html +22 -0
- package/docs/_includes/staticman-comments.html +81 -0
- package/docs/_layouts/base.html +35 -0
- package/docs/_layouts/default.html +9 -0
- package/docs/_layouts/minimal.html +26 -0
- package/docs/_layouts/page.html +26 -0
- package/docs/_layouts/post.html +82 -0
- package/docs/_posts/2015-02-28-test-markdown.md +77 -0
- package/docs/aboutme.md +18 -0
- package/docs/css/bootstrap-social.css +147 -0
- package/docs/css/bootstrap-theme.css +476 -0
- package/docs/css/bootstrap-theme.css.map +1 -0
- package/docs/css/bootstrap-theme.min.css +5 -0
- package/docs/css/bootstrap.css +6566 -0
- package/docs/css/bootstrap.css.map +1 -0
- package/docs/css/bootstrap.min.css +5 -0
- package/docs/css/main-minimal.css +13 -0
- package/docs/css/main.css +788 -0
- package/docs/css/normalize.css +427 -0
- package/docs/css/pygment_highlights.css +61 -0
- package/docs/css/staticman.css +180 -0
- package/docs/eventlog/events.md +65 -0
- package/docs/feed.xml +24 -0
- package/docs/general/architecture.md +10 -0
- package/docs/general/config.md +192 -0
- package/docs/general/field-management.md +119 -0
- package/docs/general/release-notes.md +9 -0
- package/docs/getting-started.md +19 -0
- package/docs/howto/cmdbobjects.md +339 -0
- package/docs/howto/incident-worklogs.md +186 -0
- package/docs/howto/incidents.md +244 -0
- package/docs/howto/sample-config.md +518 -0
- package/docs/howto/token.md +71 -0
- package/docs/howto/worklog-attachment.md +113 -0
- package/docs/img/404-southpark.jpg +0 -0
- package/docs/img/architecture.jpeg +0 -0
- package/docs/img/attachment-upload.png +0 -0
- package/docs/img/avatar-icon.png +0 -0
- package/docs/img/bgimage.png +0 -0
- package/docs/img/gb-isapi.jpg +0 -0
- package/docs/img/install-steps.gif +0 -0
- package/docs/img/workflow.png +0 -0
- package/docs/index.md +41 -0
- package/docs/installation.md +123 -0
- package/docs/js/bootstrap.js +2306 -0
- package/docs/js/bootstrap.min.js +7 -0
- package/docs/js/jquery-1.11.2.min.js +4 -0
- package/docs/js/main.js +140 -0
- package/docs/js/staticman.js +54 -0
- package/docs/openapi.json +15097 -0
- package/docs/postinstall.md +169 -0
- package/docs/preinstall.md +19 -0
- package/docs/spec/index.html +24 -0
- package/docs/staticman.yml +110 -0
- package/docs/tags.html +34 -0
- package/docs/workflow.md +127 -0
- package/nodemon.json +3 -0
- package/package.json +46 -0
- package/routes/appConfigRoutes.js +352 -0
- package/routes/ciRelationRoutes.js +38 -0
- package/routes/cmdbObjectRoutes.js +154 -0
- package/routes/organisationRoutes.js +121 -0
- package/routes/peopleRelationRoutes.js +38 -0
- package/routes/personRoutes.js +131 -0
- package/routes/supportgroupRoutes.js +122 -0
- package/routes/taskRoutes.js +306 -0
- package/routes/templateRoutes.js +67 -0
- package/routes/ticketRoutes.js +181 -0
- package/routes/ticketWorkLogRoutes.js +185 -0
- package/screwdriver.yaml +52 -0
- package/test/appTest.js +3 -0
- package/test/changeTest.js +541 -0
- package/test/cmdbobjectTest.js +167 -0
- package/test/files/logo.png +0 -0
- package/test/incidentTest.js +539 -0
- package/test/orgdataTest.js +156 -0
- package/test/problemTest.js +512 -0
- package/test/templateTest.js +80 -0
- package/test/testUtils.js +21 -0
- package/test/workorderTest.js +544 -0
- package/util/arquery.js +416 -0
- package/util/auth.js +37 -0
- package/util/cache.service.js +52 -0
- package/util/config.js +361 -0
- package/util/constants.js +73 -0
- package/util/mappingUtil.js +96 -0
- package/util/paramHelper.js +43 -0
- package/util/relationUtil.js +63 -0
- package/util/responsehandler.js +92 -0
- package/util/schemas/clientConfigSchema.js +180 -0
- package/util/schemas/fieldMappingSchema.js +211 -0
- 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
|
+
};
|