@contrail/flexplm 1.1.11 → 1.1.13

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.
@@ -8,6 +8,7 @@ const publish_change_data_1 = require("../interfaces/publish-change-data");
8
8
  const map_utils_1 = require("../util/map-utils");
9
9
  const fsPromise = require("fs/promises");
10
10
  const path = require("path");
11
+ const app_framework_1 = require("@contrail/app-framework");
11
12
  const type_conversion_utils_1 = require("../util/type-conversion-utils");
12
13
  class BaseProcessPublishAssortment {
13
14
  constructor(_config, _dc, _mapFileUtil) {
@@ -38,16 +39,19 @@ class BaseProcessPublishAssortment {
38
39
  return output;
39
40
  }
40
41
  const assortmentPublishChangeId = event.assortmentPublishChangeId;
41
- const sinceDate = await this.getSinceDate(assortmentId, assortmentPublishChangeId);
42
+ const apcHistory = await this.getApcHistory(assortmentId);
43
+ const sinceDate = await this.getSinceDate(assortmentId, assortmentPublishChangeId, apcHistory);
42
44
  const assortmentPublishChange = await this.downloadAssortmentPublishChange(assortmentId, assortmentPublishChangeId);
43
45
  const changeDetail = await this.downloadHydratedChangeDetail(assortmentPublishChange);
44
- const fullChange = await this.downloadFullChange(assortmentPublishChange);
45
- const releasedForDevelopmentItemIds = this.getReleasedForDevelopmentItemAndFamilyIds(fullChange);
46
+ const assortmentBaseline = await this.downloadAssortmentBaseline(assortmentPublishChange);
47
+ const deleteChanges = await this.getDeleteChanges(assortmentPublishChange, apcHistory, assortmentBaseline, sinceDate);
48
+ const releasedForDevelopmentItemIds = this.getReleasedForDevelopmentItemAndFamilyIds(assortmentBaseline, deleteChanges);
46
49
  const itemToFederatedIdMapping = await this.getItemFederatedIds();
47
- const pcd = new publish_change_data_1.PublishChangeData(assortmentId, seasonFed, assortmentPublishChangeId, sinceDate);
50
+ const publisher = this.getPublisher(assortmentPublishChange);
51
+ const pcd = new publish_change_data_1.PublishChangeData(assortmentId, seasonFed, assortmentPublishChangeId, sinceDate, publisher);
48
52
  pcd.itemToFederatedIdMapping = itemToFederatedIdMapping;
49
53
  pcd.releasedForDevelopmentItemIds = releasedForDevelopmentItemIds;
50
- const output = await this.processPublish(pcd, changeDetail, fullChange);
54
+ const output = await this.processPublish(pcd, changeDetail, assortmentBaseline, deleteChanges);
51
55
  console.info('process-end');
52
56
  return output;
53
57
  }
@@ -63,6 +67,7 @@ class BaseProcessPublishAssortment {
63
67
  entityName: 'assortment',
64
68
  id: assortmentId
65
69
  });
70
+ console.info('assortment-name: ' + assortment['name']);
66
71
  }
