@contrail/flexplm 1.5.0-alpha.6fc44c4 → 1.5.0-alpha.aaef470

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.
@@ -485,14 +485,28 @@ describe('Type Defaults', () =>{
485
485
  expect(entityClass).toBe('custom-entity');
486
486
  });
487
487
 
488
- it('item - LCSMaterial', () =>{
488
+ it('item - LCSMaterial - processAsItem=true', () =>{
489
+ const object = {
490
+ flexPLMObjectClass: 'LCSMaterial'
491
+ };
492
+
493
+ TypeDefaults.applyConfig({ LCSMaterial: { processAsItem: true } });
494
+ try {
495
+ const entityClass = TypeDefaults.getDefaultEntityClass(object);
496
+ expect(entityClass).toBe('item');
497
+ } finally {
498
+ TypeDefaults.applyConfig({});
499
+ }
500
+ });
501
+
502
+ it('custom-entity - LCSMaterial - processAsItem=false (default)', () =>{
489
503
  const object = {
490
504
  flexPLMObjectClass: 'LCSMaterial'
491
505
  };
492
506
 
493
507
  const entityClass = TypeDefaults.getDefaultEntityClass(object);
494
508
 
495
- expect(entityClass).toBe('item');
509
+ expect(entityClass).toBe('custom-entity');
496
510
  });
497
511
 
498
512
  });//getDefaultEntityClass
@@ -560,13 +574,26 @@ describe('Type Defaults', () =>{
560
574
  expect(typePath).toBe('assortment');
561
575
  });
562
576
 
563
- it('LCSMaterial', () =>{
577
+ it('LCSMaterial - processAsItem=true', () =>{
564
578
  const object = {
565
579
  flexPLMObjectClass: 'LCSMaterial'
566
580
  };
567
581
 
568
- const typePath = TypeDefaults.getDefaultEntityTypePath(object);
569
- expect(typePath).toBe('item:material');
582
+ TypeDefaults.applyConfig({ LCSMaterial: { processAsItem: true } });
583
+ try {
584
+ const typePath = TypeDefaults.getDefaultEntityTypePath(object);
585
+ expect(typePath).toBe('item:material');
586
+ } finally {
587
+ TypeDefaults.applyConfig({});
588
+ }
589
+ });
590
+
591
+ it('LCSMaterial - processAsItem=false (default) throws', () =>{
592
+ const object = {
593
+ flexPLMObjectClass: 'LCSMaterial'
594
+ };
595
+
596
+ expect(() => TypeDefaults.getDefaultEntityTypePath(object)).toThrowError(TypeDefaults.NO_TYPE_PATH);
570
597
  });
571
598
  });//getDefaultEntityTypePath
572
599
 
@@ -641,13 +668,27 @@ describe('Type Defaults', () =>{
641
668
  expect(defaultIdentifiers).toHaveLength(1);
642
669
  });
643
670
 
