@contrail/flexplm 1.1.14 → 1.1.15

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.
@@ -7,6 +7,7 @@ export declare class DataConverter {
7
7
  private transformMapFile;
8
8
  private useDisplayForEnumerationMatching;
9
9
  private objRefCache;
10
+ private userRefCache;
10
11
  constructor(config: FCConfig, mapFileUtil: MapFileUtil);
11
12
  getFlexPLMObjectDataFromEvent(event: any, dataToSkip: string[]): Promise<{}>;
12
13
  getFlexPLMObjectData(newData: any, dataToSkip: string[], inflateObjRef: boolean): Promise<{}>;
@@ -19,4 +20,7 @@ export declare class DataConverter {
19
20
  getEntityValue(prop: any, data: any): Promise<any>;
20
21
  setEnumerationKeys(prop: any, nd: any, matchByDisplay: any): any;
21
22
  getPersistableChanges(entity: object, changes: object): object;
23
+ setUserListValue(prop: any, nd: any): Promise<any>;
24
+ processGroupMemberCheck(prop: any, userEmail: any): Promise<void>;
25
+ getUserListValue(prop: any, newData: any): Promise<any>;
22
26
  }
@@ -13,6 +13,7 @@ class DataConverter {
13
13
  this.mapFileUtil = mapFileUtil;
14
14
  this.useDisplayForEnumerationMatching = false;
15
15
  this.objRefCache = {};
16
+ this.userRefCache = {};
16
17
  this.typeUtils = new type_utils_1.TypeUtils();
17
18
  this.transformMapFile = this.config['transformMapFile'];
18
19
  this.useDisplayForEnumerationMatching = this.config['dataConverter']
@@ -88,6 +89,9 @@ class DataConverter {
88
89
  else if ('json' === propertyType) {
89
90
  value = nd;
90
91
  }
92
+ else if ('userList' === propertyType) {
93
+ value = await this.getUserListValue(prop, newData);
94
+ }
91
95
  return value;
92
96
  }
93
97
  getEnumerationValue(prop, nd) {
@@ -194,8 +198,13 @@ class DataConverter {
194
198
  const dataKeys = Object.getOwnPropertyNames(data);
195
199
  typeProps = typeProps.filter(prop => dataKeys.includes(prop['slug']));
196
200
  for (const prop of typeProps) {
201
+ const propertyType = prop['propertyType'];
197
202
  const slug = prop['slug'];
198
- entity[slug] = await this.getEntityValue(prop, data);
203
+ let keyName = slug;
204
+ if (propertyType === 'userList') {
205
+ keyName = slug + 'Id';
206
+ }
207
+ entity[keyName] = await this.getEntityValue(prop, data);
199
208
  }
200
209
  return entity;
201
210
  }
@@ -260,6 +269,9 @@ class DataConverter {
260
269
  }
261
270
  else if ('json' === propertyType) {
262
271
  }
272
+ else if ('userList' === propertyType) {
273
+ value = await this.setUserListValue(prop, nd);
274
+ }
263
275
  return value;
264
276
  }
265
277
  setEnumerationKeys(prop, nd, matchByDisplay) {
@@ -309,5 +321,80 @@ class DataConverter {
309
321
  }
310
322
  return diffValues;
311
323
  }
324
+ async setUserListValue(prop, nd) {
325
+ if (!nd?.email) {
326
+ return "";
327
+ }
328
+ if (this.userRefCache[nd.email]) {
329
+ if (app_framework_1.Logger.isDebugOn()) {
330
+ console.debug('user cache hit: ' + nd.email);
331
+ }
332
+ await this.processGroupMemberCheck(prop, nd.email);
333
+ return this.userRefCache[nd.email];
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;
343
+ await this.processGroupMemberCheck(prop, nd.email);
344
+ }
345
+ return value;
346
+ }
347
+ async processGroupMemberCheck(prop, userEmail) {
348
+ let arrUserList = [];
349
+ if (this.userRefCache[prop.typePropertyUserListId]) {
350
+ arrUserList = this.userRefCache[prop.typePropertyUserListId];
351
+ }
352
+ else {
353
+ const userListResult = await new sdk_1.Entities().get({
354
+ entityName: 'user-list',
355
+ id: prop.typePropertyUserListId
356
+ });
357
+ if (userListResult && Object.keys(userListResult).length) {
358
+ arrUserList = userListResult.userList;
359
+ this.userRefCache[prop.typePropertyUserListId] = arrUserList;
360
+ }
361
+ }
362
+ if (arrUserList.length) {
363
+ const result = arrUserList.find(element => element['display'] === userEmail);
364
+ if (!result) {
365
+ console.warn(`The passed in user ${userEmail} in property slug ${prop.slug} should be a member of the group associated with the property 'typePropertyUserListId'`);
366
+ }
367
+ }
368
+ }
369
+ async getUserListValue(prop, newData) {
370
+ const slug = prop['slug'];
371
+ if (app_framework_1.Logger.isDebugOn()) {
372
+ console.debug('getUserListValue-prop: ' + slug);
373
+ }
374
+ const entityId = newData[slug + 'Id'];
375
+ if (!entityId) {
376
+ return {};
377
+ }
378
+ if (this.userRefCache[entityId]) {
379
+ if (app_framework_1.Logger.isDebugOn()) {
380
+ console.debug('user cache hit: ' + entityId);
381
+ }
382
+ return this.userRefCache[entityId];
383
+ }
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,
393
+ } : undefined;
394
+ if (value) {
395
+ this.userRefCache[entityId] = value;
396
+ }
397
+ return value;
398
+ }
312
399
  }
