@contrail/flexplm 1.0.17 → 1.0.18
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/entity-processor/base-entity-processor.d.ts +30 -30
- package/lib/entity-processor/base-entity-processor.js +143 -143
- 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/index.d.ts +19 -17
- package/lib/index.js +35 -33
- package/lib/interfaces/interfaces.d.ts +91 -91
- package/lib/interfaces/interfaces.js +2 -2
- package/lib/interfaces/item-family-changes.d.ts +19 -19
- package/lib/interfaces/item-family-changes.js +49 -49
- package/lib/interfaces/publish-change-data.d.ts +17 -17
- package/lib/interfaces/publish-change-data.js +30 -30
- package/lib/publish/base-process-publish-assortment-callback.d.ts +8 -8
- package/lib/publish/base-process-publish-assortment-callback.js +19 -19
- package/lib/publish/base-process-publish-assortment.d.ts +57 -57
- package/lib/publish/base-process-publish-assortment.js +570 -563
- package/lib/publish/mockData.d.ts +774 -774
- package/lib/publish/mockData.js +3033 -3033
- package/lib/util/config-defaults.d.ts +6 -6
- package/lib/util/config-defaults.js +71 -71
- package/lib/util/data-converter.d.ts +22 -22
- package/lib/util/data-converter.js +318 -318
- package/lib/util/federation.d.ts +15 -15
- package/lib/util/federation.js +149 -149
- package/lib/util/flexplm-connect.d.ts +16 -16
- package/lib/util/flexplm-connect.js +130 -130
- package/lib/util/logger-config.d.ts +1 -1
- package/lib/util/logger-config.js +26 -26
- package/lib/util/map-util-spec-mockData.d.ts +0 -0
- package/lib/util/map-util-spec-mockData.js +203 -0
- package/lib/util/map-utils.d.ts +4 -3
- package/lib/util/map-utils.js +28 -20
- package/lib/util/mockData.d.ts +39 -39
- package/lib/util/mockData.js +100 -100
- package/lib/util/thumbnail-util.d.ts +15 -15
- package/lib/util/thumbnail-util.js +112 -112
- package/lib/util/type-conversion-utils-spec-mockData.d.ts +0 -0
- package/lib/util/type-conversion-utils-spec-mockData.js +205 -0
- package/lib/util/type-conversion-utils.d.ts +10 -0
- package/lib/util/type-conversion-utils.js +100 -0
- package/lib/util/type-defaults.d.ts +9 -0
- package/lib/util/type-defaults.js +117 -0
- package/lib/util/type-utils.d.ts +12 -12
- package/lib/util/type-utils.js +101 -101
- package/package.json +47 -46
|
@@ -1,563 +1,570 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseProcessPublishAssortment = void 0;
|
|
4
|
-
const sdk_1 = require("@contrail/sdk");
|
|
5
|
-
const flexplm_connect_1 = require("../util/flexplm-connect");
|
|
6
|
-
const item_family_changes_1 = require("../interfaces/item-family-changes");
|
|
7
|
-
const publish_change_data_1 = require("../interfaces/publish-change-data");
|
|
8
|
-
const map_utils_1 = require("../util/map-utils");
|
|
9
|
-
const fsPromise = require("fs/promises");
|
|
10
|
-
const path = require("path");
|
|
11
|
-
class BaseProcessPublishAssortment {
|
|
12
|
-
constructor(_config, _dc, _mapFileUtil) {
|
|
13
|
-
this.TTL = 7 * 24 * 60 * 60 * 1000;
|
|
14
|
-
this.config = _config;
|
|
15
|
-
this.dc = _dc;
|
|
16
|
-
this.mapFileUtil = _mapFileUtil;
|
|
17
|
-
this.transformMapFile = this.config['transformMapFile'];
|
|
18
|
-
}
|
|
19
|
-
async process(event) {
|
|
20
|
-
try {
|
|
21
|
-
console.info('process-start!');
|
|
22
|
-
const assortmentId = event.assortmentId;
|
|
23
|
-
let seasonFed;
|
|
24
|
-
try {
|
|
25
|
-
seasonFed = await this.getSeasonFederation(assortmentId);
|
|
26
|
-
}
|
|
27
|
-
catch (e) {
|
|
28
|
-
const message = e.message;
|
|
29
|
-
console.log(message);
|
|
30
|
-
const output = {
|
|
31
|
-
results: { message },
|
|
32
|
-
skip_await: true
|
|
33
|
-
};
|
|
34
|
-
return output;
|
|
35
|
-
}
|
|
36
|
-
const assortmentPublishChangeId = event.assortmentPublishChangeId;
|
|
37
|
-
const sinceDate = await this.getSinceDate(assortmentId, assortmentPublishChangeId);
|
|
38
|
-
const assortmentPublishChange = await this.downloadAssortmentPublishChange(assortmentId, assortmentPublishChangeId);
|
|
39
|
-
const changeDetail = await this.downloadHydratedChangeDetail(assortmentPublishChange);
|
|
40
|
-
const fullChange = await this.downloadFullChange(assortmentPublishChange);
|
|
41
|
-
const releasedForDevelopmentItemIds = this.getReleasedForDevelopmentItemAndFamilyIds(fullChange);
|
|
42
|
-
const itemToFederatedIdMapping = await this.getItemFederatedIds();
|
|
43
|
-
const pcd = new publish_change_data_1.PublishChangeData(assortmentId, seasonFed, assortmentPublishChangeId, sinceDate);
|
|
44
|
-
pcd.itemToFederatedIdMapping = itemToFederatedIdMapping;
|
|
45
|
-
pcd.releasedForDevelopmentItemIds = releasedForDevelopmentItemIds;
|
|
46
|
-
const output = await this.processPublish(pcd, changeDetail, fullChange);
|
|
47
|
-
console.info('process-end');
|
|
48
|
-
return output;
|
|
49
|
-
}
|
|
50
|
-
catch (e) {
|
|
51
|
-
console.log('catch e: ' + e.message);
|
|
52
|
-
throw e;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
async getSeasonFederation(assortmentId) {
|
|
56
|
-
let assortment;
|
|
57
|
-
try {
|
|
58
|
-
assortment = await new sdk_1.Entities().get({
|
|
59
|
-
entityName: 'assortment',
|
|
60
|
-
id: assortmentId
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
catch (e) {
|
|
64
|
-
console.warn(`No Assortment found for id: ${assortmentId}`);
|
|
65
|
-
}
|
|
66
|
-
const publishToFlexPLM = assortment?.publishToFlexPLM;
|
|
67
|
-
if (!publishToFlexPLM) {
|
|
68
|
-
throw new Error(BaseProcessPublishAssortment.ASSORTMENT_NOT_PUBLISHABLE);
|
|
69
|
-
}
|
|
70
|
-
const assortmentObj = await this.dc.getFlexPLMObjectData(assortment, [], true);
|
|
71
|
-
let seasonObj = {
|
|
72
|
-
entityReference: 'assortment:' + assortmentId,
|
|
73
|
-
objectClass: 'LCSSeason',
|
|
74
|
-
};
|
|
75
|
-
const identifierKeys = this.config?.identifierAtts?.LCSSeason || [];
|
|
76
|
-
for (const key of identifierKeys) {
|
|
77
|
-
if (assortmentObj[key]) {
|
|
78
|
-
seasonObj[key] = assortmentObj[key];
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
const objectKeys = Object.keys(seasonObj);
|
|
82
|
-
const hasAllIdentifiers = identifierKeys.every(key => objectKeys.includes(key));
|
|
83
|
-
if (!hasAllIdentifiers && !seasonObj?.federationId) {
|
|
84
|
-
throw new Error(BaseProcessPublishAssortment.ASSORTMENT_NO_FED_INFO + identifierKeys);
|
|
85
|
-
}
|
|
86
|
-
seasonObj = await map_utils_1.MapUtil.applyTransformMap(this.transformMapFile, this.mapFileUtil, seasonObj, 'LCSSeason', 'vibe2flex');
|
|
87
|
-
return seasonObj;
|
|
88
|
-
}
|
|
89
|
-
async getSinceDate(assortmentId, assortmentPublishChangeId) {
|
|
90
|
-
const sinceDateString = String(this.config['sinceDate'] || '');
|
|
91
|
-
if (sinceDateString.includes('-')) {
|
|
92
|
-
const [year, month, day] = sinceDateString.split('-').map(Number);
|
|
93
|
-
const minutes = -new Date().getTimezoneOffset();
|
|
94
|
-
return new Date(year, month - 1, day, 0, minutes);
|
|
95
|
-
}
|
|
96
|
-
if (sinceDateString.includes(':')) {
|
|
97
|
-
const [type, countStr] = sinceDateString.split(':');
|
|
98
|
-
const count = parseInt(countStr);
|
|
99
|
-
if (type.trim().toLowerCase() === 'numberofdays') {
|
|
100
|
-
const currentDate = new Date();
|
|
101
|
-
return new Date(currentDate.getUTCFullYear(), currentDate.getUTCMonth(), currentDate.getUTCDate() - count, 0, -currentDate.getTimezoneOffset());
|
|
102
|
-
}
|
|
103
|
-
if (type.trim().toLowerCase() === 'numberofpublishes') {
|
|
104
|
-
const apcHistory = await this.getApcHistory(assortmentId);
|
|
105
|
-
return this.getSinceDateFromAPCs(apcHistory, assortmentPublishChangeId, count);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
const apcHistory = await this.getApcHistory(assortmentId);
|
|
109
|
-
const derivedSinceDate = this.getSinceDateFromAPCs(apcHistory, assortmentPublishChangeId);
|
|
110
|
-
if (!derivedSinceDate)
|
|
111
|
-
throw new Error('Couldn\'t set sinceDate');
|
|
112
|
-
console.info('getSinceDate:', derivedSinceDate);
|
|
113
|
-
return derivedSinceDate;
|
|
114
|
-
}
|
|
115
|
-
async getApcHistory(assortmentId) {
|
|
116
|
-
const resource = `/assortments/${assortmentId}/history/`;
|
|
117
|
-
return sdk_1.Request.request(resource, {
|
|
118
|
-
method: 'GET',
|
|
119
|
-
headers: {
|
|
120
|
-
Accept: 'application/json',
|
|
121
|
-
'Content-Type': 'application/json'
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
updatedSinceDate(entity, sinceDate) {
|
|
126
|
-
const updatedOn = entity?.updatedOn;
|
|
127
|
-
return (updatedOn && new Date(updatedOn) > sinceDate);
|
|
128
|
-
}
|
|
129
|
-
getSinceDateFromAPCs(apcHistory, assortmentPublishChangeId, pastPublishCount = 1) {
|
|
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
|
-
console.
|
|
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
|
-
const
|
|
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
|
-
|
|
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
|
-
return
|
|
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
|
-
await
|
|
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
|
-
|
|
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
|
-
console.
|
|
407
|
-
const
|
|
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
|
-
const
|
|
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
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
const
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
entityReference
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
entityReference: 'item:' + entityReference,
|
|
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
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseProcessPublishAssortment = void 0;
|
|
4
|
+
const sdk_1 = require("@contrail/sdk");
|
|
5
|
+
const flexplm_connect_1 = require("../util/flexplm-connect");
|
|
6
|
+
const item_family_changes_1 = require("../interfaces/item-family-changes");
|
|
7
|
+
const publish_change_data_1 = require("../interfaces/publish-change-data");
|
|
8
|
+
const map_utils_1 = require("../util/map-utils");
|
|
9
|
+
const fsPromise = require("fs/promises");
|
|
10
|
+
const path = require("path");
|
|
11
|
+
class BaseProcessPublishAssortment {
|
|
12
|
+
constructor(_config, _dc, _mapFileUtil) {
|
|
13
|
+
this.TTL = 7 * 24 * 60 * 60 * 1000;
|
|
14
|
+
this.config = _config;
|
|
15
|
+
this.dc = _dc;
|
|
16
|
+
this.mapFileUtil = _mapFileUtil;
|
|
17
|
+
this.transformMapFile = this.config['transformMapFile'];
|
|
18
|
+
}
|
|
19
|
+
async process(event) {
|
|
20
|
+
try {
|
|
21
|
+
console.info('process-start!');
|
|
22
|
+
const assortmentId = event.assortmentId;
|
|
23
|
+
let seasonFed;
|
|
24
|
+
try {
|
|
25
|
+
seasonFed = await this.getSeasonFederation(assortmentId);
|
|
26
|
+
}
|
|
27
|
+
catch (e) {
|
|
28
|
+
const message = e.message;
|
|
29
|
+
console.log(message);
|
|
30
|
+
const output = {
|
|
31
|
+
results: { message },
|
|
32
|
+
skip_await: true
|
|
33
|
+
};
|
|
34
|
+
return output;
|
|
35
|
+
}
|
|
36
|
+
const assortmentPublishChangeId = event.assortmentPublishChangeId;
|
|
37
|
+
const sinceDate = await this.getSinceDate(assortmentId, assortmentPublishChangeId);
|
|
38
|
+
const assortmentPublishChange = await this.downloadAssortmentPublishChange(assortmentId, assortmentPublishChangeId);
|
|
39
|
+
const changeDetail = await this.downloadHydratedChangeDetail(assortmentPublishChange);
|
|
40
|
+
const fullChange = await this.downloadFullChange(assortmentPublishChange);
|
|
41
|
+
const releasedForDevelopmentItemIds = this.getReleasedForDevelopmentItemAndFamilyIds(fullChange);
|
|
42
|
+
const itemToFederatedIdMapping = await this.getItemFederatedIds();
|
|
43
|
+
const pcd = new publish_change_data_1.PublishChangeData(assortmentId, seasonFed, assortmentPublishChangeId, sinceDate);
|
|
44
|
+
pcd.itemToFederatedIdMapping = itemToFederatedIdMapping;
|
|
45
|
+
pcd.releasedForDevelopmentItemIds = releasedForDevelopmentItemIds;
|
|
46
|
+
const output = await this.processPublish(pcd, changeDetail, fullChange);
|
|
47
|
+
console.info('process-end');
|
|
48
|
+
return output;
|
|
49
|
+
}
|
|
50
|
+
catch (e) {
|
|
51
|
+
console.log('catch e: ' + e.message);
|
|
52
|
+
throw e;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
async getSeasonFederation(assortmentId) {
|
|
56
|
+
let assortment;
|
|
57
|
+
try {
|
|
58
|
+
assortment = await new sdk_1.Entities().get({
|
|
59
|
+
entityName: 'assortment',
|
|
60
|
+
id: assortmentId
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
catch (e) {
|
|
64
|
+
console.warn(`No Assortment found for id: ${assortmentId}`);
|
|
65
|
+
}
|
|
66
|
+
const publishToFlexPLM = assortment?.publishToFlexPLM;
|
|
67
|
+
if (!publishToFlexPLM) {
|
|
68
|
+
throw new Error(BaseProcessPublishAssortment.ASSORTMENT_NOT_PUBLISHABLE);
|
|
69
|
+
}
|
|
70
|
+
const assortmentObj = await this.dc.getFlexPLMObjectData(assortment, [], true);
|
|
71
|
+
let seasonObj = {
|
|
72
|
+
entityReference: 'assortment:' + assortmentId,
|
|
73
|
+
objectClass: 'LCSSeason',
|
|
74
|
+
};
|
|
75
|
+
const identifierKeys = this.config?.identifierAtts?.LCSSeason || [];
|
|
76
|
+
for (const key of identifierKeys) {
|
|
77
|
+
if (assortmentObj[key]) {
|
|
78
|
+
seasonObj[key] = assortmentObj[key];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const objectKeys = Object.keys(seasonObj);
|
|
82
|
+
const hasAllIdentifiers = identifierKeys.every(key => objectKeys.includes(key));
|
|
83
|
+
if (!hasAllIdentifiers && !seasonObj?.federationId) {
|
|
84
|
+
throw new Error(BaseProcessPublishAssortment.ASSORTMENT_NO_FED_INFO + identifierKeys);
|
|
85
|
+
}
|
|
86
|
+
seasonObj = await map_utils_1.MapUtil.applyTransformMap(this.transformMapFile, this.mapFileUtil, seasonObj, 'LCSSeason', 'vibe2flex');
|
|
87
|
+
return seasonObj;
|
|
88
|
+
}
|
|
89
|
+
async getSinceDate(assortmentId, assortmentPublishChangeId) {
|
|
90
|
+
const sinceDateString = String(this.config['sinceDate'] || '');
|
|
91
|
+
if (sinceDateString.includes('-')) {
|
|
92
|
+
const [year, month, day] = sinceDateString.split('-').map(Number);
|
|
93
|
+
const minutes = -new Date().getTimezoneOffset();
|
|
94
|
+
return new Date(year, month - 1, day, 0, minutes);
|
|
95
|
+
}
|
|
96
|
+
if (sinceDateString.includes(':')) {
|
|
97
|
+
const [type, countStr] = sinceDateString.split(':');
|
|
98
|
+
const count = parseInt(countStr);
|
|
99
|
+
if (type.trim().toLowerCase() === 'numberofdays') {
|
|
100
|
+
const currentDate = new Date();
|
|
101
|
+
return new Date(currentDate.getUTCFullYear(), currentDate.getUTCMonth(), currentDate.getUTCDate() - count, 0, -currentDate.getTimezoneOffset());
|
|
102
|
+
}
|
|
103
|
+
if (type.trim().toLowerCase() === 'numberofpublishes') {
|
|
104
|
+
const apcHistory = await this.getApcHistory(assortmentId);
|
|
105
|
+
return this.getSinceDateFromAPCs(apcHistory, assortmentPublishChangeId, count);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const apcHistory = await this.getApcHistory(assortmentId);
|
|
109
|
+
const derivedSinceDate = this.getSinceDateFromAPCs(apcHistory, assortmentPublishChangeId);
|
|
110
|
+
if (!derivedSinceDate)
|
|
111
|
+
throw new Error('Couldn\'t set sinceDate');
|
|
112
|
+
console.info('getSinceDate:', derivedSinceDate);
|
|
113
|
+
return derivedSinceDate;
|
|
114
|
+
}
|
|
115
|
+
async getApcHistory(assortmentId) {
|
|
116
|
+
const resource = `/assortments/${assortmentId}/history/`;
|
|
117
|
+
return sdk_1.Request.request(resource, {
|
|
118
|
+
method: 'GET',
|
|
119
|
+
headers: {
|
|
120
|
+
Accept: 'application/json',
|
|
121
|
+
'Content-Type': 'application/json'
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
updatedSinceDate(entity, sinceDate) {
|
|
126
|
+
const updatedOn = entity?.updatedOn;
|
|
127
|
+
return (updatedOn && new Date(updatedOn) > sinceDate);
|
|
128
|
+
}
|
|
129
|
+
getSinceDateFromAPCs(apcHistory, assortmentPublishChangeId, pastPublishCount = 1) {
|
|
130
|
+
if (apcHistory.length === 1) {
|
|
131
|
+
return new Date(0);
|
|
132
|
+
}
|
|
133
|
+
const apcIndex = apcHistory.findIndex(apc => apc.id === assortmentPublishChangeId);
|
|
134
|
+
if (apcIndex === 0) {
|
|
135
|
+
return new Date(0);
|
|
136
|
+
}
|
|
137
|
+
const apc = apcHistory[apcIndex];
|
|
138
|
+
const apcDate = new Date(apc.createdOn);
|
|
139
|
+
const sortedPreviousDates = apcHistory
|
|
140
|
+
.filter(tempapc => tempapc.id !== assortmentPublishChangeId && new Date(tempapc.createdOn) < apcDate)
|
|
141
|
+
.map(tempapc => new Date(tempapc.createdOn))
|
|
142
|
+
.sort((a, b) => a.getTime() - b.getTime());
|
|
143
|
+
const arrIndex = Math.max(sortedPreviousDates.length - pastPublishCount, 0);
|
|
144
|
+
return sortedPreviousDates[arrIndex] || new Date(0);
|
|
145
|
+
}
|
|
146
|
+
async downloadAssortmentPublishChange(assortmentId, assortmentPublishChangeId) {
|
|
147
|
+
const resourceString = '/assortments/' + assortmentId + '/history/' + assortmentPublishChangeId;
|
|
148
|
+
return await sdk_1.Request.request(resourceString, {
|
|
149
|
+
method: 'GET',
|
|
150
|
+
Headers: {
|
|
151
|
+
Accept: 'application/json',
|
|
152
|
+
'Content-Type': 'application/json'
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
async downloadHydratedChangeDetail(assortmentPublishChange) {
|
|
157
|
+
try {
|
|
158
|
+
console.info('downloadHydratedChangeDetail-start');
|
|
159
|
+
const link = assortmentPublishChange?.hydratedDetailDownloadLink;
|
|
160
|
+
const response = await fetch(link);
|
|
161
|
+
const data = await response.json();
|
|
162
|
+
return data;
|
|
163
|
+
}
|
|
164
|
+
catch (e) {
|
|
165
|
+
console.log('Error hydratedDetailDownloadLink: ' + e.message);
|
|
166
|
+
}
|
|
167
|
+
return undefined;
|
|
168
|
+
}
|
|
169
|
+
async downloadFullChange(assortmentPublishChange) {
|
|
170
|
+
console.info('downloadFullChange-start');
|
|
171
|
+
try {
|
|
172
|
+
const link = assortmentPublishChange?.assortmentBaselineDownloadLink;
|
|
173
|
+
const response = await fetch(link);
|
|
174
|
+
const data = await response.json();
|
|
175
|
+
return data;
|
|
176
|
+
}
|
|
177
|
+
catch (e) {
|
|
178
|
+
console.log('Error assortmentBaselineDownloadLink: ' + e.message);
|
|
179
|
+
}
|
|
180
|
+
return undefined;
|
|
181
|
+
}
|
|
182
|
+
getAllItemIds(changeDetail, fullChange) {
|
|
183
|
+
console.info('getAllItemIds-start');
|
|
184
|
+
const extractItemIds = (item) => [item.id, item.itemFamilyId];
|
|
185
|
+
const assortmentItemIds = (fullChange.assortmentItems || []).flatMap(item => extractItemIds(item.item));
|
|
186
|
+
const deleteItemIds = (changeDetail.deletes || []).flatMap(hDelete => extractItemIds(hDelete.item));
|
|
187
|
+
const uniqueItemIds = new Set([...assortmentItemIds, ...deleteItemIds]);
|
|
188
|
+
return Array.from(uniqueItemIds);
|
|
189
|
+
}
|
|
190
|
+
async getItemFederatedIds() {
|
|
191
|
+
const itemFederatedIds = new Map();
|
|
192
|
+
return itemFederatedIds;
|
|
193
|
+
}
|
|
194
|
+
getFullChangeAssortmentMap(fullChange) {
|
|
195
|
+
const assortmentItemsArray = fullChange?.assortmentItems || [];
|
|
196
|
+
const assortmentItemsMap = new Map();
|
|
197
|
+
for (const aItem of assortmentItemsArray) {
|
|
198
|
+
const itemId = aItem?.itemId;
|
|
199
|
+
assortmentItemsMap.set(itemId, aItem);
|
|
200
|
+
}
|
|
201
|
+
return assortmentItemsMap;
|
|
202
|
+
}
|
|
203
|
+
getReleasedForDevelopmentItemAndFamilyIds(fullChange) {
|
|
204
|
+
console.info('getReleasedForDevelopmentItemAndFamilyIds');
|
|
205
|
+
const releasedForDevelopmentItemIds = [];
|
|
206
|
+
const itemFamilySet = new Set();
|
|
207
|
+
const assortmentItemsArray = fullChange?.assortmentItems || [];
|
|
208
|
+
for (const aItem of assortmentItemsArray) {
|
|
209
|
+
const item = aItem?.item;
|
|
210
|
+
const lifecycleStage = item?.lifecycleStage;
|
|
211
|
+
const itemId = item?.id;
|
|
212
|
+
const itemFamilyId = item?.itemFamilyId;
|
|
213
|
+
console.debug(`itemId: ${itemId}`);
|
|
214
|
+
if (lifecycleStage && !this.config?.itemPreDevelopmentLifecycleStages?.includes(lifecycleStage)) {
|
|
215
|
+
console.debug('adding item to releasedForDevelopmentItemIds');
|
|
216
|
+
console.debug(`itemFamilyId: ${itemFamilyId}`);
|
|
217
|
+
releasedForDevelopmentItemIds.push(itemId);
|
|
218
|
+
if (!itemFamilySet.has(itemFamilyId) && itemId !== itemFamilyId) {
|
|
219
|
+
const familyItem = item?.itemFamily;
|
|
220
|
+
const familyLifecycleStage = familyItem?.lifecycleStage;
|
|
221
|
+
if (familyLifecycleStage && !this.config?.itemPreDevelopmentLifecycleStages?.includes(familyLifecycleStage)) {
|
|
222
|
+
releasedForDevelopmentItemIds.push(itemFamilyId);
|
|
223
|
+
}
|
|
224
|
+
itemFamilySet.add(itemFamilyId);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return releasedForDevelopmentItemIds;
|
|
229
|
+
}
|
|
230
|
+
async processPublish(pcd, changeDetail, fullChange) {
|
|
231
|
+
console.info('processPublish-start');
|
|
232
|
+
const assortmentItemFullChangeMap = this.getFullChangeAssortmentMap(fullChange);
|
|
233
|
+
pcd.itemFamilyChanges = this.getItemFamilyChanges(pcd, changeDetail, assortmentItemFullChangeMap);
|
|
234
|
+
const events = await this.getEventsForPublishChangeData(pcd);
|
|
235
|
+
if (events.length === 0) {
|
|
236
|
+
const message = 'No Events to Send; returning';
|
|
237
|
+
console.log(message);
|
|
238
|
+
return {
|
|
239
|
+
results: { message },
|
|
240
|
+
skip_await: true
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
const results = await this.sendEvents(events);
|
|
244
|
+
return { results };
|
|
245
|
+
}
|
|
246
|
+
async sendEvents(events) {
|
|
247
|
+
console.info('sendEvents()');
|
|
248
|
+
const eventType = 'ASYNC_PUBLISH_SEASON';
|
|
249
|
+
const sendMode = (this.config['sendMode'][eventType] || '').toLowerCase();
|
|
250
|
+
switch (sendMode) {
|
|
251
|
+
case 'sendtoflexplm':
|
|
252
|
+
return this.sendToFlexPLM(events, eventType);
|
|
253
|
+
case 'localfile':
|
|
254
|
+
return this.saveToLocalFile(events, eventType);
|
|
255
|
+
case 'vibeiqfile':
|
|
256
|
+
case 'vibeiqfile-dontsendtoflexplm':
|
|
257
|
+
return this.handleVibeIQFile(events, eventType, sendMode);
|
|
258
|
+
default:
|
|
259
|
+
return {};
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
async sendToFlexPLM(events, eventType) {
|
|
263
|
+
const asyncEvent = {
|
|
264
|
+
taskId: this.config.taskId,
|
|
265
|
+
eventType,
|
|
266
|
+
objectClass: 'LCSSeason',
|
|
267
|
+
events
|
|
268
|
+
};
|
|
269
|
+
const flexPLMConnect = new flexplm_connect_1.FlexPLMConnect(this.config);
|
|
270
|
+
return await flexPLMConnect.sendToFlexPLM(asyncEvent);
|
|
271
|
+
}
|
|
272
|
+
async saveToLocalFile(events, eventType) {
|
|
273
|
+
let results = {};
|
|
274
|
+
let fileHandle;
|
|
275
|
+
try {
|
|
276
|
+
const dateString = this.getCurrentDateString();
|
|
277
|
+
const dirName = await path.resolve();
|
|
278
|
+
await fsPromise.mkdir(dirName, { recursive: true });
|
|
279
|
+
const eventDirName = 'events-output';
|
|
280
|
+
const fileName = `${path.sep}${eventDirName}${path.sep}events-${dateString}.json`;
|
|
281
|
+
fileHandle = await fsPromise.open('.' + fileName, 'a');
|
|
282
|
+
const asyncEvent = {
|
|
283
|
+
taskId: this.config.taskId,
|
|
284
|
+
eventType,
|
|
285
|
+
objectClass: 'LCSSeason',
|
|
286
|
+
events
|
|
287
|
+
};
|
|
288
|
+
await fileHandle.writeFile(JSON.stringify(asyncEvent));
|
|
289
|
+
results = {
|
|
290
|
+
message: 'Successfully Saved File',
|
|
291
|
+
fileLocation: dirName + fileName
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
catch (e) {
|
|
295
|
+
results['error'] = e.message;
|
|
296
|
+
}
|
|
297
|
+
finally {
|
|
298
|
+
await fileHandle?.close();
|
|
299
|
+
}
|
|
300
|
+
return results;
|
|
301
|
+
}
|
|
302
|
+
async handleVibeIQFile(events, eventType, sendMode) {
|
|
303
|
+
const eventBuffer = Buffer.from(JSON.stringify(events), 'utf-8');
|
|
304
|
+
const fileName = 'ASYNC_PUBLISH_SEASON-events.json';
|
|
305
|
+
const uploadFile = await new sdk_1.Files().createAndUploadFileFromBuffer(eventBuffer, 'application/json', fileName, null, this.TTL);
|
|
306
|
+
const asyncEvent = {
|
|
307
|
+
taskId: this.config.taskId,
|
|
308
|
+
eventType,
|
|
309
|
+
objectClass: 'LCSSeason',
|
|
310
|
+
eventsFileId: uploadFile.id,
|
|
311
|
+
eventsDownloadLink: uploadFile.downloadUrl
|
|
312
|
+
};
|
|
313
|
+
if (sendMode === 'vibeiqfile') {
|
|
314
|
+
const flexPLMConnect = new flexplm_connect_1.FlexPLMConnect(this.config);
|
|
315
|
+
return await flexPLMConnect.sendToFlexPLM(asyncEvent);
|
|
316
|
+
}
|
|
317
|
+
else {
|
|
318
|
+
return {
|
|
319
|
+
message: 'Successfully Uploaded File.',
|
|
320
|
+
asyncEvent
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
getCurrentDateString() {
|
|
325
|
+
const d = new Date();
|
|
326
|
+
return '' + d.getUTCFullYear()
|
|
327
|
+
+ '-' + d.getUTCMonth()
|
|
328
|
+
+ '-' + (d.getUTCDate() + 1)
|
|
329
|
+
+ '-' + d.getUTCHours()
|
|
330
|
+
+ '-' + d.getUTCMinutes()
|
|
331
|
+
+ '-' + d.getUTCSeconds()
|
|
332
|
+
+ '-' + d.getUTCMilliseconds();
|
|
333
|
+
}
|
|
334
|
+
getItemFamilyChanges(publishChangeData, changeDetail, assortmentItemFullChangeMap) {
|
|
335
|
+
console.info('getItemFamilyChanges-start');
|
|
336
|
+
const itemFamilyChanges = new Map();
|
|
337
|
+
const { adds, deletes, updates, familyItemsRemoved } = changeDetail;
|
|
338
|
+
const addIds = adds.map(item => item.id);
|
|
339
|
+
const deleteIds = deletes.map(item => item.id);
|
|
340
|
+
const updateIds = updates.map(item => item.id);
|
|
341
|
+
const familyItemsRemovedIds = familyItemsRemoved.map(item => item.itemId);
|
|
342
|
+
for (const [itemId, aItem] of assortmentItemFullChangeMap) {
|
|
343
|
+
const { item: { itemFamilyId }, projectItem } = aItem;
|
|
344
|
+
if (!publishChangeData.releasedForDevelopmentItemIds.includes(itemFamilyId) || !publishChangeData.releasedForDevelopmentItemIds.includes(itemId)) {
|
|
345
|
+
continue;
|
|
346
|
+
}
|
|
347
|
+
const ifc = itemFamilyChanges.get(itemFamilyId) || new item_family_changes_1.ItemFamilyChanges(itemFamilyId, publishChangeData.sinceDate);
|
|
348
|
+
if (!itemFamilyChanges.has(itemFamilyId)) {
|
|
349
|
+
ifc.itemFamilyObject = itemId === itemFamilyId ? aItem?.item : aItem?.item?.itemFamily;
|
|
350
|
+
itemFamilyChanges.set(itemFamilyId, ifc);
|
|
351
|
+
}
|
|
352
|
+
ifc.assortmentItemFullChangeMap.set(itemId, aItem);
|
|
353
|
+
if (publishChangeData.itemToFederatedIdMapping.has(itemId)) {
|
|
354
|
+
ifc.itemToFederatedIdMapping.set(itemId, publishChangeData.itemToFederatedIdMapping.get(itemId));
|
|
355
|
+
}
|
|
356
|
+
if (itemId === itemFamilyId) {
|
|
357
|
+
if (addIds.includes(itemId))
|
|
358
|
+
ifc.familyAdd = true;
|
|
359
|
+
else if (deleteIds.includes(itemId))
|
|
360
|
+
ifc.familyDelete = true;
|
|
361
|
+
else if (updateIds.includes(itemId))
|
|
362
|
+
ifc.familyUpdate = true;
|
|
363
|
+
else if (familyItemsRemovedIds.includes(itemId))
|
|
364
|
+
ifc.familyItemRemoved = true;
|
|
365
|
+
if (projectItem) {
|
|
366
|
+
const updatedOnDate = new Date(projectItem.updatedOn);
|
|
367
|
+
if (updatedOnDate > publishChangeData.sinceDate) {
|
|
368
|
+
ifc.familyUpdate = true;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
if (projectItem && !projectItem?.roles && aItem?.item?.roles) {
|
|
372
|
+
projectItem.roles = aItem?.item?.roles;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
else {
|
|
376
|
+
if (addIds.includes(itemId))
|
|
377
|
+
ifc.colorAdds.push(itemId);
|
|
378
|
+
else if (deleteIds.includes(itemId))
|
|
379
|
+
ifc.colorDeletes.push(itemId);
|
|
380
|
+
else if (updateIds.includes(itemId))
|
|
381
|
+
ifc.colorUpdates.push(itemId);
|
|
382
|
+
else if (projectItem && new Date(projectItem.updatedOn) > publishChangeData.sinceDate)
|
|
383
|
+
ifc.colorUpdates.push(itemId);
|
|
384
|
+
else
|
|
385
|
+
ifc.colorUnchanged.push(itemId);
|
|
386
|
+
if (projectItem && !projectItem?.roles && aItem?.item?.roles) {
|
|
387
|
+
projectItem.roles = aItem?.item?.roles;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
for (const delEntity of deletes) {
|
|
392
|
+
const itemId = delEntity.id;
|
|
393
|
+
if (!publishChangeData.itemToFederatedIdMapping.has(itemId) && !publishChangeData.releasedForDevelopmentItemIds.includes(itemId)) {
|
|
394
|
+
continue;
|
|
395
|
+
}
|
|
396
|
+
const { item: { itemFamilyId } } = delEntity;
|
|
397
|
+
const ifc = itemFamilyChanges.get(itemFamilyId) || new item_family_changes_1.ItemFamilyChanges(itemFamilyId, publishChangeData.sinceDate);
|
|
398
|
+
if (!itemFamilyChanges.has(itemFamilyId)) {
|
|
399
|
+
ifc.familyDelete = true;
|
|
400
|
+
itemFamilyChanges.set(itemFamilyId, ifc);
|
|
401
|
+
}
|
|
402
|
+
if (itemId !== itemFamilyId) {
|
|
403
|
+
ifc.colorDeletes.push(itemId);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
console.debug(`returning size: ${itemFamilyChanges.size}`);
|
|
407
|
+
for (const [key, value] of itemFamilyChanges) {
|
|
408
|
+
console.debug(`${key} => ${value}`);
|
|
409
|
+
}
|
|
410
|
+
return itemFamilyChanges;
|
|
411
|
+
}
|
|
412
|
+
async getEventsForPublishChangeData(publishChangeData) {
|
|
413
|
+
console.info('getEventsForPublishChangeData-start');
|
|
414
|
+
const seasonalPayloads = [];
|
|
415
|
+
for (const itemFamilyChange of publishChangeData.itemFamilyChanges.values()) {
|
|
416
|
+
const events = await this.getEventsForItemFamilyChanges(itemFamilyChange, publishChangeData.assortmentId, publishChangeData.seasonFed, publishChangeData.itemToFederatedIdMapping);
|
|
417
|
+
if (events.length > 0) {
|
|
418
|
+
seasonalPayloads.push(...events);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
return seasonalPayloads;
|
|
422
|
+
}
|
|
423
|
+
async getEventsForItemFamilyChanges(itemFamilyChanges, assortmentId, seasonFed, itemToFederatedIdMapping) {
|
|
424
|
+
console.info('getEventsForItemFamilyChanges()');
|
|
425
|
+
const events = [];
|
|
426
|
+
const LCSSeason = Object.assign({}, seasonFed);
|
|
427
|
+
const projectItem = this.getProjectItem(itemFamilyChanges, itemFamilyChanges.itemFamilyId);
|
|
428
|
+
const familyAssortmentItem = itemFamilyChanges.familyAdd || itemFamilyChanges.familyUpdate
|
|
429
|
+
|| itemFamilyChanges.colorAdds.length > 0 || itemFamilyChanges.colorUpdates.length > 0
|
|
430
|
+
|| (projectItem && this.updatedSinceDate(projectItem, itemFamilyChanges.sinceDate));
|
|
431
|
+
if (familyAssortmentItem) {
|
|
432
|
+
const entityReference = itemFamilyChanges.itemFamilyId;
|
|
433
|
+
const prodEntityData = (itemFamilyChanges.assortmentItemFullChangeMap.has(entityReference))
|
|
434
|
+
? itemFamilyChanges.assortmentItemFullChangeMap.get(entityReference)['item']
|
|
435
|
+
: itemFamilyChanges.itemFamilyObject;
|
|
436
|
+
let seasonalData = await this.getSeasonalData(projectItem);
|
|
437
|
+
seasonalData = await map_utils_1.MapUtil.applyTransformMap(this.transformMapFile, this.mapFileUtil, seasonalData, 'LCSProductSeasonLink', 'vibe2flex');
|
|
438
|
+
const LCSProduct = await this.getProductFederation(entityReference, itemToFederatedIdMapping, prodEntityData);
|
|
439
|
+
const psUpsert = {
|
|
440
|
+
eventType: 'UPSERT_ON_SEASON',
|
|
441
|
+
objectClass: 'LCSProductSeasonLink',
|
|
442
|
+
entityReference: 'item:' + entityReference,
|
|
443
|
+
LCSSeason,
|
|
444
|
+
LCSProduct,
|
|
445
|
+
data: seasonalData
|
|
446
|
+
};
|
|
447
|
+
events.push(psUpsert);
|
|
448
|
+
}
|
|
449
|
+
const colorAddUpdates = [];
|
|
450
|
+
colorAddUpdates.push(...itemFamilyChanges.colorAdds);
|
|
451
|
+
colorAddUpdates.push(...itemFamilyChanges.colorUpdates);
|
|
452
|
+
for (const entityReference of colorAddUpdates) {
|
|
453
|
+
let item = {};
|
|
454
|
+
if (itemFamilyChanges.assortmentItemFullChangeMap.has(entityReference)) {
|
|
455
|
+
const fullAi = itemFamilyChanges.assortmentItemFullChangeMap.get(entityReference);
|
|
456
|
+
item = fullAi['item'];
|
|
457
|
+
}
|
|
458
|
+
const projectItem = this.getProjectItem(itemFamilyChanges, entityReference);
|
|
459
|
+
let seasonalData = await this.getSeasonalData(projectItem);
|
|
460
|
+
seasonalData = await map_utils_1.MapUtil.applyTransformMap(this.transformMapFile, this.mapFileUtil, seasonalData, 'LCSSKUSeasonLink', 'vibe2flex');
|
|
461
|
+
const LCSSKU = await this.getSKUFederation(entityReference, itemToFederatedIdMapping, item);
|
|
462
|
+
const csUpsert = {
|
|
463
|
+
eventType: 'UPSERT_ON_SEASON',
|
|
464
|
+
objectClass: 'LCSSKUSeasonLink',
|
|
465
|
+
entityReference: 'item:' + entityReference,
|
|
466
|
+
LCSSeason,
|
|
467
|
+
LCSSKU,
|
|
468
|
+
data: seasonalData
|
|
469
|
+
};
|
|
470
|
+
events.push(csUpsert);
|
|
471
|
+
}
|
|
472
|
+
const data = {};
|
|
473
|
+
for (const color of itemFamilyChanges.colorDeletes) {
|
|
474
|
+
const entityReference = color;
|
|
475
|
+
let item = {};
|
|
476
|
+
if (itemFamilyChanges.assortmentItemFullChangeMap.has(entityReference)) {
|
|
477
|
+
const fullAi = itemFamilyChanges.assortmentItemFullChangeMap.get(entityReference);
|
|
478
|
+
item = fullAi['item'];
|
|
479
|
+
}
|
|
480
|
+
const LCSSKU = await this.getSKUFederation(entityReference, itemToFederatedIdMapping, item);
|
|
481
|
+
const csRemove = {
|
|
482
|
+
eventType: 'REMOVE_FROM_SEASON',
|
|
483
|
+
objectClass: 'LCSSKUSeasonLink',
|
|
484
|
+
entityReference: '',
|
|
485
|
+
LCSSeason,
|
|
486
|
+
LCSSKU,
|
|
487
|
+
data
|
|
488
|
+
};
|
|
489
|
+
events.push(csRemove);
|
|
490
|
+
}
|
|
491
|
+
if (itemFamilyChanges.familyDelete) {
|
|
492
|
+
const entityReference = itemFamilyChanges.itemFamilyId;
|
|
493
|
+
const LCSProduct = {
|
|
494
|
+
entityReference: 'item:' + entityReference,
|
|
495
|
+
objectClass: 'LCSProduct',
|
|
496
|
+
federatedId: itemToFederatedIdMapping.get(entityReference)
|
|
497
|
+
};
|
|
498
|
+
const psUpsert = {
|
|
499
|
+
eventType: 'REMOVE_FROM_SEASON',
|
|
500
|
+
objectClass: 'LCSProductSeasonLink',
|
|
501
|
+
entityReference: 'item:' + entityReference,
|
|
502
|
+
LCSSeason,
|
|
503
|
+
LCSProduct,
|
|
504
|
+
data
|
|
505
|
+
};
|
|
506
|
+
events.push(psUpsert);
|
|
507
|
+
}
|
|
508
|
+
return events;
|
|
509
|
+
}
|
|
510
|
+
getProjectItem(itemFamilyChanges, id) {
|
|
511
|
+
let projectItem = {};
|
|
512
|
+
if (itemFamilyChanges?.assortmentItemFullChangeMap.has(id)) {
|
|
513
|
+
const aItem = itemFamilyChanges?.assortmentItemFullChangeMap.get(id);
|
|
514
|
+
projectItem = aItem?.projectItem;
|
|
515
|
+
}
|
|
516
|
+
if (id === itemFamilyChanges.itemFamilyId && Object.keys(projectItem).length == 0) {
|
|
517
|
+
for (const asstItem of itemFamilyChanges.assortmentItemFullChangeMap.values()) {
|
|
518
|
+
const item = asstItem?.item;
|
|
519
|
+
if (item?.roles?.includes('color') && asstItem?.projectItem) {
|
|
520
|
+
projectItem = Object.assign({}, asstItem?.projectItem);
|
|
521
|
+
projectItem.roles = ['family'];
|
|
522
|
+
break;
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
return projectItem;
|
|
527
|
+
}
|
|
528
|
+
async getSeasonalData(projectItem) {
|
|
529
|
+
return await this.dc.getFlexPLMObjectData(projectItem, [], true);
|
|
530
|
+
}
|
|
531
|
+
async getProductFederation(entityReference, itemToFederatedIdMapping, itemFamilyObject) {
|
|
532
|
+
const identifierKeys = this.config?.identifierAtts?.LCSProduct;
|
|
533
|
+
const itemObj = await this.dc.getFlexPLMObjectData(itemFamilyObject, [], true);
|
|
534
|
+
let prodObj = {
|
|
535
|
+
entityReference: 'item:' + entityReference,
|
|
536
|
+
objectClass: 'LCSProduct',
|
|
537
|
+
};
|
|
538
|
+
for (const key of identifierKeys) {
|
|
539
|
+
if (itemObj[key]) {
|
|
540
|
+
prodObj[key] = itemObj[key];
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
if (!prodObj?.vibeIQIdentifier) {
|
|
544
|
+
prodObj.vibeIQIdentifier = itemFamilyObject?.identifier || itemFamilyObject?.itemNumber;
|
|
545
|
+
}
|
|
546
|
+
prodObj = await map_utils_1.MapUtil.applyTransformMap(this.transformMapFile, this.mapFileUtil, prodObj, 'LCSProduct', 'vibe2flex');
|
|
547
|
+
return prodObj;
|
|
548
|
+
}
|
|
549
|
+
async getSKUFederation(entityReference, itemToFederatedIdMapping, itemObject) {
|
|
550
|
+
const identifierKeys = this.config?.identifierAtts?.LCSSKU;
|
|
551
|
+
const itemObj = await this.dc.getFlexPLMObjectData(itemObject, [], true);
|
|
552
|
+
let skuObj = {
|
|
553
|
+
entityReference: 'item:' + entityReference,
|
|
554
|
+
objectClass: 'LCSSKU',
|
|
555
|
+
};
|
|
556
|
+
for (const key of identifierKeys) {
|
|
557
|
+
if (itemObj[key]) {
|
|
558
|
+
skuObj[key] = itemObj[key];
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
if (!skuObj?.vibeIQIdentifier) {
|
|
562
|
+
skuObj.vibeIQIdentifier = itemObject?.identifier || itemObject?.itemNumber;
|
|
563
|
+
}
|
|
564
|
+
skuObj = await map_utils_1.MapUtil.applyTransformMap(this.transformMapFile, this.mapFileUtil, skuObj, 'LCSSKU', 'vibe2flex');
|
|
565
|
+
return skuObj;
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
exports.BaseProcessPublishAssortment = BaseProcessPublishAssortment;
|
|
569
|
+
BaseProcessPublishAssortment.ASSORTMENT_NOT_PUBLISHABLE = 'Assortment isn\'t marked for publishing to FlexPLM';
|
|
570
|
+
BaseProcessPublishAssortment.ASSORTMENT_NO_FED_INFO = 'Assortment doesn\'t have all "identifier" properties or a federated id, so there is no processing. Identifier properties: ';
|