@manyos/smileconnect-api 1.35.0 → 1.36.1

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/conf/clients.json CHANGED
@@ -165,7 +165,14 @@
165
165
  "value": "Calbro Services and Weapons"
166
166
  }
167
167
  ],
168
- "scripts": {}
168
+ "scripts": {
169
+ "GET": {
170
+ "postMapping": [
171
+ "script1",
172
+ "script2"
173
+ ]
174
+ }
175
+ }
169
176
  },
170
177
  "change": {
171
178
  "fields": [
@@ -8,5 +8,8 @@ if (remedyResult) {
8
8
  if (weatherResponse) {
9
9
  requestData.weather = await weatherResponse.json()
10
10
  }
11
+ log.debug('testMessage')
12
+
13
+ requestData.scResults = await adapter.smileconnect.getTicket('incidents', requestData.id, {clientId:'idm'})
11
14
 
12
15
  resolve();
@@ -1,2 +1,2 @@
1
- //requestData.Status = "Horstdi2";
1
+ requestData.Status = "Horstdi2";
2
2
  resolve();
@@ -12,6 +12,7 @@ const ticketCIRelationController = require('../controller/ticketCIRelationContro
12
12
  const mappingUtil = require('../util/mappingUtil');
13
13
  const { v4 } = require('uuid');
14
14
  const CMDBOBJECT = 'cmdbobject';
15
+ const scriptController = require('./scriptController');
15
16
 
16
17
  const cmdbCache = new CacheService(process.env.CACHETTL_CMDB || 600); // Create a new cache service instance
17
18
  const schemaCache = new CacheService(process.env.CACHETTL_SCHEMANAMES || 3600); // Create a new cache service instance
@@ -175,6 +176,15 @@ async function handleCMDBObjectResult(cmdbObject, mapping, clientConfig, include
175
176
  if (deleteClassId === true) {
176
177
  delete cmdbObject[CMDBOBJECT];
177
178
  }
179
+
180
+ const scripts = clientConfig[CMDBOBJECT].scripts.GET;
181
+ //const fields = clientConfig[ticketConfig.requestType].fields
182
+
183
+ //run preScripts
184
+ if (scripts && scripts.preMapping) {
185
+ await scriptController.runScripts(scripts.preMapping, cmdbObject, clientConfig.clientId);
186
+ }
187
+
178
188
  //Apply mapping
179
189
  mapping.forEach(function (mappingEntry) {
180
190
  try {
@@ -224,6 +234,11 @@ async function handleCMDBObjectResult(cmdbObject, mapping, clientConfig, include
224
234
 
225
235
  relationUtil.getRelatedObjectList(cmdbObject, includeArray, globalRelationObjects);
226
236
 
237
+ //run preScripts
238
+ if (scripts && scripts.postMapping) {
239
+ await scriptController.runScripts(scripts.postMapping, cmdbObject, clientConfig.clientId);
240
+ }
241
+
227
242
  return cmdbObject;
228
243
  }
229
244
 
@@ -53,14 +53,15 @@ async function executeScriptInternal(scriptId, requestData, params, executedBySc
53
53
  throw (`Script ${scriptId} does not exist!`);
54
54
  }
55
55
 
56
- return executeCode(code, requestData, params, null, executedByScript, clientId);
56
+ return executeCode(code, requestData, params, null, executedByScript, clientId, scriptId);
57
57
  }
58
58
 
59
59
  async function executeScript(scriptId, requestData, params, clientId) {
60
60
  return executeScriptInternal(scriptId, requestData, params, false, clientId)
61
61
  }
62
62
 
63
- async function executeCode(code, requestData, params, logStream, executedByScript, clientId) {
63
+ async function executeCode(code, requestData, params, logStream, executedByScript, clientId, scriptId) {
64
+ const log = require('@manyos/logger').setupLog('SMILEcatalog_Script_' + scriptId);
64
65
  //todo should only be added once
65
66
  /*if (logStream) {
66
67
  log.addStream(logStream);
@@ -290,9 +290,7 @@ async function updateTicket(ticketConfig, clientConfig, id, ticketData) {
290
290
  const myClientConfig = {};
291
291
  myClientConfig[ticketConfig.requestType] = {baseQuery: clientConfig[ticketConfig.requestType].baseQuery, fields: [1]};
292
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
- //todo Abfangen wenn getTicket nichts liefert.
293
+
296
294
  const mapping = config.getMapping(ticketConfig.requestType);
297
295
 
298
296
  //Constants work only on new.
@@ -303,6 +301,9 @@ async function updateTicket(ticketConfig, clientConfig, id, ticketData) {
303
301
  await scriptController.runScripts(scripts.postMapping, ticketData, clientConfig.clientId);
304
302
  }
305
303
 
304
+ const ticket = await getTicket(ticketConfig, myClientConfig, id, myMapping);
305
+ log.debug('Ticket to Update', ticket);
306
+ //todo Abfangen wenn getTicket nichts liefert.
306
307
  const update = await arquery.updateEntry(ticketConfig.forms.regular, ticket.data.internalId, ticketData);
307
308
 
308
309
  //run afterExecution
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@manyos/smileconnect-api",
3
- "version": "1.35.0",
3
+ "version": "1.36.1",
4
4
  "description": "A proxy and abstraction layer for BMCs IT Service Management Suite",
5
5
  "main": "app.js",
6
6
  "scripts": {