313
400
  exports.DataConverter = DataConverter;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/flexplm",
3
- "version": "1.1.14",
3
+ "version": "1.1.15",
4
4
  "description": "Library used for integration with flexplm.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -1,7 +1,7 @@
1
1
  import { Entities, TypeClientOptions } from '@contrail/sdk';
2
2
  import { TypeUtils } from './type-utils';
3
3
  import { FCConfig } from '../interfaces/interfaces';
4
- import { MapFileUtil, TransformProcessor, TransformTask } from '@contrail/transform-data';
4
+ import { MapFileUtil } from '@contrail/transform-data';
5
5
  import { Logger } from '@contrail/app-framework';
6
6
  import { ObjectDiff, ObjectUtil } from '@contrail/util';
7
7
  import { TypeConversionUtils } from './type-conversion-utils';
@@ -12,6 +12,7 @@ export class DataConverter {
12
12
  private transformMapFile: string;
13
13
  private useDisplayForEnumerationMatching = false;
14
14
  private objRefCache = {};
15
+ private userRefCache = {};
15
16
  constructor(private config: FCConfig, private mapFileUtil: MapFileUtil){
16
17
  this.typeUtils = new TypeUtils();
17
18
  this.transformMapFile = this.config['transformMapFile'];
@@ -95,6 +96,8 @@ export class DataConverter {
95
96
  }else if('json' === propertyType){
96
97
  // console.log('json-TODO');
97
98
  value = nd;
99
+ } else if ('userList' === propertyType) {
100
+ value = await this.getUserListValue(prop, newData);
98
101
  }
99
102
 
100
103
  return value;
@@ -234,9 +237,13 @@ export class DataConverter {
234
237
  typeProps = typeProps.filter( prop => dataKeys.includes(prop['slug']));
235
238
 
236
239
  for(const prop of typeProps){
237
- // const propertyType = prop['propertyType'];
240
+ const propertyType = prop['propertyType'];
238
241
  const slug = prop['slug'];
239
- entity[slug] = await this.getEntityValue(prop, data);
242
+ let keyName = slug;
243
+ if(propertyType === 'userList') {
244
+ keyName = slug + 'Id';
245
+ }
246
+ entity[keyName] = await this.getEntityValue(prop, data);
240
247
  // console.log('entity[slug]: ' + entity[slug]);
241
248
  }
242
249
 
@@ -324,6 +331,8 @@ export class DataConverter {
324
331
  // console.log('TODO-formula');
325
332
  } else if ('json' === propertyType) {
326
333
  // console.log('TODO-json');
334
+ } else if ('userList' === propertyType) {
335
+ value = await this.setUserListValue(prop, nd);
327
336
  }
328
337
 
329
338
  // console.log(value);
@@ -386,4 +395,113 @@ export class DataConverter {
386
395
 
387
396
  }
388
397
 
398
+ /** Sets userListId value from FlexPLM data passed in
399
+ *
400
+ * @param prop the VibeIQ property
401
+ * @param nd the VibeIQ data
402
+ * @returns the modified entity with FlexPLM values
403
+ */
404
+ async setUserListValue(prop, nd) {
405
+ if(!nd?.email) {
406
+ return "";
407
+ }
408
+
409
+ if (this.userRefCache[nd.email]) {
410
+ if (Logger.isDebugOn()) {
411
+ console.debug('user cache hit: ' + nd.email);
412
+ }
413
+
414
+ await this.processGroupMemberCheck(prop, nd.email);
415
+ return this.userRefCache[nd.email];
416
+ }
417
+
418
+ const entities = await new Entities().get({
419
+ entityName: 'user-org',
420
+ take: 1000
421
+ });
422
+
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;
428
+ await this.processGroupMemberCheck(prop, nd.email);
429
+ }
430
+
431
+ return value;
432
+ }
433
+
434
+ /** Shows warning if user email address not present in group associated to property
435
+ *
436
+ * @param prop the VibeIQ property
437
+ * @param userEmail user email address
438
+ */
439
+ async processGroupMemberCheck(prop, userEmail) {
440
+ let arrUserList = [];
441
+ if(this.userRefCache[prop.typePropertyUserListId]) {
442
+ arrUserList = this.userRefCache[prop.typePropertyUserListId];
443
+ } else {
444
+ const userListResult = await new Entities().get({
445
+ entityName: 'user-list',
446
+ id: prop.typePropertyUserListId
447
+ });
448
+
449
+ if(userListResult && Object.keys(userListResult).length) {
450
+ arrUserList = userListResult.userList;
451
+ this.userRefCache[prop.typePropertyUserListId] = arrUserList;
452
+ }
453
+ }
454
+
455
+ if(arrUserList.length) {
456
+ const result = arrUserList.find(element => element['display'] === userEmail);
457
+ if(!result) {
458
+ console.warn(`The passed in user ${userEmail} in property slug ${prop.slug} should be a member of the group associated with the property 'typePropertyUserListId'`)
459
+ }
460
+ }
461
+ }
462
+
463
+ /** Gets the VibeIQ value for the userList property from data
464
+ *
465
+ * @param prop the VibeIQ property
466
+ * @param newData the FlexPLM data
467
+ * @returns value to be set in VibeIQ
468
+ */
469
+ async getUserListValue(prop, newData) {
470
+ const slug = prop['slug'];
471
+ if (Logger.isDebugOn()) {
472
+ console.debug('getUserListValue-prop: ' + slug);
473
+ }
474
+
475
+ const entityId = newData[slug + 'Id'];
476
+
477
+ if(!entityId) {
478
+ return {};
479
+ }
480
+
481
+ if (this.userRefCache[entityId]) {
482
+ if (Logger.isDebugOn()) {
483
+ console.debug('user cache hit: ' + entityId);
484
+ }
485
+ return this.userRefCache[entityId];
486
+ }
487
+
488
+ const entities = await new Entities().get({
489
+ entityName: 'user-org',
490
+ id: entityId
491
+ });
492
+
493
+ const value = (entities) ? {
494
+ email: entities.userEmail,
495
+ firstName: entities.first,
496
+ lastName: entities.last,
497
+ isSsoUser: entities.isSsoUser,
498
+ } : undefined;
499
+
500
+ if(value) {
501
+ this.userRefCache[entityId] = value;
502
+ }
503
+
504
+ return value;
505
+ }
506
+
389
507
  }