@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,329 @@
|
|
|
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 CONSTANTS = require('../util/constants');
|
|
8
|
+
const searchUtil = require('../util/searchUtil');
|
|
9
|
+
const {getIncludeArray, applyMapping} = require('../util/paramHelper');
|
|
10
|
+
const relationUtil = require('../util/relationUtil');
|
|
11
|
+
const ticketCIRelationController = require('./ticketCIRelationController');
|
|
12
|
+
const scriptController = require('./scriptController');
|
|
13
|
+
const mappingUtil = require('../util/mappingUtil');
|
|
14
|
+
|
|
15
|
+
const ticketCache = new CacheService(process.env.CACHETTL_TICKETS || 1); // Create a new cache service instance
|
|
16
|
+
|
|
17
|
+
function getTickets(ticketConfig, config, includeString, customOptions) {
|
|
18
|
+
let query = '1=1';
|
|
19
|
+
return queryTickets(ticketConfig, config, query, null, null, customOptions, includeString);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async function createTicket(ticketConfig, clientConfig, data) {
|
|
23
|
+
const scripts = clientConfig[ticketConfig.requestType].scripts.POST;
|
|
24
|
+
|
|
25
|
+
//run preScripts
|
|
26
|
+
if (scripts && scripts.preMapping) {
|
|
27
|
+
await scriptController.runScripts(scripts.preMapping, data);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const requestType = ticketConfig.requestType;
|
|
31
|
+
const newRequestType = 'new' + requestType.charAt(0).toUpperCase() + requestType.slice(1);
|
|
32
|
+
|
|
33
|
+
const mapping = config.getMapping(newRequestType);
|
|
34
|
+
log.debug('mapping', mapping);
|
|
35
|
+
|
|
36
|
+
const fields = mappingUtil.getFieldsForCreate(config.getMapping(requestType), mapping, clientConfig[requestType].fields)
|
|
37
|
+
|
|
38
|
+
data = mappingUtil.applyMapping2Remedy(data, mapping, clientConfig[ticketConfig.requestType].constants, fields);
|
|
39
|
+
|
|
40
|
+
//run postScripts
|
|
41
|
+
if (scripts && scripts.postMapping) {
|
|
42
|
+
await scriptController.runScripts(scripts.postMapping, data);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const result = await arquery.createEntry(ticketConfig.forms.new, data, clientConfig.options)
|
|
46
|
+
|
|
47
|
+
log.debug('TicketCreateResult', result.data);
|
|
48
|
+
const ticketCreateId = Object.values(result)[0];
|
|
49
|
+
//Find change id
|
|
50
|
+
const resultInterfaceCreate = await arquery.executeARQuery(ticketConfig.forms.new, null, "'1'=\"" + ticketCreateId + "\"", ticketConfig.ticketIdField, clientConfig.options)
|
|
51
|
+
if (resultInterfaceCreate.data && Array.isArray(resultInterfaceCreate.data) && resultInterfaceCreate.data.length && resultInterfaceCreate.data[0][ticketConfig.ticketIdField]) {
|
|
52
|
+
const ticketId = resultInterfaceCreate.data[0][ticketConfig.ticketIdField];
|
|
53
|
+
//todo fix create worklog
|
|
54
|
+
/*createWorklog(clientConfig, ticketId, 'Created', 'Incident ' + CONSTANTS.TEXT_CREATED_BY, false).then(function (worklogResult) {
|
|
55
|
+
log.debug('Worklog', worklogResult);
|
|
56
|
+
}).catch(function (error) {
|
|
57
|
+
log.error('HPD:Worklog creation error', error)
|
|
58
|
+
});*/
|
|
59
|
+
} else {
|
|
60
|
+
log.error('Cannot create Ticket', resultInterfaceCreate);
|
|
61
|
+
throw({message: 'Cannot create Ticket', details : resultInterfaceCreate});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
//run afterExecution
|
|
65
|
+
if (scripts && scripts.afterExecution) {
|
|
66
|
+
await scriptController.runScripts(scripts.afterExecution, data);
|
|
67
|
+
}
|
|
68
|
+
return resultInterfaceCreate;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function queryTickets(ticketConfig, clientConfig, query, mapping, customFields, customOptions, includeString) {
|
|
72
|
+
log.debug('config', ticketConfig);
|
|
73
|
+
const includeArray = getIncludeArray(includeString);
|
|
74
|
+
log.debug('ticketConfig.requestType', ticketConfig.requestType);
|
|
75
|
+
let fields = clientConfig[ticketConfig.requestType].fields;
|
|
76
|
+
const baseQuery = clientConfig[ticketConfig.requestType].basequery;
|
|
77
|
+
|
|
78
|
+
//check for customFields
|
|
79
|
+
if (customFields !== null && customFields !== undefined) {
|
|
80
|
+
fields = customFields;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
log.debug('fields', fields, customFields);
|
|
84
|
+
const options = {
|
|
85
|
+
...clientConfig.options, ...customOptions
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
log.debug('use joined options', options);
|
|
89
|
+
|
|
90
|
+
const key = baseQuery + fields.toString() + query + JSON.stringify(options) + includeArray;
|
|
91
|
+
log.debug('Cachekey is ', key);
|
|
92
|
+
if (mapping == null || mapping == undefined) {
|
|
93
|
+
mapping = config.getMapping(ticketConfig.requestType);
|
|
94
|
+
}
|
|
95
|
+
log.debug('mapping', mapping);
|
|
96
|
+
|
|
97
|
+
return ticketCache.get(key, async function () {
|
|
98
|
+
const result = await arquery.executeARQuery(ticketConfig.forms.regular, baseQuery || null, query, fields.toString() || '1', options);
|
|
99
|
+
const globalRelationObjects = relationUtil.prepareGlobalRelationObject();
|
|
100
|
+
const tickets = [];
|
|
101
|
+
if (result && result.data && result.data.length) {
|
|
102
|
+
let x = 0;
|
|
103
|
+
for (x=0; x< result.data.length; x++) {
|
|
104
|
+
const ticket = await handleTicket(ticketConfig, result.data[x], mapping, clientConfig, includeArray, globalRelationObjects);
|
|
105
|
+
tickets.push(ticket);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
log.debug('tickets', tickets);
|
|
109
|
+
return {
|
|
110
|
+
"data": tickets,
|
|
111
|
+
"included": globalRelationObjects
|
|
112
|
+
};
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async function handleTicket(ticketConfig, ticket, mapping, clientConfig, includeArray, globalRelationObjects) {
|
|
117
|
+
const allScripts = clientConfig[ticketConfig.requestType].scripts;
|
|
118
|
+
let scripts = [];
|
|
119
|
+
if (allScripts) {
|
|
120
|
+
scripts = allScripts.GET || [];
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const requestType = ticketConfig.requestType;
|
|
124
|
+
if (requestType === 'incident') {
|
|
125
|
+
checkFieldsIncident(ticket, globalRelationObjects);
|
|
126
|
+
} else if (requestType === 'change') {
|
|
127
|
+
checkFieldsChange(ticket, globalRelationObjects);
|
|
128
|
+
} else if (requestType === 'problem') {
|
|
129
|
+
checkFieldsProblem(ticket, globalRelationObjects);
|
|
130
|
+
} else if (requestType === 'workOrder') {
|
|
131
|
+
checkFieldsWorkOrder(ticket, globalRelationObjects);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
//run preScripts
|
|
135
|
+
if (scripts && scripts.preMapping) {
|
|
136
|
+
const preScripts = scripts.preMapping;
|
|
137
|
+
try {
|
|
138
|
+
for (let x = 0; x < preScripts.length; x++) {
|
|
139
|
+
const result = await scriptController.executeScript(preScripts[x], ticket);
|
|
140
|
+
}
|
|
141
|
+
} catch (error) {
|
|
142
|
+
throw error;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
applyMapping(ticket, mapping, ticketConfig.requestIdField);
|
|
147
|
+
|
|
148
|
+
ticket.relations = {};
|
|
149
|
+
if (includeArray.includes('ciRelations')) {
|
|
150
|
+
const relations = await ticketCIRelationController.getTicketCIRelations(ticket.id);
|
|
151
|
+
ticket.relations.ciRelations = relations;
|
|
152
|
+
}
|
|
153
|
+
if (includeArray.includes('ticketRelations')) {
|
|
154
|
+
const relations = await ticketCIRelationController.getTicket2TicketRelations(ticketConfig, ticket.id);
|
|
155
|
+
ticket.relations.ticketRelations = relations;
|
|
156
|
+
}
|
|
157
|
+
relationUtil.getRelatedObjectList(ticket, includeArray, globalRelationObjects);
|
|
158
|
+
//run postScripts
|
|
159
|
+
if (scripts && scripts.postMapping) {
|
|
160
|
+
const postScripts = scripts.postMapping;
|
|
161
|
+
try {
|
|
162
|
+
for (let x = 0; x < postScripts.length; x++) {
|
|
163
|
+
const result = await scriptController.executeScript(postScripts[x], ticket);
|
|
164
|
+
}
|
|
165
|
+
} catch (error) {
|
|
166
|
+
throw error;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return ticket;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function checkFieldsIncident(incident, globalRelationObjects) {
|
|
173
|
+
//check for included objects
|
|
174
|
+
const customerId = incident['Person ID'];
|
|
175
|
+
if (customerId != null && customerId !== undefined)
|
|
176
|
+
globalRelationObjects.persons.add(customerId);
|
|
177
|
+
|
|
178
|
+
const contactId = incident['Direct Contact Person ID'];
|
|
179
|
+
if (contactId != null && contactId !== undefined)
|
|
180
|
+
globalRelationObjects.persons.add(contactId);
|
|
181
|
+
|
|
182
|
+
const requestorId = incident['Requested By Person ID'];
|
|
183
|
+
if (requestorId != null && requestorId !== undefined)
|
|
184
|
+
globalRelationObjects.persons.add(requestorId);
|
|
185
|
+
|
|
186
|
+
const supportGroupId = incident['Assigned Group ID'];
|
|
187
|
+
if (supportGroupId != null && supportGroupId !== undefined)
|
|
188
|
+
globalRelationObjects.supportgroups.add(supportGroupId);
|
|
189
|
+
|
|
190
|
+
const ownerGroup = incident['Owner Group ID'];
|
|
191
|
+
if (ownerGroup != null && ownerGroup !== undefined)
|
|
192
|
+
globalRelationObjects.supportgroups.add(ownerGroup);
|
|
193
|
+
|
|
194
|
+
const vendorGroupId = incident['Vendor Group ID'];
|
|
195
|
+
if (vendorGroupId != null && vendorGroupId !== undefined)
|
|
196
|
+
globalRelationObjects.supportgroups.add(vendorGroupId);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function checkFieldsWorkOrder(workOrder, globalRelationObjects) {
|
|
200
|
+
const customerId = workOrder['Customer Person ID'];
|
|
201
|
+
if (customerId != null && customerId !== undefined)
|
|
202
|
+
globalRelationObjects.persons.add(customerId);
|
|
203
|
+
|
|
204
|
+
const requestorId = workOrder['Requested By Person ID'];
|
|
205
|
+
if (requestorId != null && requestorId !== undefined)
|
|
206
|
+
globalRelationObjects.persons.add(requestorId);
|
|
207
|
+
|
|
208
|
+
const supportGroupId = workOrder['Support Group ID'];
|
|
209
|
+
if (supportGroupId != null && supportGroupId !== undefined)
|
|
210
|
+
globalRelationObjects.supportgroups.add(supportGroupId);
|
|
211
|
+
|
|
212
|
+
const supportGroupId2 = workOrder['Support Group ID 2'];
|
|
213
|
+
if (supportGroupId2 != null && supportGroupId2 !== undefined)
|
|
214
|
+
globalRelationObjects.supportgroups.add(supportGroupId2);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function checkFieldsChange(change, globalRelationObjects) {
|
|
218
|
+
//check for included objects
|
|
219
|
+
const customerId = change['Customer Person ID'];
|
|
220
|
+
if (customerId != null && customerId !== undefined)
|
|
221
|
+
globalRelationObjects.persons.add(customerId);
|
|
222
|
+
|
|
223
|
+
const requestorId = change['Requested By Person ID'];
|
|
224
|
+
if (requestorId != null && requestorId !== undefined)
|
|
225
|
+
globalRelationObjects.persons.add(requestorId);
|
|
226
|
+
|
|
227
|
+
const supportGroupId = change['Support Group ID'];
|
|
228
|
+
if (supportGroupId != null && supportGroupId !== undefined)
|
|
229
|
+
globalRelationObjects.supportgroups.add(supportGroupId);
|
|
230
|
+
|
|
231
|
+
const supportGroupId2 = change['Support Group ID 2'];
|
|
232
|
+
if (supportGroupId2 != null && supportGroupId2 !== undefined)
|
|
233
|
+
globalRelationObjects.supportgroups.add(supportGroupId2);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function checkFieldsProblem(problem, globalRelationObjects) {
|
|
237
|
+
const customerId = problem['Person ID'];
|
|
238
|
+
if (customerId != null && customerId !== undefined)
|
|
239
|
+
globalRelationObjects.persons.add(customerId);
|
|
240
|
+
|
|
241
|
+
const contactId = problem['Direct Contact Person ID'];
|
|
242
|
+
if (contactId != null && contactId !== undefined)
|
|
243
|
+
globalRelationObjects.persons.add(contactId);
|
|
244
|
+
|
|
245
|
+
const requestorId = problem['Requested By Person ID'];
|
|
246
|
+
if (requestorId != null && requestorId !== undefined)
|
|
247
|
+
globalRelationObjects.persons.add(requestorId);
|
|
248
|
+
|
|
249
|
+
const supportGroupId = problem['Assigned Group ID'];
|
|
250
|
+
if (supportGroupId != null && supportGroupId !== undefined)
|
|
251
|
+
globalRelationObjects.supportgroups.add(supportGroupId);
|
|
252
|
+
|
|
253
|
+
const ownerGroup = problem['Owner Group ID'];
|
|
254
|
+
if (ownerGroup != null && ownerGroup !== undefined)
|
|
255
|
+
globalRelationObjects.supportgroups.add(ownerGroup);
|
|
256
|
+
|
|
257
|
+
const vendorGroupId = problem['Vendor Group ID'];
|
|
258
|
+
if (vendorGroupId != null && vendorGroupId !== undefined)
|
|
259
|
+
globalRelationObjects.supportgroups.add(vendorGroupId);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
async function getTicket(ticketConfig, config, id, mapping, includeString) {
|
|
264
|
+
let query = '1=2';
|
|
265
|
+
const requestType = ticketConfig.requestType;
|
|
266
|
+
if (requestType === 'incident') {
|
|
267
|
+
query = `'Incident Number'=\"${id}\"`;
|
|
268
|
+
} else if (requestType === 'change') {
|
|
269
|
+
query = `'Infrastructure Change ID'=\"${id}\"`;
|
|
270
|
+
} else if (requestType === 'problem') {
|
|
271
|
+
query = `'Problem Investigation ID'=\"${id}\"`;
|
|
272
|
+
} else if (requestType === 'workOrder') {
|
|
273
|
+
query = `'Work Order ID'=\"${id}\"`;
|
|
274
|
+
}
|
|
275
|
+
const returnValue = await queryTickets(ticketConfig, config, query, mapping, null, null, includeString);
|
|
276
|
+
const ticket = returnValue.data[0];
|
|
277
|
+
return {data: ticket, included: returnValue.included};
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
async function updateTicket(ticketConfig, clientConfig, id, ticketData) {
|
|
281
|
+
const scripts = clientConfig[ticketConfig.requestType].scripts.PUT;
|
|
282
|
+
const fields = clientConfig[ticketConfig.requestType].fields
|
|
283
|
+
|
|
284
|
+
//run preScripts
|
|
285
|
+
if (scripts && scripts.preMapping) {
|
|
286
|
+
await scriptController.runScripts(scripts.preMapping, ticketData);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
log.debug(clientConfig[ticketConfig.requestType]);
|
|
290
|
+
const myClientConfig = {};
|
|
291
|
+
myClientConfig[ticketConfig.requestType] = {baseQuery: clientConfig[ticketConfig.requestType].baseQuery, fields: [1]};
|
|
292
|
+
const myMapping = [{"oldName":ticketConfig.requestIdField, "newName" : "internalId"}];
|
|
293
|
+
const ticket = await getTicket(ticketConfig, myClientConfig, id, myMapping);
|
|
294
|
+
log.debug('Ticket to Update', ticket);
|
|
295
|
+
const mapping = config.getMapping(ticketConfig.requestType);
|
|
296
|
+
|
|
297
|
+
//Constants work only on new.
|
|
298
|
+
ticketData = mappingUtil.applyMapping2Remedy(ticketData, mapping, undefined, fields);
|
|
299
|
+
|
|
300
|
+
//run postMapping
|
|
301
|
+
if (scripts && scripts.postMapping) {
|
|
302
|
+
await scriptController.runScripts(scripts.postMapping, ticketData);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
const update = await arquery.updateEntry(ticketConfig.forms.regular, ticket.data.internalId, ticketData);
|
|
306
|
+
|
|
307
|
+
//run afterExecution
|
|
308
|
+
if (scripts && scripts.afterExecution) {
|
|
309
|
+
await scriptController.runScripts(scripts.afterExecution, ticketData);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
return update;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function searchTicket(ticketConfig, clientConfig, searchString, fields, options, includeString) {
|
|
316
|
+
const mapping = config.getMapping(ticketConfig.requestType);
|
|
317
|
+
const mappedString = searchUtil.applyMapping(searchString, mapping);
|
|
318
|
+
const customFields = searchUtil.getCustomFields(clientConfig[ticketConfig.requestType].fields, mapping, fields);
|
|
319
|
+
options.sort = searchUtil.applySortMapping(options.sort, mapping);
|
|
320
|
+
return queryTickets(ticketConfig, clientConfig, mappedString, null, customFields, options, includeString);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
module.exports = {
|
|
324
|
+
getTicket,
|
|
325
|
+
getTickets,
|
|
326
|
+
createTicket,
|
|
327
|
+
updateTicket,
|
|
328
|
+
searchTicket
|
|
329
|
+
};
|
|
@@ -0,0 +1,195 @@
|
|
|
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 searchUtil = require('../util/searchUtil');
|
|
8
|
+
const {applyMapping} = require('../util/paramHelper');
|
|
9
|
+
const mappingUtil = require('../util/mappingUtil');
|
|
10
|
+
const scriptController = require('./scriptController');
|
|
11
|
+
|
|
12
|
+
const ticketCache = new CacheService(process.env.CACHETTL_TICKETS || 1); // Create a new cache service instance
|
|
13
|
+
|
|
14
|
+
async function createWorklog(ticketConfig, clientConfig, ticketId, summary, text, isPublic) {
|
|
15
|
+
const scripts = clientConfig[ticketConfig.requestTypeWorkLog].scripts.POST;
|
|
16
|
+
const mapping = config.getMapping(ticketConfig.requestTypeWorkLog);
|
|
17
|
+
const fields = clientConfig[ticketConfig.requestTypeWorkLog].fields;
|
|
18
|
+
|
|
19
|
+
log.debug('mapping', mapping);
|
|
20
|
+
let data = {
|
|
21
|
+
"summary" : summary,
|
|
22
|
+
"text" : text
|
|
23
|
+
};
|
|
24
|
+
const requestType = ticketConfig.requestType;
|
|
25
|
+
if (requestType === 'incident') {
|
|
26
|
+
data[searchUtil.mapFieldNameReverse('Incident Number', mapping)] = ticketId;
|
|
27
|
+
data[searchUtil.mapFieldNameReverse('Incident Entry ID', mapping)] = ticketId;
|
|
28
|
+
fields.push(
|
|
29
|
+
'Incident Number',
|
|
30
|
+
'Incident Entry ID'
|
|
31
|
+
)
|
|
32
|
+
} else if (requestType === 'workOrder') {
|
|
33
|
+
data[searchUtil.mapFieldNameReverse('Work Order ID', mapping)] = ticketId;
|
|
34
|
+
data[searchUtil.mapFieldNameReverse('WorkOrder_EntryID', mapping)] = ticketId;
|
|
35
|
+
fields.push(
|
|
36
|
+
'Work Order ID',
|
|
37
|
+
'WorkOrder_EntryID'
|
|
38
|
+
)
|
|
39
|
+
} else if (requestType === 'change') {
|
|
40
|
+
data[searchUtil.mapFieldNameReverse('Infrastructure Change ID', mapping)] = ticketId;
|
|
41
|
+
data[searchUtil.mapFieldNameReverse('Infra. Change Entry ID', mapping)] = ticketId;
|
|
42
|
+
fields.push(
|
|
43
|
+
'Infrastructure Change ID',
|
|
44
|
+
'Infra. Change Entry ID'
|
|
45
|
+
)
|
|
46
|
+
} else if (requestType === 'problem') {
|
|
47
|
+
data[searchUtil.mapFieldNameReverse('Problem Investigation ID', mapping)] = ticketId;
|
|
48
|
+
data[searchUtil.mapFieldNameReverse('Problem Investigation Entry ID', mapping)] = ticketId;
|
|
49
|
+
fields.push(
|
|
50
|
+
'Problem Investigation ID',
|
|
51
|
+
'Problem Investigation Entry ID'
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const clientConstants = clientConfig[ticketConfig.requestTypeWorkLog].constants;
|
|
56
|
+
if (isPublic == true) {
|
|
57
|
+
clientConstants.push({"name": "View Access", "value" : "Public"});
|
|
58
|
+
} else {
|
|
59
|
+
clientConstants.push({"name": "View Access", "value" : "Internal"});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
//run preScripts
|
|
63
|
+
if (scripts && scripts.preMapping) {
|
|
64
|
+
await scriptController.runScripts(scripts.preMapping, data);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
data = mappingUtil.applyMapping2Remedy(data, mapping, clientConstants, fields);
|
|
68
|
+
|
|
69
|
+
//run postScripts
|
|
70
|
+
if (scripts && scripts.postMapping) {
|
|
71
|
+
await scriptController.runScripts(scripts.postMapping, data);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const result = arquery.createEntry(ticketConfig.forms.workLog, data, clientConfig.options)
|
|
75
|
+
|
|
76
|
+
//run afterExecution
|
|
77
|
+
if (scripts && scripts.afterExecution) {
|
|
78
|
+
await scriptController.runScripts(scripts.afterExecution, data);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function setWorklogAttachment(ticketConfig, clientConfig, worklogId, file, attachmentId) {
|
|
85
|
+
const fieldId = getAttachmentFieldId(attachmentId);
|
|
86
|
+
return arquery.setAttachment(ticketConfig.forms.workLog, worklogId, fieldId, file);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function getWorklogAttachment(ticketConfig, clientConfig, worklogId, attachmentId) {
|
|
90
|
+
const fieldId = getAttachmentFieldId(attachmentId);
|
|
91
|
+
return arquery.getAttachment(ticketConfig.forms.workLog, worklogId, fieldId);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function getAttachmentFieldId(attachmentId) {
|
|
95
|
+
let attachmentFieldId = 1000000351;
|
|
96
|
+
if (attachmentId == 2) {
|
|
97
|
+
attachmentFieldId = 1000000352;
|
|
98
|
+
} else if (attachmentId == 3) {
|
|
99
|
+
attachmentFieldId = 1000000353;
|
|
100
|
+
}
|
|
101
|
+
log.debug('AttachmentFieldId', attachmentFieldId);
|
|
102
|
+
return attachmentFieldId;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
async function getWorklogs(ticketConfig, clientConfig, ticketId, mapping) {
|
|
106
|
+
let query = '1=2';
|
|
107
|
+
const requestType = ticketConfig.requestType;
|
|
108
|
+
if (requestType === 'incident') {
|
|
109
|
+
query = `'Incident Number'=\"${ticketId}\"`;
|
|
110
|
+
} else if (requestType === 'change') {
|
|
111
|
+
query = `'Infrastructure Change ID'=\"${ticketId}\"`;
|
|
112
|
+
} else if (requestType === 'problem') {
|
|
113
|
+
query = `'Problem Investigation ID'=\"${ticketId}\"`;
|
|
114
|
+
} else if (requestType === 'workOrder') {
|
|
115
|
+
query = `'Work Order ID'=\"${ticketId}\"`;
|
|
116
|
+
}
|
|
117
|
+
const returnValue = await queryWorklogs(ticketConfig, clientConfig, query, mapping);
|
|
118
|
+
return {data: returnValue.data};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async function getWorklog(ticketConfig, clientConfig, ticketId, worklogId, mapping) {
|
|
122
|
+
let query = '1=2';
|
|
123
|
+
const requestType = ticketConfig.requestType;
|
|
124
|
+
if (requestType === 'incident') {
|
|
125
|
+
query = `'Incident Number'=\"${ticketId}\" AND '1' = \"${worklogId}\"`;
|
|
126
|
+
} else if (requestType === 'change') {
|
|
127
|
+
query = `'Infrastructure Change ID'=\"${ticketId}\" AND '1' = \"${worklogId}\"`;
|
|
128
|
+
} else if (requestType === 'problem') {
|
|
129
|
+
query = `'Problem Investigation ID'=\"${ticketId}\" AND '1' = \"${worklogId}\"`;
|
|
130
|
+
} else if (requestType === 'workOrder') {
|
|
131
|
+
query = `'Work Order ID'=\"${ticketId}\" AND '1' = \"${worklogId}\"`;
|
|
132
|
+
}
|
|
133
|
+
const returnValue = await queryWorklogs(ticketConfig, clientConfig, query, mapping);
|
|
134
|
+
const urls = {
|
|
135
|
+
"attachmentUrl":
|
|
136
|
+
`${ticketConfig.baseURI}/${ticketId}/worklogs/${worklogId}/attachments/1`
|
|
137
|
+
,
|
|
138
|
+
"attachmentUrl2":
|
|
139
|
+
`${ticketConfig.baseURI}/${ticketId}/worklogs/${worklogId}/attachments/2`
|
|
140
|
+
,
|
|
141
|
+
"attachmentUrl3":
|
|
142
|
+
`${ticketConfig.baseURI}/${ticketId}/worklogs/${worklogId}/attachments/3`
|
|
143
|
+
,
|
|
144
|
+
"self":
|
|
145
|
+
`${ticketConfig.baseURI}/${ticketId}/worklogs/${worklogId}`
|
|
146
|
+
};
|
|
147
|
+
return {data: returnValue.data[0], urls};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
async function queryWorklogs(ticketConfig, clientConfig, query, mapping) {
|
|
151
|
+
const baseQuery = clientConfig[ticketConfig.requestTypeWorkLog].basequery;
|
|
152
|
+
const fields = clientConfig[ticketConfig.requestTypeWorkLog].fields;
|
|
153
|
+
const key = 'worklog' + baseQuery + fields.toString() + query;
|
|
154
|
+
const scripts = clientConfig[ticketConfig.requestTypeWorkLog].scripts.GET;
|
|
155
|
+
|
|
156
|
+
log.debug('Cachekey is ', key);
|
|
157
|
+
|
|
158
|
+
if (mapping == null || mapping == undefined) {
|
|
159
|
+
mapping = config.getMapping(ticketConfig.requestTypeWorkLog);
|
|
160
|
+
}
|
|
161
|
+
log.debug('mapping', mapping);
|
|
162
|
+
log.debug('fields', fields);
|
|
163
|
+
|
|
164
|
+
return ticketCache.get(key, async function () {
|
|
165
|
+
const result = await arquery.executeARQuery(ticketConfig.forms.workLog, baseQuery || null, query, fields.toString() || '1', clientConfig.options)
|
|
166
|
+
if (result.data && Array.isArray(result.data)) {
|
|
167
|
+
let x;
|
|
168
|
+
for (x=0; x< result.data.length; x++) {
|
|
169
|
+
const element = result.data[x];
|
|
170
|
+
//run preScripts
|
|
171
|
+
if (scripts && scripts.preMapping) {
|
|
172
|
+
await scriptController.runScripts(scripts.preMapping, data);
|
|
173
|
+
}
|
|
174
|
+
applyMapping(element, mapping, 'Entry ID');
|
|
175
|
+
//run postScripts
|
|
176
|
+
if (scripts && scripts.postMapping) {
|
|
177
|
+
await scriptController.runScripts(scripts.postMapping, data);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return {
|
|
181
|
+
"data": result.data
|
|
182
|
+
};
|
|
183
|
+
} else {
|
|
184
|
+
return {"data":[]};
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
module.exports = {
|
|
190
|
+
createWorklog,
|
|
191
|
+
getWorklog,
|
|
192
|
+
getWorklogs,
|
|
193
|
+
getWorklogAttachment,
|
|
194
|
+
setWorklogAttachment
|
|
195
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Define standard eol format
|
|
2
|
+
|
|
3
|
+
# Web Files
|
|
4
|
+
*.html text eol=lf
|
|
5
|
+
*.md text eol=lf
|
|
6
|
+
*.css text eol=lf
|
|
7
|
+
*.js text eol=lf
|
|
8
|
+
|
|
9
|
+
# Jekyll related files
|
|
10
|
+
*.yml text eol=lf
|
|
11
|
+
|
|
12
|
+
# Git related files
|
|
13
|
+
.gittattributes text eol=lf
|
|
14
|
+
.gitignore text eol=lf
|
|
15
|
+
.gitkeep text eol=lf
|
|
16
|
+
|
|
17
|
+
# Ruby files
|
|
18
|
+
*.rb text eol=lf
|
|
19
|
+
Gemfile text eol=lf
|
|
20
|
+
Gemfile.lock text eol=lf
|
|
21
|
+
|
|
22
|
+
# Github specific fies
|
|
23
|
+
LICENCE text eol=lf
|
|
24
|
+
|
|
25
|
+
# Docker specific files
|
|
26
|
+
Dockerfile text eol=lf
|
|
27
|
+
|
|
28
|
+
# VSCode files
|
|
29
|
+
*.json text eol=lf
|
|
30
|
+
|
|
31
|
+
# General multimedia files
|
|
32
|
+
*.jpg binary
|
|
33
|
+
*.jpeg binary
|
|
34
|
+
*.gif binary
|
|
35
|
+
*.png binary
|
|
36
|
+
*.t3x binary
|
|
37
|
+
*.t3d binary
|
|
38
|
+
*.exe binary
|
|
39
|
+
*.data binary
|
|
40
|
+
*.ttf binary
|
|
41
|
+
*.eof binary
|
|
42
|
+
*.eot binary
|
|
43
|
+
*.swf binary
|
|
44
|
+
*.mov binary
|
|
45
|
+
*.mp4 binary
|
|
46
|
+
*.mp3 binary
|
|
47
|
+
*.ogg binary
|
|
48
|
+
*.flv binary
|
package/docs/404.html
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
---
|
|
2
|
+
layout: default
|
|
3
|
+
title: 404 - Page not found
|
|
4
|
+
permalink: /404.html
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
<div class="text-center">
|
|
8
|
+
<h1>Whoops, this page doesn't exist.</h1>
|
|
9
|
+
<h1>Move along. (404 error)</h1>
|
|
10
|
+
<br/>
|
|
11
|
+
|
|
12
|
+
<img src="{{ 'img/404-southpark.jpg' | relative_url }}" />
|
|
13
|
+
</div>
|
package/docs/CNAME
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
smileconnect.manyosdocs.de
|