644
- it('LCSMaterial', () =>{
671
+ it('LCSMaterial - processAsItem=true', () =>{
672
+ const object = {
673
+ flexPLMObjectClass: 'LCSMaterial'
674
+ };
675
+ TypeDefaults.applyConfig({ LCSMaterial: { processAsItem: true } });
676
+ try {
677
+ const defaultIdentifiers = TypeDefaults.getDefaultIdentifierPropertiesFromObject(object);
678
+ expect(defaultIdentifiers).toContain('itemNumber');
679
+ expect(defaultIdentifiers).toHaveLength(1);
680
+ } finally {
681
+ TypeDefaults.applyConfig({});
682
+ }
683
+ });
684
+
685
+ it('LCSMaterial - processAsItem=false (default)', () =>{
645
686
  const object = {
646
687
  flexPLMObjectClass: 'LCSMaterial'
647
688
  };
648
689
  const defaultIdentifiers = TypeDefaults.getDefaultIdentifierPropertiesFromObject(object);
649
690
 
650
- expect(defaultIdentifiers).toContain('itemNumber');
691
+ expect(defaultIdentifiers).toContain('name');
651
692
  expect(defaultIdentifiers).toHaveLength(1);
652
693
  });
653
694
 
@@ -694,15 +735,63 @@ describe('Type Defaults', () =>{
694
735
  expect(defaultIdentifiers).toHaveLength(1);
695
736
  });
696
737
 
697
- it('LCSMaterial', () =>{
738
+ it('LCSMaterial - processAsItem=true', () =>{
739
+ const object = {
740
+ flexPLMObjectClass: 'LCSMaterial'
741
+ };
742
+
743
+ TypeDefaults.applyConfig({ LCSMaterial: { processAsItem: true } });
744
+ try {
745
+ const defaultIdentifiers = TypeDefaults.getDefaultInformationalPropertiesFromObject(object);
746
+ expect(defaultIdentifiers).toContain('name');
747
+ expect(defaultIdentifiers).toHaveLength(1);
748
+ } finally {
749
+ TypeDefaults.applyConfig({});
750
+ }
751
+ });
752
+
753
+ it('LCSMaterial - processAsItem=false (default) yields no informational props', () =>{
698
754
  const object = {
699
755
  flexPLMObjectClass: 'LCSMaterial'
700
756
  };
701
757
 
702
758
  const defaultIdentifiers = TypeDefaults.getDefaultInformationalPropertiesFromObject(object);
703
- expect(defaultIdentifiers).toContain('name');
704
- expect(defaultIdentifiers).toHaveLength(1);
759
+ expect(defaultIdentifiers).toHaveLength(0);
705
760
  });
706
761
 
707
762
  });//getDefaultInformationalPropertiesFromObject
763
+
764
+ describe('applyConfig', () => {
765
+ afterEach(() => {
766
+ TypeDefaults.applyConfig({});
767
+ });
768
+
769
+ it('sets processLCSMaterialAsItem=true when processAsItem=true', () => {
770
+ TypeDefaults.applyConfig({ LCSMaterial: { processAsItem: true } });
771
+ expect(TypeDefaults.processLCSMaterialAsItem).toBe(true);
772
+ });
773
+
774
+ it('sets processLCSMaterialAsItem=true when processAsItem=\"true\" (string)', () => {
775
+ TypeDefaults.applyConfig({ LCSMaterial: { processAsItem: 'true' } });
776
+ expect(TypeDefaults.processLCSMaterialAsItem).toBe(true);
777
+ });
778
+
779
+ it('sets processLCSMaterialAsItem=false when processAsItem=false', () => {
780
+ TypeDefaults.processLCSMaterialAsItem = true;
781
+ TypeDefaults.applyConfig({ LCSMaterial: { processAsItem: false } });
782
+ expect(TypeDefaults.processLCSMaterialAsItem).toBe(false);
783
+ });
784
+
785
+ it('sets processLCSMaterialAsItem=false when LCSMaterial missing', () => {
786
+ TypeDefaults.processLCSMaterialAsItem = true;
787
+ TypeDefaults.applyConfig({});
788
+ expect(TypeDefaults.processLCSMaterialAsItem).toBe(false);
789
+ });
790
+
791
+ it('sets processLCSMaterialAsItem=false when config is null/undefined', () => {
792
+ TypeDefaults.processLCSMaterialAsItem = true;
793
+ TypeDefaults.applyConfig(undefined);
794
+ expect(TypeDefaults.processLCSMaterialAsItem).toBe(false);
795
+ });
796
+ });
708
797
  });
