@contrail/flexplm 1.1.41 → 1.1.43
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 +3 -0
- package/lib/entity-processor/base-entity-processor.js +48 -0
- package/lib/publish/base-process-publish-assortment.js +3 -4
- package/lib/publish/base-process-publish-assortment.spec.js +49 -0
- package/package.json +1 -1
- package/src/entity-processor/base-entity-processor.ts +80 -0
- package/src/publish/base-process-publish-assortment.spec.ts +60 -0
- package/src/publish/base-process-publish-assortment.ts +3 -4
|
@@ -31,4 +31,7 @@ export declare abstract class BaseEntityProcessor {
|
|
|
31
31
|
getOutboundEntityUpdates(event: any, flexResponse: any): Promise<any>;
|
|
32
32
|
handleOutgoingDelete(entityType: any, event: any): Promise<void>;
|
|
33
33
|
protected abstract getOutgoingUpsertPayload(entityType: any, event: any): Promise<EntityPayloadType>;
|
|
34
|
+
protected triggerNewEvent(triggerKey: string, event: any): Promise<any>;
|
|
35
|
+
protected sendUpsertToFlexPLM(event: any): Promise<any>;
|
|
36
|
+
protected getEntityCurrentStateUpsertPayload(event: any): Promise<EntityPayloadType>;
|
|
34
37
|
}
|
|
@@ -133,6 +133,8 @@ class BaseEntityProcessor {
|
|
|
133
133
|
return await this.handleOutgoingUpsert(entityType, event);
|
|
134
134
|
case 'delete':
|
|
135
135
|
return await this.handleOutgoingDelete(entityType, event);
|
|
136
|
+
case 'sendUpsertToFlexPLM':
|
|
137
|
+
return await this.sendUpsertToFlexPLM(event);
|
|
136
138
|
default:
|
|
137
139
|
console.log(UNSUPPORTED_TYPE);
|
|
138
140
|
return {
|
|
@@ -171,5 +173,51 @@ class BaseEntityProcessor {
|
|
|
171
173
|
async handleOutgoingDelete(entityType, event) {
|
|
172
174
|
console.warn('delete is not configured', entityType, event.oldData);
|
|
173
175
|
}
|
|
176
|
+
async triggerNewEvent(triggerKey, event) {
|
|
177
|
+
const newEvent = {
|
|
178
|
+
entityName: 'event-workflow-request',
|
|
179
|
+
object: {
|
|
180
|
+
triggerKey,
|
|
181
|
+
event
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
const response = await this.entities.create(newEvent);
|
|
185
|
+
return response;
|
|
186
|
+
}
|
|
187
|
+
async sendUpsertToFlexPLM(event) {
|
|
188
|
+
const payload = await this.getEntityCurrentStateUpsertPayload(event);
|
|
189
|
+
if (!payload) {
|
|
190
|
+
const message = 'No payload to send to FlexPLM';
|
|
191
|
+
console.log(message);
|
|
192
|
+
return {
|
|
193
|
+
status: 500,
|
|
194
|
+
data: { message }
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
;
|
|
198
|
+
const flexResponse = await new flexplm_connect_1.FlexPLMConnect(this.config).sendToFlexPLM(payload);
|
|
199
|
+
const outboundEntityUpdates = await this.getOutboundEntityUpdates(event, flexResponse);
|
|
200
|
+
if (outboundEntityUpdates) {
|
|
201
|
+
flexResponse['outboundEntityUpdates'] = outboundEntityUpdates;
|
|
202
|
+
}
|
|
203
|
+
return flexResponse;
|
|
204
|
+
}
|
|
205
|
+
async getEntityCurrentStateUpsertPayload(event) {
|
|
206
|
+
const id = event.id;
|
|
207
|
+
if (!id) {
|
|
208
|
+
return undefined;
|
|
209
|
+
}
|
|
210
|
+
const entity = await this.entities.get({
|
|
211
|
+
entityName: this.baseType,
|
|
212
|
+
id
|
|
213
|
+
});
|
|
214
|
+
if (!entity) {
|
|
215
|
+
return undefined;
|
|
216
|
+
}
|
|
217
|
+
event.newData = entity;
|
|
218
|
+
event.oldData = entity;
|
|
219
|
+
const payload = await this.getOutgoingUpsertPayload(this.baseType, event);
|
|
220
|
+
return payload;
|
|
221
|
+
}
|
|
174
222
|
}
|
|
175
223
|
exports.BaseEntityProcessor = BaseEntityProcessor;
|
|
@@ -92,7 +92,7 @@ class BaseProcessPublishAssortment {
|
|
|
92
92
|
return 'unknown';
|
|
93
93
|
}
|
|
94
94
|
const createdOnDate = new Date(createdOnString);
|
|
95
|
-
createdOnDate.
|
|
95
|
+
createdOnDate.setMonth(createdOnDate.getMonth() - 1);
|
|
96
96
|
const createdOnStringMinus1 = createdOnDate.toISOString();
|
|
97
97
|
const createdOn = 'ISGREATERTHAN ' + createdOnStringMinus1;
|
|
98
98
|
const snapshots = await new sdk_1.Entities().get({
|
|
@@ -108,11 +108,10 @@ class BaseProcessPublishAssortment {
|
|
|
108
108
|
if (snapshot && snapshot.versionNumber) {
|
|
109
109
|
snapshotVersion = snapshot.versionNumber;
|
|
110
110
|
}
|
|
111
|
-
else if (!snapshot) {
|
|
111
|
+
else if (!snapshot && snapshots.length > 0) {
|
|
112
112
|
const createdOnTime = new Date(createdOnString).getTime();
|
|
113
113
|
const lastSnapshot = snapshots[snapshots.length - 1];
|
|
114
|
-
|
|
115
|
-
if (createdOnTime > lastSnapshotTime) {
|
|
114
|
+
if (lastSnapshot?.createdOn && createdOnTime > new Date(lastSnapshot.createdOn).getTime()) {
|
|
116
115
|
snapshotVersion = 'after: ' + lastSnapshot.versionNumber;
|
|
117
116
|
}
|
|
118
117
|
}
|
|
@@ -364,6 +364,55 @@ describe('getSnapshotVersion', () => {
|
|
|
364
364
|
expect(getOptionsObject['criteria']['entityReference']).toEqual(assortment.createdForReference);
|
|
365
365
|
expect(getOptionsObject['criteria']['createdOn'].indexOf('ISGREATERTHAN')).toEqual(0);
|
|
366
366
|
});
|
|
367
|
+
it('doesnt find snapshot version, no snapshots returned', async () => {
|
|
368
|
+
const assortment = {
|
|
369
|
+
id: 'rm35clTNxvS4wm6y',
|
|
370
|
+
name: 'VibeIQ Fall 2023',
|
|
371
|
+
createdForReference: 'plan:w23wre'
|
|
372
|
+
};
|
|
373
|
+
const assortmentChangeId = 'sJbGx1Fpq1v2MmcI';
|
|
374
|
+
const apc = {
|
|
375
|
+
id: assortmentChangeId,
|
|
376
|
+
versionName: 'Version 1',
|
|
377
|
+
versionComments: 'Some Comments',
|
|
378
|
+
createdOn: '2023-01-15T19:13:58.902Z'
|
|
379
|
+
};
|
|
380
|
+
const snapshots = [];
|
|
381
|
+
entityObject = snapshots;
|
|
382
|
+
const versionHistoryNumber = await ppa.getSnapshotVersion(assortment, apc);
|
|
383
|
+
expect(versionHistoryNumber).toEqual('unknown');
|
|
384
|
+
expect(getOptionsObject['entityName']).toEqual('entity-snapshot');
|
|
385
|
+
expect(getOptionsObject['criteria']['entityReference']).toEqual(assortment.createdForReference);
|
|
386
|
+
expect(getOptionsObject['criteria']['createdOn'].indexOf('ISGREATERTHAN')).toEqual(0);
|
|
387
|
+
});
|
|
388
|
+
it('doesnt find snapshot version, last snapshot no createdOn', async () => {
|
|
389
|
+
const assortment = {
|
|
390
|
+
id: 'rm35clTNxvS4wm6y',
|
|
391
|
+
name: 'VibeIQ Fall 2023',
|
|
392
|
+
createdForReference: 'plan:w23wre'
|
|
393
|
+
};
|
|
394
|
+
const assortmentChangeId = 'sJbGx1Fpq1v2MmcI';
|
|
395
|
+
const apc = {
|
|
396
|
+
id: assortmentChangeId,
|
|
397
|
+
versionName: 'Version 1',
|
|
398
|
+
versionComments: 'Some Comments',
|
|
399
|
+
createdOn: '2023-01-15T19:13:58.902Z'
|
|
400
|
+
};
|
|
401
|
+
const versionNumber = 1234;
|
|
402
|
+
const snapshots = [
|
|
403
|
+
{
|
|
404
|
+
id: 'qewrwer',
|
|
405
|
+
assortmentChangeId: 'bad-id',
|
|
406
|
+
versionNumber
|
|
407
|
+
}
|
|
408
|
+
];
|
|
409
|
+
entityObject = snapshots;
|
|
410
|
+
const versionHistoryNumber = await ppa.getSnapshotVersion(assortment, apc);
|
|
411
|
+
expect(versionHistoryNumber).toEqual('unknown');
|
|
412
|
+
expect(getOptionsObject['entityName']).toEqual('entity-snapshot');
|
|
413
|
+
expect(getOptionsObject['criteria']['entityReference']).toEqual(assortment.createdForReference);
|
|
414
|
+
expect(getOptionsObject['criteria']['createdOn'].indexOf('ISGREATERTHAN')).toEqual(0);
|
|
415
|
+
});
|
|
367
416
|
});
|
|
368
417
|
describe('getSeasonFederation', () => {
|
|
369
418
|
const config = {
|
package/package.json
CHANGED
|
@@ -176,6 +176,8 @@ export abstract class BaseEntityProcessor {
|
|
|
176
176
|
return await this.handleOutgoingUpsert(entityType, event);
|
|
177
177
|
case 'delete':
|
|
178
178
|
return await this.handleOutgoingDelete(entityType, event);
|
|
179
|
+
case 'sendUpsertToFlexPLM':
|
|
180
|
+
return await this.sendUpsertToFlexPLM(event);
|
|
179
181
|
default:
|
|
180
182
|
console.log(UNSUPPORTED_TYPE);
|
|
181
183
|
return {
|
|
@@ -223,4 +225,82 @@ export abstract class BaseEntityProcessor {
|
|
|
223
225
|
|
|
224
226
|
// This method must be implemented by derived classes
|
|
225
227
|
protected abstract getOutgoingUpsertPayload(entityType, event): Promise<EntityPayloadType>;
|
|
228
|
+
|
|
229
|
+
/** Create a new event-workflow-request to rerun sending the entity to FlexPLM
|
|
230
|
+
* The event must contain any information needed to ensure it is put in the correct queue for the entity
|
|
231
|
+
*
|
|
232
|
+
* @param triggerKey Ex: event.entityType + '|sendUpsertToFlexPLM'
|
|
233
|
+
* @param event
|
|
234
|
+
* @returns
|
|
235
|
+
*/
|
|
236
|
+
|
|
237
|
+
protected async triggerNewEvent(triggerKey: string, event: any) {
|
|
238
|
+
const newEvent = {
|
|
239
|
+
entityName: 'event-workflow-request',
|
|
240
|
+
object: {
|
|
241
|
+
triggerKey,
|
|
242
|
+
event
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
const response = await this.entities.create(newEvent);
|
|
246
|
+
|
|
247
|
+
return response;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/** Sends the current state of the entity to FlexPLM.
|
|
251
|
+
* So any changes made in Vibe between the event being generated and the event being processed are sent to FlexPLM.
|
|
252
|
+
*
|
|
253
|
+
* @param event must contain entityType, id; which are used to query for the entity
|
|
254
|
+
* @returns results of sending the entity to FlexPLM
|
|
255
|
+
*/
|
|
256
|
+
protected async sendUpsertToFlexPLM(event) {
|
|
257
|
+
const payload = await this.getEntityCurrentStateUpsertPayload(event);
|
|
258
|
+
if(!payload){
|
|
259
|
+
const message = 'No payload to send to FlexPLM';
|
|
260
|
+
console.log(message);
|
|
261
|
+
return {
|
|
262
|
+
status: 500,
|
|
263
|
+
data: {message}
|
|
264
|
+
};
|
|
265
|
+
};
|
|
266
|
+
const flexResponse: any = await new FlexPLMConnect(this.config).sendToFlexPLM(payload);
|
|
267
|
+
|
|
268
|
+
const outboundEntityUpdates = await this.getOutboundEntityUpdates(event, flexResponse);
|
|
269
|
+
if(outboundEntityUpdates){
|
|
270
|
+
flexResponse['outboundEntityUpdates'] = outboundEntityUpdates;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
return flexResponse;
|
|
274
|
+
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/** Generates the payload to send to FlexPLM, based on the current state of the entity.
|
|
278
|
+
* The current state of the entity are used as the newData and oldData; which is passed
|
|
279
|
+
* to getOutgoingUpsertPayload to generate the payload.
|
|
280
|
+
* @param event information about the item to send to FlexPLM
|
|
281
|
+
* @returns The payload to send to FlexPLM
|
|
282
|
+
*/
|
|
283
|
+
protected async getEntityCurrentStateUpsertPayload(event: any): Promise<EntityPayloadType> {
|
|
284
|
+
|
|
285
|
+
const id = event.id;
|
|
286
|
+
if(!id){
|
|
287
|
+
return undefined;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
const entity = await this.entities.get({
|
|
291
|
+
entityName: this.baseType,
|
|
292
|
+
id
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
if(!entity){
|
|
296
|
+
return undefined;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
event.newData = entity;
|
|
300
|
+
event.oldData = entity;
|
|
301
|
+
|
|
302
|
+
const payload = await this.getOutgoingUpsertPayload(this.baseType, event);
|
|
303
|
+
|
|
304
|
+
return payload;
|
|
305
|
+
}
|
|
226
306
|
}
|
|
@@ -406,6 +406,66 @@ describe('getSnapshotVersion', () =>{
|
|
|
406
406
|
expect(getOptionsObject['criteria']['createdOn'].indexOf('ISGREATERTHAN')).toEqual(0);
|
|
407
407
|
});
|
|
408
408
|
|
|
409
|
+
it('doesnt find snapshot version, no snapshots returned', async () =>{
|
|
410
|
+
const assortment = {
|
|
411
|
+
id: 'rm35clTNxvS4wm6y',
|
|
412
|
+
name: 'VibeIQ Fall 2023',
|
|
413
|
+
createdForReference: 'plan:w23wre'
|
|
414
|
+
};
|
|
415
|
+
const assortmentChangeId = 'sJbGx1Fpq1v2MmcI';
|
|
416
|
+
const apc = {
|
|
417
|
+
id: assortmentChangeId,
|
|
418
|
+
versionName: 'Version 1',
|
|
419
|
+
versionComments: 'Some Comments',
|
|
420
|
+
createdOn: '2023-01-15T19:13:58.902Z'
|
|
421
|
+
};
|
|
422
|
+
|
|
423
|
+
const snapshots = [];
|
|
424
|
+
|
|
425
|
+
entityObject = snapshots;
|
|
426
|
+
|
|
427
|
+
const versionHistoryNumber = await ppa.getSnapshotVersion(assortment, apc);
|
|
428
|
+
|
|
429
|
+
expect(versionHistoryNumber).toEqual('unknown');
|
|
430
|
+
expect(getOptionsObject['entityName']).toEqual('entity-snapshot');
|
|
431
|
+
expect(getOptionsObject['criteria']['entityReference']).toEqual(assortment.createdForReference);
|
|
432
|
+
expect(getOptionsObject['criteria']['createdOn'].indexOf('ISGREATERTHAN')).toEqual(0);
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
it('doesnt find snapshot version, last snapshot no createdOn', async () =>{
|
|
436
|
+
const assortment = {
|
|
437
|
+
id: 'rm35clTNxvS4wm6y',
|
|
438
|
+
name: 'VibeIQ Fall 2023',
|
|
439
|
+
createdForReference: 'plan:w23wre'
|
|
440
|
+
};
|
|
441
|
+
const assortmentChangeId = 'sJbGx1Fpq1v2MmcI';
|
|
442
|
+
const apc = {
|
|
443
|
+
id: assortmentChangeId,
|
|
444
|
+
versionName: 'Version 1',
|
|
445
|
+
versionComments: 'Some Comments',
|
|
446
|
+
createdOn: '2023-01-15T19:13:58.902Z'
|
|
447
|
+
};
|
|
448
|
+
|
|
449
|
+
const versionNumber = 1234;
|
|
450
|
+
const snapshots = [
|
|
451
|
+
{
|
|
452
|
+
id: 'qewrwer',
|
|
453
|
+
assortmentChangeId: 'bad-id',
|
|
454
|
+
// createdOn: '2023-01-14T19:13:58.902Z',
|
|
455
|
+
versionNumber
|
|
456
|
+
}
|
|
457
|
+
];
|
|
458
|
+
|
|
459
|
+
entityObject = snapshots;
|
|
460
|
+
|
|
461
|
+
const versionHistoryNumber = await ppa.getSnapshotVersion(assortment, apc);
|
|
462
|
+
|
|
463
|
+
expect(versionHistoryNumber).toEqual('unknown');
|
|
464
|
+
expect(getOptionsObject['entityName']).toEqual('entity-snapshot');
|
|
465
|
+
expect(getOptionsObject['criteria']['entityReference']).toEqual(assortment.createdForReference);
|
|
466
|
+
expect(getOptionsObject['criteria']['createdOn'].indexOf('ISGREATERTHAN')).toEqual(0);
|
|
467
|
+
});
|
|
468
|
+
|
|
409
469
|
});
|
|
410
470
|
|
|
411
471
|
describe('getSeasonFederation', () =>{
|
|
@@ -126,7 +126,7 @@ export class BaseProcessPublishAssortment {
|
|
|
126
126
|
return 'unknown';
|
|
127
127
|
}
|
|
128
128
|
const createdOnDate = new Date(createdOnString);
|
|
129
|
-
createdOnDate.
|
|
129
|
+
createdOnDate.setMonth(createdOnDate.getMonth() - 1);//subtract 1 month
|
|
130
130
|
const createdOnStringMinus1 = createdOnDate.toISOString();
|
|
131
131
|
const createdOn = 'ISGREATERTHAN ' + createdOnStringMinus1;
|
|
132
132
|
|
|
@@ -143,11 +143,10 @@ export class BaseProcessPublishAssortment {
|
|
|
143
143
|
let snapshotVersion = 'unknown';
|
|
144
144
|
if(snapshot && snapshot.versionNumber){
|
|
145
145
|
snapshotVersion = snapshot.versionNumber;
|
|
146
|
-
} else if(!snapshot){
|
|
146
|
+
} else if(!snapshot && snapshots.length > 0){
|
|
147
147
|
const createdOnTime = new Date(createdOnString).getTime();
|
|
148
148
|
const lastSnapshot = snapshots[snapshots.length - 1];
|
|
149
|
-
|
|
150
|
-
if(createdOnTime > lastSnapshotTime){
|
|
149
|
+
if(lastSnapshot?.createdOn && createdOnTime > new Date(lastSnapshot.createdOn).getTime()){
|
|
151
150
|
snapshotVersion = 'after: ' + lastSnapshot.versionNumber;
|
|
152
151
|
}
|
|
153
152
|
|