@contrail/flexplm 1.1.15 → 1.1.16

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.
@@ -21,6 +21,8 @@ export declare class DataConverter {
21
21
  setEnumerationKeys(prop: any, nd: any, matchByDisplay: any): any;
22
22
  getPersistableChanges(entity: object, changes: object): object;
23
23
  setUserListValue(prop: any, nd: any): Promise<any>;
24
+ getUserByEmail(nd: any): Promise<any>;
24
25
  processGroupMemberCheck(prop: any, userEmail: any): Promise<void>;
25
26
  getUserListValue(prop: any, newData: any): Promise<any>;
27
+ getUserById(userId: any): Promise<any>;
26
28
  }
@@ -332,17 +332,28 @@ class DataConverter {
332
332
  await this.processGroupMemberCheck(prop, nd.email);
333
333
  return this.userRefCache[nd.email];
334
334
  }
335
- const entities = await new sdk_1.Entities().get({
336
- entityName: 'user-org',
337
- take: 1000
338
- });
339
- const result = entities.find(element => element['userEmail'] === nd.email);
340
- const value = (result) ? result.id : undefined;
341
- if (value) {
342
- this.userRefCache[nd.email] = value;
335
+ const user = await this.getUserByEmail(nd);
336
+ const userId = (user) ? user.id : undefined;
337
+ if (userId) {
338
+ this.userRefCache[nd.email] = userId;
343
339
  await this.processGroupMemberCheck(prop, nd.email);
344
340
  }
345
- return value;
341
+ return userId;
342
+ }
343
+ async getUserByEmail(nd) {
344
+ let userOrg = undefined;
345
+ let count = 0;
346
+ let size = 0;
347
+ const entities = new sdk_1.Entities();
348
+ const getOptionsCriteria = {
349
+ entityName: 'user-org',
350
+ take: 1000
351
+ };
352
+ do {
353
+ const userBatch = await entities.get(getOptionsCriteria);
354
+ userOrg = userBatch.find(uo => uo?.userEmail === nd?.email);
355
+ } while (!userOrg && size == getOptionsCriteria.take && count < 15);
356
+ return userOrg?.user;
346
357
  }
347
358
  async processGroupMemberCheck(prop, userEmail) {
348
359
  let arrUserList = [];
@@ -381,20 +392,32 @@ class DataConverter {
381
392
  }
382
393
  return this.userRefCache[entityId];
383
394
  }
384
- const entities = await new sdk_1.Entities().get({
385
- entityName: 'user-org',
386
- id: entityId
387
- });
388
- const value = (entities) ? {
389
- email: entities.userEmail,
390
- firstName: entities.first,
391
- lastName: entities.last,
392
- isSsoUser: entities.isSsoUser,
395
+ const user = await this.getUserById(entityId);
396
+ const value = (user) ? {
397
+ email: user.email,
398
+ firstName: user.first,
399
+ lastName: user.last,
400
+ isSsoUser: user.isSsoUser,
393
401
  } : undefined;
394
402
  if (value) {
395
403
  this.userRefCache[entityId] = value;
396
404
  }
397
405
  return value;
398
406
  }
407
+ async getUserById(userId) {
408
+ let userOrg = undefined;
409
+ let count = 0;
410
+ let size = 0;
411
+ const entities = new sdk_1.Entities();
412
+ const getOptionsCriteria = {
413
+ entityName: 'user-org',
414
+ take: 1000
415
+ };
416
+ do {
417
+ const userBatch = await entities.get(getOptionsCriteria);
418
+ userOrg = userBatch.find(uo => uo?.user?.id === userId);
419
+ } while (!userOrg && size == getOptionsCriteria.take && count < 15);
420
+ return userOrg?.user;
421
+ }
399
422
  }
400
423
  exports.DataConverter = DataConverter;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/flexplm",
3
- "version": "1.1.15",
3
+ "version": "1.1.16",
4
4
  "description": "Library used for integration with flexplm.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -415,20 +415,41 @@ export class DataConverter {
415
415
  return this.userRefCache[nd.email];
416
416
  }
417
417
 
418
- const entities = await new Entities().get({
419
- entityName: 'user-org',
420
- take: 1000
421
- });
418
+ const user = await this.getUserByEmail(nd);
419
+ const userId = (user)?user.id:undefined;
422
420
 
423
- const result = entities.find(element => element['userEmail'] === nd.email);
424
- const value = (result) ? result.id : undefined;
425
-
426
- if(value) {
427
- this.userRefCache[nd.email] = value;
421
+ if(userId) {
422
+ this.userRefCache[nd.email] = userId;
428
423
  await this.processGroupMemberCheck(prop, nd.email);
429
424
  }
430
425
 
431
- return value;
426
+ return userId;
427
+ }
428
+
429
+ /** Makes batch calls of 1000 of user-org entities until
430
+ * it find one with userEmail of passed in nd.email.
431
+ * Maxes out after querying for 15,000 user-org entities
432
+ *
433
+ * @param nd
434
+ * @returns
435
+ */
436
+ async getUserByEmail(nd: any) {
437
+ let userOrg = undefined;
438
+ let count =0;
439
+ let size = 0;
440
+ const entities = new Entities();
441
+ const getOptionsCriteria = {
442
+ entityName: 'user-org',
443
+ take:1000
444
+ }
445
+
446
+ do {
447
+ const userBatch: [any] = await entities.get(getOptionsCriteria);
448
+ userOrg = userBatch.find(uo => uo?.userEmail === nd?.email);
449
+
450
+ }while( !userOrg && size == getOptionsCriteria.take && count < 15);
451
+ return userOrg?.user
452
+
432
453
  }
433
454
 
434
455
  /** Shows warning if user email address not present in group associated to property
@@ -485,16 +506,13 @@ export class DataConverter {
485
506
  return this.userRefCache[entityId];
486
507
  }
487
508
 
488
- const entities = await new Entities().get({
489
- entityName: 'user-org',
490
- id: entityId
491
- });
509
+ const user = await this.getUserById(entityId);
492
510
 
493
- const value = (entities) ? {
494
- email: entities.userEmail,
495
- firstName: entities.first,
496
- lastName: entities.last,
497
- isSsoUser: entities.isSsoUser,
511
+ const value = (user) ? {
512
+ email: user.email,
513
+ firstName: user.first,
514
+ lastName: user.last,
515
+ isSsoUser: user.isSsoUser,
498
516
  } : undefined;
499
517
 
500
518
  if(value) {
@@ -504,4 +522,29 @@ export class DataConverter {
504
522
  return value;
505
523
  }
506
524
 
525
+ /** Makes batch calls of 1000 of user-org entities until
526
+ * it find one with user.id of passed in userId.
527
+ * Maxes out after querying for 15,000 user-org entities
528
+ *
529
+ * @param userId
530
+ * @returns
531
+ */
532
+ async getUserById(userId: any) {
533
+ let userOrg = undefined;
534
+ let count =0;
535
+ let size = 0;
536
+ const entities = new Entities();
537
+ const getOptionsCriteria = {
538
+ entityName: 'user-org',
539
+ take:1000
540
+ }
541
+
542
+ do {
543
+ const userBatch: [any] = await entities.get(getOptionsCriteria);
544
+ userOrg = userBatch.find(uo => uo?.user?.id === userId);
545
+
546
+ }while( !userOrg && size == getOptionsCriteria.take && count < 15);
547
+ return userOrg?.user
548
+ }
549
+
507
550
  }