@@ -2,8 +2,25 @@ export class TypeDefaults {
2
2
  static NO_ENTITY_TYPE = 'Not able to determine the entity type of the entity object';
3
3
  static NO_OBJECT_CLASS = 'Please ensure that the flexPLMObjectClass property is provided.';
4
4
  static NO_TYPE_PATH = 'Please ensure that the flexPLMTypePath property is provided.';
5
+ static processLCSMaterialAsItem = false;
5
6
  constructor() {
6
7
  }
8
+
9
+ /** Applies values from the resolved config to TypeDefaults static state.
10
+ * Currently toggles whether LCSMaterial is treated as an item (new) or a
11
+ * custom-entity (old) based on config.LCSMaterial.processAsItem.
12
+ * Technically this could cause side effects if different parts of the code
13
+ * expect different behavior, but in practice * @param config will be
14
+ * consistent across the app and this is simpler than passing this config
15
+ * through multiple layers of function calls.
16
+ */
17
+ static applyConfig(config: any): void {
18
+ TypeDefaults.processLCSMaterialAsItem = TypeDefaults.isPropertyTrue(config?.LCSMaterial?.processAsItem);
19
+ }
20
+
21
+ static isPropertyTrue(value: any): boolean {
22
+ return value === true || (typeof value === 'string' && value.toLowerCase() === 'true');
23
+ }
7
24
  /**Takes in full entity and returs the default FlexPLM
8
25
  * object class.
9
26
  *
@@ -87,7 +104,7 @@ export class TypeDefaults {
87
104
  */
88
105
 
89
106
  static getDefaultIdentifierProperties(entity): string[] {
90
- const identifierProps = [];
107
+ const identifierProps: string[] = [];
91
108
  const entityType = this.getEntityType(entity);
92
109
 
93
110
  switch (entityType) {
@@ -168,7 +185,14 @@ export class TypeDefaults {
168
185
  static getDefaultEntityClass(object): string {
169
186
  let entityClass = '';
170
187
  let objectClass = TypeDefaults.getObjectClass(object);
171
- if(['LCSProduct', 'LCSSKU', 'LCSMaterial'].includes(objectClass)){
188
+ const itemClasses = TypeDefaults.processLCSMaterialAsItem
189
+ ? ['LCSProduct', 'LCSSKU', 'LCSMaterial']
190
+ : ['LCSProduct', 'LCSSKU'];
191
+ const customEntityClasses = TypeDefaults.processLCSMaterialAsItem
192
+ ? ['LCSRevisableEntity', 'LCSLifecycleManaged', 'LCSLast']
193
+ : ['LCSRevisableEntity', 'LCSLifecycleManaged', 'LCSLast', 'LCSMaterial'];
194
+
195
+ if(itemClasses.includes(objectClass)){
172
196
  entityClass = 'item';
173
197
  }else if(['LCSProductSeasonLink', 'LCSSKUSeasonLink'].includes(objectClass)){
174
198
  entityClass = 'project-item'
@@ -176,7 +200,7 @@ export class TypeDefaults {
176
200
  entityClass = 'color';
177
201
  } else if(['LCSSeason', 'SeasonGroup'].includes(objectClass)) {
178
202
  entityClass = 'assortment';
179
- } else if(['LCSRevisableEntity', 'LCSLifecycleManaged', 'LCSLast'].includes(objectClass)) {
203
+ } else if(customEntityClasses.includes(objectClass)) {
180
204
  entityClass = 'custom-entity';
181
205
  }
182
206
 
@@ -202,7 +226,9 @@ export class TypeDefaults {
202
226
  typePath = 'item';
203
227
  break;
204
228
  case 'LCSMaterial':
205
- typePath = 'item:material';
229
+ if (TypeDefaults.processLCSMaterialAsItem) {
230
+ typePath = 'item:material';
231
+ }
206
232
  break;
207
233
  case 'LCSProductSeasonLink':
208
234
  case 'LCSSKUSeasonLink':
@@ -238,8 +264,14 @@ export class TypeDefaults {
238
264
  switch (objectClass) {
239
265
  case 'LCSProduct':
240
266
  case 'LCSSKU':
267
+ identifierProps.push('itemNumber');
268
+ break;
241
269
  case 'LCSMaterial':
270
+ if (TypeDefaults.processLCSMaterialAsItem) {
242
271
  identifierProps.push('itemNumber');
272
+ } else {
273
+ identifierProps.push('name');
274
+ }
243
275
  break;
244
276
  case 'LCSSeason':
245
277
  identifierProps.push('flexPLMSeasonName');
@@ -268,7 +300,11 @@ export class TypeDefaults {
268
300
  static getDefaultInformationalPropertiesFromObject(object): string[] {
269
301
  const objectClass = TypeDefaults.getObjectClass(object);
270
302
  let properties:string[] = [];
271
- if (['LCSProduct', 'LCSMaterial'].includes(objectClass)) {
303
+ const itemClasses = TypeDefaults.processLCSMaterialAsItem
304
+ ? ['LCSProduct', 'LCSMaterial']
305
+ : ['LCSProduct'];
306
+
307
+ if (itemClasses.includes(objectClass)) {
272
308
  properties.push('name');
273
309
  } else if ('LCSSKU' === objectClass) {
274
310
  properties.push('optionName');