67
72
  catch (e) {
68
73
  console.warn(`No Assortment found for id: ${assortmentId}`);
@@ -90,35 +95,41 @@ class BaseProcessPublishAssortment {
90
95
  seasonObj = await map_utils_1.MapUtil.applyTransformMap(this.transformMapFile, this.mapFileUtil, seasonObj, 'LCSSeason', 'vibe2flex');
91
96
  return seasonObj;
92
97
  }
93
- async getSinceDate(assortmentId, assortmentPublishChangeId) {
94
- const sinceDateString = String(this.config['sinceDate'] || '');
95
- if (sinceDateString.includes('-')) {
96
- const [year, month, day] = sinceDateString.split('-').map(Number);
97
- const d = new Date(year, month - 1, day, 0, 0);
98
- const minutes = -d.getTimezoneOffset();
99
- d.setUTCMinutes(minutes);
100
- return d;
101
- }
102
- if (sinceDateString.includes(':')) {
103
- const [type, countStr] = sinceDateString.split(':');
104
- const count = parseInt(countStr);
105
- if (type.trim().toLowerCase() === 'numberofdays') {
106
- const currentDate = new Date();
107
- const d = new Date(currentDate.getUTCFullYear(), currentDate.getUTCMonth(), currentDate.getUTCDate() - count, 0, 0);
108
- d.setUTCMinutes(-d.getTimezoneOffset());
109
- return d;
110
- }
111
- if (type.trim().toLowerCase() === 'numberofpublishes') {
112
- const apcHistory = await this.getApcHistory(assortmentId);
113
- return this.getSinceDateFromAPCs(apcHistory, assortmentPublishChangeId, count);
114
- }
115
- }
116
- const apcHistory = await this.getApcHistory(assortmentId);
117
- const derivedSinceDate = this.getSinceDateFromAPCs(apcHistory, assortmentPublishChangeId);
118
- if (!derivedSinceDate)
119
- throw new Error('Couldn\'t set sinceDate');
120
- console.info('getSinceDate:', derivedSinceDate);
121
- return derivedSinceDate;
98
+ async getSinceDate(assortmentId, assortmentPublishChangeId, apcHistory) {
99
+ let sinceDate = null;
100
+ let pastPublishCount = 1;
101
+ if (this.config['sinceDate']) {
102
+ const sinceDateString = '' + this.config['sinceDate'];
103
+ if (sinceDateString && sinceDateString.indexOf('-') > 0) {
104
+ const sinceDateParts = sinceDateString.split('-');
105
+ if (sinceDateParts.length == 3) {
106
+ const year = parseInt(sinceDateParts[0]);
107
+ const month = parseInt(sinceDateParts[1]) - 1;
108
+ const day = parseInt(sinceDateParts[2]);
109
+ const minutes = 0 - new Date().getTimezoneOffset();
110
+ sinceDate = this.getSinceDateFromAPCSpecificDate(apcHistory, assortmentPublishChangeId, new Date(year, month, day, 0, minutes, 0));
111
+ }
112
+ }
113
+ else if (sinceDateString && sinceDateString.indexOf(':') > 0) {
114
+ const sinceDateParts = sinceDateString.split(':');
115
+ const type = sinceDateParts[0];
116
+ const count = parseInt(sinceDateParts[1]);
117
+ if ('numberofdays' == type.toLocaleLowerCase()) {
118
+ sinceDate = this.getSinceDateDaysPrevious(apcHistory, assortmentPublishChangeId, count);
119
+ }
120
+ else if ('numberofpublishes' == type.toLocaleLowerCase()) {
121
+ pastPublishCount = count;
122
+ }
123
+ }
124
+ }
125
+ if (sinceDate == null) {
126
+ sinceDate = this.getSinceDateFromAPCs(apcHistory, assortmentPublishChangeId, pastPublishCount);
127
+ }
128
+ if (sinceDate == null) {
129
+ throw new Error('Couldnt set sinceDate');
130
+ }
131
+ console.info('getSinceDate: ' + sinceDate);
132
+ return sinceDate;
122
133
  }
123
134
  async getApcHistory(assortmentId) {
124
135
  const resource = `/assortments/${assortmentId}/history/`;
@@ -134,6 +145,54 @@ class BaseProcessPublishAssortment {
134
145
  const updatedOn = entity?.updatedOn;
135
146
  return (updatedOn && new Date(updatedOn) > sinceDate);
136
147
  }
148
+ getSinceDateFromAPCSpecificDate(apcHistory, assortmentPublishChangeId, specificDate) {
149
+ const apc = apcHistory.find(apc => apc['id'] === assortmentPublishChangeId);
150
+ const apcDate = new Date(apc['createdOn']);
151
+ const dateArray = [];
152
+ for (const tempapc of apcHistory) {
153
+ if (assortmentPublishChangeId !== tempapc['id']) {
154
+ const tempDate = new Date(tempapc['createdOn']);
155
+ if (tempDate < apcDate) {
156
+ dateArray.push(tempDate);
157
+ }
158
+ }
159
+ }
160
+ dateArray.sort((a, b) => { return Date.parse(a) - Date.parse(b); });
161
+ let sinceDate = specificDate;
162
+ const sinceDateMilliseconds = sinceDate.getTime();
163
+ for (const d of dateArray) {
164
+ const milli = Date.parse(d);
165
+ if (milli >= sinceDateMilliseconds) {
166
+ sinceDate = d;
167
+ break;
168
+ }
169
+ }
170
+ return sinceDate;
171
+ }
172
+ getSinceDateDaysPrevious(apcHistory, assortmentPublishChangeId, daysBack) {
173
+ const apc = apcHistory.find(apc => apc['id'] === assortmentPublishChangeId);
174
+ const apcDate = new Date(apc['createdOn']);
175
+ const dateArray = [];
176
+ for (const tempapc of apcHistory) {
177
+ if (assortmentPublishChangeId !== tempapc['id']) {
178
+ const tempDate = new Date(tempapc['createdOn']);
179
+ if (tempDate < apcDate) {
180
+ dateArray.push(tempDate);
181
+ }
182
+ }
183
+ }
184
+ dateArray.sort((a, b) => { return Date.parse(a) - Date.parse(b); });
185
+ let sinceDate = new Date(apcDate.getUTCFullYear(), apcDate.getUTCMonth(), apcDate.getUTCDate() - daysBack, 0, (0 - apcDate.getTimezoneOffset()), 0);
186
+ const sinceDateMilliseconds = sinceDate.getTime();
187
+ for (const d of dateArray) {
188
+ const milli = Date.parse(d);
189
+ if (milli >= sinceDateMilliseconds) {
190
+ sinceDate = d;
191
+ break;
192
+ }
193
+ }
194
+ return sinceDate;
195
+ }
137
196
  getSinceDateFromAPCs(apcHistory, assortmentPublishChangeId, pastPublishCount = 1) {
138
197
  if (apcHistory.length === 1) {
139
198
  return new Date(0);
@@ -143,13 +202,32 @@ class BaseProcessPublishAssortment {
143
202
  return new Date(0);
144
203
  }
145
204
  const apc = apcHistory[apcIndex];
146
- const apcDate = new Date(apc.createdOn);
147
- const sortedPreviousDates = apcHistory
148
- .filter(tempapc => tempapc.id !== assortmentPublishChangeId && new Date(tempapc.createdOn) < apcDate)
149
- .map(tempapc => new Date(tempapc.createdOn))
150
- .sort((a, b) => a.getTime() - b.getTime());
151
- const arrIndex = Math.max(sortedPreviousDates.length - pastPublishCount, 0);
152
- return sortedPreviousDates[arrIndex] || new Date(0);
205
+ const apcDate = new Date(apc['createdOn']);
206
+ let sinceDate = new Date(0);
207
+ const dateArray = [];
208
+ for (const tempapc of apcHistory) {
209
+ if (assortmentPublishChangeId !== tempapc['id']) {
210
+ const tempDate = new Date(tempapc['createdOn']);
211
+ if (tempDate < apcDate) {
212
+ dateArray.push(tempDate);
213
+ }
214
+ }
215
+ }
216
+ dateArray.sort((a, b) => { return Date.parse(a) - Date.parse(b); });
217
+ const arrIndex = (dateArray.length - pastPublishCount > 0) ? dateArray.length - pastPublishCount : 0;
218
+ sinceDate = dateArray[arrIndex];
219
+ return sinceDate;
220
+ }
221
+ getPublisher(assortmentPublishChange) {
222
+ const createdBy = assortmentPublishChange?.createdBy;
223
+ const publisher = {};
224
+ const includeKeys = ['email', 'firstName', 'isSsoUser', 'lastName'];
225
+ for (const [key, value] of Object.entries(createdBy)) {
226
+ if (includeKeys.includes(key)) {
227
+ publisher[key] = value;
228
+ }
229
+ }
230
+ return publisher;
153
231
  }
154
232
  async downloadAssortmentPublishChange(assortmentId, assortmentPublishChangeId) {
155
233
  const resourceString = '/assortments/' + assortmentId + '/history/' + assortmentPublishChangeId;
@@ -174,8 +252,8 @@ class BaseProcessPublishAssortment {
174
252
  }
175
253
  return undefined;
176
254
  }
177
- async downloadFullChange(assortmentPublishChange) {
178
- console.info('downloadFullChange-start');
255
+ async downloadAssortmentBaseline(assortmentPublishChange) {
256
+ console.info('downloadAssortmentBaseline-start');
179
257
  try {
180
258
  const link = assortmentPublishChange?.assortmentBaselineDownloadLink;
181
259
  const response = await fetch(link);
@@ -187,13 +265,114 @@ class BaseProcessPublishAssortment {
187
265
  }
188
266
  return undefined;
189
267
  }
190
- getAllItemIds(changeDetail, fullChange) {
191
- console.info('getAllItemIds-start');
192
- const extractItemIds = (item) => [item.id, item.itemFamilyId];
193
- const assortmentItemIds = (fullChange.assortmentItems || []).flatMap(item => extractItemIds(item.item));
194
- const deleteItemIds = (changeDetail.deletes || []).flatMap(hDelete => extractItemIds(hDelete.item));
195
- const uniqueItemIds = new Set([...assortmentItemIds, ...deleteItemIds]);
196
- return Array.from(uniqueItemIds);
268
+ async getDeleteChanges(assortmentPublishChange, apcHistory, assortmentBaseline, sinceDate) {
269
+ console.info('getDeleteChanges(): ' + assortmentPublishChange['id']);
270
+ console.info(sinceDate);
271
+ const currentAPCIndex = apcHistory.findIndex(pc => pc['id'] === assortmentPublishChange['id']);
272
+ console.info(' currentAPCIndex: ' + currentAPCIndex);
273
+ if (currentAPCIndex == 0) {
274
+ return [];
275
+ }
276
+ const previousApcIndex = (currentAPCIndex > 0) ? currentAPCIndex - 1 : 0;
277
+ const apcCreatedOn = apcHistory[previousApcIndex]['createdOn'];
278
+ console.info('apcCreatedOn: ' + apcCreatedOn);
279
+ const apcDeletes = await this.downloadDeleteChanges(assortmentPublishChange);
280
+ let previousApcDate = Date.parse(apcCreatedOn);
281
+ const sinceDateMilliseconds = sinceDate.getTime();
282
+ if (app_framework_1.Logger.isInfoOn()) {
283
+ console.info('apcCreatedOn: ' + apcCreatedOn);
284
+ console.info('sinceDate: ' + sinceDate);
285
+ console.info('sinceDateMilliseconds: ' + sinceDateMilliseconds);
286
+ console.info('apcDateMilliseconds: ' + previousApcDate);
287
+ }
288
+ if (sinceDateMilliseconds !== previousApcDate) {
289
+ console.info('sinceDateMilliseconds !== apcDateMilliseconds');
290
+ const currentAssortmentItemIds = this.getBaselineItemIds(assortmentBaseline);
291
+ const deleteIds = (apcDeletes.length === 0)
292
+ ? []
293
+ : apcDeletes.map(item => item['itemId']);
294
+ for (let i = currentAPCIndex - 1; i > 0; i--) {
295
+ const workingAPC = apcHistory[i];
296
+ previousApcDate = Date.parse(workingAPC['createdOn']);
297
+ if (sinceDateMilliseconds === previousApcDate) {
298
+ break;
299
+ }
300
+ if (workingAPC['deletes'] > 0) {
301
+ const previousApc = (i > 0)
302
+ ? apcHistory[i - 1]
303
+ : undefined;
304
+ const deleteChanges = await this.buildDeleteChanges(workingAPC, previousApc);
305
+ console.info('checking deleteChanges');
306
+ for (const dItem of deleteChanges) {
307
+ const dItemId = dItem['itemId'];
308
+ console.info(dItemId);
309
+ if (!currentAssortmentItemIds.includes(dItemId) && !deleteIds.includes(dItemId)) {
310
+ console.info('adding');
311
+ deleteIds.push(dItemId);
312
+ apcDeletes.push(dItem);
313
+ }
314
+ }
315
+ }
316
+ }
317
+ console.info('getDeleteChanges()-currentAssortmentItemIds: ' + currentAssortmentItemIds);
318
+ console.info('getDeleteChanges()-deleteIds: ' + deleteIds);
319
+ }
320
+ return apcDeletes;
321
+ }
322
+ getBaselineItemIds(assortmentBaseline) {
323
+ const itemIds = [];
324
+ const assortmentItemsArray = assortmentBaseline['assortmentItems'];
325
+ for (const aItem of assortmentItemsArray) {
326
+ itemIds.push(aItem['itemId']);
327
+ }
328
+ return itemIds;
329
+ }
330
+ async downloadDeleteChanges(apc) {
331
+ console.info('deleteDataDownloadLink-start');
332
+ try {
333
+ const link = apc['deleteDataDownloadLink'];
334
+ const response = await fetch(link);
335
+ const data = await response.json();
336
+ return data;
337
+ }
338
+ catch (e) {
339
+ console.log('Error deleteDataDownloadLink: ' + e.message);
340
+ }
341
+ return undefined;
342
+ }
343
+ async buildDeleteChanges(apc, previousApc) {
344
+ console.info('buildDeleteChanges()');
345
+ if (apc['deleteDataDownloadLink']) {
346
+ const deleteChanges = await this.downloadDeleteChanges(apc);
347
+ if (deleteChanges) {
348
+ return deleteChanges;
349
+ }
350
+ }
351
+ console.info('pulling down full APC');
352
+ apc = await this.downloadAssortmentPublishChange(apc['assortmentId'], apc['id']);
353
+ if (apc['deleteDataDownloadLink']) {
354
+ const deleteChanges = await this.downloadDeleteChanges(apc);
355
+ if (deleteChanges) {
356
+ return deleteChanges;
357
+ }
358
+ }
359
+ if (!previousApc) {
360
+ throw new Error(BaseProcessPublishAssortment.NOT_ABLE_TO_PROCESS_DELETE_CHANGES);
361
+ }
362
+ let previousBaseline;
363
+ console.info('check previousApc');
364
+ if (previousApc['assortmentBaselineDownloadLink']) {
365
+ previousBaseline = await this.downloadAssortmentBaseline(previousApc);
366
+ }
367
+ else {
368
+ console.info('previousApc pulling down full APC');
369
+ previousApc = await this.downloadAssortmentPublishChange(previousApc['assortmentId'], previousApc['id']);
370
+ previousBaseline = await this.downloadAssortmentBaseline(previousApc);
371
+ }
372
+ const deleteIds = apc['detail']['deletes'].map(dItem => dItem['id']);
373
+ const deleteArray = previousBaseline['assortmentItems'].filter(aItem => deleteIds.includes(aItem['itemId']));
374
+ console.info('deleteArray.length: ' + deleteArray.length);
375
+ return deleteArray;
197
376
  }
198
377
  async getItemFederatedIds() {
199
378
  const itemFederatedIds = new Map();
@@ -208,37 +387,73 @@ class BaseProcessPublishAssortment {
208
387
  }
209
388
  return assortmentItemsMap;
210
389
  }
211
- getReleasedForDevelopmentItemAndFamilyIds(fullChange) {
390
+ getDeleteChangesAssortmentMap(deleteChanges) {
391
+ const deleteItems = new Map();
392
+ for (const dItem of deleteChanges) {
393
+ deleteItems.set(dItem['itemId'], dItem);
394
+ }
395
+ return deleteItems;
396
+ }
397
+ getReleasedForDevelopmentItemAndFamilyIds(fullChange, deleteChanges) {
212
398
  console.info('getReleasedForDevelopmentItemAndFamilyIds');
213
399
  const releasedForDevelopmentItemIds = [];
214
400
  const itemFamilySet = new Set();
215
- const assortmentItemsArray = fullChange?.assortmentItems || [];
401
+ const assortmentItemsArray = fullChange['assortmentItems'];
216
402
  for (const aItem of assortmentItemsArray) {
217
- const item = aItem?.item;
218
- const lifecycleStage = item?.lifecycleStage;
219
- const itemId = item?.id;
220
- const itemFamilyId = item?.itemFamilyId;
221
- console.debug(`itemId: ${itemId}`);
222
- if (lifecycleStage && !this.config?.itemPreDevelopmentLifecycleStages?.includes(lifecycleStage)) {
403
+ const meetsCriteria = this.meetsCriteria(aItem);
404
+ const item = aItem['item'];
405
+ const itemId = item['id'];
406
+ const itemFamilyId = item['itemFamilyId'];
407
+ console.debug('itemId: ' + item['id']);
408
+ if (meetsCriteria) {
223
409
  console.debug('adding item to releasedForDevelopmentItemIds');
224
- console.debug(`itemFamilyId: ${itemFamilyId}`);
410
+ console.debug('itemFamilyId: ' + item['itemFamilyId']);
225
411
  releasedForDevelopmentItemIds.push(itemId);
226
412
  if (!itemFamilySet.has(itemFamilyId) && itemId !== itemFamilyId) {
227
- const familyItem = item?.itemFamily;
228
- const familyLifecycleStage = familyItem?.lifecycleStage;
229
- if (familyLifecycleStage && !this.config?.itemPreDevelopmentLifecycleStages?.includes(familyLifecycleStage)) {
413
+ const familyItem = item['itemFamily'];
414
+ const familyItemMeetsCriteria = this.meetsCriteria({ item: familyItem });
415
+ if (familyItemMeetsCriteria) {
230
416
  releasedForDevelopmentItemIds.push(itemFamilyId);
231
417
  }
232
418
  itemFamilySet.add(itemFamilyId);
233
419
  }
234
420
  }
235
421
  }
422
+ for (const dItem of deleteChanges) {
423
+ const meetsCriteria = this.meetsCriteria(dItem);
424
+ const item = dItem['item'];
425
+ const itemId = item['id'];
426
+ const itemFamilyId = item['itemFamilyId'];
427
+ console.debug('itemId: ' + item['id']);
428
+ if (meetsCriteria) {
429
+ releasedForDevelopmentItemIds.push(itemId);
430
+ if (!itemFamilySet.has(itemFamilyId) && itemId !== itemFamilyId) {
431
+ const familyItem = item['itemFamily'];
432
+ if (familyItem) {
433
+ const familyItemMeetsCriteria = this.meetsCriteria({ item: familyItem });
434
+ if (familyItemMeetsCriteria) {
435
+ releasedForDevelopmentItemIds.push(itemFamilyId);
436
+ }
437
+ itemFamilySet.add(itemFamilyId);
438
+ }
439
+ else {
440
+ itemFamilySet.add(itemFamilyId);
441
+ }
442
+ }
443
+ }
444
+ }
236
445
  return releasedForDevelopmentItemIds;
237
446
  }
238
- async processPublish(pcd, changeDetail, fullChange) {
447
+ meetsCriteria(aItem) {
448
+ const item = aItem['item'];
449
+ const lifecycleStage = item['lifecycleStage'];
450
+ return lifecycleStage && !this.config.itemPreDevelopmentLifecycleStages.includes(lifecycleStage);
451
+ }
452
+ async processPublish(pcd, changeDetail, fullChange, deleteChanges) {
239
453
  console.info('processPublish-start');
240
454
  const assortmentItemFullChangeMap = this.getFullChangeAssortmentMap(fullChange);
241
- pcd.itemFamilyChanges = this.getItemFamilyChanges(pcd, changeDetail, assortmentItemFullChangeMap);
455
+ const assortmentItemDeleteMap = this.getDeleteChangesAssortmentMap(deleteChanges);
456
+ pcd.itemFamilyChanges = this.getItemFamilyChanges(pcd, changeDetail, assortmentItemFullChangeMap, assortmentItemDeleteMap);
242
457
  const events = await this.getEventsForPublishChangeData(pcd);
243
458
  if (events.length === 0) {
244
459
  const message = 'No Events to Send; returning';
@@ -339,7 +554,7 @@ class BaseProcessPublishAssortment {
339
554
  + '-' + d.getUTCSeconds()
340
555
  + '-' + d.getUTCMilliseconds();
341
556
  }
342
- getItemFamilyChanges(publishChangeData, changeDetail, assortmentItemFullChangeMap) {
557
+ getItemFamilyChanges(pcd, changeDetail, assortmentItemFullChangeMap, assortmentItemDeleteMap) {
343
558
  console.info('getItemFamilyChanges-start');
344
559
  const itemFamilyChanges = new Map();
345
560
  const { adds, deletes, updates, familyItemsRemoved } = changeDetail;
@@ -349,17 +564,17 @@ class BaseProcessPublishAssortment {
349
564
  const familyItemsRemovedIds = familyItemsRemoved.map(item => item.itemId);
350
565
  for (const [itemId, aItem] of assortmentItemFullChangeMap) {
351
566
  const { item: { itemFamilyId }, projectItem } = aItem;
352
- if (!publishChangeData.releasedForDevelopmentItemIds.includes(itemFamilyId) || !publishChangeData.releasedForDevelopmentItemIds.includes(itemId)) {
567
+ if (!pcd.releasedForDevelopmentItemIds.includes(itemFamilyId) || !pcd.releasedForDevelopmentItemIds.includes(itemId)) {
353
568
  continue;
354
569
  }
355
- const ifc = itemFamilyChanges.get(itemFamilyId) || new item_family_changes_1.ItemFamilyChanges(itemFamilyId, publishChangeData.sinceDate);
570
+ const ifc = itemFamilyChanges.get(itemFamilyId) || new item_family_changes_1.ItemFamilyChanges(itemFamilyId, pcd.sinceDate);
356
571
  if (!itemFamilyChanges.has(itemFamilyId)) {
357
572
  ifc.itemFamilyObject = itemId === itemFamilyId ? aItem?.item : aItem?.item?.itemFamily;
358
573
  itemFamilyChanges.set(itemFamilyId, ifc);
359
574
  }
360
575
  ifc.assortmentItemFullChangeMap.set(itemId, aItem);
361
- if (publishChangeData.itemToFederatedIdMapping.has(itemId)) {
362
- ifc.itemToFederatedIdMapping.set(itemId, publishChangeData.itemToFederatedIdMapping.get(itemId));
576
+ if (pcd.itemToFederatedIdMapping.has(itemId)) {
577
+ ifc.itemToFederatedIdMapping.set(itemId, pcd.itemToFederatedIdMapping.get(itemId));
363
578
  }
364
579
  if (itemId === itemFamilyId) {
365
580
  if (addIds.includes(itemId))
@@ -372,7 +587,7 @@ class BaseProcessPublishAssortment {
372
587
  ifc.familyItemRemoved = true;
373
588
  if (projectItem) {
374
589
  const updatedOnDate = new Date(projectItem.updatedOn);
375
- if (updatedOnDate > publishChangeData.sinceDate) {
590
+ if (updatedOnDate > pcd.sinceDate) {
376
591
  ifc.familyUpdate = true;
377
592
  }
378
593
  }
@@ -387,7 +602,7 @@ class BaseProcessPublishAssortment {
387
602
  ifc.colorDeletes.push(itemId);
388
603
  else if (updateIds.includes(itemId))
389
604
  ifc.colorUpdates.push(itemId);
390
- else if (projectItem && new Date(projectItem.updatedOn) > publishChangeData.sinceDate)
605
+ else if (projectItem && new Date(projectItem.updatedOn) > pcd.sinceDate)
391
606
  ifc.colorUpdates.push(itemId);
392
607
  else
393
608
  ifc.colorUnchanged.push(itemId);
@@ -396,24 +611,48 @@ class BaseProcessPublishAssortment {
396
611
  }
397
612
  }
398
613
  }
399
- for (const delEntity of deletes) {
400
- const itemId = delEntity.id;
401
- if (!publishChangeData.itemToFederatedIdMapping.has(itemId) && !publishChangeData.releasedForDevelopmentItemIds.includes(itemId)) {
614
+ for (const [itemId, delEntity] of assortmentItemDeleteMap) {
615
+ const itemFamilyId = delEntity['item']['itemFamilyId'];
616
+ const item = delEntity['item'];
617
+ if (!pcd.releasedForDevelopmentItemIds.includes(itemFamilyId) || !pcd.releasedForDevelopmentItemIds.includes(itemId)) {
402
618
  continue;
403
619
  }
404
- const { item: { itemFamilyId } } = delEntity;
405
- const ifc = itemFamilyChanges.get(itemFamilyId) || new item_family_changes_1.ItemFamilyChanges(itemFamilyId, publishChangeData.sinceDate);
406
- if (!itemFamilyChanges.has(itemFamilyId)) {
407
- ifc.familyDelete = true;
620
+ else {
621
+ if (!item) {
622
+ console.error('Failed to find deleted item entity');
623
+ console.error(' itemFamilyId: ' + itemFamilyId + ' -itemId: ' + itemId);
624
+ continue;
625
+ }
626
+ }
627
+ let ifc = itemFamilyChanges.get(itemFamilyId);
628
+ if (!ifc) {
629
+ ifc = new item_family_changes_1.ItemFamilyChanges(itemFamilyId, pcd.sinceDate);
630
+ if (itemId === itemFamilyId) {
631
+ ifc.familyDelete = true;
632
+ ifc.itemFamilyObject = item;
633
+ }
634
+ else {
635
+ ifc.itemFamilyObject = item?.itemFamily;
636
+ }
408
637
  itemFamilyChanges.set(itemFamilyId, ifc);
409
638
  }
410
- if (itemId !== itemFamilyId) {
639
+ if (pcd.itemToFederatedIdMapping.has(itemId)) {
640
+ ifc.itemToFederatedIdMapping.set(itemId, pcd.itemToFederatedIdMapping.get(itemId));
641
+ }
642
+ ifc.assortmentItemDeleteMap.set(itemId, delEntity);
643
+ ifc.assortmentItemFullChangeMap.set(itemId, delEntity);
644
+ if (itemId === itemFamilyId) {
645
+ ifc.familyDelete = true;
646
+ }
647
+ else {
411
648
  ifc.colorDeletes.push(itemId);
412
649
  }
413
650
  }
414
- console.debug(`returning size: ${itemFamilyChanges.size}`);
415
- for (const [key, value] of itemFamilyChanges) {
416
- console.debug(`${key} => ${value}`);
651
+ if (app_framework_1.Logger.isDebugOn()) {
652
+ console.debug('returning size: ' + itemFamilyChanges.size);
653
+ for (const [key, value] of itemFamilyChanges) {
654
+ console.debug(key + ' => ' + value);
655
+ }
417
656
  }
418
657
  return itemFamilyChanges;
419
658
  }
@@ -433,8 +672,8 @@ class BaseProcessPublishAssortment {
433
672
  const events = [];
434
673
  const LCSSeason = Object.assign({}, seasonFed);
435
674
  const projectItem = this.getProjectItem(itemFamilyChanges, itemFamilyChanges.itemFamilyId);
436
- const familyAssortmentItem = itemFamilyChanges.familyAdd || itemFamilyChanges.familyUpdate
437
- || itemFamilyChanges.colorAdds.length > 0 || itemFamilyChanges.colorUpdates.length > 0
675
+ const familyAssortmentItem = itemFamilyChanges.familyAdd || itemFamilyChanges.familyUpdate || itemFamilyChanges.familyDelete
676
+ || itemFamilyChanges.colorAdds.length > 0 || itemFamilyChanges.colorUpdates.length > 0 || itemFamilyChanges.colorDeletes.length > 0
438
677
  || (projectItem && this.updatedSinceDate(projectItem, itemFamilyChanges.sinceDate));
439
678
  if (familyAssortmentItem) {
440
679
  const entityReference = itemFamilyChanges.itemFamilyId;
@@ -460,10 +699,11 @@ class BaseProcessPublishAssortment {
460
699
  }
461
700
  events.push(psUpsert);
462
701
  }
463
- const colorAddUpdates = [];
464
- colorAddUpdates.push(...itemFamilyChanges.colorAdds);
465
- colorAddUpdates.push(...itemFamilyChanges.colorUpdates);
466
- for (const entityReference of colorAddUpdates) {
702
+ const colorwayChanges = [];
703
+ colorwayChanges.push(...itemFamilyChanges.colorAdds);
704
+ colorwayChanges.push(...itemFamilyChanges.colorUpdates);
705
+ colorwayChanges.push(...itemFamilyChanges.colorDeletes);
706
+ for (const entityReference of colorwayChanges) {
467
707
  let item = {};
468
708
  if (itemFamilyChanges.assortmentItemFullChangeMap.has(entityReference)) {
469
709
  const fullAi = itemFamilyChanges.assortmentItemFullChangeMap.get(entityReference);
@@ -489,42 +729,6 @@ class BaseProcessPublishAssortment {
489
729
  }
490
730
  events.push(csUpsert);
491
731
  }
492
- const data = {};
493
- for (const color of itemFamilyChanges.colorDeletes) {
494
- const entityReference = color;
495
- let item = {};
496
- if (itemFamilyChanges.assortmentItemFullChangeMap.has(entityReference)) {
497
- const fullAi = itemFamilyChanges.assortmentItemFullChangeMap.get(entityReference);
498
- item = fullAi['item'];
499
- }
500
- const LCSSKU = await this.getSKUFederation(entityReference, itemToFederatedIdMapping, item);
501
- const csRemove = {
502
- eventType: 'REMOVE_FROM_SEASON',
503
- objectClass: 'LCSSKUSeasonLink',
504
- entityReference: '',
505
- LCSSeason,
506
- LCSSKU,
507
- data
508
- };
509
- events.push(csRemove);
510
- }
511
- if (itemFamilyChanges.familyDelete) {
512
- const entityReference = itemFamilyChanges.itemFamilyId;
513
- const LCSProduct = {
514
- entityReference: 'item:' + entityReference,
515
- objectClass: 'LCSProduct',
516
- federatedId: itemToFederatedIdMapping.get(entityReference)
517
- };
518
- const psUpsert = {
519
- eventType: 'REMOVE_FROM_SEASON',
520
- objectClass: 'LCSProductSeasonLink',
521
- entityReference: 'item:' + entityReference,
522
- LCSSeason,
523
- LCSProduct,
524
- data
525
- };
526
- events.push(psUpsert);
527
- }
528
732
  return events;
529
733
  }
530
734
  getProjectItem(itemFamilyChanges, id) {
@@ -535,10 +739,8 @@ class BaseProcessPublishAssortment {
535
739
  }
536
740
  if (id === itemFamilyChanges.itemFamilyId && Object.keys(projectItem).length == 0) {
537
741
  for (const asstItem of itemFamilyChanges.assortmentItemFullChangeMap.values()) {
538
- const item = asstItem?.item;
539
- if (item?.roles?.includes('color') && asstItem?.projectItem) {
540
- projectItem = Object.assign({}, asstItem?.projectItem);
541
- projectItem.roles = ['family'];
742
+ if (asstItem?.familyProjectItem) {
743
+ projectItem = asstItem?.familyProjectItem;
542
744
  break;
543
745
  }
544
746
  }
@@ -644,3 +846,4 @@ class BaseProcessPublishAssortment {
644
846
  exports.BaseProcessPublishAssortment = BaseProcessPublishAssortment;
645
847
  BaseProcessPublishAssortment.ASSORTMENT_NOT_PUBLISHABLE = 'Assortment isn\'t marked for publishing to FlexPLM';
646
848
  BaseProcessPublishAssortment.ASSORTMENT_NO_FED_INFO = 'Assortment doesn\'t have all "identifier" properties or a federated id, so there is no processing. Identifier properties: ';
849
+ BaseProcessPublishAssortment.NOT_ABLE_TO_PROCESS_DELETE_CHANGES = 'Error: Not able to process delete changes';