@contrail/flexplm 1.3.1 → 1.3.2-alpha.328325d

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 CHANGED
@@ -7,6 +7,9 @@ Versioning follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ### Added
11
+ - 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
+
10
13
  ## [1.3.0] - 2026-04-15
11
14
  ### Added
12
15
  - Added inbound thumbnail/primary content syncing from FlexPLM to VibeIQ via `ThumbnailUtil.syncThumbnailToVibeIQ`.
@@ -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
+ getEntityUsingIdentityService(params: {
23
+ poolKey: string;
24
+ propertyName: string;
25
+ propertyValue: string;
26
+ }): Promise<any | undefined>;
22
27
  queryEntityWithSubTypeCriteria(entityType: string, entityTypePath: string, propertyCriteria: any): Promise<any[]>;
23
28
  getCriteriaForEntity(entityType: string, entityTypePath: string, propertyCriteria: any): Promise<any>;
24
29
  getRootTypePropertyKeys(rootType: any, propertyCriteria?: any): string[];
@@ -136,6 +136,34 @@ class BaseEntityProcessor {
136
136
  + ', federatedId: ' + statusObject.federatedId
137
137
  + ', orgSlug: ' + this.orgSlug;
138
138
  }
139
+ async getEntityUsingIdentityService(params) {
140
+ const { poolKey, propertyName, propertyValue } = params;
141
+ if (!poolKey || !propertyName || !propertyValue) {
142
+ throw new Error('poolKey, propertyName, and propertyValue must be defined');
143
+ }
144
+ const identityEntities = await this.entities.get({
145
+ entityName: 'identity',
146
+ criteria: {
147
+ poolKey,
148
+ propertyName,
149
+ propertyValue
150
+ }
151
+ });
152
+ if (!identityEntities || (Array.isArray(identityEntities) && identityEntities.length === 0)) {
153
+ return undefined;
154
+ }
155
+ if (Array.isArray(identityEntities) && identityEntities.length > 1) {
156
+ throw new Error('Multiple identity entities found for poolKey: ' + poolKey + ', ' + propertyName + ': ' + propertyValue);
157
+ }
158
+ const identityEntity = Array.isArray(identityEntities) ? identityEntities[0] : identityEntities;
159
+ const entityReference = identityEntity.entityReference;
160
+ const [entityName, id] = entityReference.split(':');
161
+ const entity = await this.entities.get({
162
+ entityName,
163
+ id
164
+ });
165
+ return entity;
166
+ }
139
167
  async queryEntityWithSubTypeCriteria(entityType, entityTypePath, propertyCriteria) {
140
168
  if (!entityType || !entityTypePath) {
141
169
  throw new Error('type and entityTypePath must be defined');
@@ -394,4 +394,107 @@ 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('getEntityUsingIdentityService', () => {
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.getEntityUsingIdentityService({
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.getEntityUsingIdentityService({
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.getEntityUsingIdentityService({
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.getEntityUsingIdentityService({
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.getEntityUsingIdentityService({
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.getEntityUsingIdentityService({
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 entity when one identity entity is found (array)', async () => {
463
+ const mockEntity = { id: '1', name: 'Test Item' };
464
+ mockEntitiesGet
465
+ .mockResolvedValueOnce([{ entityReference: 'item:1' }])
466
+ .mockResolvedValueOnce(mockEntity);
467
+ const result = await btep.getEntityUsingIdentityService({
468
+ poolKey: 'item',
469
+ propertyName: 'itemNumber',
470
+ propertyValue: '12345'
471
+ });
472
+ expect(result).toEqual(mockEntity);
473
+ expect(mockEntitiesGet).toHaveBeenCalledTimes(2);
474
+ expect(mockEntitiesGet).toHaveBeenNthCalledWith(1, {
475
+ entityName: 'identity',
476
+ criteria: { poolKey: 'item', propertyName: 'itemNumber', propertyValue: '12345' }
477
+ });
478
+ expect(mockEntitiesGet).toHaveBeenNthCalledWith(2, {
479
+ entityName: 'item',
480
+ id: '1'
481
+ });
482
+ });
483
+ it('should return the entity when identity result is a single object (not array)', async () => {
484
+ const mockEntity = { id: '5', name: 'Test Material' };
485
+ mockEntitiesGet
486
+ .mockResolvedValueOnce({ entityReference: 'item:5' })
487
+ .mockResolvedValueOnce(mockEntity);
488
+ const result = await btep.getEntityUsingIdentityService({
489
+ poolKey: 'item:material',
490
+ propertyName: 'materialNumber',
491
+ propertyValue: 'MAT-001'
492
+ });
493
+ expect(result).toEqual(mockEntity);
494
+ expect(mockEntitiesGet).toHaveBeenNthCalledWith(2, {
495
+ entityName: 'item',
496
+ id: '5'
497
+ });
498
+ });
499
+ });
397
500
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/flexplm",
3
- "version": "1.3.1",
3
+ "version": "1.3.2-alpha.328325d",
4
4
  "description": "Library used for integration with flexplm.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -457,4 +457,126 @@ describe('BaseEntityProcessor', () =>{
457
457
  });
458
458
  });
459
459
 
460
+ describe('getEntityUsingIdentityService', () => {
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.getEntityUsingIdentityService({
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.getEntityUsingIdentityService({
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.getEntityUsingIdentityService({
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.getEntityUsingIdentityService({
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.getEntityUsingIdentityService({
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.getEntityUsingIdentityService({
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 entity when one identity entity is found (array)', async () => {
539
+ const mockEntity = { id: '1', name: 'Test Item' };
540
+ mockEntitiesGet
541
+ .mockResolvedValueOnce([{ entityReference: 'item:1' }])
542
+ .mockResolvedValueOnce(mockEntity);
543
+
544
+ const result = await btep.getEntityUsingIdentityService({
545
+ poolKey: 'item',
546
+ propertyName: 'itemNumber',
547
+ propertyValue: '12345'
548
+ });
549
+
550
+ expect(result).toEqual(mockEntity);
551
+ expect(mockEntitiesGet).toHaveBeenCalledTimes(2);
552
+ expect(mockEntitiesGet).toHaveBeenNthCalledWith(1, {
553
+ entityName: 'identity',
554
+ criteria: { poolKey: 'item', propertyName: 'itemNumber', propertyValue: '12345' }
555
+ });
556
+ expect(mockEntitiesGet).toHaveBeenNthCalledWith(2, {
557
+ entityName: 'item',
558
+ id: '1'
559
+ });
560
+ });
561
+
562
+ it('should return the entity when identity result is a single object (not array)', async () => {
563
+ const mockEntity = { id: '5', name: 'Test Material' };
564
+ mockEntitiesGet
565
+ .mockResolvedValueOnce({ entityReference: 'item:5' })
566
+ .mockResolvedValueOnce(mockEntity);
567
+
568
+ const result = await btep.getEntityUsingIdentityService({
569
+ poolKey: 'item:material',
570
+ propertyName: 'materialNumber',
571
+ propertyValue: 'MAT-001'
572
+ });
573
+
574
+ expect(result).toEqual(mockEntity);
575
+ expect(mockEntitiesGet).toHaveBeenNthCalledWith(2, {
576
+ entityName: 'item',
577
+ id: '5'
578
+ });
579
+ });
580
+ });
581
+
460
582
  });
@@ -163,6 +163,56 @@ export abstract class BaseEntityProcessor {
163
163
  + ', orgSlug: ' + this.orgSlug;
164
164
  }
165
165
 
166
+ /** This function is to get the entity using the identity service based on the passed in criteria.
167
+ * If no entity is found, it will return undefined. If multiple entities are found, it will throw an error.
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.
171
+ *
172
+ * @param params.poolKey the key to use for the identity service pool. The default poolKey is the entityType. Ex: 'item' or 'item:material'
173
+ * @param params.propertyName the name of the property to use for the criteria. Ex: 'itemNumber'
174
+ * @param params.propertyValue the value of the property to use for the criteria. Ex: '12345'
175
+ * @return the entity that is found based on the criteria, or undefined if no entity is found
176
+ * @throws error if multiple entities are found based on the criteria
177
+ */
178
+ async getEntityUsingIdentityService(params :{
179
+ poolKey: string,
180
+ propertyName: string,
181
+ propertyValue: string
182
+ }): Promise<any | undefined> {
183
+ const {poolKey, propertyName, propertyValue} = params;
184
+ if(!poolKey || !propertyName || !propertyValue){
185
+ throw new Error('poolKey, propertyName, and propertyValue must be defined');
186
+ }
187
+
188
+ const identityEntities = await this.entities.get({
189
+ entityName: 'identity',
190
+ criteria: {
191
+ poolKey,
192
+ propertyName,
193
+ propertyValue
194
+ }
195
+ });
196
+
197
+ if(!identityEntities || (Array.isArray(identityEntities) && identityEntities.length === 0)){
198
+ return undefined;
199
+ }
200
+
201
+ if(Array.isArray(identityEntities) && identityEntities.length > 1){
202
+ throw new Error('Multiple identity entities found for poolKey: ' + poolKey + ', ' + propertyName + ': ' + propertyValue);
203
+ }
204
+
205
+ const identityEntity = Array.isArray(identityEntities) ? identityEntities[0] : identityEntities;
206
+ const entityReference = identityEntity.entityReference;
207
+ const [entityName, id] = entityReference.split(':');
208
+
209
+ const entity = await this.entities.get({
210
+ entityName,
211
+ id
212
+ });
213
+
214
+ return entity;
215
+ }
166
216
  /**This will query for the entity, and handle post-processing
167
217
  * of any critieria that is defined at the sub-type level.
168
218
  * Because sub-type criteria can't be used in the search done