@contrail/flexplm 1.3.0 → 1.3.1-alpha.585afc1
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 +219 -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 +18 -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 +429 -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,385 +1,438 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseEntityProcessor = exports.IncomingEntityResponse = void 0;
|
|
4
|
-
const type_utils_1 = require("../util/type-utils");
|
|
5
|
-
const flexplm_connect_1 = require("../util/flexplm-connect");
|
|
6
|
-
const map_utils_1 = require("../util/map-utils");
|
|
7
|
-
const sdk_1 = require("@contrail/sdk");
|
|
8
|
-
const type_conversion_utils_1 = require("../util/type-conversion-utils");
|
|
9
|
-
const thumbnail_util_1 = require("../util/thumbnail-util");
|
|
10
|
-
const event_short_message_status_1 = require("../util/event-short-message-status");
|
|
11
|
-
const UNSUPPORTED_TYPE = 'Unsupported eventType.';
|
|
12
|
-
class IncomingEntityResponse {
|
|
13
|
-
}
|
|
14
|
-
exports.IncomingEntityResponse = IncomingEntityResponse;
|
|
15
|
-
class BaseEntityProcessor {
|
|
16
|
-
constructor(config, dc, mapFileUtil, baseType) {
|
|
17
|
-
this.config = config;
|
|
18
|
-
this.dc = dc;
|
|
19
|
-
this.mapFileUtil = mapFileUtil;
|
|
20
|
-
this.baseType = baseType;
|
|
21
|
-
this.typeUtil = new type_utils_1.TypeUtils();
|
|
22
|
-
this.transformMapFile = this.config?.transformMapFile;
|
|
23
|
-
this.entities = new sdk_1.Entities();
|
|
24
|
-
this.orgSlug = this.config?.orgSlug || 'unset-orgSlug';
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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
|
-
const rootTypeCriteria =
|
|
160
|
-
const
|
|
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
|
-
|
|
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
|
-
async
|
|
214
|
-
let
|
|
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
|
-
|
|
255
|
-
|
|
256
|
-
|
|
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
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
const
|
|
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
|
-
if (!
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseEntityProcessor = exports.IncomingEntityResponse = void 0;
|
|
4
|
+
const type_utils_1 = require("../util/type-utils");
|
|
5
|
+
const flexplm_connect_1 = require("../util/flexplm-connect");
|
|
6
|
+
const map_utils_1 = require("../util/map-utils");
|
|
7
|
+
const sdk_1 = require("@contrail/sdk");
|
|
8
|
+
const type_conversion_utils_1 = require("../util/type-conversion-utils");
|
|
9
|
+
const thumbnail_util_1 = require("../util/thumbnail-util");
|
|
10
|
+
const event_short_message_status_1 = require("../util/event-short-message-status");
|
|
11
|
+
const UNSUPPORTED_TYPE = 'Unsupported eventType.';
|
|
12
|
+
class IncomingEntityResponse {
|
|
13
|
+
}
|
|
14
|
+
exports.IncomingEntityResponse = IncomingEntityResponse;
|
|
15
|
+
class BaseEntityProcessor {
|
|
16
|
+
constructor(config, dc, mapFileUtil, baseType) {
|
|
17
|
+
this.config = config;
|
|
18
|
+
this.dc = dc;
|
|
19
|
+
this.mapFileUtil = mapFileUtil;
|
|
20
|
+
this.baseType = baseType;
|
|
21
|
+
this.typeUtil = new type_utils_1.TypeUtils();
|
|
22
|
+
this.transformMapFile = this.config?.transformMapFile;
|
|
23
|
+
this.entities = new sdk_1.Entities();
|
|
24
|
+
this.orgSlug = this.config?.orgSlug || 'unset-orgSlug';
|
|
25
|
+
}
|
|
26
|
+
// inbound
|
|
27
|
+
async inbound(event) {
|
|
28
|
+
const eventType = event.eventType;
|
|
29
|
+
console.log(`inbound entity: ${eventType}:${event.objectClass}`);
|
|
30
|
+
switch (eventType) {
|
|
31
|
+
case 'PERSIST':
|
|
32
|
+
return await this.handleIncomingUpsert(event);
|
|
33
|
+
case 'DELETE':
|
|
34
|
+
return await this.handleIncomingDelete(event);
|
|
35
|
+
default:
|
|
36
|
+
console.error(UNSUPPORTED_TYPE);
|
|
37
|
+
return {
|
|
38
|
+
status: 500,
|
|
39
|
+
data: { UNSUPPORTED_TYPE }
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
async handleIncomingUpsert(event) {
|
|
44
|
+
const inboundData = await this.getTransformedData(event);
|
|
45
|
+
const incomingEntityResponse = await this.getIncomingEntity(event, inboundData);
|
|
46
|
+
// This case means there was an early return in the getIncomingEntity method
|
|
47
|
+
if (incomingEntityResponse.earlyReturn) {
|
|
48
|
+
const statusMsg = this.getInboundStatusMessage({
|
|
49
|
+
status: event_short_message_status_1.EventShortMessageStatus.FAILURE,
|
|
50
|
+
statusMessage: incomingEntityResponse.earlyReturn.shortStatusMessage || '',
|
|
51
|
+
objectClass: event.objectClass,
|
|
52
|
+
federatedId: event.federatedId
|
|
53
|
+
});
|
|
54
|
+
console.log(statusMsg);
|
|
55
|
+
return incomingEntityResponse.earlyReturn;
|
|
56
|
+
}
|
|
57
|
+
const entity = incomingEntityResponse.entity;
|
|
58
|
+
if (!entity) {
|
|
59
|
+
const createEntityResponse = await this.getCreateEntity(inboundData);
|
|
60
|
+
if (createEntityResponse.earlyReturn) {
|
|
61
|
+
const status = (createEntityResponse.earlyReturn.shortStatusMessage === event_short_message_status_1.EventShortMessageStatus.NOT_CREATABLE)
|
|
62
|
+
? event_short_message_status_1.EventShortMessageStatus.SUCCESS
|
|
63
|
+
: event_short_message_status_1.EventShortMessageStatus.FAILURE;
|
|
64
|
+
const statusMsg = this.getInboundStatusMessage({
|
|
65
|
+
status,
|
|
66
|
+
statusMessage: createEntityResponse.earlyReturn.shortStatusMessage || '',
|
|
67
|
+
objectClass: event.objectClass,
|
|
68
|
+
federatedId: event.federatedId
|
|
69
|
+
});
|
|
70
|
+
console.log(statusMsg);
|
|
71
|
+
return createEntityResponse.earlyReturn;
|
|
72
|
+
}
|
|
73
|
+
let createdEntity = await this.createEntity(this.baseType, createEntityResponse.entity);
|
|
74
|
+
const shouldSyncThumbnail = await type_conversion_utils_1.TypeConversionUtils.syncInboundImages(this.transformMapFile, this.mapFileUtil, event.data);
|
|
75
|
+
if (shouldSyncThumbnail) {
|
|
76
|
+
createdEntity = await new thumbnail_util_1.ThumbnailUtil(this.config).syncThumbnailToVibeIQ({ entityId: createdEntity.id, primaryViewableId: createdEntity.primaryViewableId, event, entityName: this.baseType }) || createdEntity;
|
|
77
|
+
}
|
|
78
|
+
const statusMsg = this.getInboundStatusMessage({
|
|
79
|
+
status: event_short_message_status_1.EventShortMessageStatus.SUCCESS,
|
|
80
|
+
statusMessage: event_short_message_status_1.EventShortMessageStatus.CREATED,
|
|
81
|
+
objectClass: event.objectClass,
|
|
82
|
+
entityId: 'id',
|
|
83
|
+
federatedId: event.federatedId
|
|
84
|
+
});
|
|
85
|
+
console.log(statusMsg);
|
|
86
|
+
return createdEntity;
|
|
87
|
+
}
|
|
88
|
+
const diffs = await this.getUpdatesForEntity(entity, inboundData);
|
|
89
|
+
const shouldSyncThumbnail = await type_conversion_utils_1.TypeConversionUtils.syncInboundImages(this.transformMapFile, this.mapFileUtil, event.data);
|
|
90
|
+
let thumbnailEntity;
|
|
91
|
+
if (shouldSyncThumbnail) {
|
|
92
|
+
thumbnailEntity = await new thumbnail_util_1.ThumbnailUtil(this.config).syncThumbnailToVibeIQ({ entityId: entity.id, primaryViewableId: entity.primaryViewableId, event, entityName: this.baseType });
|
|
93
|
+
}
|
|
94
|
+
const hasPropertyChanges = Object.getOwnPropertyNames(diffs).length > 0;
|
|
95
|
+
if (!hasPropertyChanges && thumbnailEntity) {
|
|
96
|
+
const statusMsg = this.getInboundStatusMessage({
|
|
97
|
+
status: event_short_message_status_1.EventShortMessageStatus.SUCCESS,
|
|
98
|
+
statusMessage: event_short_message_status_1.EventShortMessageStatus.PRIMARY_CONTENT_UPDATED,
|
|
99
|
+
objectClass: event.objectClass,
|
|
100
|
+
entityId: entity.id,
|
|
101
|
+
federatedId: event.federatedId
|
|
102
|
+
});
|
|
103
|
+
console.log(statusMsg);
|
|
104
|
+
return thumbnailEntity;
|
|
105
|
+
}
|
|
106
|
+
if (!hasPropertyChanges) {
|
|
107
|
+
const statusMsg = this.getInboundStatusMessage({
|
|
108
|
+
status: event_short_message_status_1.EventShortMessageStatus.SUCCESS,
|
|
109
|
+
statusMessage: event_short_message_status_1.EventShortMessageStatus.NO_CHANGES,
|
|
110
|
+
objectClass: event.objectClass,
|
|
111
|
+
entityId: entity.id,
|
|
112
|
+
federatedId: event.federatedId
|
|
113
|
+
});
|
|
114
|
+
console.log(statusMsg);
|
|
115
|
+
const message = 'No Changes to persist for entity: ' + entity.id;
|
|
116
|
+
return {
|
|
117
|
+
status: 200,
|
|
118
|
+
data: { message }
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
const updatedEntity = await this.updateEntity(this.baseType, entity, diffs);
|
|
122
|
+
const statusMsg = this.getInboundStatusMessage({
|
|
123
|
+
status: event_short_message_status_1.EventShortMessageStatus.SUCCESS,
|
|
124
|
+
statusMessage: event_short_message_status_1.EventShortMessageStatus.UPDATED,
|
|
125
|
+
objectClass: event.objectClass,
|
|
126
|
+
entityId: entity.id,
|
|
127
|
+
federatedId: event.federatedId
|
|
128
|
+
});
|
|
129
|
+
console.log(statusMsg);
|
|
130
|
+
return updatedEntity;
|
|
131
|
+
}
|
|
132
|
+
getInboundStatusMessage(statusObject) {
|
|
133
|
+
return 'BaseEntityProcessor: inbound: status: ' + statusObject.status
|
|
134
|
+
+ ', statusMessage: ' + statusObject.statusMessage
|
|
135
|
+
+ ', entityType: ' + this.baseType
|
|
136
|
+
+ ', entityId: ' + statusObject.entityId
|
|
137
|
+
+ ', objectClass: ' + statusObject.objectClass
|
|
138
|
+
+ ', federatedId: ' + statusObject.federatedId
|
|
139
|
+
+ ', orgSlug: ' + this.orgSlug;
|
|
140
|
+
}
|
|
141
|
+
/**This will query for the entity, and handle post-processing
|
|
142
|
+
* of any critieria that is defined at the sub-type level.
|
|
143
|
+
* Because sub-type criteria can't be used in the search done
|
|
144
|
+
* on the server. This is expected to be called by getIncomingEntity().
|
|
145
|
+
*
|
|
146
|
+
* @param entityType: the root type of the entity
|
|
147
|
+
* @param entityTypePath: the full type path of the entity. Ex: custom-entity:sample
|
|
148
|
+
* @param propertyCriteria: all the criteria to search for the entity
|
|
149
|
+
* @returns the entities that match the criteria
|
|
150
|
+
*/
|
|
151
|
+
async queryEntityWithSubTypeCriteria(entityType, entityTypePath, propertyCriteria) {
|
|
152
|
+
//allCriteria; identifierKeys; entityType; entityTypePath
|
|
153
|
+
if (!entityType || !entityTypePath) {
|
|
154
|
+
throw new Error('type and entityTypePath must be defined');
|
|
155
|
+
}
|
|
156
|
+
if (!propertyCriteria || Object.getOwnPropertyNames(propertyCriteria).length == 0) {
|
|
157
|
+
throw new Error('propertyCriteria must be defined and have at least one property');
|
|
158
|
+
}
|
|
159
|
+
const { rootTypeCriteria, subTypeCriteria } = await this.getCriteriaForEntity(entityType, entityTypePath, propertyCriteria);
|
|
160
|
+
const returnedEntities = await this.dc.getAllObjectReferences(entityType, rootTypeCriteria, subTypeCriteria);
|
|
161
|
+
return returnedEntities;
|
|
162
|
+
}
|
|
163
|
+
/** This is to get the criteria for the entity that is being processed.
|
|
164
|
+
* This is to be overridden for item & project-item because of the need for
|
|
165
|
+
* setting the roles criteria.
|
|
166
|
+
*
|
|
167
|
+
* @param entityType: the root type of the entity
|
|
168
|
+
* @param entityTypePath: the full type path of the entity. Ex: custom-entity:sample
|
|
169
|
+
* @param propertyCriteria: all the criteria to search for the entity
|
|
170
|
+
* @returns the criteria for the entity
|
|
171
|
+
*/
|
|
172
|
+
async getCriteriaForEntity(entityType, entityTypePath, propertyCriteria) {
|
|
173
|
+
if (!entityType || !entityTypePath) {
|
|
174
|
+
throw new Error('type and entityTypePath must be defined');
|
|
175
|
+
}
|
|
176
|
+
if (!propertyCriteria || Object.getOwnPropertyNames(propertyCriteria).length == 0) {
|
|
177
|
+
throw new Error('propertyCriteria must be defined and have at least one property');
|
|
178
|
+
}
|
|
179
|
+
const rootType = await this.typeUtil.getByRootAndPath({ root: entityType });
|
|
180
|
+
const rootTypePropertyKeys = await this.getRootTypePropertyKeys(rootType, propertyCriteria);
|
|
181
|
+
const rootTypeCriteria = {};
|
|
182
|
+
const subTypeCriteria = {};
|
|
183
|
+
if (entityType !== entityTypePath) {
|
|
184
|
+
subTypeCriteria['typePath'] = entityTypePath;
|
|
185
|
+
}
|
|
186
|
+
for (const key in propertyCriteria) {
|
|
187
|
+
if (rootTypePropertyKeys.includes(key)) {
|
|
188
|
+
rootTypeCriteria[key] = propertyCriteria[key];
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
subTypeCriteria[key] = propertyCriteria[key];
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return { rootTypeCriteria, subTypeCriteria };
|
|
195
|
+
}
|
|
196
|
+
/** This is to get the properties that are owned by the root type
|
|
197
|
+
* This needs to be overridded for multi-level types, such as item
|
|
198
|
+
* and project-item. And for those types, the propertyCriteria
|
|
199
|
+
* will be needed to determine the correct level.
|
|
200
|
+
*
|
|
201
|
+
* @param rootType: the full root type entity for the processed entity
|
|
202
|
+
* @param propertyCriteria: the criteria to determine the correct level (unused for single level types)
|
|
203
|
+
* @returns: string[] of the property keys
|
|
204
|
+
*/
|
|
205
|
+
getRootTypePropertyKeys(rootType, propertyCriteria = null) {
|
|
206
|
+
const props = rootType['typeProperties'];
|
|
207
|
+
const rootTypePropertyKeys = props.map(prop => prop.slug);
|
|
208
|
+
return rootTypePropertyKeys;
|
|
209
|
+
}
|
|
210
|
+
async handleIncomingDelete(event) {
|
|
211
|
+
console.warn('delete is not configured', event);
|
|
212
|
+
}
|
|
213
|
+
async getTransformedData(event) {
|
|
214
|
+
let inboundData = event.data;
|
|
215
|
+
console.debug('inboundData: ' + JSON.stringify(inboundData));
|
|
216
|
+
const mapKey = await type_conversion_utils_1.TypeConversionUtils.getMapKeyFromObject(this.transformMapFile, this.mapFileUtil, inboundData, type_conversion_utils_1.TypeConversionUtils.FLEX2VIBE_DIRECTION);
|
|
217
|
+
inboundData = await map_utils_1.MapUtil.applyTransformMap(this.transformMapFile, this.mapFileUtil, inboundData, mapKey, type_conversion_utils_1.TypeConversionUtils.FLEX2VIBE_DIRECTION);
|
|
218
|
+
console.debug('Transformed-inboundData: ' + JSON.stringify(inboundData));
|
|
219
|
+
return inboundData;
|
|
220
|
+
}
|
|
221
|
+
async getUpdatesForEntity(entity, inboundData) {
|
|
222
|
+
const vibeOwningKeys = await this.getVibeOwningKeys(entity);
|
|
223
|
+
let updates = {
|
|
224
|
+
typeId: entity.typeId,
|
|
225
|
+
roles: entity.roles,
|
|
226
|
+
id: entity.id,
|
|
227
|
+
};
|
|
228
|
+
updates = await this.dc.setEntityValues(updates, inboundData, vibeOwningKeys);
|
|
229
|
+
for (const prop of ['typeId', 'roles', 'id']) {
|
|
230
|
+
delete updates[prop];
|
|
231
|
+
}
|
|
232
|
+
return this.dc.getPersistableChanges(entity, updates);
|
|
233
|
+
}
|
|
234
|
+
async getVibeOwningKeys(entity) {
|
|
235
|
+
let vibeOwningKeys = [];
|
|
236
|
+
if (this.transformMapFile && entity) {
|
|
237
|
+
//Technically the transform is flex->vibe. But the vibe entity being updated was passed in,
|
|
238
|
+
// so we use VIBE2FLEX_DIRECTION to get the mapKey
|
|
239
|
+
const mapKey = await type_conversion_utils_1.TypeConversionUtils.getMapKey(this.transformMapFile, this.mapFileUtil, entity, type_conversion_utils_1.TypeConversionUtils.VIBE2FLEX_DIRECTION);
|
|
240
|
+
const mapSection = await map_utils_1.MapUtil.getFullMapSection(this.transformMapFile, this.mapFileUtil, mapKey);
|
|
241
|
+
vibeOwningKeys = mapSection?.vibeOwningKeys || [];
|
|
242
|
+
}
|
|
243
|
+
console.debug('vibeOwningKeys: ' + vibeOwningKeys);
|
|
244
|
+
return vibeOwningKeys;
|
|
245
|
+
}
|
|
246
|
+
async getVibeOwningKeysFromInbound(entity) {
|
|
247
|
+
let vibeOwningKeys = [];
|
|
248
|
+
if (this.transformMapFile && entity) {
|
|
249
|
+
const mapKey = await type_conversion_utils_1.TypeConversionUtils.getMapKeyFromObject(this.transformMapFile, this.mapFileUtil, entity, type_conversion_utils_1.TypeConversionUtils.FLEX2VIBE_DIRECTION);
|
|
250
|
+
const mapSection = await map_utils_1.MapUtil.getFullMapSection(this.transformMapFile, this.mapFileUtil, mapKey);
|
|
251
|
+
vibeOwningKeys = mapSection?.vibeOwningKeys || [];
|
|
252
|
+
}
|
|
253
|
+
console.debug('vibeOwningKeys: ' + vibeOwningKeys);
|
|
254
|
+
return vibeOwningKeys;
|
|
255
|
+
}
|
|
256
|
+
async createEntity(entityName, changes) {
|
|
257
|
+
const options = {
|
|
258
|
+
entityName: entityName,
|
|
259
|
+
object: changes,
|
|
260
|
+
};
|
|
261
|
+
console.log("createEntity: " + JSON.stringify(options));
|
|
262
|
+
return await new sdk_1.Entities().create(options);
|
|
263
|
+
}
|
|
264
|
+
async updateEntity(entityName, entity, diffs) {
|
|
265
|
+
const options = {
|
|
266
|
+
entityName: entityName,
|
|
267
|
+
id: entity['id'],
|
|
268
|
+
object: diffs
|
|
269
|
+
};
|
|
270
|
+
console.log('updateEntity: ' + JSON.stringify(options));
|
|
271
|
+
return await new sdk_1.Entities().update(options);
|
|
272
|
+
}
|
|
273
|
+
// outbound
|
|
274
|
+
async outbound(event) {
|
|
275
|
+
const entityType = event.entityType;
|
|
276
|
+
const eventType = event.eventType;
|
|
277
|
+
const entityId = event.id;
|
|
278
|
+
console.log(`outbound: ${entityType}:${entityId}`);
|
|
279
|
+
switch (eventType) {
|
|
280
|
+
case 'update':
|
|
281
|
+
case 'create':
|
|
282
|
+
return await this.handleOutgoingUpsert(entityType, event);
|
|
283
|
+
case 'delete':
|
|
284
|
+
return await this.handleOutgoingDelete(entityType, event);
|
|
285
|
+
case 'sendUpsertToFlexPLM':
|
|
286
|
+
return await this.sendUpsertToFlexPLM(event);
|
|
287
|
+
default:
|
|
288
|
+
console.log(UNSUPPORTED_TYPE);
|
|
289
|
+
return {
|
|
290
|
+
status: 500,
|
|
291
|
+
data: { UNSUPPORTED_TYPE }
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
async handleOutgoingUpsert(entityType, event) {
|
|
296
|
+
const objectClass = await type_conversion_utils_1.TypeConversionUtils.getObjectClass(this.transformMapFile, this.mapFileUtil, event.newData);
|
|
297
|
+
if (!objectClass) {
|
|
298
|
+
const message = 'ObjectClass must have a value.';
|
|
299
|
+
console.log(message);
|
|
300
|
+
return {
|
|
301
|
+
status: 500,
|
|
302
|
+
data: { message }
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
try {
|
|
306
|
+
const payload = await this.getOutgoingUpsertPayload(entityType, event);
|
|
307
|
+
const flexResponse = await new flexplm_connect_1.FlexPLMConnect(this.config).sendToFlexPLM(payload);
|
|
308
|
+
const outboundEntityUpdates = await this.getOutboundEntityUpdates(event, flexResponse);
|
|
309
|
+
if (outboundEntityUpdates) {
|
|
310
|
+
flexResponse['outboundEntityUpdates'] = outboundEntityUpdates;
|
|
311
|
+
}
|
|
312
|
+
const statusMsg = 'BaseEntityProcessor: outbound: status: ' + event_short_message_status_1.EventShortMessageStatus.SUCCESS
|
|
313
|
+
+ ', statusMessage: ' + flexResponse.status
|
|
314
|
+
+ ', entityType: ' + this.baseType
|
|
315
|
+
+ ', entityId: ' + event.id
|
|
316
|
+
+ ', objectClass: ' + payload.objectClass
|
|
317
|
+
+ ', updateFromResponse: ' + ((outboundEntityUpdates && Object.keys(outboundEntityUpdates).length > 0) ? 'true' : 'false')
|
|
318
|
+
+ ', orgSlug: ' + this.orgSlug;
|
|
319
|
+
console.log(statusMsg);
|
|
320
|
+
return flexResponse;
|
|
321
|
+
}
|
|
322
|
+
catch (e) {
|
|
323
|
+
const statusMsg = 'BaseEntityProcessor: outbound: status: ' + event_short_message_status_1.EventShortMessageStatus.FAILURE
|
|
324
|
+
+ ', statusMessage: ' + e.httpResponseStatus
|
|
325
|
+
+ ', entityType: ' + this.baseType
|
|
326
|
+
+ ', entityId: ' + event.id
|
|
327
|
+
+ ', objectClass: ' + objectClass
|
|
328
|
+
+ ', updateFromResponse: ' + 'false'
|
|
329
|
+
+ ', orgSlug: ' + this.orgSlug;
|
|
330
|
+
console.log(statusMsg);
|
|
331
|
+
throw e;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
async getOutboundEntityUpdates(event, flexResponse) {
|
|
335
|
+
const payload = flexResponse?.data?.payload;
|
|
336
|
+
const flexPayload = (payload) ? payload[0] : undefined;
|
|
337
|
+
let outboundEntityUpdates = undefined;
|
|
338
|
+
if (flexPayload && 'OK' === flexPayload.status) {
|
|
339
|
+
if (flexPayload.data && !flexPayload.data?.flexPLMObjectClass) {
|
|
340
|
+
flexPayload.data.flexPLMObjectClass = flexPayload.objectClass;
|
|
341
|
+
}
|
|
342
|
+
const inboundData = await this.getTransformedData(flexPayload);
|
|
343
|
+
outboundEntityUpdates = await this.getUpdatesForEntity(event.newData, inboundData);
|
|
344
|
+
}
|
|
345
|
+
return outboundEntityUpdates;
|
|
346
|
+
}
|
|
347
|
+
async handleOutgoingDelete(entityType, event) {
|
|
348
|
+
console.warn('delete is not configured', entityType, event.oldData);
|
|
349
|
+
}
|
|
350
|
+
/** Create a new event-workflow-request to rerun sending the entity to FlexPLM
|
|
351
|
+
* The event must contain any information needed to ensure it is put in the correct queue for the entity
|
|
352
|
+
*
|
|
353
|
+
* @param triggerKey Ex: event.entityType + '|sendUpsertToFlexPLM'
|
|
354
|
+
* @param event
|
|
355
|
+
* @returns
|
|
356
|
+
*/
|
|
357
|
+
async triggerNewEvent(triggerKey, event) {
|
|
358
|
+
const newEvent = {
|
|
359
|
+
entityName: 'event-workflow-request',
|
|
360
|
+
object: {
|
|
361
|
+
triggerKey,
|
|
362
|
+
event
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
const response = await this.entities.create(newEvent);
|
|
366
|
+
return response;
|
|
367
|
+
}
|
|
368
|
+
/** Sends the current state of the entity to FlexPLM.
|
|
369
|
+
* So any changes made in Vibe between the event being generated and the event being processed are sent to FlexPLM.
|
|
370
|
+
*
|
|
371
|
+
* @param event must contain entityType, id; which are used to query for the entity
|
|
372
|
+
* @returns results of sending the entity to FlexPLM
|
|
373
|
+
*/
|
|
374
|
+
async sendUpsertToFlexPLM(event) {
|
|
375
|
+
const payload = await this.getEntityCurrentStateUpsertPayload(event);
|
|
376
|
+
if (!payload) {
|
|
377
|
+
const message = 'No payload to send to FlexPLM';
|
|
378
|
+
console.log(message);
|
|
379
|
+
return {
|
|
380
|
+
status: 500,
|
|
381
|
+
data: { message }
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
;
|
|
385
|
+
let objectClass = payload.objectClass;
|
|
386
|
+
try {
|
|
387
|
+
const flexResponse = await new flexplm_connect_1.FlexPLMConnect(this.config).sendToFlexPLM(payload);
|
|
388
|
+
const outboundEntityUpdates = await this.getOutboundEntityUpdates(event, flexResponse);
|
|
389
|
+
if (outboundEntityUpdates) {
|
|
390
|
+
flexResponse['outboundEntityUpdates'] = outboundEntityUpdates;
|
|
391
|
+
}
|
|
392
|
+
const statusMsg = 'BaseEntityProcessor: outbound: status: ' + event_short_message_status_1.EventShortMessageStatus.SUCCESS
|
|
393
|
+
+ ', statusMessage: ' + flexResponse.status
|
|
394
|
+
+ ', entityType: ' + this.baseType
|
|
395
|
+
+ ', entityId: ' + event.id
|
|
396
|
+
+ ', objectClass: ' + objectClass
|
|
397
|
+
+ ', updateFromResponse: ' + ((outboundEntityUpdates && Object.keys(outboundEntityUpdates).length > 0) ? 'true' : 'false')
|
|
398
|
+
+ ', orgSlug: ' + this.orgSlug;
|
|
399
|
+
console.log(statusMsg);
|
|
400
|
+
return flexResponse;
|
|
401
|
+
}
|
|
402
|
+
catch (e) {
|
|
403
|
+
const statusMsg = 'BaseEntityProcessor: outbound: status: ' + event_short_message_status_1.EventShortMessageStatus.FAILURE
|
|
404
|
+
+ ', statusMessage: ' + e.httpResponseStatus
|
|
405
|
+
+ ', entityType: ' + this.baseType
|
|
406
|
+
+ ', entityId: ' + event.id
|
|
407
|
+
+ ', objectClass: ' + objectClass
|
|
408
|
+
+ ', updateFromResponse: ' + 'false'
|
|
409
|
+
+ ', orgSlug: ' + this.orgSlug;
|
|
410
|
+
console.log(statusMsg);
|
|
411
|
+
throw e;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
/** Generates the payload to send to FlexPLM, based on the current state of the entity.
|
|
415
|
+
* The current state of the entity are used as the newData and oldData; which is passed
|
|
416
|
+
* to getOutgoingUpsertPayload to generate the payload.
|
|
417
|
+
* @param event information about the item to send to FlexPLM
|
|
418
|
+
* @returns The payload to send to FlexPLM
|
|
419
|
+
*/
|
|
420
|
+
async getEntityCurrentStateUpsertPayload(event) {
|
|
421
|
+
const id = event.id;
|
|
422
|
+
if (!id) {
|
|
423
|
+
return undefined;
|
|
424
|
+
}
|
|
425
|
+
const entity = await this.entities.get({
|
|
426
|
+
entityName: this.baseType,
|
|
427
|
+
id
|
|
428
|
+
});
|
|
429
|
+
if (!entity) {
|
|
430
|
+
return undefined;
|
|
431
|
+
}
|
|
432
|
+
event.newData = entity;
|
|
433
|
+
event.oldData = entity;
|
|
434
|
+
const payload = await this.getOutgoingUpsertPayload(this.baseType, event);
|
|
435
|
+
return payload;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
exports.BaseEntityProcessor = BaseEntityProcessor;
|