@contrail/flexplm 1.3.2-alpha.328325d → 1.3.2-alpha.c32d413
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/CHANGELOG.md +1 -0
- package/lib/entity-processor/base-entity-processor.d.ts +5 -0
- package/lib/entity-processor/base-entity-processor.js +8 -2
- package/lib/entity-processor/base-entity-processor.spec.js +88 -0
- package/lib/util/type-conversion-utils-spec-mockData.js +1 -0
- package/lib/util/type-conversion-utils.d.ts +1 -0
- package/lib/util/type-conversion-utils.js +16 -0
- package/lib/util/type-conversion-utils.spec.js +59 -0
- package/package.json +1 -1
- package/src/entity-processor/base-entity-processor.spec.ts +107 -0
- package/src/entity-processor/base-entity-processor.ts +28 -10
- package/src/util/type-conversion-utils-spec-mockData.ts +1 -0
- package/src/util/type-conversion-utils.spec.ts +63 -0
- package/src/util/type-conversion-utils.ts +30 -0
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,7 @@ Versioning follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [1.3.2] - 2026-04-24
|
|
10
11
|
### Added
|
|
11
12
|
- Added `getEntityUsingIdentityService` method to `BaseEntityProcessor` for looking up entities via the identity service using a pool key and property criteria. Returns the resolved entity from the identity's `entityReference`, `undefined` if not found, or throws if multiple matches exist.
|
|
12
13
|
|
|
@@ -19,6 +19,11 @@ export declare abstract class BaseEntityProcessor {
|
|
|
19
19
|
inbound(event: EntityPayloadType): Promise<any>;
|
|
20
20
|
handleIncomingUpsert(event: EntityPayloadType): Promise<any>;
|
|
21
21
|
getInboundStatusMessage(statusObject: any): string;
|
|
22
|
+
getIdentityEntity(params: {
|
|
23
|
+
poolKey: string;
|
|
24
|
+
propertyName: string;
|
|
25
|
+
propertyValue: string;
|
|
26
|
+
}): Promise<any | undefined>;
|
|
22
27
|
getEntityUsingIdentityService(params: {
|
|
23
28
|
poolKey: string;
|
|
24
29
|
propertyName: string;
|
|
@@ -136,7 +136,7 @@ class BaseEntityProcessor {
|
|
|
136
136
|
+ ', federatedId: ' + statusObject.federatedId
|
|
137
137
|
+ ', orgSlug: ' + this.orgSlug;
|
|
138
138
|
}
|
|
139
|
-
async
|
|
139
|
+
async getIdentityEntity(params) {
|
|
140
140
|
const { poolKey, propertyName, propertyValue } = params;
|
|
141
141
|
if (!poolKey || !propertyName || !propertyValue) {
|
|
142
142
|
throw new Error('poolKey, propertyName, and propertyValue must be defined');
|
|
@@ -155,7 +155,13 @@ class BaseEntityProcessor {
|
|
|
155
155
|
if (Array.isArray(identityEntities) && identityEntities.length > 1) {
|
|
156
156
|
throw new Error('Multiple identity entities found for poolKey: ' + poolKey + ', ' + propertyName + ': ' + propertyValue);
|
|
157
157
|
}
|
|
158
|
-
|
|
158
|
+
return Array.isArray(identityEntities) ? identityEntities[0] : identityEntities;
|
|
159
|
+
}
|
|
160
|
+
async getEntityUsingIdentityService(params) {
|
|
161
|
+
const identityEntity = await this.getIdentityEntity(params);
|
|
162
|
+
if (!identityEntity) {
|
|
163
|
+
return undefined;
|
|
164
|
+
}
|
|
159
165
|
const entityReference = identityEntity.entityReference;
|
|
160
166
|
const [entityName, id] = entityReference.split(':');
|
|
161
167
|
const entity = await this.entities.get({
|
|
@@ -394,6 +394,94 @@ describe('BaseEntityProcessor', () => {
|
|
|
394
394
|
expect(result).toEqual({ status: 200, data: { message: 'No Changes to persist for entity: existing-1' } });
|
|
395
395
|
});
|
|
396
396
|
});
|
|
397
|
+
describe('getIdentityEntity', () => {
|
|
398
|
+
const config = {};
|
|
399
|
+
const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
|
|
400
|
+
const dc = new data_converter_1.DataConverter(config, mapFileUtil);
|
|
401
|
+
let btep;
|
|
402
|
+
let mockEntitiesGet;
|
|
403
|
+
beforeEach(() => {
|
|
404
|
+
btep = new TestBaseEntityProcessor(config, dc, mapFileUtil, 'item');
|
|
405
|
+
mockEntitiesGet = jest.fn();
|
|
406
|
+
btep.entities = { get: mockEntitiesGet };
|
|
407
|
+
});
|
|
408
|
+
it('should throw error when poolKey is missing', async () => {
|
|
409
|
+
await expect(btep.getIdentityEntity({
|
|
410
|
+
poolKey: '',
|
|
411
|
+
propertyName: 'itemNumber',
|
|
412
|
+
propertyValue: '12345'
|
|
413
|
+
})).rejects.toThrow('poolKey, propertyName, and propertyValue must be defined');
|
|
414
|
+
});
|
|
415
|
+
it('should throw error when propertyName is missing', async () => {
|
|
416
|
+
await expect(btep.getIdentityEntity({
|
|
417
|
+
poolKey: 'item',
|
|
418
|
+
propertyName: '',
|
|
419
|
+
propertyValue: '12345'
|
|
420
|
+
})).rejects.toThrow('poolKey, propertyName, and propertyValue must be defined');
|
|
421
|
+
});
|
|
422
|
+
it('should throw error when propertyValue is missing', async () => {
|
|
423
|
+
await expect(btep.getIdentityEntity({
|
|
424
|
+
poolKey: 'item',
|
|
425
|
+
propertyName: 'itemNumber',
|
|
426
|
+
propertyValue: ''
|
|
427
|
+
})).rejects.toThrow('poolKey, propertyName, and propertyValue must be defined');
|
|
428
|
+
});
|
|
429
|
+
it('should return undefined when no identity entities are found (empty array)', async () => {
|
|
430
|
+
mockEntitiesGet.mockResolvedValue([]);
|
|
431
|
+
const result = await btep.getIdentityEntity({
|
|
432
|
+
poolKey: 'item',
|
|
433
|
+
propertyName: 'itemNumber',
|
|
434
|
+
propertyValue: '12345'
|
|
435
|
+
});
|
|
436
|
+
expect(result).toBeUndefined();
|
|
437
|
+
expect(mockEntitiesGet).toHaveBeenCalledWith({
|
|
438
|
+
entityName: 'identity',
|
|
439
|
+
criteria: { poolKey: 'item', propertyName: 'itemNumber', propertyValue: '12345' }
|
|
440
|
+
});
|
|
441
|
+
});
|
|
442
|
+
it('should return undefined when identity entities result is null', async () => {
|
|
443
|
+
mockEntitiesGet.mockResolvedValue(null);
|
|
444
|
+
const result = await btep.getIdentityEntity({
|
|
445
|
+
poolKey: 'item',
|
|
446
|
+
propertyName: 'itemNumber',
|
|
447
|
+
propertyValue: '12345'
|
|
448
|
+
});
|
|
449
|
+
expect(result).toBeUndefined();
|
|
450
|
+
});
|
|
451
|
+
it('should throw error when multiple identity entities are found', async () => {
|
|
452
|
+
mockEntitiesGet.mockResolvedValue([
|
|
453
|
+
{ entityReference: 'item:1' },
|
|
454
|
+
{ entityReference: 'item:2' }
|
|
455
|
+
]);
|
|
456
|
+
await expect(btep.getIdentityEntity({
|
|
457
|
+
poolKey: 'item',
|
|
458
|
+
propertyName: 'itemNumber',
|
|
459
|
+
propertyValue: '12345'
|
|
460
|
+
})).rejects.toThrow('Multiple identity entities found for poolKey: item, itemNumber: 12345');
|
|
461
|
+
});
|
|
462
|
+
it('should return the identity entity when one is found (array)', async () => {
|
|
463
|
+
const identityEntity = { entityReference: 'item:1' };
|
|
464
|
+
mockEntitiesGet.mockResolvedValue([identityEntity]);
|
|
465
|
+
const result = await btep.getIdentityEntity({
|
|
466
|
+
poolKey: 'item',
|
|
467
|
+
propertyName: 'itemNumber',
|
|
468
|
+
propertyValue: '12345'
|
|
469
|
+
});
|
|
470
|
+
expect(result).toEqual(identityEntity);
|
|
471
|
+
expect(mockEntitiesGet).toHaveBeenCalledTimes(1);
|
|
472
|
+
});
|
|
473
|
+
it('should return the identity entity when result is a single object (not array)', async () => {
|
|
474
|
+
const identityEntity = { entityReference: 'item:5' };
|
|
475
|
+
mockEntitiesGet.mockResolvedValue(identityEntity);
|
|
476
|
+
const result = await btep.getIdentityEntity({
|
|
477
|
+
poolKey: 'item:material',
|
|
478
|
+
propertyName: 'materialNumber',
|
|
479
|
+
propertyValue: 'MAT-001'
|
|
480
|
+
});
|
|
481
|
+
expect(result).toEqual(identityEntity);
|
|
482
|
+
expect(mockEntitiesGet).toHaveBeenCalledTimes(1);
|
|
483
|
+
});
|
|
484
|
+
});
|
|
397
485
|
describe('getEntityUsingIdentityService', () => {
|
|
398
486
|
const config = {};
|
|
399
487
|
const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
|
|
@@ -11,6 +11,7 @@ export declare class TypeConversionUtils {
|
|
|
11
11
|
static getMapKey(transformMapFile: any, mapFileUtil: MapFileUtil, entity: any, direction: string): Promise<string>;
|
|
12
12
|
static getEntityType(entity: any): any;
|
|
13
13
|
static getEntityClassFromObject(fileId: any, mapFileUtil: any, object: any): Promise<string>;
|
|
14
|
+
static getUniquenessPoolKeyFromObject(fileId: any, mapFileUtil: any, object: any): Promise<string>;
|
|
14
15
|
static getEntityTypePathFromOjbect(fileId: any, mapFileUtil: any, object: any): Promise<string>;
|
|
15
16
|
static getIdentifierPropertiesFromObject(fileId: any, mapFileUtil: MapFileUtil, object: any): Promise<string[]>;
|
|
16
17
|
static getInformationalPropertiesFromObject(fileId: any, mapFileUtil: MapFileUtil, object: any): Promise<string[]>;
|
|
@@ -118,6 +118,22 @@ class TypeConversionUtils {
|
|
|
118
118
|
}
|
|
119
119
|
return type_defaults_1.TypeDefaults.getDefaultEntityClass(object);
|
|
120
120
|
}
|
|
121
|
+
static async getUniquenessPoolKeyFromObject(fileId, mapFileUtil, object) {
|
|
122
|
+
let uniquenessPool;
|
|
123
|
+
if (fileId) {
|
|
124
|
+
const mapKey = await this.getMapKeyFromObject(fileId, mapFileUtil, object, TypeConversionUtils.FLEX2VIBE_DIRECTION);
|
|
125
|
+
if (mapKey) {
|
|
126
|
+
const mapData = await map_utils_1.MapUtil.getFullMapSection(fileId, mapFileUtil, mapKey);
|
|
127
|
+
if (mapData && mapData['uniquenessPool']) {
|
|
128
|
+
uniquenessPool = mapData['uniquenessPool'];
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (uniquenessPool) {
|
|
133
|
+
return uniquenessPool;
|
|
134
|
+
}
|
|
135
|
+
return type_defaults_1.TypeDefaults.getDefaultEntityClass(object);
|
|
136
|
+
}
|
|
121
137
|
static async getEntityTypePathFromOjbect(fileId, mapFileUtil, object) {
|
|
122
138
|
let typePath = object['vibeIQTypePath'];
|
|
123
139
|
if (typePath) {
|
|
@@ -328,6 +328,65 @@ describe('conversion-utils', () => {
|
|
|
328
328
|
}
|
|
329
329
|
});
|
|
330
330
|
});
|
|
331
|
+
describe('getUniquenessPoolKeyFromObject', () => {
|
|
332
|
+
const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
|
|
333
|
+
it('uses mapping-catName', async () => {
|
|
334
|
+
const expectedPool = 'catName-pool';
|
|
335
|
+
const object = {
|
|
336
|
+
flexPLMObjectClass: 'LCSLast',
|
|
337
|
+
flexPLMTypePath: 'Last\\catName'
|
|
338
|
+
};
|
|
339
|
+
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
340
|
+
.mockImplementation(async () => {
|
|
341
|
+
return mapping;
|
|
342
|
+
});
|
|
343
|
+
try {
|
|
344
|
+
const results = await type_conversion_utils_1.TypeConversionUtils.getUniquenessPoolKeyFromObject(TRANSFORM_MAP_FILE, mapFileUtil, object);
|
|
345
|
+
expect(results).toEqual(expectedPool);
|
|
346
|
+
}
|
|
347
|
+
finally {
|
|
348
|
+
spy.mockRestore();
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
it('uses default-noMap', async () => {
|
|
352
|
+
const expectedClass = 'color';
|
|
353
|
+
const object = {
|
|
354
|
+
flexPLMObjectClass: 'LCSColor',
|
|
355
|
+
flexPLMTypePath: 'Color'
|
|
356
|
+
};
|
|
357
|
+
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
358
|
+
.mockImplementation(async () => {
|
|
359
|
+
return mapping;
|
|
360
|
+
});
|
|
361
|
+
const spyDefaults = jest.spyOn(type_defaults_1.TypeDefaults, 'getDefaultEntityClass')
|
|
362
|
+
.mockImplementation(() => expectedClass);
|
|
363
|
+
try {
|
|
364
|
+
const results = await type_conversion_utils_1.TypeConversionUtils.getUniquenessPoolKeyFromObject(TRANSFORM_MAP_FILE, mapFileUtil, object);
|
|
365
|
+
expect(results).toEqual(expectedClass);
|
|
366
|
+
expect(spyDefaults).toBeCalledTimes(1);
|
|
367
|
+
}
|
|
368
|
+
finally {
|
|
369
|
+
spy.mockRestore();
|
|
370
|
+
spyDefaults.mockRestore();
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
it('uses default-noFileId', async () => {
|
|
374
|
+
const expectedClass = 'color';
|
|
375
|
+
const object = {
|
|
376
|
+
flexPLMObjectClass: 'LCSColor',
|
|
377
|
+
};
|
|
378
|
+
const spyDefaults = jest.spyOn(type_defaults_1.TypeDefaults, 'getDefaultEntityClass')
|
|
379
|
+
.mockImplementation(() => expectedClass);
|
|
380
|
+
try {
|
|
381
|
+
const results = await type_conversion_utils_1.TypeConversionUtils.getUniquenessPoolKeyFromObject(null, mapFileUtil, object);
|
|
382
|
+
expect(results).toEqual(expectedClass);
|
|
383
|
+
expect(spyDefaults).toBeCalledTimes(1);
|
|
384
|
+
}
|
|
385
|
+
finally {
|
|
386
|
+
spyDefaults.mockRestore();
|
|
387
|
+
}
|
|
388
|
+
});
|
|
389
|
+
});
|
|
331
390
|
describe('getEntityTypePathFromOjbect', () => {
|
|
332
391
|
const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
|
|
333
392
|
it('vibeIQTypePath', async () => {
|
package/package.json
CHANGED
|
@@ -457,6 +457,113 @@ describe('BaseEntityProcessor', () =>{
|
|
|
457
457
|
});
|
|
458
458
|
});
|
|
459
459
|
|
|
460
|
+
describe('getIdentityEntity', () => {
|
|
461
|
+
const config = {} as FCConfig;
|
|
462
|
+
const mapFileUtil = new MapFileUtil(new Entities());
|
|
463
|
+
const dc = new DataConverter(config, mapFileUtil);
|
|
464
|
+
let btep: TestBaseEntityProcessor;
|
|
465
|
+
let mockEntitiesGet: jest.Mock;
|
|
466
|
+
|
|
467
|
+
beforeEach(() => {
|
|
468
|
+
btep = new TestBaseEntityProcessor(config, dc, mapFileUtil, 'item');
|
|
469
|
+
mockEntitiesGet = jest.fn();
|
|
470
|
+
(btep as any).entities = { get: mockEntitiesGet };
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
it('should throw error when poolKey is missing', async () => {
|
|
474
|
+
await expect(btep.getIdentityEntity({
|
|
475
|
+
poolKey: '',
|
|
476
|
+
propertyName: 'itemNumber',
|
|
477
|
+
propertyValue: '12345'
|
|
478
|
+
})).rejects.toThrow('poolKey, propertyName, and propertyValue must be defined');
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
it('should throw error when propertyName is missing', async () => {
|
|
482
|
+
await expect(btep.getIdentityEntity({
|
|
483
|
+
poolKey: 'item',
|
|
484
|
+
propertyName: '',
|
|
485
|
+
propertyValue: '12345'
|
|
486
|
+
})).rejects.toThrow('poolKey, propertyName, and propertyValue must be defined');
|
|
487
|
+
});
|
|
488
|
+
|
|
489
|
+
it('should throw error when propertyValue is missing', async () => {
|
|
490
|
+
await expect(btep.getIdentityEntity({
|
|
491
|
+
poolKey: 'item',
|
|
492
|
+
propertyName: 'itemNumber',
|
|
493
|
+
propertyValue: ''
|
|
494
|
+
})).rejects.toThrow('poolKey, propertyName, and propertyValue must be defined');
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
it('should return undefined when no identity entities are found (empty array)', async () => {
|
|
498
|
+
mockEntitiesGet.mockResolvedValue([]);
|
|
499
|
+
|
|
500
|
+
const result = await btep.getIdentityEntity({
|
|
501
|
+
poolKey: 'item',
|
|
502
|
+
propertyName: 'itemNumber',
|
|
503
|
+
propertyValue: '12345'
|
|
504
|
+
});
|
|
505
|
+
|
|
506
|
+
expect(result).toBeUndefined();
|
|
507
|
+
expect(mockEntitiesGet).toHaveBeenCalledWith({
|
|
508
|
+
entityName: 'identity',
|
|
509
|
+
criteria: { poolKey: 'item', propertyName: 'itemNumber', propertyValue: '12345' }
|
|
510
|
+
});
|
|
511
|
+
});
|
|
512
|
+
|
|
513
|
+
it('should return undefined when identity entities result is null', async () => {
|
|
514
|
+
mockEntitiesGet.mockResolvedValue(null);
|
|
515
|
+
|
|
516
|
+
const result = await btep.getIdentityEntity({
|
|
517
|
+
poolKey: 'item',
|
|
518
|
+
propertyName: 'itemNumber',
|
|
519
|
+
propertyValue: '12345'
|
|
520
|
+
});
|
|
521
|
+
|
|
522
|
+
expect(result).toBeUndefined();
|
|
523
|
+
});
|
|
524
|
+
|
|
525
|
+
it('should throw error when multiple identity entities are found', async () => {
|
|
526
|
+
mockEntitiesGet.mockResolvedValue([
|
|
527
|
+
{ entityReference: 'item:1' },
|
|
528
|
+
{ entityReference: 'item:2' }
|
|
529
|
+
]);
|
|
530
|
+
|
|
531
|
+
await expect(btep.getIdentityEntity({
|
|
532
|
+
poolKey: 'item',
|
|
533
|
+
propertyName: 'itemNumber',
|
|
534
|
+
propertyValue: '12345'
|
|
535
|
+
})).rejects.toThrow('Multiple identity entities found for poolKey: item, itemNumber: 12345');
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
it('should return the identity entity when one is found (array)', async () => {
|
|
539
|
+
const identityEntity = { entityReference: 'item:1' };
|
|
540
|
+
mockEntitiesGet.mockResolvedValue([identityEntity]);
|
|
541
|
+
|
|
542
|
+
const result = await btep.getIdentityEntity({
|
|
543
|
+
poolKey: 'item',
|
|
544
|
+
propertyName: 'itemNumber',
|
|
545
|
+
propertyValue: '12345'
|
|
546
|
+
});
|
|
547
|
+
|
|
548
|
+
expect(result).toEqual(identityEntity);
|
|
549
|
+
expect(mockEntitiesGet).toHaveBeenCalledTimes(1);
|
|
550
|
+
});
|
|
551
|
+
|
|
552
|
+
it('should return the identity entity when result is a single object (not array)', async () => {
|
|
553
|
+
const identityEntity = { entityReference: 'item:5' };
|
|
554
|
+
mockEntitiesGet.mockResolvedValue(identityEntity);
|
|
555
|
+
|
|
556
|
+
const result = await btep.getIdentityEntity({
|
|
557
|
+
poolKey: 'item:material',
|
|
558
|
+
propertyName: 'materialNumber',
|
|
559
|
+
propertyValue: 'MAT-001'
|
|
560
|
+
});
|
|
561
|
+
|
|
562
|
+
expect(result).toEqual(identityEntity);
|
|
563
|
+
expect(mockEntitiesGet).toHaveBeenCalledTimes(1);
|
|
564
|
+
});
|
|
565
|
+
});
|
|
566
|
+
|
|
460
567
|
describe('getEntityUsingIdentityService', () => {
|
|
461
568
|
const config = {} as FCConfig;
|
|
462
569
|
const mapFileUtil = new MapFileUtil(new Entities());
|
|
@@ -163,19 +163,16 @@ export abstract class BaseEntityProcessor {
|
|
|
163
163
|
+ ', orgSlug: ' + this.orgSlug;
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
-
/**
|
|
167
|
-
*
|
|
168
|
-
* The criteria is expected to be based on the identifier properties defined in the transformMapFile for the entity,
|
|
169
|
-
* but it can be any criteria.
|
|
170
|
-
* If not all parameters needed for the criteria are present, it will throw an error.
|
|
166
|
+
/** Looks up an identity record from the identity service based on the passed in criteria.
|
|
167
|
+
* If no identity record is found, returns undefined. If multiple are found, throws an error.
|
|
171
168
|
*
|
|
172
|
-
* @param params.poolKey the key to use for the identity service pool.
|
|
169
|
+
* @param params.poolKey the key to use for the identity service pool. This will be the subtype uniqueness is defined on, typically the root type. Ex: 'item' or 'item:material'
|
|
173
170
|
* @param params.propertyName the name of the property to use for the criteria. Ex: 'itemNumber'
|
|
174
171
|
* @param params.propertyValue the value of the property to use for the criteria. Ex: '12345'
|
|
175
|
-
* @
|
|
176
|
-
* @throws error if multiple entities are found
|
|
172
|
+
* @returns the identity entity, or undefined if no identity record is found
|
|
173
|
+
* @throws error if multiple identity entities are found, or if required parameters are missing
|
|
177
174
|
*/
|
|
178
|
-
async
|
|
175
|
+
async getIdentityEntity(params: {
|
|
179
176
|
poolKey: string,
|
|
180
177
|
propertyName: string,
|
|
181
178
|
propertyValue: string
|
|
@@ -202,7 +199,28 @@ export abstract class BaseEntityProcessor {
|
|
|
202
199
|
throw new Error('Multiple identity entities found for poolKey: ' + poolKey + ', ' + propertyName + ': ' + propertyValue);
|
|
203
200
|
}
|
|
204
201
|
|
|
205
|
-
|
|
202
|
+
return Array.isArray(identityEntities) ? identityEntities[0] : identityEntities;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** Looks up an entity via the identity service. Uses {@link getIdentityEntity} to find the identity record,
|
|
206
|
+
* then resolves the entity reference to fetch and return the actual entity.
|
|
207
|
+
*
|
|
208
|
+
* @param params.poolKey the key to use for the identity service pool. This will be the subtype uniqueness is defined on, typically the root type. Ex: 'item' or 'item:material'
|
|
209
|
+
* @param params.propertyName the name of the property to use for the criteria. Ex: 'itemNumber'
|
|
210
|
+
* @param params.propertyValue the value of the property to use for the criteria. Ex: '12345'
|
|
211
|
+
* @returns the resolved entity, or undefined if no identity record is found
|
|
212
|
+
* @throws error if multiple identity entities are found, or if required parameters are missing
|
|
213
|
+
*/
|
|
214
|
+
async getEntityUsingIdentityService(params: {
|
|
215
|
+
poolKey: string,
|
|
216
|
+
propertyName: string,
|
|
217
|
+
propertyValue: string
|
|
218
|
+
}): Promise<any | undefined> {
|
|
219
|
+
const identityEntity = await this.getIdentityEntity(params);
|
|
220
|
+
if(!identityEntity){
|
|
221
|
+
return undefined;
|
|
222
|
+
}
|
|
223
|
+
|
|
206
224
|
const entityReference = identityEntity.entityReference;
|
|
207
225
|
const [entityName, id] = entityReference.split(':');
|
|
208
226
|
|
|
@@ -360,6 +360,69 @@ describe('conversion-utils', () => {
|
|
|
360
360
|
});
|
|
361
361
|
});
|
|
362
362
|
|
|
363
|
+
describe('getUniquenessPoolKeyFromObject', () =>{
|
|
364
|
+
const mapFileUtil = new MapFileUtil(new Entities());
|
|
365
|
+
|
|
366
|
+
it('uses mapping-catName', async () =>{
|
|
367
|
+
const expectedPool = 'catName-pool';
|
|
368
|
+
const object = {
|
|
369
|
+
flexPLMObjectClass: 'LCSLast',
|
|
370
|
+
flexPLMTypePath: 'Last\\catName'
|
|
371
|
+
};
|
|
372
|
+
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
373
|
+
.mockImplementation(async () =>{
|
|
374
|
+
return mapping;
|
|
375
|
+
});
|
|
376
|
+
try{
|
|
377
|
+
const results = await TypeConversionUtils.getUniquenessPoolKeyFromObject(TRANSFORM_MAP_FILE, mapFileUtil, object);
|
|
378
|
+
expect(results).toEqual(expectedPool);
|
|
379
|
+
|
|
380
|
+
} finally {
|
|
381
|
+
spy.mockRestore();
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
it('uses default-noMap', async () =>{
|
|
386
|
+
const expectedClass = 'color';
|
|
387
|
+
const object = {
|
|
388
|
+
flexPLMObjectClass: 'LCSColor',
|
|
389
|
+
flexPLMTypePath: 'Color'
|
|
390
|
+
};
|
|
391
|
+
const spy = jest.spyOn(mapFileUtil, 'getMapFile')
|
|
392
|
+
.mockImplementation(async () =>{
|
|
393
|
+
return mapping;
|
|
394
|
+
});
|
|
395
|
+
const spyDefaults = jest.spyOn(TypeDefaults, 'getDefaultEntityClass')
|
|
396
|
+
.mockImplementation(() => expectedClass);
|
|
397
|
+
try{
|
|
398
|
+
const results = await TypeConversionUtils.getUniquenessPoolKeyFromObject(TRANSFORM_MAP_FILE, mapFileUtil, object);
|
|
399
|
+
expect(results).toEqual(expectedClass);
|
|
400
|
+
expect(spyDefaults).toBeCalledTimes(1);
|
|
401
|
+
|
|
402
|
+
} finally {
|
|
403
|
+
spy.mockRestore();
|
|
404
|
+
spyDefaults.mockRestore();
|
|
405
|
+
}
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
it('uses default-noFileId', async () =>{
|
|
409
|
+
const expectedClass = 'color';
|
|
410
|
+
const object = {
|
|
411
|
+
flexPLMObjectClass: 'LCSColor',
|
|
412
|
+
};
|
|
413
|
+
const spyDefaults = jest.spyOn(TypeDefaults, 'getDefaultEntityClass')
|
|
414
|
+
.mockImplementation(() => expectedClass);
|
|
415
|
+
try{
|
|
416
|
+
const results = await TypeConversionUtils.getUniquenessPoolKeyFromObject(null, mapFileUtil, object);
|
|
417
|
+
expect(results).toEqual(expectedClass);
|
|
418
|
+
expect(spyDefaults).toBeCalledTimes(1);
|
|
419
|
+
|
|
420
|
+
} finally {
|
|
421
|
+
spyDefaults.mockRestore();
|
|
422
|
+
}
|
|
423
|
+
});
|
|
424
|
+
});
|
|
425
|
+
|
|
363
426
|
describe('getEntityTypePathFromOjbect', () =>{
|
|
364
427
|
const mapFileUtil = new MapFileUtil(new Entities());
|
|
365
428
|
|
|
@@ -224,6 +224,36 @@ export class TypeConversionUtils {
|
|
|
224
224
|
return TypeDefaults.getDefaultEntityClass(object);
|
|
225
225
|
}
|
|
226
226
|
|
|
227
|
+
/** Takes in a FlexPLM object and returns the correct VibeIQ uniqueness
|
|
228
|
+
* pool key. Order of precedence:
|
|
229
|
+
* Map file entry in 'typeConversion:flex2vibe:<value>:getUniquenessPool()'
|
|
230
|
+
* for value from 'objectClass'
|
|
231
|
+
* TypeDefaults.getDefaultEntityClass() function
|
|
232
|
+
*
|
|
233
|
+
* @param fileId id for mapFile
|
|
234
|
+
* @param mapFileUtil class to get mapfile
|
|
235
|
+
* @param object FlexPLM object
|
|
236
|
+
* @returns Promise<string>
|
|
237
|
+
*/
|
|
238
|
+
static async getUniquenessPoolKeyFromObject(fileId, mapFileUtil, object): Promise<string>{
|
|
239
|
+
let uniquenessPool;
|
|
240
|
+
|
|
241
|
+
if(fileId){
|
|
242
|
+
const mapKey = await this.getMapKeyFromObject(fileId, mapFileUtil, object, TypeConversionUtils.FLEX2VIBE_DIRECTION);
|
|
243
|
+
if(mapKey){
|
|
244
|
+
const mapData = await MapUtil.getFullMapSection(fileId, mapFileUtil, mapKey);
|
|
245
|
+
if(mapData && mapData['uniquenessPool']){
|
|
246
|
+
uniquenessPool = mapData['uniquenessPool'];
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if(uniquenessPool){
|
|
252
|
+
return uniquenessPool;
|
|
253
|
+
}
|
|
254
|
+
return TypeDefaults.getDefaultEntityClass(object);
|
|
255
|
+
}
|
|
256
|
+
|
|
227
257
|
/** Takes in a FlexPLM object and returns the correct VibeIQ
|
|
228
258
|
* type associated to the object. Order of precedence
|
|
229
259
|
* Property 'vibeIQTypePath'
|