@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
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
require('dotenv').config();
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const log = require('@manyos/logger').setupLog('SMILEconnect_' + path.basename(__filename));
|
|
4
|
+
const arquery = require('../util/arquery');
|
|
5
|
+
const CacheService = require ('../util/cache.service');
|
|
6
|
+
const config = require('../util/config');
|
|
7
|
+
const {getIncludeArray} = require('../util/paramHelper');
|
|
8
|
+
const searchUtil = require('../util/searchUtil');
|
|
9
|
+
const CONSTANTS = require('../util/constants');
|
|
10
|
+
const relationUtil = require('../util/relationUtil');
|
|
11
|
+
|
|
12
|
+
const orgDataCache = new CacheService(process.env.CACHETTL_ORGDATA || 3600); // Create a new cache service instance
|
|
13
|
+
|
|
14
|
+
function queryPersons(clientConfig, query, mapping, customFields, customOptions, includeString) {
|
|
15
|
+
const includeArray = getIncludeArray(includeString);
|
|
16
|
+
let fields = clientConfig.person.fields;
|
|
17
|
+
|
|
18
|
+
//check for customFields
|
|
19
|
+
if (customFields !== null && customFields !== undefined) {
|
|
20
|
+
fields = customFields;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
log.debug('fields', fields, customFields);
|
|
24
|
+
log.debug('customOptions', customOptions);
|
|
25
|
+
const options = {
|
|
26
|
+
...clientConfig.options, ...customOptions
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
log.debug('use joined options', options);
|
|
30
|
+
|
|
31
|
+
const key = clientConfig.person.basequery + fields + query + JSON.stringify(options) + includeArray;
|
|
32
|
+
log.debug('Cachekey is ', key);
|
|
33
|
+
if (mapping == null || mapping == undefined) {
|
|
34
|
+
mapping = config.getMapping('person');
|
|
35
|
+
}
|
|
36
|
+
log.debug('mapping', mapping);
|
|
37
|
+
|
|
38
|
+
return orgDataCache.get(key, async function () {
|
|
39
|
+
const result = await arquery.executeARQuery('CTM:People', clientConfig.person.basequery || null, query, fields, customOptions);
|
|
40
|
+
const persons = [];
|
|
41
|
+
const globalRelationObjects = relationUtil.prepareGlobalRelationObject();
|
|
42
|
+
if (result && result.data && result.data.length) {
|
|
43
|
+
let x = 0;
|
|
44
|
+
for (x=0; x< result.data.length; x++) {
|
|
45
|
+
const person = await handlePerson(result.data[x], mapping, clientConfig, includeArray, globalRelationObjects);
|
|
46
|
+
persons.push(person)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
log.debug('persons', persons);
|
|
50
|
+
return {
|
|
51
|
+
"data": persons,
|
|
52
|
+
"included": globalRelationObjects
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async function handlePerson(person, mapping, clientConfig, includeArray, globalRelationObjects) {
|
|
58
|
+
mapping.forEach(function (mappingEntry) {
|
|
59
|
+
try {
|
|
60
|
+
Object.defineProperty(person, mappingEntry.newName, Object.getOwnPropertyDescriptor(person, mappingEntry.oldName));
|
|
61
|
+
delete person[mappingEntry.oldName];
|
|
62
|
+
} catch (e) {
|
|
63
|
+
//ignore missing mapping
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
//delete element['Entry ID'];
|
|
67
|
+
if (includeArray.includes('groupMembership')) {
|
|
68
|
+
log.debug('Read GroupMembership');
|
|
69
|
+
const groups = await getPersonGroups(clientConfig, person.id);
|
|
70
|
+
person.supportGroups = groups || [];
|
|
71
|
+
person.supportGroups.forEach(supportGroup => {
|
|
72
|
+
globalRelationObjects.supportgroups.add(supportGroup.supportGroupId);
|
|
73
|
+
});
|
|
74
|
+
log.debug('gr', groups);
|
|
75
|
+
}
|
|
76
|
+
return person;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function querySupportGroups(clientConfig, query, mapping, customFields, customOptions, includeString) {
|
|
80
|
+
const includeArray = getIncludeArray(includeString);
|
|
81
|
+
let fields = clientConfig.supportGroup.fields;
|
|
82
|
+
|
|
83
|
+
//check for customFields
|
|
84
|
+
if (customFields !== null && customFields !== undefined) {
|
|
85
|
+
fields = customFields;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
log.debug('fields', fields, customFields);
|
|
89
|
+
const options = {
|
|
90
|
+
...clientConfig.options, ...customOptions
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
log.debug('use joined options', options);
|
|
94
|
+
|
|
95
|
+
const key = clientConfig.supportGroup.basequery + fields + query + JSON.stringify(options) + includeArray;
|
|
96
|
+
log.debug('Cachekey is ', key);
|
|
97
|
+
if (mapping == null || mapping == undefined) {
|
|
98
|
+
mapping = config.getMapping('supportGroup');
|
|
99
|
+
}
|
|
100
|
+
log.debug('mapping', mapping);
|
|
101
|
+
|
|
102
|
+
return orgDataCache.get(key, async function () {
|
|
103
|
+
const result = await arquery.executeARQuery(CONSTANTS.FORM_SUPPORTGROUP, clientConfig.supportGroup.basequery || null, query, fields, customOptions);
|
|
104
|
+
const supportGroups = [];
|
|
105
|
+
const globalRelationObjects = relationUtil.prepareGlobalRelationObject();
|
|
106
|
+
if (result && result.data && result.data.length) {
|
|
107
|
+
let x = 0;
|
|
108
|
+
for (x=0; x< result.data.length; x++) {
|
|
109
|
+
const supportGroup = await handleSupportGroup(result.data[x], mapping, clientConfig, includeArray, globalRelationObjects);
|
|
110
|
+
supportGroups.push(supportGroup)
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
log.debug('persons', supportGroups);
|
|
114
|
+
return {
|
|
115
|
+
"data": supportGroups,
|
|
116
|
+
"included": globalRelationObjects
|
|
117
|
+
};
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async function handleSupportGroup(supportGroup, mapping, clientConfig, includeArray, globalRelationObjects) {
|
|
122
|
+
mapping.forEach(function (mappingEntry) {
|
|
123
|
+
try {
|
|
124
|
+
Object.defineProperty(supportGroup, mappingEntry.newName, Object.getOwnPropertyDescriptor(supportGroup, mappingEntry.oldName));
|
|
125
|
+
delete supportGroup[mappingEntry.oldName];
|
|
126
|
+
} catch (e) {
|
|
127
|
+
//ignore missing mapping
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
//delete element['Entry ID'];
|
|
131
|
+
if (includeArray.includes('personRelations')) {
|
|
132
|
+
log.debug('Read personRelations', supportGroup.id);
|
|
133
|
+
const relations = await getGroupMembers(clientConfig, supportGroup.id);
|
|
134
|
+
log.debug('Relations', relations);
|
|
135
|
+
supportGroup.relations = {};
|
|
136
|
+
supportGroup.relations.personRelations = relations || [];
|
|
137
|
+
}
|
|
138
|
+
relationUtil.getRelatedObjectList(supportGroup, includeArray, globalRelationObjects);
|
|
139
|
+
return supportGroup;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
function queryOrganisations(clientConfig, query, mapping, customFields, customOptions, includeString) {
|
|
144
|
+
const includeArray = getIncludeArray(includeString);
|
|
145
|
+
let fields = clientConfig.organisation.fields;
|
|
146
|
+
|
|
147
|
+
//check for customFields
|
|
148
|
+
if (customFields !== null && customFields !== undefined) {
|
|
149
|
+
fields = customFields;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
log.debug('fields', fields, customFields);
|
|
153
|
+
const options = {
|
|
154
|
+
...clientConfig.options, ...customOptions
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
log.debug('use joined options', options);
|
|
158
|
+
|
|
159
|
+
const key = clientConfig.organisation.basequery + fields + query + JSON.stringify(options) + includeArray;
|
|
160
|
+
log.debug('Cachekey is ', key);
|
|
161
|
+
if (mapping == null || mapping == undefined) {
|
|
162
|
+
mapping = config.getMapping('organisation');
|
|
163
|
+
}
|
|
164
|
+
log.debug('mapping', mapping);
|
|
165
|
+
|
|
166
|
+
return orgDataCache.get(key, async function () {
|
|
167
|
+
const result = await arquery.executeARQuery(CONSTANTS.FORM_ORGANISATION, clientConfig.organisation.basequery || null, query, fields, customOptions);
|
|
168
|
+
const organisations = [];
|
|
169
|
+
const globalRelationObjects = relationUtil.prepareGlobalRelationObject();
|
|
170
|
+
if (result && result.data && result.data.length) {
|
|
171
|
+
let x = 0;
|
|
172
|
+
for (x=0; x< result.data.length; x++) {
|
|
173
|
+
const organisation = await handleOrganisation(result.data[x], mapping, clientConfig, includeArray, globalRelationObjects);
|
|
174
|
+
organisations.push(organisation)
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
log.debug('persons', organisations);
|
|
178
|
+
return {
|
|
179
|
+
"data": organisations,
|
|
180
|
+
"included": globalRelationObjects
|
|
181
|
+
};
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
async function handleOrganisation(organisation, mapping, clientConfig, includeArray, globalRelationObjects) {
|
|
186
|
+
mapping.forEach(function (mappingEntry) {
|
|
187
|
+
try {
|
|
188
|
+
Object.defineProperty(organisation, mappingEntry.newName, Object.getOwnPropertyDescriptor(organisation, mappingEntry.oldName));
|
|
189
|
+
delete organisation[mappingEntry.oldName];
|
|
190
|
+
} catch (e) {
|
|
191
|
+
//ignore missing mapping
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
//delete element['Entry ID'];
|
|
195
|
+
if (includeArray.includes('personRelations')) {
|
|
196
|
+
log.debug('Read personRelations', organisation.id);
|
|
197
|
+
const relations = await getOrgMembers(clientConfig, organisation.company, organisation.organisation, organisation.department);
|
|
198
|
+
log.debug('Relations', relations);
|
|
199
|
+
organisation.relations = {};
|
|
200
|
+
organisation.relations.personRelations = relations || [];
|
|
201
|
+
}
|
|
202
|
+
relationUtil.getRelatedObjectList(organisation, includeArray, globalRelationObjects);
|
|
203
|
+
return organisation;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
function getPersonGroups(clientConfig, personId) {
|
|
209
|
+
const query = `'Person ID'=\"${personId}\" AND 'Status-SGP' = \"Enabled\" AND 'Status-SGA' = \"Enabled\"`;
|
|
210
|
+
return orgDataCache.get(query, function () {
|
|
211
|
+
return new Promise((resolve, reject) => {
|
|
212
|
+
arquery.executeARQuery('CTM:Support Group Assoc LookUp', null, query, 'Default, Assignment Availability, Support Group ID', clientConfig.options)
|
|
213
|
+
.then(function (result) {
|
|
214
|
+
const data = result.data.map(entry => {
|
|
215
|
+
const newEntry = {};
|
|
216
|
+
newEntry.supportGroupId = entry['Support Group ID'];
|
|
217
|
+
newEntry.isDefault = entry['Default'];
|
|
218
|
+
newEntry.assignmentAvailability = entry['Assignment Availability'];
|
|
219
|
+
return newEntry;
|
|
220
|
+
});
|
|
221
|
+
const rolePromises = [];
|
|
222
|
+
|
|
223
|
+
data.forEach (record => {
|
|
224
|
+
rolePromises.push(
|
|
225
|
+
getFunctionalRoles(clientConfig, personId, record.supportGroupId).then(rolesResult => {
|
|
226
|
+
record.roles = rolesResult;
|
|
227
|
+
})
|
|
228
|
+
);
|
|
229
|
+
});
|
|
230
|
+
Promise.all(rolePromises).then(function() {
|
|
231
|
+
resolve(data || {});
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
})
|
|
235
|
+
.catch(function (reason) {
|
|
236
|
+
log.error(reason);
|
|
237
|
+
reject(reason);
|
|
238
|
+
})
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function getGroupMembers(clientConfig, supportGroupId) {
|
|
244
|
+
|
|
245
|
+
const query = `'Support Group ID'=\"${supportGroupId}\" AND 'Status-SGA' = \"Enabled\"`;
|
|
246
|
+
return orgDataCache.get(query, async function () {
|
|
247
|
+
const result = await arquery.executeARQuery('CTM:Support Group Assoc LookUp', null, query, 'Default, Assignment Availability, Person ID', clientConfig.options);
|
|
248
|
+
const data = result.data.map(entry => {
|
|
249
|
+
const newEntry = {};
|
|
250
|
+
newEntry.id = entry['Person ID'];
|
|
251
|
+
newEntry.isDefaultGroup = entry['Default'];
|
|
252
|
+
newEntry.assignmentAvailability = entry['Assignment Availability'];
|
|
253
|
+
return newEntry;
|
|
254
|
+
});
|
|
255
|
+
const rolePromises = [];
|
|
256
|
+
data.forEach (record => {
|
|
257
|
+
rolePromises.push(
|
|
258
|
+
getFunctionalRoles(clientConfig, record.id, supportGroupId).then(rolesResult => {
|
|
259
|
+
record.roles = rolesResult;
|
|
260
|
+
})
|
|
261
|
+
);
|
|
262
|
+
});
|
|
263
|
+
return data;
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function getOrgMembers(clientConfig, company, organisation, department) {
|
|
268
|
+
|
|
269
|
+
const query = `'Company'="${company}" AND 'Organization' = "${organisation}" AND 'Department' = "${department}"`;
|
|
270
|
+
return orgDataCache.get(query, async function () {
|
|
271
|
+
const result = await arquery.executeARQuery(CONSTANTS.FORM_PEOPLE, null, query, 'Person ID', clientConfig.options);
|
|
272
|
+
const data = result.data.map(entry => {
|
|
273
|
+
const newEntry = {};
|
|
274
|
+
newEntry.id = entry['Person ID'];
|
|
275
|
+
return newEntry;
|
|
276
|
+
});
|
|
277
|
+
return data;
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function getFunctionalRoles(clientConfig, personId, supportGroupId) {
|
|
282
|
+
const query = `'Person ID'=\"${personId}\" AND 'Status' = \"Enabled\" AND 'Support Group ID' = \"${supportGroupId}\"`;
|
|
283
|
+
return orgDataCache.get(query, function () {
|
|
284
|
+
return new Promise((resolve, reject) => {
|
|
285
|
+
arquery.executeARQuery('CTM:SupportGroupFunctionalRole', null, query, 'Functional Role, FunctionalRoleAlias', clientConfig.options)
|
|
286
|
+
.then(function (result) {
|
|
287
|
+
const data = result.data.map(entry => {
|
|
288
|
+
return entry['FunctionalRoleAlias'];
|
|
289
|
+
});
|
|
290
|
+
resolve(data || {});
|
|
291
|
+
})
|
|
292
|
+
.catch(function (reason) {
|
|
293
|
+
log.error(reason);
|
|
294
|
+
reject(reason);
|
|
295
|
+
})
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
async function getOrganisation(clientConfig, orgId, mapping, include) {
|
|
301
|
+
const query = `'People Organization ID' = "${orgId}"`;
|
|
302
|
+
try {
|
|
303
|
+
const returnValue = await queryOrganisations(clientConfig, query, mapping, null,null, include);
|
|
304
|
+
const organisation = returnValue.data[0];
|
|
305
|
+
return {data: organisation, included: returnValue.included};
|
|
306
|
+
} catch (error) {
|
|
307
|
+
throw error;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
async function getSupportGroup(clientConfig, groupId, mapping, include) {
|
|
312
|
+
const query = `'Support Group ID' = "${groupId}"`;
|
|
313
|
+
try {
|
|
314
|
+
const returnValue = await querySupportGroups(clientConfig, query, mapping, null,null, include);
|
|
315
|
+
const supportGroup = returnValue.data[0];
|
|
316
|
+
return {data: supportGroup, included: returnValue.included};
|
|
317
|
+
} catch (error) {
|
|
318
|
+
throw error;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
function resolveIncludedOrgData(clientConfig, includedObjects) {
|
|
323
|
+
return new Promise((resolve, reject) => {
|
|
324
|
+
if (includedObjects) {
|
|
325
|
+
let result = {"persons":[], "organisations": [], "supportgroups": []};
|
|
326
|
+
const queryPromises = [];
|
|
327
|
+
if (includedObjects.persons) {
|
|
328
|
+
includedObjects.persons.forEach(function (personId) {
|
|
329
|
+
log.debug('searchPeople', personId);
|
|
330
|
+
queryPromises.push(
|
|
331
|
+
getPerson(clientConfig, personId).then(function (personData) {
|
|
332
|
+
log.debug('persData', {id:personId, data: personData});
|
|
333
|
+
result.persons.push(personData);
|
|
334
|
+
})
|
|
335
|
+
);
|
|
336
|
+
})
|
|
337
|
+
}
|
|
338
|
+
if (includedObjects.organisations) {
|
|
339
|
+
includedObjects.organisations.forEach(function (orgId) {
|
|
340
|
+
log.debug('searchOrganisation', orgId);
|
|
341
|
+
queryPromises.push(
|
|
342
|
+
getOrganisation(clientConfig, orgId).then(function (orgData) {
|
|
343
|
+
log.debug('orgData', {id:orgId, data: orgData});
|
|
344
|
+
result.organisations.push(orgData);
|
|
345
|
+
})
|
|
346
|
+
);
|
|
347
|
+
})
|
|
348
|
+
}
|
|
349
|
+
if (includedObjects.supportgroups) {
|
|
350
|
+
includedObjects.supportgroups.forEach(function (groupId) {
|
|
351
|
+
log.debug('searchSupportGroup', groupId);
|
|
352
|
+
queryPromises.push(
|
|
353
|
+
getSupportGroup(clientConfig, groupId).then(function (groupData) {
|
|
354
|
+
//todo check for empty groups isEmpty(groupData)
|
|
355
|
+
if (groupData != null && groupData != undefined) {
|
|
356
|
+
log.debug('groupData', {id:groupId, data: groupData});
|
|
357
|
+
result.supportgroups.push(groupData);
|
|
358
|
+
}
|
|
359
|
+
})
|
|
360
|
+
);
|
|
361
|
+
})
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
Promise.all(queryPromises).then(function() {
|
|
365
|
+
resolve(result);
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
async function getPersons(config, mapping, include, customOptions) {
|
|
372
|
+
const query = `1=1`;
|
|
373
|
+
const returnValue = await queryPersons(config, query, mapping, null, customOptions, include);
|
|
374
|
+
return {data: returnValue.data};
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
async function getSupportGroups(config, mapping, include, customOptions) {
|
|
378
|
+
const query = `1=1`;
|
|
379
|
+
const returnValue = await querySupportGroups(config, query, mapping, null, customOptions, include);
|
|
380
|
+
return returnValue;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
async function getOrganisations(config, mapping, include, customOptions) {
|
|
384
|
+
const query = `1=1`;
|
|
385
|
+
const returnValue = await queryOrganisations(config, query, mapping, null, customOptions, include);
|
|
386
|
+
return returnValue;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
async function getPerson(config, personId, isLoginId, mapping, include) {
|
|
390
|
+
let query = '';
|
|
391
|
+
if (isLoginId === true) {
|
|
392
|
+
query = `'Remedy Login ID'=\"${personId}\"`;
|
|
393
|
+
} else {
|
|
394
|
+
query = `'Person ID'=\"${personId}\"`;
|
|
395
|
+
}
|
|
396
|
+
try {
|
|
397
|
+
const returnValue = await queryPersons(config, query, mapping, null,null, include);
|
|
398
|
+
const person = returnValue.data[0];
|
|
399
|
+
return {data: person, included: returnValue.included};
|
|
400
|
+
} catch (error) {
|
|
401
|
+
throw error;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
async function searchPerson(clientConfig, searchString, fields, options, include) {
|
|
406
|
+
const mapping = config.getMapping('person');
|
|
407
|
+
const mappedString = searchUtil.applyMapping(searchString, mapping);
|
|
408
|
+
const customFields = searchUtil.getCustomFields(clientConfig.person.fields, mapping, fields);
|
|
409
|
+
options.sort = searchUtil.applySortMapping(options.sort, mapping);
|
|
410
|
+
return await queryPersons(clientConfig, mappedString, null, customFields, options, include);
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
async function searchSupportGroup(clientConfig, searchString, fields, options, include) {
|
|
414
|
+
const mapping = config.getMapping('supportGroup');
|
|
415
|
+
const mappedString = searchUtil.applyMapping(searchString, mapping);
|
|
416
|
+
const customFields = searchUtil.getCustomFields(clientConfig.supportGroup.fields, mapping, fields);
|
|
417
|
+
options.sort = searchUtil.applySortMapping(options.sort, mapping);
|
|
418
|
+
return await querySupportGroups(clientConfig, mappedString, null, customFields, options, include);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
async function searchOrganisations(clientConfig, searchString, fields, options, include) {
|
|
422
|
+
const mapping = config.getMapping('organisation');
|
|
423
|
+
const mappedString = searchUtil.applyMapping(searchString, mapping);
|
|
424
|
+
const customFields = searchUtil.getCustomFields(clientConfig.organisation.fields, mapping, fields);
|
|
425
|
+
options.sort = searchUtil.applySortMapping(options.sort, mapping);
|
|
426
|
+
return await queryOrganisations(clientConfig, mappedString, null, customFields, options, include);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
module.exports = {
|
|
430
|
+
getPerson,
|
|
431
|
+
getPersons,
|
|
432
|
+
searchPerson,
|
|
433
|
+
getOrganisation,
|
|
434
|
+
getOrganisations,
|
|
435
|
+
searchOrganisations,
|
|
436
|
+
getSupportGroup,
|
|
437
|
+
getSupportGroups,
|
|
438
|
+
searchSupportGroup,
|
|
439
|
+
resolveIncludedOrgData
|
|
440
|
+
};
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
require('dotenv').config();
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const log = require('@manyos/logger').setupLog('SMILEconnect_' + path.basename(__filename));
|
|
4
|
+
const orgdata = require('../controller/orgdataController');
|
|
5
|
+
const cmdbObjectController = require('../controller/cmdbobjectController');
|
|
6
|
+
const ticketCiRelation = require('./ticketCIRelationController');
|
|
7
|
+
|
|
8
|
+
async function getRelatedObjects(req, res, next) {
|
|
9
|
+
log.debug('include Data', req.includeArray);
|
|
10
|
+
log.debug('include Objects', req.includeObjectsList);
|
|
11
|
+
if (req.result && req.includeObjectsList && req.includeArray) {
|
|
12
|
+
let result = {};
|
|
13
|
+
const includedObjects = req.includeObjectsList;
|
|
14
|
+
const clientConfig = req.user.config;
|
|
15
|
+
|
|
16
|
+
if (req.includeArray.includes('persons') && includedObjects.persons) {
|
|
17
|
+
const persons = [];
|
|
18
|
+
const personArray = Array.from(includedObjects.persons);
|
|
19
|
+
let x=0;
|
|
20
|
+
for (x=0; x < personArray.length; x++) {
|
|
21
|
+
const personId = personArray[x];
|
|
22
|
+
log.debug('searchPeople', personId);
|
|
23
|
+
const result = await orgdata.getPerson(clientConfig, personId);
|
|
24
|
+
const person = result.data;
|
|
25
|
+
log.debug('pers', person);
|
|
26
|
+
if (person) {
|
|
27
|
+
persons.push(person);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
result.persons = persons;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (req.includeArray.includes('organisations') && includedObjects.organisations) {
|
|
34
|
+
const organisations = [];
|
|
35
|
+
const organisationArray = Array.from(includedObjects.organisations);
|
|
36
|
+
let x=0;
|
|
37
|
+
for (x=0; x < organisationArray.length; x++) {
|
|
38
|
+
const orgId = organisationArray[x];
|
|
39
|
+
log.debug('searchOrganisation', orgId);
|
|
40
|
+
const result = await orgdata.getOrganisation(clientConfig, orgId);
|
|
41
|
+
const org = result.data;
|
|
42
|
+
if (org) {
|
|
43
|
+
organisations.push(org);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
result.organisations = organisations;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (req.includeArray.includes('supportGroups') && includedObjects.supportgroups) {
|
|
50
|
+
const supportGroups = [];
|
|
51
|
+
const supportGroupArray = Array.from(includedObjects.supportgroups);
|
|
52
|
+
let x=0;
|
|
53
|
+
for (x=0; x < supportGroupArray.length; x++) {
|
|
54
|
+
const groupId = supportGroupArray[x];
|
|
55
|
+
log.debug('searchSupportGroup', groupId);
|
|
56
|
+
const result = await orgdata.getSupportGroup(clientConfig, groupId);
|
|
57
|
+
const supportGroup = result.data;
|
|
58
|
+
if (supportGroup) {
|
|
59
|
+
supportGroups.push(supportGroup);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
result.supportgroups = supportGroups;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (req.includeArray.includes('cmdbObjects') && includedObjects.cmdbObjects) {
|
|
66
|
+
const cmdbObjects = [];
|
|
67
|
+
let x=0;
|
|
68
|
+
const cmdbObjectArray = Array.from(includedObjects.cmdbObjects);
|
|
69
|
+
log.debug(cmdbObjectArray);
|
|
70
|
+
for (x=0; x < cmdbObjectArray.length; x++) {
|
|
71
|
+
const ciId = cmdbObjectArray[x];
|
|
72
|
+
log.debug('searchCMDBObject', ciId);
|
|
73
|
+
const cmdbObject = await cmdbObjectController.getCmdbObject(clientConfig, ciId);
|
|
74
|
+
if (cmdbObjects !== null && cmdbObjects !== undefined && cmdbObject && cmdbObject.data) {
|
|
75
|
+
cmdbObjects.push(cmdbObject.data);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
result.cmdbObjects = cmdbObjects;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (req.includeArray.includes('incidents') && includedObjects.incidents) {
|
|
82
|
+
const incidents = [];
|
|
83
|
+
const incidentArray = Array.from(includedObjects.incidents);
|
|
84
|
+
let x=0;
|
|
85
|
+
for (x=0; x < incidentArray.length; x++) {
|
|
86
|
+
const id = incidentArray[x];
|
|
87
|
+
log.debug('searchIncident', id);
|
|
88
|
+
const result = await incidentController.getIncident(clientConfig, id);
|
|
89
|
+
if (result && result.data) {
|
|
90
|
+
incidents.push(result.data);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
result.incidents = incidents;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (req.includeArray.includes('workOrders') && includedObjects.workOrders) {
|
|
97
|
+
const tickets = [];
|
|
98
|
+
const ticketIdArray = Array.from(includedObjects.workOrders);
|
|
99
|
+
let x=0;
|
|
100
|
+
for (x=0; x < ticketIdArray.length; x++) {
|
|
101
|
+
const id = ticketIdArray[x];
|
|
102
|
+
log.debug('searchWorkOrder', id);
|
|
103
|
+
const result = await workOrderController.getWorkOrder(clientConfig, id);
|
|
104
|
+
if (result && result.data) {
|
|
105
|
+
tickets.push(result.data);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
result.workOrders = tickets;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (req.includeArray.includes('problems') && includedObjects.problems) {
|
|
112
|
+
const tickets = [];
|
|
113
|
+
const ticketIdArray = Array.from(includedObjects.problems);
|
|
114
|
+
let x=0;
|
|
115
|
+
for (x=0; x < ticketIdArray.length; x++) {
|
|
116
|
+
const id = ticketIdArray[x];
|
|
117
|
+
log.debug('searchProblem', id);
|
|
118
|
+
const result = await problemController.getProblem(clientConfig, id);
|
|
119
|
+
if (result && result.data) {
|
|
120
|
+
tickets.push(result.data);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
result.problems = tickets;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (req.includeArray.includes('changes') && includedObjects.changes) {
|
|
127
|
+
const tickets = [];
|
|
128
|
+
const ticketIdArray = Array.from(includedObjects.changes);
|
|
129
|
+
let x=0;
|
|
130
|
+
for (x=0; x < ticketIdArray.length; x++) {
|
|
131
|
+
const id = ticketIdArray[x];
|
|
132
|
+
log.debug('searchChange', id);
|
|
133
|
+
const result = await changeController.getChange(clientConfig, id);
|
|
134
|
+
if (result && result.data) {
|
|
135
|
+
tickets.push(result.data);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
result.changes = tickets;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
log.debug('done');
|
|
142
|
+
|
|
143
|
+
//backward compatibility
|
|
144
|
+
if (req.includeObjects || (req.body && req.body.getRelations)) {
|
|
145
|
+
replaceAllKeys(req.result.data);
|
|
146
|
+
}
|
|
147
|
+
req.result.included = result || {};
|
|
148
|
+
next();
|
|
149
|
+
} else {
|
|
150
|
+
if (req.result) {
|
|
151
|
+
req.result.included = {};
|
|
152
|
+
}
|
|
153
|
+
next();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function replaceAllKeys(objects) {
|
|
158
|
+
log.debug('replaceKeys in', objects);
|
|
159
|
+
if (objects !== null && objects !== undefined) {
|
|
160
|
+
if (Array.isArray(objects)) {
|
|
161
|
+
objects.forEach(item => {
|
|
162
|
+
replaceObjectKeys(item);
|
|
163
|
+
});
|
|
164
|
+
} else {
|
|
165
|
+
replaceObjectKeys(objects);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return objects;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function replaceObjectKeys(item) {
|
|
172
|
+
if (item.relations !== null && item.relations !== undefined) {
|
|
173
|
+
log.debug('keys', Object.keys(item.relations));
|
|
174
|
+
Object.keys(item.relations).forEach(key => {
|
|
175
|
+
if (key === 'ciRelations') {
|
|
176
|
+
log.debug ('Rename', key);
|
|
177
|
+
item.relations.relatedCIs = item.relations[key];
|
|
178
|
+
} else if (key === 'personRelations') {
|
|
179
|
+
log.debug ('Rename', key);
|
|
180
|
+
item.relations.relatedPersons = item.relations[key];
|
|
181
|
+
} else if (key === 'supportGroupRelations') {
|
|
182
|
+
log.debug ('Rename', key);
|
|
183
|
+
item.relations.relatedSupportGroups = item.relations[key];
|
|
184
|
+
} else if (key === 'organisationRelations') {
|
|
185
|
+
log.debug ('Rename', key);
|
|
186
|
+
item.relations.relatedOrganisations = item.relations[key];
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
module.exports = {
|
|
193
|
+
getRelatedObjects
|
|
194
|
+
}
|