@contrail/flexplm 1.3.0 → 1.3.1-alpha.3e8dbdd
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/lib/cli/commands/compile.d.ts +1 -0
- package/lib/cli/commands/compile.js +71 -0
- package/lib/cli/commands/compile.spec.d.ts +1 -0
- package/lib/cli/commands/compile.spec.js +80 -0
- package/lib/cli/commands/create.d.ts +1 -0
- package/lib/cli/commands/create.js +75 -0
- package/lib/cli/commands/create.spec.d.ts +1 -0
- package/lib/cli/commands/create.spec.js +78 -0
- package/lib/cli/commands/upload.d.ts +10 -0
- package/lib/cli/commands/upload.js +226 -0
- package/lib/cli/commands/upload.spec.d.ts +1 -0
- package/lib/cli/commands/upload.spec.js +88 -0
- package/lib/cli/index.d.ts +2 -0
- package/lib/cli/index.js +64 -0
- package/lib/cli/index.spec.d.ts +1 -0
- package/lib/cli/index.spec.js +79 -0
- package/lib/cli/template/mapping-template.ts.template +62 -0
- package/lib/entity-processor/base-entity-processor.d.ts +89 -42
- package/lib/entity-processor/base-entity-processor.js +438 -385
- package/lib/entity-processor/base-entity-processor.spec.d.ts +1 -1
- package/lib/entity-processor/base-entity-processor.spec.js +398 -397
- package/lib/flexplm-request.d.ts +3 -3
- package/lib/flexplm-request.js +34 -34
- package/lib/flexplm-utils.d.ts +5 -5
- package/lib/flexplm-utils.js +33 -33
- package/lib/flexplm-utils.spec.d.ts +1 -1
- package/lib/flexplm-utils.spec.js +26 -26
- package/lib/index.d.ts +23 -22
- package/lib/index.js +39 -38
- package/lib/interfaces/interfaces.d.ts +105 -105
- package/lib/interfaces/interfaces.js +2 -2
- package/lib/interfaces/item-family-changes.d.ts +20 -20
- package/lib/interfaces/item-family-changes.js +56 -56
- package/lib/interfaces/mapping-file.d.ts +460 -0
- package/lib/interfaces/mapping-file.js +2 -0
- package/lib/interfaces/publish-change-data.d.ts +19 -19
- package/lib/interfaces/publish-change-data.js +32 -32
- package/lib/publish/base-process-publish-assortment-callback.d.ts +9 -9
- package/lib/publish/base-process-publish-assortment-callback.js +38 -38
- package/lib/publish/base-process-publish-assortment.d.ts +118 -93
- package/lib/publish/base-process-publish-assortment.js +998 -944
- package/lib/publish/base-process-publish-assortment.spec.d.ts +1 -1
- package/lib/publish/base-process-publish-assortment.spec.js +1688 -1670
- package/lib/publish/mockData.d.ts +1389 -1389
- package/lib/publish/mockData.js +4524 -4519
- package/lib/transform/identifier-conversion-spec-mockData.js +472 -444
- package/lib/transform/identifier-conversion.d.ts +51 -15
- package/lib/transform/identifier-conversion.js +248 -212
- package/lib/transform/identifier-conversion.spec.d.ts +1 -1
- package/lib/transform/identifier-conversion.spec.js +343 -339
- package/lib/util/config-defaults.d.ts +8 -8
- package/lib/util/config-defaults.js +88 -85
- package/lib/util/config-defaults.spec.d.ts +1 -1
- package/lib/util/config-defaults.spec.js +302 -293
- package/lib/util/data-converter-spec-mockData.js +219 -205
- package/lib/util/data-converter.d.ts +136 -39
- package/lib/util/data-converter.js +718 -592
- package/lib/util/data-converter.spec.d.ts +1 -1
- package/lib/util/data-converter.spec.js +906 -904
- package/lib/util/error-response-object.d.ts +9 -4
- package/lib/util/error-response-object.js +54 -47
- package/lib/util/error-response-object.spec.d.ts +1 -1
- package/lib/util/error-response-object.spec.js +99 -99
- package/lib/util/event-short-message-status.d.ts +19 -19
- package/lib/util/event-short-message-status.js +24 -23
- package/lib/util/federation.d.ts +15 -15
- package/lib/util/federation.js +157 -149
- package/lib/util/flexplm-connect.d.ts +29 -22
- package/lib/util/flexplm-connect.js +190 -176
- package/lib/util/flexplm-connect.spec.d.ts +1 -1
- package/lib/util/flexplm-connect.spec.js +88 -88
- package/lib/util/logger-config.d.ts +1 -1
- package/lib/util/logger-config.js +27 -26
- package/lib/util/map-util-spec-mockData.js +219 -205
- package/lib/util/map-utils.d.ts +33 -6
- package/lib/util/map-utils.js +42 -15
- package/lib/util/map-utils.spec.d.ts +1 -1
- package/lib/util/map-utils.spec.js +89 -89
- package/lib/util/mockData.d.ts +80 -80
- package/lib/util/mockData.js +103 -103
- package/lib/util/thumbnail-util.d.ts +55 -34
- package/lib/util/thumbnail-util.js +242 -215
- package/lib/util/thumbnail-util.spec.d.ts +1 -1
- package/lib/util/thumbnail-util.spec.js +440 -434
- package/lib/util/type-conversion-utils-spec-mockData.js +259 -259
- package/lib/util/type-conversion-utils.d.ts +163 -23
- package/lib/util/type-conversion-utils.js +408 -265
- package/lib/util/type-conversion-utils.spec.d.ts +1 -1
- package/lib/util/type-conversion-utils.spec.js +868 -868
- package/lib/util/type-defaults.d.ts +74 -16
- package/lib/util/type-defaults.js +279 -221
- package/lib/util/type-defaults.spec.d.ts +1 -1
- package/lib/util/type-defaults.spec.js +516 -516
- package/lib/util/type-utils.d.ts +34 -13
- package/lib/util/type-utils.js +137 -114
- package/lib/util/type-utils.spec.d.ts +1 -1
- package/lib/util/type-utils.spec.js +192 -190
- package/package.json +21 -6
- package/scripts/copy-template.js +10 -0
- package/.claude/settings.local.json +0 -8
- package/.github/pull_request_template.md +0 -31
- package/.github/workflows/flexplm-lib.yml +0 -27
- package/.github/workflows/publish-to-npm.yml +0 -124
- package/CHANGELOG.md +0 -32
- package/publish.bat +0 -5
- package/publish.sh +0 -5
- package/src/entity-processor/base-entity-processor.spec.ts +0 -460
- package/src/entity-processor/base-entity-processor.ts +0 -515
- package/src/flexplm-request.ts +0 -28
- package/src/flexplm-utils.spec.ts +0 -27
- package/src/flexplm-utils.ts +0 -29
- package/src/index.ts +0 -22
- package/src/interfaces/interfaces.ts +0 -122
- package/src/interfaces/item-family-changes.ts +0 -67
- package/src/interfaces/publish-change-data.ts +0 -43
- package/src/publish/base-process-publish-assortment-callback.ts +0 -50
- package/src/publish/base-process-publish-assortment.spec.ts +0 -1992
- package/src/publish/base-process-publish-assortment.ts +0 -1134
- package/src/publish/mockData.ts +0 -4561
- package/src/transform/identifier-conversion-spec-mockData.ts +0 -496
- package/src/transform/identifier-conversion.spec.ts +0 -354
- package/src/transform/identifier-conversion.ts +0 -282
- package/src/util/config-defaults.spec.ts +0 -350
- package/src/util/config-defaults.ts +0 -93
- package/src/util/data-converter-spec-mockData.ts +0 -231
- package/src/util/data-converter.spec.ts +0 -1041
- package/src/util/data-converter.ts +0 -762
- package/src/util/error-response-object.spec.ts +0 -116
- package/src/util/error-response-object.ts +0 -50
- package/src/util/event-short-message-status.ts +0 -22
- package/src/util/federation.ts +0 -172
- package/src/util/flexplm-connect.spec.ts +0 -132
- package/src/util/flexplm-connect.ts +0 -208
- package/src/util/logger-config.ts +0 -20
- package/src/util/map-util-spec-mockData.ts +0 -231
- package/src/util/map-utils.spec.ts +0 -103
- package/src/util/map-utils.ts +0 -41
- package/src/util/mockData.ts +0 -101
- package/src/util/thumbnail-util.spec.ts +0 -508
- package/src/util/thumbnail-util.ts +0 -272
- package/src/util/type-conversion-utils-spec-mockData.ts +0 -271
- package/src/util/type-conversion-utils.spec.ts +0 -968
- package/src/util/type-conversion-utils.ts +0 -460
- package/src/util/type-defaults.spec.ts +0 -669
- package/src/util/type-defaults.ts +0 -281
- package/src/util/type-utils.spec.ts +0 -227
- package/src/util/type-utils.ts +0 -144
- package/tsconfig.json +0 -29
- package/tslint.json +0 -57
|
@@ -1,592 +1,718 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DataConverter = void 0;
|
|
4
|
-
const sdk_1 = require("@contrail/sdk");
|
|
5
|
-
const type_utils_1 = require("./type-utils");
|
|
6
|
-
const app_framework_1 = require("@contrail/app-framework");
|
|
7
|
-
const util_1 = require("@contrail/util");
|
|
8
|
-
const type_conversion_utils_1 = require("./type-conversion-utils");
|
|
9
|
-
const map_utils_1 = require("./map-utils");
|
|
10
|
-
class DataConverter {
|
|
11
|
-
static clearStaticUserCache() {
|
|
12
|
-
DataConverter.staticUserCache = {};
|
|
13
|
-
}
|
|
14
|
-
static getFromStaticCache(id) {
|
|
15
|
-
return DataConverter.staticUserCache[id];
|
|
16
|
-
}
|
|
17
|
-
static setToStaticCache(id, value) {
|
|
18
|
-
DataConverter.staticUserCache[id] = value;
|
|
19
|
-
}
|
|
20
|
-
constructor(config, mapFileUtil) {
|
|
21
|
-
this.config = config;
|
|
22
|
-
this.mapFileUtil = mapFileUtil;
|
|
23
|
-
this.useDisplayForEnumerationMatching = false;
|
|
24
|
-
this.verboseDebug = false;
|
|
25
|
-
this.objRefCache = {};
|
|
26
|
-
this.userRefCache = {};
|
|
27
|
-
this.typeUtils = new type_utils_1.TypeUtils();
|
|
28
|
-
this.transformMapFile = this.config['transformMapFile'];
|
|
29
|
-
this.useDisplayForEnumerationMatching = this.config['dataConverter']
|
|
30
|
-
&& this.config['dataConverter']['useDisplayForEnumerationMatching'];
|
|
31
|
-
this.verboseDebug = this.config['dataConverter']
|
|
32
|
-
&& this.config['dataConverter']['verboseDebug'];
|
|
33
|
-
}
|
|
34
|
-
setVerboseDebug(val = false) {
|
|
35
|
-
this.verboseDebug = val;
|
|
36
|
-
}
|
|
37
|
-
isVerboseDebugOn() {
|
|
38
|
-
return this.verboseDebug && app_framework_1.Logger.isDebugOn();
|
|
39
|
-
}
|
|
40
|
-
async getFlexPLMObjectDataFromEvent(event, dataToSkip) {
|
|
41
|
-
return this.getFlexPLMObjectData(event.newData, dataToSkip, true);
|
|
42
|
-
}
|
|
43
|
-
async getFlexPLMObjectData(newData, dataToSkip, inflateObjRef) {
|
|
44
|
-
if (this.isVerboseDebugOn()) {
|
|
45
|
-
console.debug('newData: ' + JSON.stringify(newData));
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
else if ('
|
|
105
|
-
value = nd;
|
|
106
|
-
}
|
|
107
|
-
else if ('
|
|
108
|
-
value =
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
const
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
const
|
|
255
|
-
|
|
256
|
-
const
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
value = await this.
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
let
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DataConverter = void 0;
|
|
4
|
+
const sdk_1 = require("@contrail/sdk");
|
|
5
|
+
const type_utils_1 = require("./type-utils");
|
|
6
|
+
const app_framework_1 = require("@contrail/app-framework");
|
|
7
|
+
const util_1 = require("@contrail/util");
|
|
8
|
+
const type_conversion_utils_1 = require("./type-conversion-utils");
|
|
9
|
+
const map_utils_1 = require("./map-utils");
|
|
10
|
+
class DataConverter {
|
|
11
|
+
static clearStaticUserCache() {
|
|
12
|
+
DataConverter.staticUserCache = {};
|
|
13
|
+
}
|
|
14
|
+
static getFromStaticCache(id) {
|
|
15
|
+
return DataConverter.staticUserCache[id];
|
|
16
|
+
}
|
|
17
|
+
static setToStaticCache(id, value) {
|
|
18
|
+
DataConverter.staticUserCache[id] = value;
|
|
19
|
+
}
|
|
20
|
+
constructor(config, mapFileUtil) {
|
|
21
|
+
this.config = config;
|
|
22
|
+
this.mapFileUtil = mapFileUtil;
|
|
23
|
+
this.useDisplayForEnumerationMatching = false;
|
|
24
|
+
this.verboseDebug = false;
|
|
25
|
+
this.objRefCache = {};
|
|
26
|
+
this.userRefCache = {};
|
|
27
|
+
this.typeUtils = new type_utils_1.TypeUtils();
|
|
28
|
+
this.transformMapFile = this.config['transformMapFile'];
|
|
29
|
+
this.useDisplayForEnumerationMatching = this.config['dataConverter']
|
|
30
|
+
&& this.config['dataConverter']['useDisplayForEnumerationMatching'];
|
|
31
|
+
this.verboseDebug = this.config['dataConverter']
|
|
32
|
+
&& this.config['dataConverter']['verboseDebug'];
|
|
33
|
+
}
|
|
34
|
+
setVerboseDebug(val = false) {
|
|
35
|
+
this.verboseDebug = val;
|
|
36
|
+
}
|
|
37
|
+
isVerboseDebugOn() {
|
|
38
|
+
return this.verboseDebug && app_framework_1.Logger.isDebugOn();
|
|
39
|
+
}
|
|
40
|
+
async getFlexPLMObjectDataFromEvent(event, dataToSkip) {
|
|
41
|
+
return this.getFlexPLMObjectData(event.newData, dataToSkip, true);
|
|
42
|
+
}
|
|
43
|
+
async getFlexPLMObjectData(newData, dataToSkip, inflateObjRef) {
|
|
44
|
+
if (this.isVerboseDebugOn()) {
|
|
45
|
+
console.debug('newData: ' + JSON.stringify(newData));
|
|
46
|
+
}
|
|
47
|
+
//Using event to get propertyDiffs to find emptied values
|
|
48
|
+
//Add standard atts to skip
|
|
49
|
+
dataToSkip = dataToSkip.concat(['updatedOn', 'updatedById', 'createdOn', 'createdById', 'modifiedAt', 'orgId', 'createdAt', 'id', 'typeId', 'workspaceId']);
|
|
50
|
+
// const oldData = event.oldData;
|
|
51
|
+
const data = {};
|
|
52
|
+
const typeId = newData?.typeId;
|
|
53
|
+
if (!typeId) {
|
|
54
|
+
return; // Don't have a type; so can't process
|
|
55
|
+
}
|
|
56
|
+
data['typePath'] = newData['typePath'];
|
|
57
|
+
const type = await this.typeUtils.getTypeById(typeId);
|
|
58
|
+
const typeProps = this.typeUtils.filterTypeProperties(type, newData);
|
|
59
|
+
for (const prop of typeProps) {
|
|
60
|
+
// if(this.logger.isTraceOn()){
|
|
61
|
+
// this.logger.log('prop: ' + JSON.stringify(prop));
|
|
62
|
+
// }
|
|
63
|
+
const slug = prop['slug'];
|
|
64
|
+
if (dataToSkip.includes(slug)) {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
data[slug] = await this.getFlexPLMValue(prop, newData, inflateObjRef);
|
|
68
|
+
}
|
|
69
|
+
if (this.isVerboseDebugOn()) {
|
|
70
|
+
console.debug('getFlexPLMObjectData-data: ' + JSON.stringify(data));
|
|
71
|
+
}
|
|
72
|
+
return data;
|
|
73
|
+
}
|
|
74
|
+
async getFlexPLMValue(prop, newData, inflateObjRef) {
|
|
75
|
+
const propertyType = prop['propertyType'];
|
|
76
|
+
const slug = prop['slug'];
|
|
77
|
+
const nd = newData[slug];
|
|
78
|
+
// console.log('getFlexPLMValue: ' + propertyType + ', ' +slug + ', ' + nd + ', ' + od);
|
|
79
|
+
let value;
|
|
80
|
+
if (['string', 'text'].includes(propertyType)) {
|
|
81
|
+
value = nd || '';
|
|
82
|
+
}
|
|
83
|
+
else if (['number', 'currency', 'percent', 'sequence'].includes(propertyType)) {
|
|
84
|
+
value = nd || 0;
|
|
85
|
+
}
|
|
86
|
+
else if ('date' === propertyType) {
|
|
87
|
+
if (nd) {
|
|
88
|
+
value = nd;
|
|
89
|
+
// const d = new Date(nd);
|
|
90
|
+
// console.log('Date.getTimezoneOffset(): ' + d.getTimezoneOffset());
|
|
91
|
+
// value = d.toISOString();
|
|
92
|
+
// console.log('date: ' + nd + ' -- ' + value);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
value = null;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
else if ('boolean' === propertyType) {
|
|
99
|
+
value = (nd) ? true : false;
|
|
100
|
+
}
|
|
101
|
+
else if ('choice' === propertyType) {
|
|
102
|
+
value = this.getEnumerationValue(prop, nd);
|
|
103
|
+
}
|
|
104
|
+
else if ('multi_select' === propertyType) {
|
|
105
|
+
value = this.getEnumerationValue(prop, nd);
|
|
106
|
+
}
|
|
107
|
+
else if ('object_reference' === propertyType) {
|
|
108
|
+
value = await this.getObjectReferenceValue(prop, newData, inflateObjRef);
|
|
109
|
+
if (this.isVerboseDebugOn()) {
|
|
110
|
+
console.debug('object_reference: ' + JSON.stringify(value));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
else if ('image' === propertyType) {
|
|
114
|
+
// console.log('image-TODO');
|
|
115
|
+
}
|
|
116
|
+
else if ('formula' === propertyType) {
|
|
117
|
+
value = nd;
|
|
118
|
+
}
|
|
119
|
+
else if ('json' === propertyType) {
|
|
120
|
+
// console.log('json-TODO');
|
|
121
|
+
value = nd;
|
|
122
|
+
}
|
|
123
|
+
else if ('userList' === propertyType) {
|
|
124
|
+
value = await this.getUserListValue(prop, newData);
|
|
125
|
+
}
|
|
126
|
+
return value;
|
|
127
|
+
}
|
|
128
|
+
/** Returns the display values for list properties (choice & multi_select)
|
|
129
|
+
*
|
|
130
|
+
* @param prop
|
|
131
|
+
* @param newData
|
|
132
|
+
* @returns
|
|
133
|
+
*/
|
|
134
|
+
getEnumerationValue(prop, nd) {
|
|
135
|
+
const propertyType = prop['propertyType'];
|
|
136
|
+
let value;
|
|
137
|
+
if (['choice', 'multi_select'].includes(propertyType)) {
|
|
138
|
+
const options = prop['options'] || [];
|
|
139
|
+
if ('choice' === propertyType) {
|
|
140
|
+
if (nd) {
|
|
141
|
+
const option = options.find(option => option.value == nd);
|
|
142
|
+
if (option) {
|
|
143
|
+
value = Object.assign({}, option);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (!value) {
|
|
147
|
+
value = {};
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
else if ('multi_select' === propertyType) {
|
|
151
|
+
value = [];
|
|
152
|
+
if (nd instanceof Array) {
|
|
153
|
+
nd.forEach(key => {
|
|
154
|
+
const optionObject = options.find(option => option.value == key);
|
|
155
|
+
if (optionObject) {
|
|
156
|
+
const option = Object.assign({}, optionObject);
|
|
157
|
+
value.push(option);
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
else if (typeof nd === 'string' && '' !== nd) {
|
|
162
|
+
const optionObject = options.find(option => option.value == nd);
|
|
163
|
+
if (optionObject) {
|
|
164
|
+
const option = Object.assign({}, optionObject);
|
|
165
|
+
value.push(option);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return value;
|
|
171
|
+
}
|
|
172
|
+
async getObjectReferenceValue(prop, newData, inflateObjRef = false) {
|
|
173
|
+
const slug = prop['slug'];
|
|
174
|
+
if (app_framework_1.Logger.isDebugOn()) {
|
|
175
|
+
console.debug('getObjectReferenceValue-prop: ' + slug);
|
|
176
|
+
}
|
|
177
|
+
let value = newData[slug];
|
|
178
|
+
const entityType = prop['referencedTypeRootSlug'];
|
|
179
|
+
const entityId = newData[slug + 'Id'];
|
|
180
|
+
if ((!value || typeof value === 'string') && inflateObjRef) {
|
|
181
|
+
if (entityId) {
|
|
182
|
+
if (this.objRefCache[entityId]) {
|
|
183
|
+
if (app_framework_1.Logger.isDebugOn()) {
|
|
184
|
+
console.debug('cache hit: ' + entityId);
|
|
185
|
+
}
|
|
186
|
+
return this.objRefCache[entityId];
|
|
187
|
+
}
|
|
188
|
+
const criteria = {
|
|
189
|
+
id: entityId
|
|
190
|
+
};
|
|
191
|
+
const entities = await new sdk_1.Entities().get({
|
|
192
|
+
entityName: entityType,
|
|
193
|
+
criteria
|
|
194
|
+
});
|
|
195
|
+
value = (entities && entities[0]) ? entities[0] : undefined;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (value && !(typeof value === 'string')) {
|
|
199
|
+
const unprocessedValue = value;
|
|
200
|
+
const objectClass = await type_conversion_utils_1.TypeConversionUtils.getObjectClass(this.transformMapFile, this.mapFileUtil, unprocessedValue);
|
|
201
|
+
const flexPLMTypePath = await type_conversion_utils_1.TypeConversionUtils.getObjectTypePath(this.transformMapFile, this.mapFileUtil, unprocessedValue);
|
|
202
|
+
value = await this.getFlexPLMObjectData(value, [], false);
|
|
203
|
+
value['entityReference'] = entityType + ':' + entityId;
|
|
204
|
+
value['objectClass'] = objectClass;
|
|
205
|
+
value['flexPLMTypePath'] = flexPLMTypePath;
|
|
206
|
+
if (this.transformMapFile) {
|
|
207
|
+
const mapKey = await type_conversion_utils_1.TypeConversionUtils.getMapKey(this.transformMapFile, this.mapFileUtil, unprocessedValue, type_conversion_utils_1.TypeConversionUtils.VIBE2FLEX_DIRECTION);
|
|
208
|
+
value = await map_utils_1.MapUtil.applyTransformMap(this.transformMapFile, this.mapFileUtil, value, mapKey, type_conversion_utils_1.TypeConversionUtils.VIBE2FLEX_DIRECTION);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
value = {};
|
|
213
|
+
}
|
|
214
|
+
this.objRefCache[entityId] = value;
|
|
215
|
+
return value;
|
|
216
|
+
}
|
|
217
|
+
/** (Deprecated) Use TypeConversionUtils.getMapKey()
|
|
218
|
+
* Will return the class to use to get mapping.
|
|
219
|
+
* This is needed because mappings will be different for different sub types
|
|
220
|
+
* of custom-entity
|
|
221
|
+
*
|
|
222
|
+
* @param obj: Entity being checked
|
|
223
|
+
* @param mapping: The whole mapping file
|
|
224
|
+
*/
|
|
225
|
+
getMappingClass(entity, mapping) {
|
|
226
|
+
const entityTypePath = entity['typePath'];
|
|
227
|
+
const typeMapKey = mapping['typeMapKey'];
|
|
228
|
+
let objClass = typeMapKey[entityTypePath];
|
|
229
|
+
const entityType = entity['entityType'];
|
|
230
|
+
if (!objClass) {
|
|
231
|
+
objClass = this.typeUtils.getEventObjectClass(entityType, entity);
|
|
232
|
+
}
|
|
233
|
+
if (!objClass) {
|
|
234
|
+
objClass = entityType;
|
|
235
|
+
}
|
|
236
|
+
return objClass;
|
|
237
|
+
}
|
|
238
|
+
/** Sets entity values from FlexPLM data passed in
|
|
239
|
+
* Assumes the entity has a VibeIQ typeId and 'roles' value to filter if necessary.
|
|
240
|
+
* @param entity the entity to update
|
|
241
|
+
* @param data the FlexPLM data
|
|
242
|
+
* @param keysToSkip properties to skip
|
|
243
|
+
* @returns the modified entity with VibeIQ values
|
|
244
|
+
*/
|
|
245
|
+
async setEntityValues(entity, data, keysToSkip = []) {
|
|
246
|
+
// this.logger.log('setEntityValues: ' + JSON.stringify(entity));
|
|
247
|
+
// this.logger.log('data: ' + JSON.stringify(data));
|
|
248
|
+
const type = await this.typeUtils.getTypeById(entity.typeId);
|
|
249
|
+
keysToSkip = keysToSkip.concat(['updatedOn', 'updatedById', 'createdOn', 'createdById', 'modifiedAt', 'orgId', 'createdAt', 'id', 'typeId', 'typePath', 'workspaceId']);
|
|
250
|
+
let typeProps = this.typeUtils.filterTypeProperties(type, entity);
|
|
251
|
+
typeProps = typeProps.filter(prop => !keysToSkip.includes(prop['slug']));
|
|
252
|
+
//Only process properties that had a value sent; to not accidentally clear out values
|
|
253
|
+
//for properties that weren't sent.
|
|
254
|
+
const dataKeys = Object.getOwnPropertyNames(data);
|
|
255
|
+
typeProps = typeProps.filter(prop => dataKeys.includes(prop['slug']));
|
|
256
|
+
for (const prop of typeProps) {
|
|
257
|
+
const propertyType = prop['propertyType'];
|
|
258
|
+
const slug = prop['slug'];
|
|
259
|
+
let keyName = slug;
|
|
260
|
+
if (propertyType === 'userList' || propertyType === 'object_reference') {
|
|
261
|
+
keyName = slug + 'Id';
|
|
262
|
+
}
|
|
263
|
+
entity[keyName] = await this.getEntityValue(prop, data);
|
|
264
|
+
// console.log('entity[slug]: ' + entity[slug]);
|
|
265
|
+
}
|
|
266
|
+
return entity;
|
|
267
|
+
}
|
|
268
|
+
/** Gets the entity values from FlexPLM data
|
|
269
|
+
* Assumes there isn't a VibeIQ typeId, so uses FlexPLM data to determine type
|
|
270
|
+
* @param objectClass FlexPLM object class
|
|
271
|
+
* @param data object data
|
|
272
|
+
* @param keysToSkip type properties to not process
|
|
273
|
+
* @returns object with VibeIQ values
|
|
274
|
+
*/
|
|
275
|
+
async getEntityValues(objectClass, data, keysToSkip = []) {
|
|
276
|
+
const entityValues = {};
|
|
277
|
+
const tco = await this.typeUtils.getEntityTypeClientOptionsUsingMapping(this.transformMapFile, this.mapFileUtil, data);
|
|
278
|
+
const type = await this.typeUtils.getByRootAndPath(tco);
|
|
279
|
+
const typePath = type['typePath'];
|
|
280
|
+
if (typePath && (typePath.startsWith('item') || typePath.startsWith('project-item'))) {
|
|
281
|
+
if (['LCSProduct', 'LCSProductSeasonLink'].includes(objectClass)) {
|
|
282
|
+
entityValues['roles'] = ['family'];
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
entityValues['roles'] = ['color', 'option'];
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
let typeProps = this.typeUtils.filterTypeProperties(type, entityValues);
|
|
289
|
+
typeProps = typeProps.filter(prop => !keysToSkip.includes(prop['slug']));
|
|
290
|
+
for (const prop of typeProps) {
|
|
291
|
+
const slug = prop['slug'];
|
|
292
|
+
const value = await this.getEntityValue(prop, data);
|
|
293
|
+
if (value) {
|
|
294
|
+
entityValues[slug] = value;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
return entityValues;
|
|
298
|
+
}
|
|
299
|
+
/** Gets the VibeIQ value for the property from data
|
|
300
|
+
*
|
|
301
|
+
* @param prop the VibeIQ property
|
|
302
|
+
* @param data the FlexPLM data
|
|
303
|
+
* @returns value to be set in VibeIQ
|
|
304
|
+
*/
|
|
305
|
+
async getEntityValue(prop, data) {
|
|
306
|
+
const propertyType = prop['propertyType'];
|
|
307
|
+
const slug = prop['slug'];
|
|
308
|
+
const nd = data[slug];
|
|
309
|
+
// this.logger.log('getValue: ' + propertyType + ', ' +slug + ', ' + nd);
|
|
310
|
+
let value;
|
|
311
|
+
if (['string', 'text'].includes(propertyType)) {
|
|
312
|
+
value = nd;
|
|
313
|
+
}
|
|
314
|
+
else if (['number', 'currency', 'percent', 'sequence'].includes(propertyType)) {
|
|
315
|
+
value = (null === nd) ? 0 : nd;
|
|
316
|
+
}
|
|
317
|
+
else if ('date' === propertyType) {
|
|
318
|
+
if (nd) {
|
|
319
|
+
// const offset = new Date(nd).getTimezoneOffset() * 60 * 1_000;
|
|
320
|
+
// this.logger.log('nd: ' + nd);
|
|
321
|
+
// this.logger.log(offset);
|
|
322
|
+
// this.logger.log('No Offset: ' + new Date(nd).toISOString());
|
|
323
|
+
// const d = new Date(nd + offset);// Take system Timezone into account.
|
|
324
|
+
const d = new Date(nd);
|
|
325
|
+
value = d.toISOString();
|
|
326
|
+
}
|
|
327
|
+
else {
|
|
328
|
+
value = null;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
else if ('boolean' === propertyType) {
|
|
332
|
+
value = (nd) ? true : false;
|
|
333
|
+
}
|
|
334
|
+
else if ('choice' === propertyType) {
|
|
335
|
+
value = this.setEnumerationKeys(prop, nd, this.useDisplayForEnumerationMatching);
|
|
336
|
+
}
|
|
337
|
+
else if ('multi_select' === propertyType) {
|
|
338
|
+
value = this.setEnumerationKeys(prop, nd, this.useDisplayForEnumerationMatching);
|
|
339
|
+
}
|
|
340
|
+
else if ('object_reference' === propertyType) {
|
|
341
|
+
value = await this.setObjectReferenceValue(prop, nd);
|
|
342
|
+
}
|
|
343
|
+
else if ('image' === propertyType) {
|
|
344
|
+
// console.log('TODO-image');
|
|
345
|
+
}
|
|
346
|
+
else if ('formula' === propertyType) {
|
|
347
|
+
// console.log('TODO-formula');
|
|
348
|
+
}
|
|
349
|
+
else if ('json' === propertyType) {
|
|
350
|
+
// console.log('TODO-json');
|
|
351
|
+
}
|
|
352
|
+
else if ('userList' === propertyType) {
|
|
353
|
+
value = await this.setUserListValue(prop, nd);
|
|
354
|
+
}
|
|
355
|
+
// console.log(value);
|
|
356
|
+
return value;
|
|
357
|
+
}
|
|
358
|
+
setEnumerationKeys(prop, nd, matchByDisplay) {
|
|
359
|
+
const propertyType = prop['propertyType'];
|
|
360
|
+
let value;
|
|
361
|
+
if (['choice', 'multi_select'].includes(propertyType)) {
|
|
362
|
+
//If there are no options, use empty array to not error out and don't set anything
|
|
363
|
+
const options = prop['options'] || [];
|
|
364
|
+
if ('choice' === propertyType) {
|
|
365
|
+
if (nd) {
|
|
366
|
+
const matchKey = (matchByDisplay) ? 'display' : 'value';
|
|
367
|
+
const option = options.find(option => option[matchKey] == nd[matchKey]);
|
|
368
|
+
if (option) {
|
|
369
|
+
value = option.value;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
else {
|
|
373
|
+
value = undefined;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
else if ('multi_select' === propertyType) {
|
|
377
|
+
value = [];
|
|
378
|
+
const matchKey = (matchByDisplay) ? 'display' : 'value';
|
|
379
|
+
if (nd instanceof Array) {
|
|
380
|
+
nd.forEach(selectedOpt => {
|
|
381
|
+
const optionObject = options.find(option => option[matchKey] == selectedOpt[matchKey]);
|
|
382
|
+
if (optionObject) {
|
|
383
|
+
const option = optionObject.value;
|
|
384
|
+
value.push(option);
|
|
385
|
+
}
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
return value;
|
|
391
|
+
}
|
|
392
|
+
/** Compares the potential changes to the entity and returns only the actual differences.
|
|
393
|
+
*
|
|
394
|
+
* @param entity the full entity
|
|
395
|
+
* @param changes the potential changes
|
|
396
|
+
* @returns only the change values that are different from the entity's value
|
|
397
|
+
*/
|
|
398
|
+
getPersistableChanges(entity, changes) {
|
|
399
|
+
const entityCompareValues = {};
|
|
400
|
+
for (const key of (Object.getOwnPropertyNames(changes))) {
|
|
401
|
+
entityCompareValues[key] = entity[key];
|
|
402
|
+
}
|
|
403
|
+
const diffs = util_1.ObjectUtil.compareDeep(entityCompareValues, changes, '');
|
|
404
|
+
const diffValues = {};
|
|
405
|
+
if (diffs && diffs.length > 0) {
|
|
406
|
+
for (const diff of diffs) {
|
|
407
|
+
diffValues[diff.propertyName] = diff.newValue;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
return diffValues;
|
|
411
|
+
}
|
|
412
|
+
/** Sets object reference value from FlexPLM data passed in
|
|
413
|
+
*
|
|
414
|
+
* @param prop the VibeIQ property
|
|
415
|
+
* @param nd the VibeIQ data
|
|
416
|
+
* @returns the object reference id from VibeIQ
|
|
417
|
+
*/
|
|
418
|
+
async setObjectReferenceValue(prop, nd) {
|
|
419
|
+
let objectReferenceId = "";
|
|
420
|
+
if (!nd) {
|
|
421
|
+
return objectReferenceId;
|
|
422
|
+
}
|
|
423
|
+
if (this.transformMapFile) {
|
|
424
|
+
const mapKey = await type_conversion_utils_1.TypeConversionUtils.getMapKeyFromObject(this.transformMapFile, this.mapFileUtil, nd, type_conversion_utils_1.TypeConversionUtils.FLEX2VIBE_DIRECTION);
|
|
425
|
+
nd = await map_utils_1.MapUtil.applyTransformMap(this.transformMapFile, this.mapFileUtil, nd, mapKey, type_conversion_utils_1.TypeConversionUtils.FLEX2VIBE_DIRECTION);
|
|
426
|
+
}
|
|
427
|
+
const entityType = prop['referencedTypeRootSlug'];
|
|
428
|
+
const entityTypePath = prop['referencedTypePath'];
|
|
429
|
+
const entityKeys = Object.keys(nd);
|
|
430
|
+
const identifierKeys = await type_conversion_utils_1.TypeConversionUtils.getIdentifierPropertiesFromObject(this.transformMapFile, this.mapFileUtil, nd);
|
|
431
|
+
const hasAllIdentifiers = identifierKeys.every(key => entityKeys.includes(key));
|
|
432
|
+
if (identifierKeys.length == 0 || !hasAllIdentifiers) {
|
|
433
|
+
console.warn(`The inbound ${entityType} for prop '${prop['slug']}' doesnt have all "identifier" properties, so there is no processing. Identifier properties: ${identifierKeys}`);
|
|
434
|
+
return objectReferenceId;
|
|
435
|
+
}
|
|
436
|
+
const rootType = await this.typeUtils.getByRootAndPath({ root: entityType });
|
|
437
|
+
const rootTypeProps = this.typeUtils.filterTypeProperties(rootType, nd);
|
|
438
|
+
let rootTypeCriteria = {};
|
|
439
|
+
let typeCriteria = {};
|
|
440
|
+
identifierKeys.forEach(keyName => {
|
|
441
|
+
const foundInObjects = rootTypeProps.some(obj => obj.slug === keyName);
|
|
442
|
+
if (foundInObjects) {
|
|
443
|
+
rootTypeCriteria[keyName] = nd[keyName];
|
|
444
|
+
}
|
|
445
|
+
else {
|
|
446
|
+
typeCriteria[keyName] = nd[keyName];
|
|
447
|
+
}
|
|
448
|
+
});
|
|
449
|
+
const combinedCriteria = { ...rootTypeCriteria, ...typeCriteria, typePath: entityTypePath };
|
|
450
|
+
const cacheKey = Object.values(combinedCriteria).join('_');
|
|
451
|
+
if (this.objRefCache[cacheKey]) {
|
|
452
|
+
if (app_framework_1.Logger.isDebugOn()) {
|
|
453
|
+
console.debug(`object reference cache hit: ${cacheKey}`);
|
|
454
|
+
}
|
|
455
|
+
return this.objRefCache[cacheKey];
|
|
456
|
+
}
|
|
457
|
+
let arrObjectReferences = await this.getAllObjectReferences(entityType, rootTypeCriteria);
|
|
458
|
+
if (entityType !== entityTypePath) {
|
|
459
|
+
arrObjectReferences = this.checkKeysAndValues(typeCriteria, arrObjectReferences, entityTypePath);
|
|
460
|
+
}
|
|
461
|
+
if (arrObjectReferences.length) {
|
|
462
|
+
if (arrObjectReferences.length === 1) {
|
|
463
|
+
objectReferenceId = arrObjectReferences[0].id;
|
|
464
|
+
}
|
|
465
|
+
else {
|
|
466
|
+
console.warn(`The passed in object reference criteria has duplicate records found ${JSON.stringify(combinedCriteria)}.`);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
if (!objectReferenceId) {
|
|
470
|
+
console.warn(`The passed in object reference criteria ${JSON.stringify(combinedCriteria)} didn't match any entities.`);
|
|
471
|
+
return objectReferenceId;
|
|
472
|
+
}
|
|
473
|
+
this.objRefCache[cacheKey] = objectReferenceId;
|
|
474
|
+
return objectReferenceId;
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Retrieves all object references of a specified entity type based on the provided criteria.
|
|
478
|
+
* This function handles pagination and asynchronously fetches object references until there are no more pages.
|
|
479
|
+
* @param {string} entityType - The type of entity for which object references are to be retrieved.
|
|
480
|
+
* @param {object} rootTypeCriteria - The criteria used to filter object references.
|
|
481
|
+
* @returns {Promise<Array>} A Promise that resolves to an array containing all object references.
|
|
482
|
+
*/
|
|
483
|
+
async getAllObjectReferences(entityType, rootTypeCriteria, postProcessCriteria = null) {
|
|
484
|
+
const entities = new sdk_1.Entities();
|
|
485
|
+
let loads = [];
|
|
486
|
+
let nextPageKey;
|
|
487
|
+
let usedV2 = false;
|
|
488
|
+
do {
|
|
489
|
+
const take = 1000;
|
|
490
|
+
const loadPage = await entities.get({
|
|
491
|
+
entityName: entityType,
|
|
492
|
+
criteria: rootTypeCriteria,
|
|
493
|
+
apiVersion: sdk_1.API_VERSION.V2,
|
|
494
|
+
take,
|
|
495
|
+
nextPageKey,
|
|
496
|
+
});
|
|
497
|
+
nextPageKey = loadPage?.nextPageKey;
|
|
498
|
+
if (Object.keys(loadPage).includes('results')) {
|
|
499
|
+
usedV2 = true;
|
|
500
|
+
let postProcessedResults = this.filterOutArchivedAndTrashedEntities(loadPage?.results);
|
|
501
|
+
if (postProcessedResults?.length > 0 && postProcessCriteria && Object.keys(postProcessCriteria).length !== 0) {
|
|
502
|
+
const subEntityTypePath = rootTypeCriteria.typePath || entityType;
|
|
503
|
+
postProcessedResults = this.checkKeysAndValues(postProcessCriteria, postProcessedResults, subEntityTypePath);
|
|
504
|
+
}
|
|
505
|
+
loads.push(...postProcessedResults);
|
|
506
|
+
}
|
|
507
|
+
else {
|
|
508
|
+
nextPageKey = null;
|
|
509
|
+
}
|
|
510
|
+
} while (nextPageKey);
|
|
511
|
+
if (!usedV2) {
|
|
512
|
+
const take = 1000;
|
|
513
|
+
let skip = 0;
|
|
514
|
+
let done = false;
|
|
515
|
+
while (!done) {
|
|
516
|
+
const loadPage = await entities.get({
|
|
517
|
+
entityName: entityType,
|
|
518
|
+
criteria: rootTypeCriteria,
|
|
519
|
+
take,
|
|
520
|
+
skip,
|
|
521
|
+
});
|
|
522
|
+
let postProcessedResults = this.filterOutArchivedAndTrashedEntities(loadPage);
|
|
523
|
+
if (postProcessCriteria && Object.keys(postProcessCriteria).length !== 0) {
|
|
524
|
+
const subEntityTypePath = rootTypeCriteria.typePath || entityType;
|
|
525
|
+
postProcessedResults = this.checkKeysAndValues(postProcessCriteria, postProcessedResults, subEntityTypePath);
|
|
526
|
+
}
|
|
527
|
+
loads.push(...postProcessedResults);
|
|
528
|
+
if (loadPage.length !== take) {
|
|
529
|
+
done = true;
|
|
530
|
+
}
|
|
531
|
+
else {
|
|
532
|
+
skip += take;
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
return loads;
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* Checks if all keys and values of a given object are present in an array of objects.
|
|
540
|
+
* @param {Object} criteria - The object whose keys and values are to be checked in the array of objects.
|
|
541
|
+
* @param {Array<Object>} arrayOfObjects - The array of objects to be searched for matching keys and values.
|
|
542
|
+
* @param {string} entityTypePath - The type / subtype for the property; objects must be this type or a sub type of it.
|
|
543
|
+
* @returns {(Object|boolean)} Returns the array of objects that matches all keys and values of the provided object.
|
|
544
|
+
* If no match is found, returns empty array.
|
|
545
|
+
*/
|
|
546
|
+
checkKeysAndValues(criteria, arrayOfObjects, entityTypePath) {
|
|
547
|
+
let arrOfMatchObjects = [];
|
|
548
|
+
for (let i = 0; i < arrayOfObjects.length; i++) {
|
|
549
|
+
const currentObj = arrayOfObjects[i];
|
|
550
|
+
let found = true;
|
|
551
|
+
if (entityTypePath && currentObj['typePath']) {
|
|
552
|
+
const currentObjPath = '' + currentObj['typePath'];
|
|
553
|
+
if (!currentObjPath.startsWith(entityTypePath)) {
|
|
554
|
+
found = false;
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
for (const key in criteria) {
|
|
558
|
+
if (!(key in currentObj) || currentObj[key] !== criteria[key]) {
|
|
559
|
+
found = false;
|
|
560
|
+
break;
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
if (found) {
|
|
564
|
+
arrOfMatchObjects.push(currentObj);
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
return arrOfMatchObjects;
|
|
568
|
+
}
|
|
569
|
+
/** Filters out archived and trashed entities from the provided array of entities.
|
|
570
|
+
*
|
|
571
|
+
* @param entities
|
|
572
|
+
* @returns
|
|
573
|
+
*/
|
|
574
|
+
filterOutArchivedAndTrashedEntities(entities) {
|
|
575
|
+
if (!entities || !Array.isArray(entities) || entities.length === 0) {
|
|
576
|
+
return [];
|
|
577
|
+
}
|
|
578
|
+
return entities.filter(entity => {
|
|
579
|
+
const isArchived = entity?.isArchived;
|
|
580
|
+
const isTrashed = entity?.isTrashed;
|
|
581
|
+
return !isArchived && !isTrashed;
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
/** Sets userListId value from FlexPLM data passed in
|
|
585
|
+
*
|
|
586
|
+
* @param prop the VibeIQ property
|
|
587
|
+
* @param nd the VibeIQ data
|
|
588
|
+
* @returns the modified entity with FlexPLM values
|
|
589
|
+
*/
|
|
590
|
+
async setUserListValue(prop, nd) {
|
|
591
|
+
if (!nd?.email) {
|
|
592
|
+
return "";
|
|
593
|
+
}
|
|
594
|
+
let cacheUser = DataConverter.getFromStaticCache(nd.email);
|
|
595
|
+
if (cacheUser) {
|
|
596
|
+
if (app_framework_1.Logger.isDebugOn()) {
|
|
597
|
+
console.debug('user cache hit: ' + nd.email);
|
|
598
|
+
}
|
|
599
|
+
await this.processGroupMemberCheck(prop, nd.email);
|
|
600
|
+
return cacheUser;
|
|
601
|
+
}
|
|
602
|
+
const user = await this.getUserByEmail(nd);
|
|
603
|
+
const userId = (user) ? user.id : undefined;
|
|
604
|
+
if (userId) {
|
|
605
|
+
DataConverter.setToStaticCache(nd.email, userId);
|
|
606
|
+
await this.processGroupMemberCheck(prop, nd.email);
|
|
607
|
+
}
|
|
608
|
+
return userId;
|
|
609
|
+
}
|
|
610
|
+
/** Makes batch calls of 1000 of user-org entities until
|
|
611
|
+
* it find one with userEmail of passed in nd.email.
|
|
612
|
+
* Maxes out after querying for 15,000 user-org entities
|
|
613
|
+
*
|
|
614
|
+
* @param nd
|
|
615
|
+
* @returns
|
|
616
|
+
*/
|
|
617
|
+
async getUserByEmail(nd) {
|
|
618
|
+
let userOrg = undefined;
|
|
619
|
+
let count = 0;
|
|
620
|
+
let size = 0;
|
|
621
|
+
let emailInput = nd?.email.toLowerCase();
|
|
622
|
+
const entities = new sdk_1.Entities();
|
|
623
|
+
const getOptionsCriteria = {
|
|
624
|
+
entityName: 'user-org',
|
|
625
|
+
take: 1000
|
|
626
|
+
};
|
|
627
|
+
do {
|
|
628
|
+
const userBatch = await entities.get(getOptionsCriteria);
|
|
629
|
+
userOrg = userBatch.find(uo => uo?.userEmail.toLowerCase() === emailInput);
|
|
630
|
+
} while (!userOrg && size == getOptionsCriteria.take && count < 15);
|
|
631
|
+
return userOrg?.user;
|
|
632
|
+
}
|
|
633
|
+
/** Shows warning if user email address not present in group associated to property
|
|
634
|
+
*
|
|
635
|
+
* @param prop the VibeIQ property
|
|
636
|
+
* @param userEmail user email address
|
|
637
|
+
*/
|
|
638
|
+
async processGroupMemberCheck(prop, userEmail) {
|
|
639
|
+
let arrUserList = [];
|
|
640
|
+
if (this.userRefCache[prop.typePropertyUserListId]) {
|
|
641
|
+
arrUserList = this.userRefCache[prop.typePropertyUserListId];
|
|
642
|
+
}
|
|
643
|
+
else {
|
|
644
|
+
const userListResult = await new sdk_1.Entities().get({
|
|
645
|
+
entityName: 'user-list',
|
|
646
|
+
id: prop.typePropertyUserListId
|
|
647
|
+
});
|
|
648
|
+
if (userListResult && Object.keys(userListResult).length) {
|
|
649
|
+
arrUserList = userListResult.userList;
|
|
650
|
+
this.userRefCache[prop.typePropertyUserListId] = arrUserList;
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
if (arrUserList.length) {
|
|
654
|
+
const result = arrUserList.find(element => element['display'] === userEmail);
|
|
655
|
+
if (!result) {
|
|
656
|
+
console.warn(`The passed in user ${userEmail} in property slug ${prop.slug} should be a member of the group associated with the property 'typePropertyUserListId'`);
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
/** Gets the VibeIQ value for the userList property from data
|
|
661
|
+
*
|
|
662
|
+
* @param prop the VibeIQ property
|
|
663
|
+
* @param newData the FlexPLM data
|
|
664
|
+
* @returns value to be set in VibeIQ
|
|
665
|
+
*/
|
|
666
|
+
async getUserListValue(prop, newData) {
|
|
667
|
+
const slug = prop['slug'];
|
|
668
|
+
if (app_framework_1.Logger.isDebugOn()) {
|
|
669
|
+
console.debug('getUserListValue-prop: ' + slug);
|
|
670
|
+
}
|
|
671
|
+
const entityId = newData[slug + 'Id'];
|
|
672
|
+
if (!entityId) {
|
|
673
|
+
return {};
|
|
674
|
+
}
|
|
675
|
+
const cacheUser = DataConverter.getFromStaticCache(entityId);
|
|
676
|
+
if (cacheUser) {
|
|
677
|
+
if (app_framework_1.Logger.isDebugOn()) {
|
|
678
|
+
console.debug('user cache hit: ' + entityId);
|
|
679
|
+
}
|
|
680
|
+
return Object.assign({}, cacheUser);
|
|
681
|
+
}
|
|
682
|
+
const user = await this.getUserById(entityId);
|
|
683
|
+
const value = (user) ? {
|
|
684
|
+
email: user.email,
|
|
685
|
+
firstName: user.first,
|
|
686
|
+
lastName: user.last,
|
|
687
|
+
isSsoUser: user.isSsoUser,
|
|
688
|
+
} : undefined;
|
|
689
|
+
if (value) {
|
|
690
|
+
DataConverter.setToStaticCache(entityId, value);
|
|
691
|
+
}
|
|
692
|
+
return value;
|
|
693
|
+
}
|
|
694
|
+
/** Makes batch calls of 1000 of user-org entities until
|
|
695
|
+
* it find one with user.id of passed in userId.
|
|
696
|
+
* Maxes out after querying for 15,000 user-org entities
|
|
697
|
+
*
|
|
698
|
+
* @param userId
|
|
699
|
+
* @returns
|
|
700
|
+
*/
|
|
701
|
+
async getUserById(userId) {
|
|
702
|
+
let userOrg = undefined;
|
|
703
|
+
let count = 0;
|
|
704
|
+
let size = 0;
|
|
705
|
+
const entities = new sdk_1.Entities();
|
|
706
|
+
const getOptionsCriteria = {
|
|
707
|
+
entityName: 'user-org',
|
|
708
|
+
take: 1000
|
|
709
|
+
};
|
|
710
|
+
do {
|
|
711
|
+
const userBatch = await entities.get(getOptionsCriteria);
|
|
712
|
+
userOrg = userBatch.find(uo => uo?.user?.id === userId);
|
|
713
|
+
} while (!userOrg && size == getOptionsCriteria.take && count < 15);
|
|
714
|
+
return userOrg?.user;
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
exports.DataConverter = DataConverter;
|
|
718
|
+
DataConverter.staticUserCache = {};
|