@contrail/flexplm 2.0.0-alpha.df05bb5 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/entity-processor/base-entity-processor.d.ts +0 -29
- package/lib/entity-processor/base-entity-processor.js +143 -238
- package/lib/entity-processor/base-entity-processor.spec.js +0 -210
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -1
- package/lib/publish/base-process-publish-assortment-callback.js +0 -30
- package/lib/publish/base-process-publish-assortment.d.ts +0 -24
- package/lib/publish/base-process-publish-assortment.js +132 -234
- package/lib/publish/base-process-publish-assortment.spec.js +0 -188
- package/lib/util/error-response-object.js +0 -2
- package/lib/util/flexplm-connect.d.ts +9 -4
- package/lib/util/flexplm-connect.js +172 -202
- package/lib/util/flexplm-connect.spec.js +166 -2
- package/lib/util/thumbnail-util.d.ts +1 -2
- package/lib/util/thumbnail-util.js +6 -34
- package/lib/util/thumbnail-util.spec.js +0 -42
- package/lib/util/type-utils.d.ts +3 -3
- package/package.json +10 -11
- package/lib/__tests__/telemetry-test-utils.d.ts +0 -8
- package/lib/__tests__/telemetry-test-utils.js +0 -30
- package/lib/publish/base-process-publish-assortment-callback.spec.d.ts +0 -1
- package/lib/publish/base-process-publish-assortment-callback.spec.js +0 -62
- package/lib/util/flexplm-connect.telemetry.spec.d.ts +0 -1
- package/lib/util/flexplm-connect.telemetry.spec.js +0 -212
- package/lib/util/telemetry-attributes.d.ts +0 -68
- package/lib/util/telemetry-attributes.js +0 -73
- package/lib/util/telemetry-utils.d.ts +0 -3
- package/lib/util/telemetry-utils.js +0 -10
|
@@ -11,12 +11,6 @@ const fsPromise = require("fs/promises");
|
|
|
11
11
|
const path = require("path");
|
|
12
12
|
const app_framework_1 = require("@contrail/app-framework");
|
|
13
13
|
const event_short_message_status_1 = require("../util/event-short-message-status");
|
|
14
|
-
const telemetry_1 = require("@contrail/telemetry");
|
|
15
|
-
const api_1 = require("@opentelemetry/api");
|
|
16
|
-
const telemetry_attributes_1 = require("../util/telemetry-attributes");
|
|
17
|
-
const telemetry_utils_1 = require("../util/telemetry-utils");
|
|
18
|
-
const PUBLISH_FILE_HYDRATED_DETAIL = 'hydrated_detail';
|
|
19
|
-
const PUBLISH_FILE_BASELINE = 'baseline';
|
|
20
14
|
class BaseProcessPublishAssortment {
|
|
21
15
|
constructor(_config, _dc, _mapFileUtil) {
|
|
22
16
|
this.TTL = 30 * 24 * 60 * 60 * 1000; // 30 days
|
|
@@ -30,115 +24,61 @@ class BaseProcessPublishAssortment {
|
|
|
30
24
|
this.orgSlug = this.config?.orgSlug || 'unset-orgSlug';
|
|
31
25
|
}
|
|
32
26
|
async process(event) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
});
|
|
27
|
+
const assortmentPublishChangeId = event.assortmentPublishChangeId;
|
|
28
|
+
let apcHistory;
|
|
29
|
+
let publisher;
|
|
30
|
+
const assortmentId = event.assortmentId;
|
|
31
|
+
try {
|
|
32
|
+
console.info('process-start: assortmentId: ' + assortmentId
|
|
33
|
+
+ ', assortmentPublishChangeId: ' + assortmentPublishChangeId);
|
|
34
|
+
let seasonFed;
|
|
42
35
|
try {
|
|
43
|
-
|
|
44
|
-
try {
|
|
45
|
-
seasonFed = await this.getSeasonFederation(assortmentId);
|
|
46
|
-
}
|
|
47
|
-
catch (e) {
|
|
48
|
-
const message = e.message;
|
|
49
|
-
const eventStatus = (message.includes(BaseProcessPublishAssortment.ASSORTMENT_NOT_PUBLISHABLE)) ? event_short_message_status_1.EventShortMessageStatus.NOT_PUBLISHABLE :
|
|
50
|
-
(message.startsWith(BaseProcessPublishAssortment.ASSORTMENT_NO_FED_INFO)) ? event_short_message_status_1.EventShortMessageStatus.NO_FEDERATION_INFO :
|
|
51
|
-
event_short_message_status_1.EventShortMessageStatus.FAILURE;
|
|
52
|
-
this.recordPublishStatus({
|
|
53
|
-
status: eventStatus,
|
|
54
|
-
assortmentId,
|
|
55
|
-
assortmentPublishChangeId,
|
|
56
|
-
message,
|
|
57
|
-
// Only an unexpected error is swallowed here; the other two are expected skips.
|
|
58
|
-
error: eventStatus === event_short_message_status_1.EventShortMessageStatus.FAILURE ? e : undefined,
|
|
59
|
-
});
|
|
60
|
-
const output = {
|
|
61
|
-
results: { message, event },
|
|
62
|
-
skip_await: true
|
|
63
|
-
};
|
|
64
|
-
return output;
|
|
65
|
-
}
|
|
66
|
-
apcHistory = await this.getApcHistory(assortmentId);
|
|
67
|
-
const sinceDate = await this.getSinceDate(assortmentId, assortmentPublishChangeId, apcHistory);
|
|
68
|
-
//Get detail information
|
|
69
|
-
const assortmentPublishChange = await this.downloadAssortmentPublishChange(assortmentId, assortmentPublishChangeId);
|
|
70
|
-
publisher = this.getPublisher(assortmentPublishChange);
|
|
71
|
-
const changeDetail = await this.downloadHydratedChangeDetail(assortmentPublishChange);
|
|
72
|
-
// Without the change detail the counts are unknown, not zero; failed_downloads says why.
|
|
73
|
-
if (changeDetail) {
|
|
74
|
-
span.setAttributes({
|
|
75
|
-
[telemetry_attributes_1.ATTR_FLEXPLM_PUBLISH_ADDED_COUNT]: changeDetail.adds?.length ?? 0,
|
|
76
|
-
[telemetry_attributes_1.ATTR_FLEXPLM_PUBLISH_REMOVED_COUNT]: changeDetail.deletes?.length ?? 0,
|
|
77
|
-
[telemetry_attributes_1.ATTR_FLEXPLM_PUBLISH_CHANGED_COUNT]: changeDetail.updates?.length ?? 0,
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
const assortmentBaseline = await this.downloadAssortmentBaseline(assortmentPublishChange);
|
|
81
|
-
const failedDownloads = [!changeDetail && PUBLISH_FILE_HYDRATED_DETAIL, !assortmentBaseline && PUBLISH_FILE_BASELINE].filter(Boolean);
|
|
82
|
-
if (failedDownloads.length > 0) {
|
|
83
|
-
span.setAttribute(telemetry_attributes_1.ATTR_FLEXPLM_PUBLISH_FAILED_DOWNLOADS, failedDownloads);
|
|
84
|
-
}
|
|
85
|
-
const deleteChanges = await this.getDeleteChanges(assortmentPublishChange, apcHistory, assortmentBaseline, sinceDate);
|
|
86
|
-
const releasedForDevelopmentItemIds = this.getReleasedForDevelopmentItemAndFamilyIds(assortmentBaseline, deleteChanges);
|
|
87
|
-
const itemToFederatedIdMapping = await this.getItemFederatedIds( /*allItemIds*/);
|
|
88
|
-
const pcd = new publish_change_data_1.PublishChangeData(assortmentId, seasonFed, assortmentPublishChangeId, sinceDate, publisher);
|
|
89
|
-
pcd.itemToFederatedIdMapping = itemToFederatedIdMapping;
|
|
90
|
-
pcd.releasedForDevelopmentItemIds = releasedForDevelopmentItemIds;
|
|
91
|
-
const output = await this.processPublish(pcd, changeDetail, assortmentBaseline, deleteChanges);
|
|
92
|
-
output['publishInfo'] = await this.getPublishInfo(assortmentId, assortmentPublishChangeId, apcHistory, publisher);
|
|
93
|
-
return output;
|
|
36
|
+
seasonFed = await this.getSeasonFederation(assortmentId);
|
|
94
37
|
}
|
|
95
38
|
catch (e) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
39
|
+
const message = e.message;
|
|
40
|
+
const eventStatus = (message.includes(BaseProcessPublishAssortment.ASSORTMENT_NOT_PUBLISHABLE)) ? event_short_message_status_1.EventShortMessageStatus.NOT_PUBLISHABLE :
|
|
41
|
+
(message.startsWith(BaseProcessPublishAssortment.ASSORTMENT_NO_FED_INFO)) ? event_short_message_status_1.EventShortMessageStatus.NO_FEDERATION_INFO :
|
|
42
|
+
event_short_message_status_1.EventShortMessageStatus.FAILURE;
|
|
43
|
+
const processStatus = 'BaseProcessPublishAssortment: ' + eventStatus
|
|
44
|
+
+ ': assortmentId: ' + event.assortmentId + ': assortmentPublishChangeId: ' + event.assortmentPublishChangeId
|
|
45
|
+
+ ', orgSlug: ' + this.orgSlug;
|
|
46
|
+
console.log(JSON.stringify(processStatus));
|
|
47
|
+
console.log(message);
|
|
48
|
+
const output = {
|
|
49
|
+
results: { message, event },
|
|
50
|
+
skip_await: true
|
|
51
|
+
};
|
|
52
|
+
return output;
|
|
109
53
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
[
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
direction: 'publish', status, assortment_id: assortmentId, publish_change_id: assortmentPublishChangeId,
|
|
128
|
-
product_season_count: resultsCount?.productSeasons, colorway_season_count: resultsCount?.colorwaySeasons, reason: message,
|
|
129
|
-
sent_unrecorded: sentUnrecorded,
|
|
130
|
-
};
|
|
131
|
-
if (sentUnrecorded) {
|
|
132
|
-
telemetry_1.logger.error({ error, flexplm }, 'FlexPLM assortment publish sent but not recorded');
|
|
54
|
+
apcHistory = await this.getApcHistory(assortmentId);
|
|
55
|
+
const sinceDate = await this.getSinceDate(assortmentId, assortmentPublishChangeId, apcHistory);
|
|
56
|
+
//Get detail information
|
|
57
|
+
const assortmentPublishChange = await this.downloadAssortmentPublishChange(assortmentId, assortmentPublishChangeId);
|
|
58
|
+
publisher = this.getPublisher(assortmentPublishChange);
|
|
59
|
+
const changeDetail = await this.downloadHydratedChangeDetail(assortmentPublishChange);
|
|
60
|
+
const assortmentBaseline = await this.downloadAssortmentBaseline(assortmentPublishChange);
|
|
61
|
+
const deleteChanges = await this.getDeleteChanges(assortmentPublishChange, apcHistory, assortmentBaseline, sinceDate);
|
|
62
|
+
const releasedForDevelopmentItemIds = this.getReleasedForDevelopmentItemAndFamilyIds(assortmentBaseline, deleteChanges);
|
|
63
|
+
const itemToFederatedIdMapping = await this.getItemFederatedIds( /*allItemIds*/);
|
|
64
|
+
const pcd = new publish_change_data_1.PublishChangeData(assortmentId, seasonFed, assortmentPublishChangeId, sinceDate, publisher);
|
|
65
|
+
pcd.itemToFederatedIdMapping = itemToFederatedIdMapping;
|
|
66
|
+
pcd.releasedForDevelopmentItemIds = releasedForDevelopmentItemIds;
|
|
67
|
+
const output = await this.processPublish(pcd, changeDetail, assortmentBaseline, deleteChanges);
|
|
68
|
+
output['publishInfo'] = await this.getPublishInfo(assortmentId, assortmentPublishChangeId, apcHistory, publisher);
|
|
69
|
+
console.info('process-end');
|
|
70
|
+
return output;
|
|
133
71
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
72
|
+
catch (e) {
|
|
73
|
+
try {
|
|
74
|
+
const publishInfo = await this.getPublishInfo(assortmentId, assortmentPublishChangeId, apcHistory, publisher);
|
|
75
|
+
e.publishInfo = publishInfo;
|
|
76
|
+
}
|
|
77
|
+
catch (e2) {
|
|
78
|
+
console.error('getPublishInfo failed: ' + e2.message);
|
|
79
|
+
}
|
|
80
|
+
console.error('process failed: assortmentId: ' + assortmentId + ': ' + e.message);
|
|
81
|
+
throw e;
|
|
142
82
|
}
|
|
143
83
|
}
|
|
144
84
|
async getPublishInfo(assortmentId, assortmentPublishChangeId, apcHistory, publisher) {
|
|
@@ -271,18 +211,13 @@ class BaseProcessPublishAssortment {
|
|
|
271
211
|
return sinceDate;
|
|
272
212
|
}
|
|
273
213
|
async getApcHistory(assortmentId) {
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
}
|
|
282
|
-
});
|
|
283
|
-
if (Array.isArray(history))
|
|
284
|
-
span.setAttribute(telemetry_attributes_1.ATTR_FLEXPLM_PUBLISH_HISTORY_COUNT, history.length);
|
|
285
|
-
return history;
|
|
214
|
+
const resource = `/assortments/${assortmentId}/history/`;
|
|
215
|
+
return sdk_1.Request.request(resource, {
|
|
216
|
+
method: 'GET',
|
|
217
|
+
headers: {
|
|
218
|
+
Accept: 'application/json',
|
|
219
|
+
'Content-Type': 'application/json'
|
|
220
|
+
}
|
|
286
221
|
});
|
|
287
222
|
}
|
|
288
223
|
updatedSinceDate(entity, sinceDate) {
|
|
@@ -380,42 +315,30 @@ class BaseProcessPublishAssortment {
|
|
|
380
315
|
});
|
|
381
316
|
}
|
|
382
317
|
async downloadHydratedChangeDetail(assortmentPublishChange) {
|
|
383
|
-
|
|
318
|
+
try {
|
|
319
|
+
const link = assortmentPublishChange?.hydratedDetailDownloadLink;
|
|
320
|
+
const response = await fetch(link);
|
|
321
|
+
const data = await response.json();
|
|
322
|
+
return data;
|
|
323
|
+
}
|
|
324
|
+
catch (e) {
|
|
325
|
+
console.error('Error hydratedDetailDownloadLink: ' + e.message);
|
|
326
|
+
}
|
|
327
|
+
return undefined;
|
|
384
328
|
}
|
|
385
329
|
async downloadAssortmentBaseline(assortmentPublishChange) {
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
httpStatus = response.status;
|
|
397
|
-
span.setAttribute(telemetry_attributes_1.ATTR_HTTP_RESPONSE_STATUS_CODE, httpStatus);
|
|
398
|
-
if (!response.ok) {
|
|
399
|
-
throw new Error('Download failed: status: ' + httpStatus);
|
|
400
|
-
}
|
|
401
|
-
return await response.json();
|
|
402
|
-
}
|
|
403
|
-
catch (e) {
|
|
404
|
-
span.recordException(e);
|
|
405
|
-
span.setStatus({ code: api_1.SpanStatusCode.ERROR, message: e?.message });
|
|
406
|
-
telemetry_1.logger.error({ error: e, flexplm: { direction: 'publish', publish_file: file, http_status: httpStatus } }, 'FlexPLM publish file download failed');
|
|
407
|
-
return undefined;
|
|
408
|
-
}
|
|
409
|
-
});
|
|
330
|
+
try {
|
|
331
|
+
const link = assortmentPublishChange?.assortmentBaselineDownloadLink;
|
|
332
|
+
const response = await fetch(link);
|
|
333
|
+
const data = await response.json();
|
|
334
|
+
return data;
|
|
335
|
+
}
|
|
336
|
+
catch (e) {
|
|
337
|
+
console.error('Error assortmentBaselineDownloadLink: ' + e.message);
|
|
338
|
+
}
|
|
339
|
+
return undefined;
|
|
410
340
|
}
|
|
411
341
|
async getDeleteChanges(assortmentPublishChange, apcHistory, assortmentBaseline, sinceDate) {
|
|
412
|
-
return (0, telemetry_1.traceSection)('get_delete_changes', {}, async (span) => {
|
|
413
|
-
const deleteChanges = await this.collectDeleteChanges(assortmentPublishChange, apcHistory, assortmentBaseline, sinceDate);
|
|
414
|
-
span.setAttribute(telemetry_attributes_1.ATTR_FLEXPLM_PUBLISH_DELETE_CHANGE_COUNT, deleteChanges?.length ?? 0);
|
|
415
|
-
return deleteChanges;
|
|
416
|
-
});
|
|
417
|
-
}
|
|
418
|
-
async collectDeleteChanges(assortmentPublishChange, apcHistory, assortmentBaseline, sinceDate) {
|
|
419
342
|
const currentAPCIndex = apcHistory.findIndex(pc => pc?.id === assortmentPublishChange?.id);
|
|
420
343
|
if (currentAPCIndex == 0) {
|
|
421
344
|
return [];
|
|
@@ -460,7 +383,6 @@ class BaseProcessPublishAssortment {
|
|
|
460
383
|
console.info('getDeleteChanges(): baselineItems: ' + currentAssortmentItemIds.length
|
|
461
384
|
+ ', scanned ' + scannedCount + ' historical delete changes, added ' + addedCount
|
|
462
385
|
+ ', deleteIds: ' + deleteIds.length);
|
|
463
|
-
(0, telemetry_utils_1.setActiveSpanAttributes)({ [telemetry_attributes_1.ATTR_FLEXPLM_PUBLISH_HISTORICAL_DELETE_COUNT]: addedCount });
|
|
464
386
|
console.info('getDeleteChanges()-deleteIds: ' + deleteIds);
|
|
465
387
|
}
|
|
466
388
|
return apcDeletes;
|
|
@@ -637,12 +559,12 @@ class BaseProcessPublishAssortment {
|
|
|
637
559
|
pcd.itemFamilyChanges = this.getItemFamilyChanges(pcd, changeDetail, assortmentItemFullChangeMap, assortmentItemDeleteMap);
|
|
638
560
|
const events = await this.getEventsForPublishChangeData(pcd);
|
|
639
561
|
if (events.length === 0) {
|
|
562
|
+
const processStatus = 'BaseProcessPublishAssortment: ' + event_short_message_status_1.EventShortMessageStatus.NO_EVENTS_TO_SEND
|
|
563
|
+
+ ': assortmentId: ' + pcd.assortmentId + ': assortmentPublishChangeId: ' + pcd.assortmentPublishChangeId
|
|
564
|
+
+ ', orgSlug: ' + this.orgSlug;
|
|
565
|
+
console.log(processStatus);
|
|
640
566
|
const message = 'No Events to Send; returning';
|
|
641
|
-
|
|
642
|
-
status: event_short_message_status_1.EventShortMessageStatus.NO_EVENTS_TO_SEND,
|
|
643
|
-
assortmentId: pcd.assortmentId,
|
|
644
|
-
assortmentPublishChangeId: pcd.assortmentPublishChangeId,
|
|
645
|
-
});
|
|
567
|
+
console.log(message);
|
|
646
568
|
return {
|
|
647
569
|
results: { message, event },
|
|
648
570
|
skip_await: true
|
|
@@ -650,12 +572,11 @@ class BaseProcessPublishAssortment {
|
|
|
650
572
|
}
|
|
651
573
|
const results = await this.sendEvents(events);
|
|
652
574
|
const resultsCount = this.getResultsCount(events);
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
});
|
|
575
|
+
const processStatus = 'BaseProcessPublishAssortment: ' + event_short_message_status_1.EventShortMessageStatus.SENDING_EVENTS
|
|
576
|
+
+ ': assortmentId: ' + pcd.assortmentId + ': assortmentPublishChangeId: ' + pcd.assortmentPublishChangeId
|
|
577
|
+
+ ': resultsCount: ' + JSON.stringify(resultsCount)
|
|
578
|
+
+ ', orgSlug: ' + this.orgSlug;
|
|
579
|
+
console.log(processStatus);
|
|
659
580
|
return { results, event, resultsCount };
|
|
660
581
|
}
|
|
661
582
|
getResultsCount(events) {
|
|
@@ -674,7 +595,6 @@ class BaseProcessPublishAssortment {
|
|
|
674
595
|
console.info('sendEvents()');
|
|
675
596
|
const eventType = 'ASYNC_PUBLISH_SEASON';
|
|
676
597
|
const sendMode = (this.config?.sendMode[eventType] || '').toLowerCase();
|
|
677
|
-
(0, telemetry_utils_1.setActiveSpanAttributes)({ [telemetry_attributes_1.ATTR_FLEXPLM_PUBLISH_SEND_MODE]: sendMode });
|
|
678
598
|
switch (sendMode) {
|
|
679
599
|
case 'sendtoflexplm':
|
|
680
600
|
return this.sendToFlexPLM(events, eventType);
|
|
@@ -684,25 +604,22 @@ class BaseProcessPublishAssortment {
|
|
|
684
604
|
case 'vibeiqfile-dontsendtoflexplm':
|
|
685
605
|
return this.handleVibeIQFile(events, eventType, sendMode);
|
|
686
606
|
default:
|
|
687
|
-
telemetry_1.logger.warn({ flexplm: { direction: 'publish', send_mode: sendMode, payload_count: events?.length ?? 0 } }, 'Unknown FlexPLM publish sendMode; events not sent');
|
|
688
607
|
return {}; // Or handle other cases as required
|
|
689
608
|
}
|
|
690
609
|
}
|
|
691
610
|
async sendToFlexPLM(events, eventType) {
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
: { result, outboundPublishEvent };
|
|
705
|
-
});
|
|
611
|
+
const outboundPublishEvent = {
|
|
612
|
+
taskId: this.config.taskId,
|
|
613
|
+
eventType,
|
|
614
|
+
objectClass: 'LCSSeason',
|
|
615
|
+
events
|
|
616
|
+
};
|
|
617
|
+
const flexPLMConnect = new flexplm_connect_1.FlexPLMConnect(this.config);
|
|
618
|
+
const result = await this.sendAndRecordPublishEvent(flexPLMConnect, outboundPublishEvent);
|
|
619
|
+
const isResultObject = typeof result === 'object' && result !== null;
|
|
620
|
+
return isResultObject
|
|
621
|
+
? { ...result, outboundPublishEvent }
|
|
622
|
+
: { result, outboundPublishEvent };
|
|
706
623
|
}
|
|
707
624
|
async sendAndRecordPublishEvent(flexPLMConnect, outboundPublishEvent) {
|
|
708
625
|
let sendResult;
|
|
@@ -751,7 +668,6 @@ class BaseProcessPublishAssortment {
|
|
|
751
668
|
};
|
|
752
669
|
}
|
|
753
670
|
catch (e) {
|
|
754
|
-
telemetry_1.logger.error({ error: e, flexplm: { direction: 'publish', send_mode: 'localfile' } }, 'Saving FlexPLM publish events to a local file failed');
|
|
755
671
|
results['error'] = e.message;
|
|
756
672
|
}
|
|
757
673
|
finally {
|
|
@@ -762,7 +678,7 @@ class BaseProcessPublishAssortment {
|
|
|
762
678
|
async handleVibeIQFile(events, eventType, sendMode) {
|
|
763
679
|
const eventBuffer = Buffer.from(JSON.stringify(events), 'utf-8');
|
|
764
680
|
const fileName = 'ASYNC_PUBLISH_SEASON-events.json';
|
|
765
|
-
const uploadFile = await
|
|
681
|
+
const uploadFile = await new sdk_1.Files().createAndUploadFileFromBuffer(eventBuffer, 'application/json', fileName, null, this.TTL);
|
|
766
682
|
const outboundPublishEvent = {
|
|
767
683
|
taskId: this.config.taskId,
|
|
768
684
|
eventType,
|
|
@@ -772,14 +688,12 @@ class BaseProcessPublishAssortment {
|
|
|
772
688
|
eventsAdminDownloadLink: uploadFile.adminDownloadUrl
|
|
773
689
|
};
|
|
774
690
|
if (sendMode === 'vibeiqfile') {
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
: { result, outboundPublishEvent };
|
|
782
|
-
});
|
|
691
|
+
const flexPLMConnect = new flexplm_connect_1.FlexPLMConnect(this.config);
|
|
692
|
+
const result = await this.sendAndRecordPublishEvent(flexPLMConnect, outboundPublishEvent);
|
|
693
|
+
const isResultObject = typeof result === 'object' && result !== null;
|
|
694
|
+
return isResultObject
|
|
695
|
+
? { ...result, outboundPublishEvent }
|
|
696
|
+
: { result, outboundPublishEvent };
|
|
783
697
|
}
|
|
784
698
|
else {
|
|
785
699
|
await this.sendPublishPayloadEvent(outboundPublishEvent);
|
|
@@ -790,24 +704,22 @@ class BaseProcessPublishAssortment {
|
|
|
790
704
|
}
|
|
791
705
|
}
|
|
792
706
|
async sendPublishPayloadEvent(outboundPublishEvent) {
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
object: eventBody
|
|
810
|
-
});
|
|
707
|
+
console.info('sendPublishPayloadEvent()');
|
|
708
|
+
let initialEvent = {};
|
|
709
|
+
if (this.config?.event) {
|
|
710
|
+
initialEvent = (typeof this.config?.event === 'string')
|
|
711
|
+
? JSON.parse(this.config?.event)
|
|
712
|
+
: this.config?.event;
|
|
713
|
+
}
|
|
714
|
+
const eventBody = {
|
|
715
|
+
originSystemType: 'VibeIQ',
|
|
716
|
+
objectClass: 'AssortmentPublishedToFlexPLM',
|
|
717
|
+
outboundPublishEvent,
|
|
718
|
+
initialEvent
|
|
719
|
+
};
|
|
720
|
+
await new sdk_1.Entities().create({
|
|
721
|
+
entityName: 'external-event',
|
|
722
|
+
object: eventBody
|
|
811
723
|
});
|
|
812
724
|
}
|
|
813
725
|
getCurrentDateString() {
|
|
@@ -900,7 +812,6 @@ class BaseProcessPublishAssortment {
|
|
|
900
812
|
}
|
|
901
813
|
}
|
|
902
814
|
}
|
|
903
|
-
const skippedDeletes = [];
|
|
904
815
|
for (const [itemId, delEntity] of assortmentItemDeleteMap) {
|
|
905
816
|
const itemFamilyId = delEntity?.item?.itemFamilyId;
|
|
906
817
|
const item = delEntity?.item;
|
|
@@ -912,7 +823,7 @@ class BaseProcessPublishAssortment {
|
|
|
912
823
|
}
|
|
913
824
|
else {
|
|
914
825
|
if (!item) {
|
|
915
|
-
|
|
826
|
+
console.error('Failed to find deleted item entity: itemFamilyId: ' + itemFamilyId + ', itemId: ' + itemId);
|
|
916
827
|
continue;
|
|
917
828
|
}
|
|
918
829
|
}
|
|
@@ -944,14 +855,6 @@ class BaseProcessPublishAssortment {
|
|
|
944
855
|
ifc.colorDeletes.push(itemId);
|
|
945
856
|
}
|
|
946
857
|
} //End deletes for loop
|
|
947
|
-
if (skippedDeletes.length > 0) {
|
|
948
|
-
// These deletes are not sent to FlexPLM; one warning for the publish rather than one per item.
|
|
949
|
-
(0, telemetry_utils_1.setActiveSpanAttributes)({ [telemetry_attributes_1.ATTR_FLEXPLM_PUBLISH_SKIPPED_DELETE_COUNT]: skippedDeletes.length });
|
|
950
|
-
telemetry_1.logger.warn({ flexplm: {
|
|
951
|
-
direction: 'publish', assortment_id: pcd.assortmentId, publish_change_id: pcd.assortmentPublishChangeId,
|
|
952
|
-
skipped_delete_count: skippedDeletes.length, skipped_deletes: skippedDeletes,
|
|
953
|
-
} }, 'FlexPLM publish skipped deleted items with no item entity');
|
|
954
|
-
}
|
|
955
858
|
if (app_framework_1.Logger.isDebugOn()) {
|
|
956
859
|
console.debug('returning size: ' + itemFamilyChanges.size);
|
|
957
860
|
for (const [key, value] of itemFamilyChanges) {
|
|
@@ -961,21 +864,16 @@ class BaseProcessPublishAssortment {
|
|
|
961
864
|
return itemFamilyChanges;
|
|
962
865
|
}
|
|
963
866
|
async getEventsForPublishChangeData(publishChangeData) {
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
const events = await this.getEventsForItemFamilyChanges(itemFamilyChange, publishChangeData.assortmentId, publishChangeData.seasonFed, publishChangeData.itemToFederatedIdMapping);
|
|
970
|
-
if (events.length > 0) {
|
|
971
|
-
seasonalPayloads.push(...events);
|
|
972
|
-
}
|
|
867
|
+
const seasonalPayloads = [];
|
|
868
|
+
for (const itemFamilyChange of publishChangeData.itemFamilyChanges.values()) {
|
|
869
|
+
const events = await this.getEventsForItemFamilyChanges(itemFamilyChange, publishChangeData.assortmentId, publishChangeData.seasonFed, publishChangeData.itemToFederatedIdMapping);
|
|
870
|
+
if (events.length > 0) {
|
|
871
|
+
seasonalPayloads.push(...events);
|
|
973
872
|
}
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
});
|
|
873
|
+
}
|
|
874
|
+
console.info('getEventsForPublishChangeData: itemFamilies: '
|
|
875
|
+
+ publishChangeData.itemFamilyChanges.size + ', payloads: ' + seasonalPayloads.length);
|
|
876
|
+
return seasonalPayloads;
|
|
979
877
|
}
|
|
980
878
|
/**Returns the events for a given ItemFamilyChanges object
|
|
981
879
|
*
|