@contrail/flexplm 1.1.67-alpha.4 → 1.3.0-alpha.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/.claude/settings.local.json +7 -0
- package/package.json +1 -1
- package/scripts/output.png +0 -0
- package/scripts/test-get-request.ts +35 -0
- package/src/util/flexplm-connect.spec.ts +132 -0
- package/src/util/flexplm-connect.ts +14 -5
- package/src/util/type-conversion-utils-spec-mockData.ts +18 -0
- package/src/util/type-conversion-utils.spec.ts +184 -0
- package/src/util/type-conversion-utils.ts +74 -0
- package/lib/entity-processor/base-entity-processor.d.ts +0 -42
- package/lib/entity-processor/base-entity-processor.js +0 -363
- package/lib/entity-processor/base-entity-processor.spec.d.ts +0 -1
- package/lib/entity-processor/base-entity-processor.spec.js +0 -302
- package/lib/flexplm-request.d.ts +0 -3
- package/lib/flexplm-request.js +0 -34
- package/lib/flexplm-utils.d.ts +0 -5
- package/lib/flexplm-utils.js +0 -33
- package/lib/flexplm-utils.spec.d.ts +0 -1
- package/lib/flexplm-utils.spec.js +0 -26
- package/lib/index.d.ts +0 -22
- package/lib/index.js +0 -38
- package/lib/interfaces/interfaces.d.ts +0 -105
- package/lib/interfaces/interfaces.js +0 -2
- package/lib/interfaces/item-family-changes.d.ts +0 -20
- package/lib/interfaces/item-family-changes.js +0 -56
- package/lib/interfaces/publish-change-data.d.ts +0 -19
- package/lib/interfaces/publish-change-data.js +0 -32
- package/lib/publish/base-process-publish-assortment-callback.d.ts +0 -9
- package/lib/publish/base-process-publish-assortment-callback.js +0 -38
- package/lib/publish/base-process-publish-assortment.d.ts +0 -93
- package/lib/publish/base-process-publish-assortment.js +0 -944
- package/lib/publish/base-process-publish-assortment.spec.d.ts +0 -1
- package/lib/publish/base-process-publish-assortment.spec.js +0 -1670
- package/lib/publish/mockData.d.ts +0 -1389
- package/lib/publish/mockData.js +0 -4519
- package/lib/transform/identifier-conversion-spec-mockData.d.ts +0 -0
- package/lib/transform/identifier-conversion-spec-mockData.js +0 -444
- package/lib/transform/identifier-conversion.d.ts +0 -15
- package/lib/transform/identifier-conversion.js +0 -212
- package/lib/transform/identifier-conversion.spec.d.ts +0 -1
- package/lib/transform/identifier-conversion.spec.js +0 -339
- package/lib/util/config-defaults.d.ts +0 -8
- package/lib/util/config-defaults.js +0 -85
- package/lib/util/config-defaults.spec.d.ts +0 -1
- package/lib/util/config-defaults.spec.js +0 -293
- package/lib/util/data-converter-spec-mockData.d.ts +0 -0
- package/lib/util/data-converter-spec-mockData.js +0 -205
- package/lib/util/data-converter.d.ts +0 -39
- package/lib/util/data-converter.js +0 -592
- package/lib/util/data-converter.spec.d.ts +0 -1
- package/lib/util/data-converter.spec.js +0 -904
- package/lib/util/error-response-object.d.ts +0 -4
- package/lib/util/error-response-object.js +0 -47
- package/lib/util/error-response-object.spec.d.ts +0 -1
- package/lib/util/error-response-object.spec.js +0 -99
- package/lib/util/event-short-message-status.d.ts +0 -18
- package/lib/util/event-short-message-status.js +0 -22
- package/lib/util/federation.d.ts +0 -15
- package/lib/util/federation.js +0 -149
- package/lib/util/flexplm-connect.d.ts +0 -18
- package/lib/util/flexplm-connect.js +0 -171
- package/lib/util/logger-config.d.ts +0 -1
- package/lib/util/logger-config.js +0 -26
- package/lib/util/map-util-spec-mockData.d.ts +0 -0
- package/lib/util/map-util-spec-mockData.js +0 -205
- package/lib/util/map-utils.d.ts +0 -6
- package/lib/util/map-utils.js +0 -15
- package/lib/util/map-utils.spec.d.ts +0 -1
- package/lib/util/map-utils.spec.js +0 -89
- package/lib/util/mockData.d.ts +0 -79
- package/lib/util/mockData.js +0 -99
- package/lib/util/thumbnail-util.d.ts +0 -19
- package/lib/util/thumbnail-util.js +0 -114
- package/lib/util/thumbnail-util.spec.d.ts +0 -1
- package/lib/util/thumbnail-util.spec.js +0 -242
- package/lib/util/type-conversion-utils-spec-mockData.d.ts +0 -0
- package/lib/util/type-conversion-utils-spec-mockData.js +0 -241
- package/lib/util/type-conversion-utils.d.ts +0 -21
- package/lib/util/type-conversion-utils.js +0 -223
- package/lib/util/type-conversion-utils.spec.d.ts +0 -1
- package/lib/util/type-conversion-utils.spec.js +0 -708
- package/lib/util/type-defaults.d.ts +0 -16
- package/lib/util/type-defaults.js +0 -221
- package/lib/util/type-defaults.spec.d.ts +0 -1
- package/lib/util/type-defaults.spec.js +0 -516
- package/lib/util/type-utils.d.ts +0 -13
- package/lib/util/type-utils.js +0 -114
- package/lib/util/type-utils.spec.d.ts +0 -1
- package/lib/util/type-utils.spec.js +0 -190
|
@@ -1,944 +0,0 @@
|
|
|
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 type_conversion_utils_1 = require("../util/type-conversion-utils");
|
|
10
|
-
const fsPromise = require("fs/promises");
|
|
11
|
-
const path = require("path");
|
|
12
|
-
const app_framework_1 = require("@contrail/app-framework");
|
|
13
|
-
const event_short_message_status_1 = require("../util/event-short-message-status");
|
|
14
|
-
class BaseProcessPublishAssortment {
|
|
15
|
-
constructor(_config, _dc, _mapFileUtil) {
|
|
16
|
-
this.TTL = 30 * 24 * 60 * 60 * 1000;
|
|
17
|
-
this.cache = {
|
|
18
|
-
carriedFromSeason: {}
|
|
19
|
-
};
|
|
20
|
-
this.config = _config;
|
|
21
|
-
this.dc = _dc;
|
|
22
|
-
this.mapFileUtil = _mapFileUtil;
|
|
23
|
-
this.transformMapFile = this.config?.transformMapFile;
|
|
24
|
-
this.orgSlug = this.config?.orgSlug || 'unset-orgSlug';
|
|
25
|
-
}
|
|
26
|
-
async process(event) {
|
|
27
|
-
const assortmentPublishChangeId = event.assortmentPublishChangeId;
|
|
28
|
-
let apcHistory;
|
|
29
|
-
let publisher;
|
|
30
|
-
const assortmentId = event.assortmentId;
|
|
31
|
-
try {
|
|
32
|
-
console.info('process-start!');
|
|
33
|
-
let seasonFed;
|
|
34
|
-
try {
|
|
35
|
-
seasonFed = await this.getSeasonFederation(assortmentId);
|
|
36
|
-
}
|
|
37
|
-
catch (e) {
|
|
38
|
-
const message = e.message;
|
|
39
|
-
const eventStatus = (message.includes(BaseProcessPublishAssortment.ASSORTMENT_NOT_PUBLISHABLE)) ? event_short_message_status_1.EventShortMessageStatus.NOT_PUBLISHABLE :
|
|
40
|
-
(message.startsWith(BaseProcessPublishAssortment.ASSORTMENT_NO_FED_INFO)) ? event_short_message_status_1.EventShortMessageStatus.NO_FEDERATION_INFO :
|
|
41
|
-
event_short_message_status_1.EventShortMessageStatus.FAILURE;
|
|
42
|
-
const processStatus = 'BaseProcessPublishAssortment: ' + eventStatus
|
|
43
|
-
+ ': assortmentId: ' + event.assortmentId + ': assortmentPublishChangeId: ' + event.assortmentPublishChangeId
|
|
44
|
-
+ ', orgSlug: ' + this.orgSlug;
|
|
45
|
-
console.log(JSON.stringify(processStatus));
|
|
46
|
-
console.log(message);
|
|
47
|
-
const output = {
|
|
48
|
-
results: { message, event },
|
|
49
|
-
skip_await: true
|
|
50
|
-
};
|
|
51
|
-
return output;
|
|
52
|
-
}
|
|
53
|
-
apcHistory = await this.getApcHistory(assortmentId);
|
|
54
|
-
const sinceDate = await this.getSinceDate(assortmentId, assortmentPublishChangeId, apcHistory);
|
|
55
|
-
const assortmentPublishChange = await this.downloadAssortmentPublishChange(assortmentId, assortmentPublishChangeId);
|
|
56
|
-
publisher = this.getPublisher(assortmentPublishChange);
|
|
57
|
-
const changeDetail = await this.downloadHydratedChangeDetail(assortmentPublishChange);
|
|
58
|
-
const assortmentBaseline = await this.downloadAssortmentBaseline(assortmentPublishChange);
|
|
59
|
-
const deleteChanges = await this.getDeleteChanges(assortmentPublishChange, apcHistory, assortmentBaseline, sinceDate);
|
|
60
|
-
const releasedForDevelopmentItemIds = this.getReleasedForDevelopmentItemAndFamilyIds(assortmentBaseline, deleteChanges);
|
|
61
|
-
const itemToFederatedIdMapping = await this.getItemFederatedIds();
|
|
62
|
-
const pcd = new publish_change_data_1.PublishChangeData(assortmentId, seasonFed, assortmentPublishChangeId, sinceDate, publisher);
|
|
63
|
-
pcd.itemToFederatedIdMapping = itemToFederatedIdMapping;
|
|
64
|
-
pcd.releasedForDevelopmentItemIds = releasedForDevelopmentItemIds;
|
|
65
|
-
const output = await this.processPublish(pcd, changeDetail, assortmentBaseline, deleteChanges);
|
|
66
|
-
output['publishInfo'] = await this.getPublishInfo(assortmentId, assortmentPublishChangeId, apcHistory, publisher);
|
|
67
|
-
console.info('process-end');
|
|
68
|
-
return output;
|
|
69
|
-
}
|
|
70
|
-
catch (e) {
|
|
71
|
-
try {
|
|
72
|
-
const publishInfo = await this.getPublishInfo(assortmentId, assortmentPublishChangeId, apcHistory, publisher);
|
|
73
|
-
e.publishInfo = publishInfo;
|
|
74
|
-
}
|
|
75
|
-
catch (e2) {
|
|
76
|
-
console.log('catch e2: ' + e2.message);
|
|
77
|
-
}
|
|
78
|
-
console.log('catch e: ' + e.message);
|
|
79
|
-
throw e;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
async getPublishInfo(assortmentId, assortmentPublishChangeId, apcHistory, publisher) {
|
|
83
|
-
const apc = apcHistory?.find(apc => apc?.id === assortmentPublishChangeId) || {};
|
|
84
|
-
const assortment = await this.getAssortment(assortmentId);
|
|
85
|
-
const assortmentName = assortment?.name;
|
|
86
|
-
const versionHistoryNumber = await this.getSnapshotVersion(assortment, apc);
|
|
87
|
-
const publishInfo = {
|
|
88
|
-
assortmentName,
|
|
89
|
-
versionName: apc?.versionName,
|
|
90
|
-
versionComments: apc?.versionComments,
|
|
91
|
-
publishDate: apc?.createdOn,
|
|
92
|
-
publisher,
|
|
93
|
-
versionHistoryNumber
|
|
94
|
-
};
|
|
95
|
-
return publishInfo;
|
|
96
|
-
}
|
|
97
|
-
async getSnapshotVersion(assortment, apc) {
|
|
98
|
-
const entityReference = assortment?.createdForReference;
|
|
99
|
-
const createdOnString = apc?.createdOn;
|
|
100
|
-
if (!entityReference || !createdOnString || !apc?.id) {
|
|
101
|
-
return 'unknown';
|
|
102
|
-
}
|
|
103
|
-
const createdOnDate = new Date(createdOnString);
|
|
104
|
-
createdOnDate.setMonth(createdOnDate.getMonth() - 1);
|
|
105
|
-
const createdOnStringMinus1 = createdOnDate.toISOString();
|
|
106
|
-
const createdOn = 'ISGREATERTHAN ' + createdOnStringMinus1;
|
|
107
|
-
const snapshots = await new sdk_1.Entities().get({
|
|
108
|
-
entityName: 'entity-snapshot',
|
|
109
|
-
criteria: {
|
|
110
|
-
entityReference,
|
|
111
|
-
createdOn
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
const assortmentPublishChangeId = apc?.id;
|
|
115
|
-
const snapshot = snapshots.find(snap => snap?.assortmentChangeId === assortmentPublishChangeId);
|
|
116
|
-
let snapshotVersion = 'unknown';
|
|
117
|
-
if (snapshot && snapshot.versionNumber) {
|
|
118
|
-
snapshotVersion = snapshot.versionNumber;
|
|
119
|
-
}
|
|
120
|
-
else if (!snapshot && snapshots.length > 0) {
|
|
121
|
-
const createdOnTime = new Date(createdOnString).getTime();
|
|
122
|
-
const lastSnapshot = snapshots[snapshots.length - 1];
|
|
123
|
-
if (lastSnapshot?.createdOn && createdOnTime > new Date(lastSnapshot.createdOn).getTime()) {
|
|
124
|
-
snapshotVersion = 'after: ' + lastSnapshot.versionNumber;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
return snapshotVersion;
|
|
128
|
-
}
|
|
129
|
-
async getSeasonFederation(assortmentId) {
|
|
130
|
-
const assortment = await this.getAssortment(assortmentId);
|
|
131
|
-
console.error('assortment-name: ' + assortment?.name);
|
|
132
|
-
const publishToFlexPLM = assortment?.publishToFlexPLM;
|
|
133
|
-
if (!publishToFlexPLM) {
|
|
134
|
-
throw new Error(BaseProcessPublishAssortment.ASSORTMENT_NOT_PUBLISHABLE);
|
|
135
|
-
}
|
|
136
|
-
const assortmentObj = await this.dc.getFlexPLMObjectData(assortment, [], true);
|
|
137
|
-
let seasonObj = {
|
|
138
|
-
entityReference: 'assortment:' + assortmentId,
|
|
139
|
-
objectClass: 'LCSSeason',
|
|
140
|
-
};
|
|
141
|
-
const identifierKeys = await type_conversion_utils_1.TypeConversionUtils.getIdentifierProperties(this.transformMapFile, this.mapFileUtil, assortmentObj);
|
|
142
|
-
const informationKeys = await type_conversion_utils_1.TypeConversionUtils.getInformationalProperties(this.transformMapFile, this.mapFileUtil, assortmentObj);
|
|
143
|
-
for (const key of identifierKeys.concat(informationKeys)) {
|
|
144
|
-
if (assortmentObj[key]) {
|
|
145
|
-
seasonObj[key] = assortmentObj[key];
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
const objectKeys = Object.keys(seasonObj);
|
|
149
|
-
const hasAllIdentifiers = identifierKeys.every(key => objectKeys.includes(key));
|
|
150
|
-
if (!hasAllIdentifiers) {
|
|
151
|
-
throw new Error(BaseProcessPublishAssortment.ASSORTMENT_NO_FED_INFO + identifierKeys);
|
|
152
|
-
}
|
|
153
|
-
seasonObj = await map_utils_1.MapUtil.applyTransformMap(this.transformMapFile, this.mapFileUtil, seasonObj, 'LCSSeason', 'vibe2flex');
|
|
154
|
-
return seasonObj;
|
|
155
|
-
}
|
|
156
|
-
async getAssortment(assortmentId) {
|
|
157
|
-
if (this.assortment != undefined) {
|
|
158
|
-
return this.assortment;
|
|
159
|
-
}
|
|
160
|
-
this.assortment = await new sdk_1.Entities().get({
|
|
161
|
-
entityName: 'assortment',
|
|
162
|
-
id: assortmentId
|
|
163
|
-
});
|
|
164
|
-
return this.assortment;
|
|
165
|
-
}
|
|
166
|
-
async getSinceDate(assortmentId, assortmentPublishChangeId, apcHistory) {
|
|
167
|
-
let sinceDate = null;
|
|
168
|
-
let pastPublishCount = 1;
|
|
169
|
-
if (this.config?.sinceDate) {
|
|
170
|
-
const sinceDateString = '' + this.config?.sinceDate;
|
|
171
|
-
if (sinceDateString && sinceDateString.indexOf('-') > 0) {
|
|
172
|
-
const sinceDateParts = sinceDateString.split('-');
|
|
173
|
-
if (sinceDateParts.length == 3) {
|
|
174
|
-
const year = parseInt(sinceDateParts[0]);
|
|
175
|
-
const month = parseInt(sinceDateParts[1]) - 1;
|
|
176
|
-
const day = parseInt(sinceDateParts[2]);
|
|
177
|
-
const minutes = 0 - new Date().getTimezoneOffset();
|
|
178
|
-
sinceDate = this.getSinceDateFromAPCSpecificDate(apcHistory, assortmentPublishChangeId, new Date(year, month, day, 0, minutes, 0));
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
else if (sinceDateString && sinceDateString.indexOf(':') > 0) {
|
|
182
|
-
const sinceDateParts = sinceDateString.split(':');
|
|
183
|
-
const type = sinceDateParts[0];
|
|
184
|
-
const count = parseInt(sinceDateParts[1]);
|
|
185
|
-
if ('numberofdays' == type.toLocaleLowerCase()) {
|
|
186
|
-
sinceDate = this.getSinceDateDaysPrevious(apcHistory, assortmentPublishChangeId, count);
|
|
187
|
-
}
|
|
188
|
-
else if ('numberofpublishes' == type.toLocaleLowerCase()) {
|
|
189
|
-
pastPublishCount = count;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
if (sinceDate == null) {
|
|
194
|
-
sinceDate = this.getSinceDateFromAPCs(apcHistory, assortmentPublishChangeId, pastPublishCount);
|
|
195
|
-
}
|
|
196
|
-
if (sinceDate == null) {
|
|
197
|
-
throw new Error('Couldnt set sinceDate');
|
|
198
|
-
}
|
|
199
|
-
console.info('getSinceDate: ' + sinceDate);
|
|
200
|
-
return sinceDate;
|
|
201
|
-
}
|
|
202
|
-
async getApcHistory(assortmentId) {
|
|
203
|
-
const resource = `/assortments/${assortmentId}/history/`;
|
|
204
|
-
return sdk_1.Request.request(resource, {
|
|
205
|
-
method: 'GET',
|
|
206
|
-
headers: {
|
|
207
|
-
Accept: 'application/json',
|
|
208
|
-
'Content-Type': 'application/json'
|
|
209
|
-
}
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
updatedSinceDate(entity, sinceDate) {
|
|
213
|
-
const updatedOn = entity?.updatedOn;
|
|
214
|
-
return (updatedOn && new Date(updatedOn) > sinceDate);
|
|
215
|
-
}
|
|
216
|
-
getSinceDateFromAPCSpecificDate(apcHistory, assortmentPublishChangeId, specificDate) {
|
|
217
|
-
const apc = apcHistory.find(apc => apc?.id === assortmentPublishChangeId);
|
|
218
|
-
const apcDate = new Date(apc?.createdOn);
|
|
219
|
-
let afterDate = apcDate;
|
|
220
|
-
let beforeDate = new Date(0);
|
|
221
|
-
const sinceDate = specificDate;
|
|
222
|
-
for (const tempapc of apcHistory) {
|
|
223
|
-
if (assortmentPublishChangeId !== tempapc?.id) {
|
|
224
|
-
const tempDate = new Date(tempapc?.createdOn);
|
|
225
|
-
if (tempDate < apcDate) {
|
|
226
|
-
if (tempDate > sinceDate && tempDate < afterDate) {
|
|
227
|
-
afterDate = tempDate;
|
|
228
|
-
}
|
|
229
|
-
else if (tempDate < sinceDate && tempDate > beforeDate) {
|
|
230
|
-
beforeDate = tempDate;
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
const selectedDate = (beforeDate.getTime() !== 0) ? beforeDate : afterDate;
|
|
236
|
-
return selectedDate;
|
|
237
|
-
}
|
|
238
|
-
getSinceDateDaysPrevious(apcHistory, assortmentPublishChangeId, daysBack) {
|
|
239
|
-
const apc = apcHistory.find(apc => apc?.id === assortmentPublishChangeId);
|
|
240
|
-
const apcDate = new Date(apc?.createdOn);
|
|
241
|
-
let afterDate = apcDate;
|
|
242
|
-
let beforeDate = new Date(0);
|
|
243
|
-
const sinceDate = new Date(apcDate.getUTCFullYear(), apcDate.getUTCMonth(), apcDate.getUTCDate() - daysBack, 0, (0 - apcDate.getTimezoneOffset()), 0);
|
|
244
|
-
for (const tempapc of apcHistory) {
|
|
245
|
-
if (assortmentPublishChangeId !== tempapc?.id) {
|
|
246
|
-
const tempDate = new Date(tempapc?.createdOn);
|
|
247
|
-
if (tempDate < apcDate) {
|
|
248
|
-
if (tempDate > sinceDate && tempDate < afterDate) {
|
|
249
|
-
afterDate = tempDate;
|
|
250
|
-
}
|
|
251
|
-
else if (tempDate < sinceDate && tempDate > beforeDate) {
|
|
252
|
-
beforeDate = tempDate;
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
const selectedDate = (beforeDate.getTime() !== 0) ? beforeDate : afterDate;
|
|
258
|
-
return selectedDate;
|
|
259
|
-
}
|
|
260
|
-
getSinceDateFromAPCs(apcHistory, assortmentPublishChangeId, pastPublishCount = 1) {
|
|
261
|
-
if (apcHistory.length === 1) {
|
|
262
|
-
return new Date(0);
|
|
263
|
-
}
|
|
264
|
-
const apcIndex = apcHistory.findIndex(apc => apc.id === assortmentPublishChangeId);
|
|
265
|
-
if (apcIndex === 0) {
|
|
266
|
-
return new Date(0);
|
|
267
|
-
}
|
|
268
|
-
const apc = apcHistory[apcIndex];
|
|
269
|
-
const apcDate = new Date(apc?.createdOn);
|
|
270
|
-
let sinceDate = new Date(0);
|
|
271
|
-
const dateArray = [];
|
|
272
|
-
for (const tempapc of apcHistory) {
|
|
273
|
-
if (assortmentPublishChangeId !== tempapc?.id) {
|
|
274
|
-
const tempDate = new Date(tempapc?.createdOn);
|
|
275
|
-
if (tempDate < apcDate) {
|
|
276
|
-
dateArray.push(tempDate);
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
dateArray.sort((a, b) => { return Date.parse(a) - Date.parse(b); });
|
|
281
|
-
const arrIndex = (dateArray.length - pastPublishCount > 0) ? dateArray.length - pastPublishCount : 0;
|
|
282
|
-
sinceDate = dateArray[arrIndex];
|
|
283
|
-
return sinceDate;
|
|
284
|
-
}
|
|
285
|
-
getPublisher(assortmentPublishChange) {
|
|
286
|
-
const createdBy = assortmentPublishChange?.createdBy;
|
|
287
|
-
const publisher = {};
|
|
288
|
-
const includeKeys = ['email', 'firstName', 'isSsoUser', 'lastName'];
|
|
289
|
-
for (const [key, value] of Object.entries(createdBy)) {
|
|
290
|
-
if (includeKeys.includes(key)) {
|
|
291
|
-
publisher[key] = value;
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
return publisher;
|
|
295
|
-
}
|
|
296
|
-
async downloadAssortmentPublishChange(assortmentId, assortmentPublishChangeId) {
|
|
297
|
-
const resourceString = '/assortments/' + assortmentId + '/history/' + assortmentPublishChangeId + '?relations=createdBy';
|
|
298
|
-
return await sdk_1.Request.request(resourceString, {
|
|
299
|
-
method: 'GET',
|
|
300
|
-
Headers: {
|
|
301
|
-
Accept: 'application/json',
|
|
302
|
-
'Content-Type': 'application/json'
|
|
303
|
-
}
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
|
-
async downloadHydratedChangeDetail(assortmentPublishChange) {
|
|
307
|
-
try {
|
|
308
|
-
console.info('downloadHydratedChangeDetail-start');
|
|
309
|
-
const link = assortmentPublishChange?.hydratedDetailDownloadLink;
|
|
310
|
-
const response = await fetch(link);
|
|
311
|
-
const data = await response.json();
|
|
312
|
-
return data;
|
|
313
|
-
}
|
|
314
|
-
catch (e) {
|
|
315
|
-
console.log('Error hydratedDetailDownloadLink: ' + e.message);
|
|
316
|
-
}
|
|
317
|
-
return undefined;
|
|
318
|
-
}
|
|
319
|
-
async downloadAssortmentBaseline(assortmentPublishChange) {
|
|
320
|
-
console.info('downloadAssortmentBaseline-start');
|
|
321
|
-
try {
|
|
322
|
-
const link = assortmentPublishChange?.assortmentBaselineDownloadLink;
|
|
323
|
-
const response = await fetch(link);
|
|
324
|
-
const data = await response.json();
|
|
325
|
-
return data;
|
|
326
|
-
}
|
|
327
|
-
catch (e) {
|
|
328
|
-
console.log('Error assortmentBaselineDownloadLink: ' + e.message);
|
|
329
|
-
}
|
|
330
|
-
return undefined;
|
|
331
|
-
}
|
|
332
|
-
async getDeleteChanges(assortmentPublishChange, apcHistory, assortmentBaseline, sinceDate) {
|
|
333
|
-
console.info('getDeleteChanges(): ' + assortmentPublishChange?.id);
|
|
334
|
-
console.info(sinceDate);
|
|
335
|
-
const currentAPCIndex = apcHistory.findIndex(pc => pc?.id === assortmentPublishChange?.id);
|
|
336
|
-
console.info(' currentAPCIndex: ' + currentAPCIndex);
|
|
337
|
-
if (currentAPCIndex == 0) {
|
|
338
|
-
return [];
|
|
339
|
-
}
|
|
340
|
-
const previousApcIndex = (currentAPCIndex > 0) ? currentAPCIndex - 1 : 0;
|
|
341
|
-
const apcCreatedOn = apcHistory[previousApcIndex]?.createdOn;
|
|
342
|
-
const apcDeletes = await this.downloadDeleteChanges(assortmentPublishChange);
|
|
343
|
-
let previousApcDate = Date.parse(apcCreatedOn);
|
|
344
|
-
const sinceDateMilliseconds = sinceDate.getTime();
|
|
345
|
-
if (app_framework_1.Logger.isInfoOn()) {
|
|
346
|
-
console.info('apcCreatedOn: ' + apcCreatedOn);
|
|
347
|
-
console.info('sinceDate: ' + sinceDate);
|
|
348
|
-
console.info('sinceDateMilliseconds: ' + sinceDateMilliseconds);
|
|
349
|
-
console.info('apcDateMilliseconds: ' + previousApcDate);
|
|
350
|
-
}
|
|
351
|
-
if (sinceDateMilliseconds !== previousApcDate) {
|
|
352
|
-
console.info('sinceDateMilliseconds !== apcDateMilliseconds');
|
|
353
|
-
const currentAssortmentItemIds = this.getBaselineItemIds(assortmentBaseline);
|
|
354
|
-
const deleteIds = (apcDeletes.length === 0)
|
|
355
|
-
? []
|
|
356
|
-
: apcDeletes.map(item => item?.itemId);
|
|
357
|
-
for (let i = currentAPCIndex - 1; i > 0; i--) {
|
|
358
|
-
const workingAPC = apcHistory[i];
|
|
359
|
-
previousApcDate = Date.parse(workingAPC?.createdOn);
|
|
360
|
-
if (sinceDateMilliseconds === previousApcDate) {
|
|
361
|
-
break;
|
|
362
|
-
}
|
|
363
|
-
if (workingAPC?.deletes > 0) {
|
|
364
|
-
const previousApc = (i > 0)
|
|
365
|
-
? apcHistory[i - 1]
|
|
366
|
-
: undefined;
|
|
367
|
-
const deleteChanges = await this.buildDeleteChanges(workingAPC, previousApc);
|
|
368
|
-
console.info('checking deleteChanges');
|
|
369
|
-
for (const dItem of deleteChanges) {
|
|
370
|
-
const dItemId = dItem?.itemId;
|
|
371
|
-
console.info(dItemId);
|
|
372
|
-
if (!currentAssortmentItemIds.includes(dItemId) && !deleteIds.includes(dItemId)) {
|
|
373
|
-
console.info('adding');
|
|
374
|
-
deleteIds.push(dItemId);
|
|
375
|
-
apcDeletes.push(dItem);
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
console.info('getDeleteChanges()-currentAssortmentItemIds: ' + currentAssortmentItemIds);
|
|
381
|
-
console.info('getDeleteChanges()-deleteIds: ' + deleteIds);
|
|
382
|
-
}
|
|
383
|
-
return apcDeletes;
|
|
384
|
-
}
|
|
385
|
-
getBaselineItemIds(assortmentBaseline) {
|
|
386
|
-
const itemIds = [];
|
|
387
|
-
const assortmentItemsArray = assortmentBaseline?.assortmentItems;
|
|
388
|
-
for (const aItem of assortmentItemsArray) {
|
|
389
|
-
itemIds.push(aItem?.itemId);
|
|
390
|
-
}
|
|
391
|
-
return itemIds;
|
|
392
|
-
}
|
|
393
|
-
async downloadDeleteChanges(apc) {
|
|
394
|
-
console.info('deleteDataDownloadLink-start');
|
|
395
|
-
try {
|
|
396
|
-
const link = apc?.deleteDataDownloadLink;
|
|
397
|
-
const response = await fetch(link);
|
|
398
|
-
const data = await response.json();
|
|
399
|
-
return data;
|
|
400
|
-
}
|
|
401
|
-
catch (e) {
|
|
402
|
-
console.log('Error deleteDataDownloadLink: ' + e.message);
|
|
403
|
-
}
|
|
404
|
-
return undefined;
|
|
405
|
-
}
|
|
406
|
-
async buildDeleteChanges(apc, previousApc) {
|
|
407
|
-
console.info('buildDeleteChanges()');
|
|
408
|
-
if (apc?.deleteDataDownloadLink) {
|
|
409
|
-
const deleteChanges = await this.downloadDeleteChanges(apc);
|
|
410
|
-
if (deleteChanges) {
|
|
411
|
-
return deleteChanges;
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
console.info('pulling down full APC');
|
|
415
|
-
apc = await this.downloadAssortmentPublishChange(apc?.assortmentId, apc?.id);
|
|
416
|
-
if (apc?.deleteDataDownloadLink) {
|
|
417
|
-
const deleteChanges = await this.downloadDeleteChanges(apc);
|
|
418
|
-
if (deleteChanges) {
|
|
419
|
-
return deleteChanges;
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
if (!previousApc) {
|
|
423
|
-
throw new Error(BaseProcessPublishAssortment.NOT_ABLE_TO_PROCESS_DELETE_CHANGES);
|
|
424
|
-
}
|
|
425
|
-
let previousBaseline;
|
|
426
|
-
console.info('check previousApc');
|
|
427
|
-
if (previousApc?.assortmentBaselineDownloadLink) {
|
|
428
|
-
previousBaseline = await this.downloadAssortmentBaseline(previousApc);
|
|
429
|
-
}
|
|
430
|
-
else {
|
|
431
|
-
console.info('previousApc pulling down full APC');
|
|
432
|
-
previousApc = await this.downloadAssortmentPublishChange(previousApc?.assortmentId, previousApc?.id);
|
|
433
|
-
previousBaseline = await this.downloadAssortmentBaseline(previousApc);
|
|
434
|
-
}
|
|
435
|
-
const deleteIds = apc?.detail?.deletes.map(dItem => dItem?.id);
|
|
436
|
-
const deleteArray = previousBaseline?.assortmentItems.filter(aItem => deleteIds.includes(aItem?.itemId));
|
|
437
|
-
console.info('deleteArray.length: ' + deleteArray.length);
|
|
438
|
-
return deleteArray;
|
|
439
|
-
}
|
|
440
|
-
async getItemFederatedIds() {
|
|
441
|
-
const itemFederatedIds = new Map();
|
|
442
|
-
return itemFederatedIds;
|
|
443
|
-
}
|
|
444
|
-
getFullChangeAssortmentMap(fullChange) {
|
|
445
|
-
const assortmentItemsArray = fullChange?.assortmentItems || [];
|
|
446
|
-
const assortmentItemsMap = new Map();
|
|
447
|
-
for (const aItem of assortmentItemsArray) {
|
|
448
|
-
const itemId = aItem?.itemId;
|
|
449
|
-
assortmentItemsMap.set(itemId, aItem);
|
|
450
|
-
}
|
|
451
|
-
return assortmentItemsMap;
|
|
452
|
-
}
|
|
453
|
-
getDeleteChangesAssortmentMap(deleteChanges) {
|
|
454
|
-
const deleteItems = new Map();
|
|
455
|
-
for (const dItem of deleteChanges) {
|
|
456
|
-
deleteItems.set(dItem?.itemId, dItem);
|
|
457
|
-
}
|
|
458
|
-
return deleteItems;
|
|
459
|
-
}
|
|
460
|
-
getReleasedForDevelopmentItemAndFamilyIds(fullChange, deleteChanges) {
|
|
461
|
-
console.info('getReleasedForDevelopmentItemAndFamilyIds');
|
|
462
|
-
const releasedForDevelopmentItemIds = [];
|
|
463
|
-
const itemFamilySet = new Set();
|
|
464
|
-
const assortmentItemsArray = fullChange?.assortmentItems;
|
|
465
|
-
for (const aItem of assortmentItemsArray) {
|
|
466
|
-
const meetsCriteria = this.meetsCriteria(aItem);
|
|
467
|
-
const item = aItem?.item;
|
|
468
|
-
const itemId = item?.id;
|
|
469
|
-
const itemFamilyId = item?.itemFamilyId;
|
|
470
|
-
if (meetsCriteria) {
|
|
471
|
-
releasedForDevelopmentItemIds.push(itemId);
|
|
472
|
-
if (!itemFamilySet.has(itemFamilyId) && itemId !== itemFamilyId) {
|
|
473
|
-
const familyItem = item?.itemFamily;
|
|
474
|
-
const familyItemMeetsCriteria = this.meetsCriteria({ item: familyItem });
|
|
475
|
-
if (familyItemMeetsCriteria) {
|
|
476
|
-
releasedForDevelopmentItemIds.push(itemFamilyId);
|
|
477
|
-
}
|
|
478
|
-
itemFamilySet.add(itemFamilyId);
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
for (const dItem of deleteChanges) {
|
|
483
|
-
const meetsCriteria = this.meetsCriteria(dItem);
|
|
484
|
-
const item = dItem?.item;
|
|
485
|
-
const itemId = item?.id;
|
|
486
|
-
const itemFamilyId = item?.itemFamilyId;
|
|
487
|
-
if (meetsCriteria) {
|
|
488
|
-
releasedForDevelopmentItemIds.push(itemId);
|
|
489
|
-
if (!itemFamilySet.has(itemFamilyId) && itemId !== itemFamilyId) {
|
|
490
|
-
const familyItem = item?.itemFamily;
|
|
491
|
-
if (familyItem) {
|
|
492
|
-
const familyItemMeetsCriteria = this.meetsCriteria({ item: familyItem });
|
|
493
|
-
if (familyItemMeetsCriteria) {
|
|
494
|
-
releasedForDevelopmentItemIds.push(itemFamilyId);
|
|
495
|
-
}
|
|
496
|
-
itemFamilySet.add(itemFamilyId);
|
|
497
|
-
}
|
|
498
|
-
else {
|
|
499
|
-
itemFamilySet.add(itemFamilyId);
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
console.info('releasedForDevelopmentItemIds: ' + releasedForDevelopmentItemIds);
|
|
505
|
-
return releasedForDevelopmentItemIds;
|
|
506
|
-
}
|
|
507
|
-
meetsCriteria(aItem) {
|
|
508
|
-
const item = aItem?.item;
|
|
509
|
-
const lifecycleStage = item?.lifecycleStage;
|
|
510
|
-
return !!lifecycleStage && !this.config.itemPreDevelopmentLifecycleStages.includes(lifecycleStage);
|
|
511
|
-
}
|
|
512
|
-
async processPublish(pcd, changeDetail, fullChange, deleteChanges) {
|
|
513
|
-
console.info('processPublish-start');
|
|
514
|
-
const event = {
|
|
515
|
-
assortmentId: pcd.assortmentId,
|
|
516
|
-
assortmentPublishChangeId: pcd.assortmentPublishChangeId
|
|
517
|
-
};
|
|
518
|
-
const assortmentItemFullChangeMap = this.getFullChangeAssortmentMap(fullChange);
|
|
519
|
-
const assortmentItemDeleteMap = this.getDeleteChangesAssortmentMap(deleteChanges);
|
|
520
|
-
pcd.itemFamilyChanges = this.getItemFamilyChanges(pcd, changeDetail, assortmentItemFullChangeMap, assortmentItemDeleteMap);
|
|
521
|
-
const events = await this.getEventsForPublishChangeData(pcd);
|
|
522
|
-
if (events.length === 0) {
|
|
523
|
-
const processStatus = 'BaseProcessPublishAssortment: ' + event_short_message_status_1.EventShortMessageStatus.NO_EVENTS_TO_SEND
|
|
524
|
-
+ ': assortmentId: ' + pcd.assortmentId + ': assortmentPublishChangeId: ' + pcd.assortmentPublishChangeId
|
|
525
|
-
+ ', orgSlug: ' + this.orgSlug;
|
|
526
|
-
console.log(processStatus);
|
|
527
|
-
const message = 'No Events to Send; returning';
|
|
528
|
-
console.log(message);
|
|
529
|
-
return {
|
|
530
|
-
results: { message, event },
|
|
531
|
-
skip_await: true
|
|
532
|
-
};
|
|
533
|
-
}
|
|
534
|
-
const results = await this.sendEvents(events);
|
|
535
|
-
const resultsCount = this.getResultsCount(events);
|
|
536
|
-
const processStatus = 'BaseProcessPublishAssortment: ' + event_short_message_status_1.EventShortMessageStatus.SENDING_EVENTS
|
|
537
|
-
+ ': assortmentId: ' + pcd.assortmentId + ': assortmentPublishChangeId: ' + pcd.assortmentPublishChangeId
|
|
538
|
-
+ ': resultsCount: ' + JSON.stringify(resultsCount)
|
|
539
|
-
+ ', orgSlug: ' + this.orgSlug;
|
|
540
|
-
console.log(processStatus);
|
|
541
|
-
return { results, event, resultsCount };
|
|
542
|
-
}
|
|
543
|
-
getResultsCount(events) {
|
|
544
|
-
return events.reduce((acc, event) => {
|
|
545
|
-
const objectClass = event?.objectClass;
|
|
546
|
-
if (objectClass === 'LCSProductSeasonLink') {
|
|
547
|
-
acc.productSeasons++;
|
|
548
|
-
}
|
|
549
|
-
else if (objectClass === 'LCSSKUSeasonLink') {
|
|
550
|
-
acc.colorwaySeasons++;
|
|
551
|
-
}
|
|
552
|
-
return acc;
|
|
553
|
-
}, { productSeasons: 0, colorwaySeasons: 0 });
|
|
554
|
-
}
|
|
555
|
-
async sendEvents(events) {
|
|
556
|
-
console.info('sendEvents()');
|
|
557
|
-
const eventType = 'ASYNC_PUBLISH_SEASON';
|
|
558
|
-
const sendMode = (this.config?.sendMode[eventType] || '').toLowerCase();
|
|
559
|
-
switch (sendMode) {
|
|
560
|
-
case 'sendtoflexplm':
|
|
561
|
-
return this.sendToFlexPLM(events, eventType);
|
|
562
|
-
case 'localfile':
|
|
563
|
-
return this.saveToLocalFile(events, eventType);
|
|
564
|
-
case 'vibeiqfile':
|
|
565
|
-
case 'vibeiqfile-dontsendtoflexplm':
|
|
566
|
-
return this.handleVibeIQFile(events, eventType, sendMode);
|
|
567
|
-
default:
|
|
568
|
-
return {};
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
async sendToFlexPLM(events, eventType) {
|
|
572
|
-
const asyncEvent = {
|
|
573
|
-
taskId: this.config.taskId,
|
|
574
|
-
eventType,
|
|
575
|
-
objectClass: 'LCSSeason',
|
|
576
|
-
events
|
|
577
|
-
};
|
|
578
|
-
const flexPLMConnect = new flexplm_connect_1.FlexPLMConnect(this.config);
|
|
579
|
-
return await flexPLMConnect.sendToFlexPLM(asyncEvent);
|
|
580
|
-
}
|
|
581
|
-
async saveToLocalFile(events, eventType) {
|
|
582
|
-
let results = {};
|
|
583
|
-
let fileHandle;
|
|
584
|
-
try {
|
|
585
|
-
const dateString = this.getCurrentDateString();
|
|
586
|
-
const dirName = await path.resolve();
|
|
587
|
-
await fsPromise.mkdir(dirName, { recursive: true });
|
|
588
|
-
const eventDirName = 'events-output';
|
|
589
|
-
const fileName = `${path.sep}${eventDirName}${path.sep}events-${dateString}.json`;
|
|
590
|
-
fileHandle = await fsPromise.open('.' + fileName, 'a');
|
|
591
|
-
const asyncEvent = {
|
|
592
|
-
taskId: this.config.taskId,
|
|
593
|
-
eventType,
|
|
594
|
-
objectClass: 'LCSSeason',
|
|
595
|
-
events
|
|
596
|
-
};
|
|
597
|
-
await fileHandle.writeFile(JSON.stringify(asyncEvent));
|
|
598
|
-
results = {
|
|
599
|
-
message: 'Successfully Saved File',
|
|
600
|
-
fileLocation: dirName + fileName
|
|
601
|
-
};
|
|
602
|
-
}
|
|
603
|
-
catch (e) {
|
|
604
|
-
results['error'] = e.message;
|
|
605
|
-
}
|
|
606
|
-
finally {
|
|
607
|
-
await fileHandle?.close();
|
|
608
|
-
}
|
|
609
|
-
return results;
|
|
610
|
-
}
|
|
611
|
-
async handleVibeIQFile(events, eventType, sendMode) {
|
|
612
|
-
const eventBuffer = Buffer.from(JSON.stringify(events), 'utf-8');
|
|
613
|
-
const fileName = 'ASYNC_PUBLISH_SEASON-events.json';
|
|
614
|
-
const uploadFile = await new sdk_1.Files().createAndUploadFileFromBuffer(eventBuffer, 'application/json', fileName, null, this.TTL);
|
|
615
|
-
const asyncEvent = {
|
|
616
|
-
taskId: this.config.taskId,
|
|
617
|
-
eventType,
|
|
618
|
-
objectClass: 'LCSSeason',
|
|
619
|
-
eventsFileId: uploadFile.id,
|
|
620
|
-
eventsDownloadLink: uploadFile.downloadUrl,
|
|
621
|
-
eventsAdminDownloadLink: uploadFile.adminDownloadUrl
|
|
622
|
-
};
|
|
623
|
-
if (sendMode === 'vibeiqfile') {
|
|
624
|
-
const flexPLMConnect = new flexplm_connect_1.FlexPLMConnect(this.config);
|
|
625
|
-
return await flexPLMConnect.sendToFlexPLM(asyncEvent);
|
|
626
|
-
}
|
|
627
|
-
else {
|
|
628
|
-
return {
|
|
629
|
-
message: 'Successfully Uploaded File.',
|
|
630
|
-
asyncEvent
|
|
631
|
-
};
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
getCurrentDateString() {
|
|
635
|
-
const d = new Date();
|
|
636
|
-
return '' + d.getUTCFullYear()
|
|
637
|
-
+ '-' + d.getUTCMonth()
|
|
638
|
-
+ '-' + (d.getUTCDate() + 1)
|
|
639
|
-
+ '-' + d.getUTCHours()
|
|
640
|
-
+ '-' + d.getUTCMinutes()
|
|
641
|
-
+ '-' + d.getUTCSeconds()
|
|
642
|
-
+ '-' + d.getUTCMilliseconds();
|
|
643
|
-
}
|
|
644
|
-
getItemFamilyChanges(pcd, changeDetail, assortmentItemFullChangeMap, assortmentItemDeleteMap) {
|
|
645
|
-
console.info('getItemFamilyChanges-start');
|
|
646
|
-
const itemFamilyChanges = new Map();
|
|
647
|
-
const { adds, deletes, updates, familyItemsRemoved } = changeDetail;
|
|
648
|
-
const addIds = adds.map(item => item.id);
|
|
649
|
-
const deleteIds = deletes.map(item => item.id);
|
|
650
|
-
const updateIds = updates.map(item => item.id);
|
|
651
|
-
const familyItemsRemovedIds = familyItemsRemoved.map(item => item.itemId);
|
|
652
|
-
for (const [itemId, aItem] of assortmentItemFullChangeMap) {
|
|
653
|
-
const projectItem = aItem?.projectItem;
|
|
654
|
-
const itemFamilyId = aItem?.item?.itemFamilyId;
|
|
655
|
-
if (!pcd.releasedForDevelopmentItemIds.includes(itemFamilyId) || !pcd.releasedForDevelopmentItemIds.includes(itemId)) {
|
|
656
|
-
continue;
|
|
657
|
-
}
|
|
658
|
-
const ifc = itemFamilyChanges.get(itemFamilyId) || new item_family_changes_1.ItemFamilyChanges(itemFamilyId, pcd.sinceDate);
|
|
659
|
-
if (!itemFamilyChanges.has(itemFamilyId)) {
|
|
660
|
-
ifc.itemFamilyObject = itemId === itemFamilyId ? aItem?.item : aItem?.item?.itemFamily;
|
|
661
|
-
itemFamilyChanges.set(itemFamilyId, ifc);
|
|
662
|
-
}
|
|
663
|
-
ifc.assortmentItemFullChangeMap.set(itemId, aItem);
|
|
664
|
-
if (pcd.itemToFederatedIdMapping.has(itemId)) {
|
|
665
|
-
ifc.itemToFederatedIdMapping.set(itemId, pcd.itemToFederatedIdMapping.get(itemId));
|
|
666
|
-
}
|
|
667
|
-
if (itemId === itemFamilyId) {
|
|
668
|
-
if (addIds.includes(itemId))
|
|
669
|
-
ifc.familyAdd = true;
|
|
670
|
-
else if (deleteIds.includes(itemId))
|
|
671
|
-
ifc.familyDelete = true;
|
|
672
|
-
else if (updateIds.includes(itemId))
|
|
673
|
-
ifc.familyUpdate = true;
|
|
674
|
-
else if (familyItemsRemovedIds.includes(itemId))
|
|
675
|
-
ifc.familyItemRemoved = true;
|
|
676
|
-
if (projectItem) {
|
|
677
|
-
const updatedOnDate = new Date(projectItem.updatedOn);
|
|
678
|
-
if (updatedOnDate > pcd.sinceDate) {
|
|
679
|
-
ifc.familyUpdate = true;
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
|
-
if (projectItem && !projectItem?.roles && aItem?.item?.roles) {
|
|
683
|
-
projectItem.roles = aItem?.item?.roles;
|
|
684
|
-
}
|
|
685
|
-
}
|
|
686
|
-
else {
|
|
687
|
-
if (addIds.includes(itemId))
|
|
688
|
-
ifc.colorAdds.push(itemId);
|
|
689
|
-
else if (deleteIds.includes(itemId))
|
|
690
|
-
ifc.colorDeletes.push(itemId);
|
|
691
|
-
else if (updateIds.includes(itemId))
|
|
692
|
-
ifc.colorUpdates.push(itemId);
|
|
693
|
-
else if (projectItem && new Date(projectItem.updatedOn) > pcd.sinceDate)
|
|
694
|
-
ifc.colorUpdates.push(itemId);
|
|
695
|
-
else
|
|
696
|
-
ifc.colorUnchanged.push(itemId);
|
|
697
|
-
if (projectItem && !projectItem?.roles && aItem?.item?.roles) {
|
|
698
|
-
projectItem.roles = aItem?.item?.roles;
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
for (const [itemId, delEntity] of assortmentItemDeleteMap) {
|
|
703
|
-
const itemFamilyId = delEntity?.item?.itemFamilyId;
|
|
704
|
-
const item = delEntity?.item;
|
|
705
|
-
if (!pcd.releasedForDevelopmentItemIds.includes(itemFamilyId) || !pcd.releasedForDevelopmentItemIds.includes(itemId)) {
|
|
706
|
-
continue;
|
|
707
|
-
}
|
|
708
|
-
else {
|
|
709
|
-
if (!item) {
|
|
710
|
-
console.error('Failed to find deleted item entity');
|
|
711
|
-
console.error(' itemFamilyId: ' + itemFamilyId + ' -itemId: ' + itemId);
|
|
712
|
-
continue;
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
let ifc = itemFamilyChanges.get(itemFamilyId);
|
|
716
|
-
if (!ifc) {
|
|
717
|
-
ifc = new item_family_changes_1.ItemFamilyChanges(itemFamilyId, pcd.sinceDate);
|
|
718
|
-
if (itemId === itemFamilyId) {
|
|
719
|
-
ifc.familyDelete = true;
|
|
720
|
-
ifc.itemFamilyObject = item;
|
|
721
|
-
}
|
|
722
|
-
else {
|
|
723
|
-
ifc.itemFamilyObject = item?.itemFamily;
|
|
724
|
-
}
|
|
725
|
-
itemFamilyChanges.set(itemFamilyId, ifc);
|
|
726
|
-
}
|
|
727
|
-
if (pcd.itemToFederatedIdMapping.has(itemId)) {
|
|
728
|
-
ifc.itemToFederatedIdMapping.set(itemId, pcd.itemToFederatedIdMapping.get(itemId));
|
|
729
|
-
}
|
|
730
|
-
ifc.assortmentItemDeleteMap.set(itemId, delEntity);
|
|
731
|
-
ifc.assortmentItemFullChangeMap.set(itemId, delEntity);
|
|
732
|
-
if (itemId === itemFamilyId) {
|
|
733
|
-
ifc.familyDelete = true;
|
|
734
|
-
}
|
|
735
|
-
else {
|
|
736
|
-
ifc.colorDeletes.push(itemId);
|
|
737
|
-
}
|
|
738
|
-
}
|
|
739
|
-
if (app_framework_1.Logger.isDebugOn()) {
|
|
740
|
-
console.debug('returning size: ' + itemFamilyChanges.size);
|
|
741
|
-
for (const [key, value] of itemFamilyChanges) {
|
|
742
|
-
console.debug(key + ' => ' + value);
|
|
743
|
-
}
|
|
744
|
-
}
|
|
745
|
-
return itemFamilyChanges;
|
|
746
|
-
}
|
|
747
|
-
async getEventsForPublishChangeData(publishChangeData) {
|
|
748
|
-
console.info('getEventsForPublishChangeData-start');
|
|
749
|
-
const seasonalPayloads = [];
|
|
750
|
-
for (const itemFamilyChange of publishChangeData.itemFamilyChanges.values()) {
|
|
751
|
-
const events = await this.getEventsForItemFamilyChanges(itemFamilyChange, publishChangeData.assortmentId, publishChangeData.seasonFed, publishChangeData.itemToFederatedIdMapping);
|
|
752
|
-
if (events.length > 0) {
|
|
753
|
-
seasonalPayloads.push(...events);
|
|
754
|
-
}
|
|
755
|
-
}
|
|
756
|
-
return seasonalPayloads;
|
|
757
|
-
}
|
|
758
|
-
async getEventsForItemFamilyChanges(itemFamilyChanges, assortmentId, seasonFed, itemToFederatedIdMapping) {
|
|
759
|
-
console.info('getEventsForItemFamilyChanges()');
|
|
760
|
-
const events = [];
|
|
761
|
-
const LCSSeason = Object.assign({}, seasonFed);
|
|
762
|
-
const assortment = await this.getAssortment(assortmentId);
|
|
763
|
-
const projectItem = this.getProjectItem(itemFamilyChanges, itemFamilyChanges.itemFamilyId);
|
|
764
|
-
const familyAssortmentItem = itemFamilyChanges.familyAdd || itemFamilyChanges.familyUpdate || itemFamilyChanges.familyDelete
|
|
765
|
-
|| itemFamilyChanges.colorAdds.length > 0 || itemFamilyChanges.colorUpdates.length > 0 || itemFamilyChanges.colorDeletes.length > 0
|
|
766
|
-
|| (projectItem && this.updatedSinceDate(projectItem, itemFamilyChanges.sinceDate));
|
|
767
|
-
if (familyAssortmentItem) {
|
|
768
|
-
const entityReference = itemFamilyChanges.itemFamilyId;
|
|
769
|
-
const prodEntityData = (itemFamilyChanges.assortmentItemFullChangeMap.has(entityReference))
|
|
770
|
-
? itemFamilyChanges.assortmentItemFullChangeMap.get(entityReference)?.item
|
|
771
|
-
: itemFamilyChanges.itemFamilyObject;
|
|
772
|
-
let seasonalData = await this.getSeasonalData(projectItem);
|
|
773
|
-
seasonalData = await map_utils_1.MapUtil.applyTransformMap(this.transformMapFile, this.mapFileUtil, seasonalData, 'LCSProductSeasonLink', 'vibe2flex');
|
|
774
|
-
const LCSProduct = await this.getProductFederation(entityReference, itemToFederatedIdMapping, prodEntityData);
|
|
775
|
-
const isCreatable = await type_conversion_utils_1.TypeConversionUtils.isOutboundCreatableFromEntity(this.transformMapFile, this.mapFileUtil, projectItem, { item: prodEntityData, assortment });
|
|
776
|
-
const eventType = isCreatable ? 'UPSERT_ON_SEASON' : 'UPDATE_ON_SEASON';
|
|
777
|
-
const psUpsert = {
|
|
778
|
-
eventType,
|
|
779
|
-
objectClass: 'LCSProductSeasonLink',
|
|
780
|
-
entityReference: 'item:' + entityReference,
|
|
781
|
-
LCSSeason,
|
|
782
|
-
LCSProduct,
|
|
783
|
-
data: seasonalData
|
|
784
|
-
};
|
|
785
|
-
if ('ASSORTMENT' === projectItem.addedFromSource && projectItem.addedFromAssortment) {
|
|
786
|
-
const carriedFromSeason = await this.getCarriedFromSeason(projectItem);
|
|
787
|
-
if (carriedFromSeason) {
|
|
788
|
-
psUpsert['carriedFromSeason'] = carriedFromSeason;
|
|
789
|
-
}
|
|
790
|
-
}
|
|
791
|
-
events.push(psUpsert);
|
|
792
|
-
}
|
|
793
|
-
const colorwayChanges = [];
|
|
794
|
-
colorwayChanges.push(...itemFamilyChanges.colorAdds);
|
|
795
|
-
colorwayChanges.push(...itemFamilyChanges.colorUpdates);
|
|
796
|
-
colorwayChanges.push(...itemFamilyChanges.colorDeletes);
|
|
797
|
-
for (const entityReference of colorwayChanges) {
|
|
798
|
-
let item = {};
|
|
799
|
-
if (itemFamilyChanges.assortmentItemFullChangeMap.has(entityReference)) {
|
|
800
|
-
const fullAi = itemFamilyChanges.assortmentItemFullChangeMap.get(entityReference);
|
|
801
|
-
item = fullAi?.item;
|
|
802
|
-
}
|
|
803
|
-
const projectItem = this.getProjectItem(itemFamilyChanges, entityReference);
|
|
804
|
-
let seasonalData = await this.getSeasonalData(projectItem);
|
|
805
|
-
seasonalData = await map_utils_1.MapUtil.applyTransformMap(this.transformMapFile, this.mapFileUtil, seasonalData, 'LCSSKUSeasonLink', 'vibe2flex');
|
|
806
|
-
const LCSSKU = await this.getSKUFederation(entityReference, itemToFederatedIdMapping, item);
|
|
807
|
-
const isCreatable = await type_conversion_utils_1.TypeConversionUtils.isOutboundCreatableFromEntity(this.transformMapFile, this.mapFileUtil, projectItem, { item, assortment });
|
|
808
|
-
const eventType = isCreatable ? 'UPSERT_ON_SEASON' : 'UPDATE_ON_SEASON';
|
|
809
|
-
const csUpsert = {
|
|
810
|
-
eventType,
|
|
811
|
-
objectClass: 'LCSSKUSeasonLink',
|
|
812
|
-
entityReference: 'item:' + entityReference,
|
|
813
|
-
LCSSeason,
|
|
814
|
-
LCSSKU,
|
|
815
|
-
data: seasonalData
|
|
816
|
-
};
|
|
817
|
-
if ('ASSORTMENT' === projectItem.addedFromSource && projectItem.addedFromAssortment) {
|
|
818
|
-
const carriedFromSeason = await this.getCarriedFromSeason(projectItem);
|
|
819
|
-
if (carriedFromSeason) {
|
|
820
|
-
csUpsert['carriedFromSeason'] = carriedFromSeason;
|
|
821
|
-
}
|
|
822
|
-
}
|
|
823
|
-
events.push(csUpsert);
|
|
824
|
-
}
|
|
825
|
-
return events;
|
|
826
|
-
}
|
|
827
|
-
getProjectItem(itemFamilyChanges, id) {
|
|
828
|
-
let projectItem = {};
|
|
829
|
-
if (itemFamilyChanges?.assortmentItemFullChangeMap.has(id)) {
|
|
830
|
-
const aItem = itemFamilyChanges?.assortmentItemFullChangeMap.get(id);
|
|
831
|
-
projectItem = aItem?.projectItem;
|
|
832
|
-
}
|
|
833
|
-
if (id === itemFamilyChanges.itemFamilyId && Object.keys(projectItem).length == 0) {
|
|
834
|
-
for (const asstItem of itemFamilyChanges.assortmentItemFullChangeMap.values()) {
|
|
835
|
-
if (asstItem?.familyProjectItem) {
|
|
836
|
-
projectItem = asstItem?.familyProjectItem;
|
|
837
|
-
break;
|
|
838
|
-
}
|
|
839
|
-
}
|
|
840
|
-
}
|
|
841
|
-
return projectItem;
|
|
842
|
-
}
|
|
843
|
-
async getSeasonalData(projectItem) {
|
|
844
|
-
return await this.dc.getFlexPLMObjectData(projectItem, [], true);
|
|
845
|
-
}
|
|
846
|
-
async getProductFederation(entityReference, itemToFederatedIdMapping, itemFamilyObject) {
|
|
847
|
-
const itemObj = await this.dc.getFlexPLMObjectData(itemFamilyObject, [], true);
|
|
848
|
-
let prodObj = {
|
|
849
|
-
entityReference: 'item:' + entityReference,
|
|
850
|
-
objectClass: 'LCSProduct',
|
|
851
|
-
};
|
|
852
|
-
const identifierKeys = await type_conversion_utils_1.TypeConversionUtils.getIdentifierProperties(this.transformMapFile, this.mapFileUtil, itemFamilyObject);
|
|
853
|
-
const informationKeys = await type_conversion_utils_1.TypeConversionUtils.getInformationalProperties(this.transformMapFile, this.mapFileUtil, itemFamilyObject);
|
|
854
|
-
for (const key of identifierKeys.concat(informationKeys)) {
|
|
855
|
-
if (itemObj[key]) {
|
|
856
|
-
prodObj[key] = itemObj[key];
|
|
857
|
-
}
|
|
858
|
-
}
|
|
859
|
-
if (!prodObj?.vibeIQIdentifier) {
|
|
860
|
-
prodObj.vibeIQIdentifier = itemFamilyObject?.identifier || itemFamilyObject?.itemNumber;
|
|
861
|
-
}
|
|
862
|
-
prodObj = await map_utils_1.MapUtil.applyTransformMap(this.transformMapFile, this.mapFileUtil, prodObj, 'LCSProduct', 'vibe2flex');
|
|
863
|
-
return prodObj;
|
|
864
|
-
}
|
|
865
|
-
async getSKUFederation(entityReference, itemToFederatedIdMapping, itemObject) {
|
|
866
|
-
const itemObj = await this.dc.getFlexPLMObjectData(itemObject, [], true);
|
|
867
|
-
let skuObj = {
|
|
868
|
-
entityReference: 'item:' + entityReference,
|
|
869
|
-
objectClass: 'LCSSKU',
|
|
870
|
-
};
|
|
871
|
-
const identifierKeys = await type_conversion_utils_1.TypeConversionUtils.getIdentifierProperties(this.transformMapFile, this.mapFileUtil, itemObject);
|
|
872
|
-
const informationKeys = await type_conversion_utils_1.TypeConversionUtils.getInformationalProperties(this.transformMapFile, this.mapFileUtil, itemObject);
|
|
873
|
-
for (const key of identifierKeys.concat(informationKeys)) {
|
|
874
|
-
if (itemObj[key]) {
|
|
875
|
-
skuObj[key] = itemObj[key];
|
|
876
|
-
}
|
|
877
|
-
}
|
|
878
|
-
if (!skuObj?.vibeIQIdentifier) {
|
|
879
|
-
skuObj.vibeIQIdentifier = itemObject?.identifier || itemObject?.itemNumber;
|
|
880
|
-
}
|
|
881
|
-
skuObj = await map_utils_1.MapUtil.applyTransformMap(this.transformMapFile, this.mapFileUtil, skuObj, 'LCSSKU', 'vibe2flex');
|
|
882
|
-
return skuObj;
|
|
883
|
-
}
|
|
884
|
-
async getCarriedFromSeason(projectItem) {
|
|
885
|
-
const addedFromAssortment = projectItem.addedFromAssortment;
|
|
886
|
-
if (this.cache.carriedFromSeason[addedFromAssortment]) {
|
|
887
|
-
return this.cache.carriedFromSeason[addedFromAssortment];
|
|
888
|
-
}
|
|
889
|
-
let seasonFederation = undefined;
|
|
890
|
-
const assortmentEntity = await this.getAssormentEntityFromId(addedFromAssortment);
|
|
891
|
-
if (assortmentEntity) {
|
|
892
|
-
seasonFederation = await this.getSeasonFederationFromAssortment(assortmentEntity);
|
|
893
|
-
}
|
|
894
|
-
this.cache.carriedFromSeason[addedFromAssortment] = seasonFederation;
|
|
895
|
-
return seasonFederation;
|
|
896
|
-
}
|
|
897
|
-
async getAssormentEntityFromId(assortmentId) {
|
|
898
|
-
let assortment;
|
|
899
|
-
try {
|
|
900
|
-
assortment = await new sdk_1.Entities().get({
|
|
901
|
-
entityName: 'assortment',
|
|
902
|
-
id: assortmentId
|
|
903
|
-
});
|
|
904
|
-
}
|
|
905
|
-
catch (e) {
|
|
906
|
-
console.warn(`No Assortment found for id: ${assortmentId}`);
|
|
907
|
-
}
|
|
908
|
-
return assortment;
|
|
909
|
-
}
|
|
910
|
-
async getSeasonFederationFromAssortment(assortment) {
|
|
911
|
-
assortment['flex2vibeMapKeyRoot'] = 'LCSSeason';
|
|
912
|
-
const flexPLMTypePath = await type_conversion_utils_1.TypeConversionUtils.getObjectTypePath(this.transformMapFile, this.mapFileUtil, assortment);
|
|
913
|
-
let seasonObj = {
|
|
914
|
-
entityReference: 'assortment:' + assortment.id,
|
|
915
|
-
objectClass: 'LCSSeason',
|
|
916
|
-
flexPLMTypePath
|
|
917
|
-
};
|
|
918
|
-
try {
|
|
919
|
-
const assortmentObj = await this.dc.getFlexPLMObjectData(assortment, [], true);
|
|
920
|
-
const identifierKeys = await type_conversion_utils_1.TypeConversionUtils.getIdentifierProperties(this.transformMapFile, this.mapFileUtil, assortment);
|
|
921
|
-
const informationKeys = await type_conversion_utils_1.TypeConversionUtils.getInformationalProperties(this.transformMapFile, this.mapFileUtil, assortment);
|
|
922
|
-
for (const key of identifierKeys.concat(informationKeys)) {
|
|
923
|
-
if (assortmentObj[key]) {
|
|
924
|
-
seasonObj[key] = assortmentObj[key];
|
|
925
|
-
}
|
|
926
|
-
}
|
|
927
|
-
const objectKeys = Object.keys(seasonObj);
|
|
928
|
-
const hasAllIdentifiers = identifierKeys.every(key => objectKeys.includes(key));
|
|
929
|
-
if (!hasAllIdentifiers) {
|
|
930
|
-
return undefined;
|
|
931
|
-
}
|
|
932
|
-
const mapKey = await type_conversion_utils_1.TypeConversionUtils.getMapKey(this.transformMapFile, this.mapFileUtil, assortment, type_conversion_utils_1.TypeConversionUtils.VIBE2FLEX_DIRECTION);
|
|
933
|
-
seasonObj = await map_utils_1.MapUtil.applyTransformMap(this.transformMapFile, this.mapFileUtil, seasonObj, mapKey, type_conversion_utils_1.TypeConversionUtils.VIBE2FLEX_DIRECTION);
|
|
934
|
-
}
|
|
935
|
-
finally {
|
|
936
|
-
delete assortment['flex2vibeMapKeyRoot'];
|
|
937
|
-
}
|
|
938
|
-
return seasonObj;
|
|
939
|
-
}
|
|
940
|
-
}
|
|
941
|
-
exports.BaseProcessPublishAssortment = BaseProcessPublishAssortment;
|
|
942
|
-
BaseProcessPublishAssortment.ASSORTMENT_NOT_PUBLISHABLE = 'Assortment isn\'t marked for publishing to FlexPLM';
|
|
943
|
-
BaseProcessPublishAssortment.ASSORTMENT_NO_FED_INFO = 'Assortment doesn\'t have all "identifier" properties, so there is no processing. Identifier properties: ';
|
|
944
|
-
BaseProcessPublishAssortment.NOT_ABLE_TO_PROCESS_DELETE_CHANGES = 'Error: Not able to process delete changes';
|