@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.
- package/CHANGELOG.md +1 -0
- package/lib/transform/identifier-conversion.spec.js +3 -0
- package/lib/util/config-defaults.js +2 -0
- package/lib/util/config-defaults.spec.js +14 -0
- package/lib/util/data-converter.d.ts +5 -0
- package/lib/util/data-converter.js +65 -32
- package/lib/util/data-converter.spec.js +387 -0
- package/lib/util/type-defaults.d.ts +3 -0
- package/lib/util/type-defaults.js +30 -5
- package/lib/util/type-defaults.spec.js +90 -10
- package/package.json +1 -1
- package/src/transform/identifier-conversion.spec.ts +3 -0
- package/src/util/config-defaults.spec.ts +15 -0
- package/src/util/config-defaults.ts +3 -0
- package/src/util/data-converter.spec.ts +457 -0
- package/src/util/data-converter.ts +87 -36
- package/src/util/type-defaults.spec.ts +99 -10
- package/src/util/type-defaults.ts +41 -5
|
@@ -4,6 +4,12 @@ exports.TypeDefaults = void 0;
|
|
|
4
4
|
class TypeDefaults {
|
|
5
5
|
constructor() {
|
|
6
6
|
}
|
|
7
|
+
static applyConfig(config) {
|
|
8
|
+
TypeDefaults.processLCSMaterialAsItem = TypeDefaults.isPropertyTrue(config?.LCSMaterial?.processAsItem);
|
|
9
|
+
}
|
|
10
|
+
static isPropertyTrue(value) {
|
|
11
|
+
return value === true || (typeof value === 'string' && value.toLowerCase() === 'true');
|
|
12
|
+
}
|
|
7
13
|
static getDefaultObjectClass(entity) {
|
|
8
14
|
const entityType = this.getEntityType(entity);
|
|
9
15
|
let objectClass = '';
|
|
@@ -130,7 +136,13 @@ class TypeDefaults {
|
|
|
130
136
|
static getDefaultEntityClass(object) {
|
|
131
137
|
let entityClass = '';
|
|
132
138
|
let objectClass = TypeDefaults.getObjectClass(object);
|
|
133
|
-
|
|
139
|
+
const itemClasses = TypeDefaults.processLCSMaterialAsItem
|
|
140
|
+
? ['LCSProduct', 'LCSSKU', 'LCSMaterial']
|
|
141
|
+
: ['LCSProduct', 'LCSSKU'];
|
|
142
|
+
const customEntityClasses = TypeDefaults.processLCSMaterialAsItem
|
|
143
|
+
? ['LCSRevisableEntity', 'LCSLifecycleManaged', 'LCSLast']
|
|
144
|
+
: ['LCSRevisableEntity', 'LCSLifecycleManaged', 'LCSLast', 'LCSMaterial'];
|
|
145
|
+
if (itemClasses.includes(objectClass)) {
|
|
134
146
|
entityClass = 'item';
|
|
135
147
|
}
|
|
136
148
|
else if (['LCSProductSeasonLink', 'LCSSKUSeasonLink'].includes(objectClass)) {
|
|
@@ -142,7 +154,7 @@ class TypeDefaults {
|
|
|
142
154
|
else if (['LCSSeason', 'SeasonGroup'].includes(objectClass)) {
|
|
143
155
|
entityClass = 'assortment';
|
|
144
156
|
}
|
|
145
|
-
else if (
|
|
157
|
+
else if (customEntityClasses.includes(objectClass)) {
|
|
146
158
|
entityClass = 'custom-entity';
|
|
147
159
|
}
|
|
148
160
|
if (entityClass === '')
|
|
@@ -158,7 +170,9 @@ class TypeDefaults {
|
|
|
158
170
|
typePath = 'item';
|
|
159
171
|
break;
|
|
160
172
|
case 'LCSMaterial':
|
|
161
|
-
|
|
173
|
+
if (TypeDefaults.processLCSMaterialAsItem) {
|
|
174
|
+
typePath = 'item:material';
|
|
175
|
+
}
|
|
162
176
|
break;
|
|
163
177
|
case 'LCSProductSeasonLink':
|
|
164
178
|
case 'LCSSKUSeasonLink':
|
|
@@ -182,9 +196,16 @@ class TypeDefaults {
|
|
|
182
196
|
switch (objectClass) {
|
|
183
197
|
case 'LCSProduct':
|
|
184
198
|
case 'LCSSKU':
|
|
185
|
-
case 'LCSMaterial':
|
|
186
199
|
identifierProps.push('itemNumber');
|
|
187
200
|
break;
|
|
201
|
+
case 'LCSMaterial':
|
|
202
|
+
if (TypeDefaults.processLCSMaterialAsItem) {
|
|
203
|
+
identifierProps.push('itemNumber');
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
identifierProps.push('name');
|
|
207
|
+
}
|
|
208
|
+
break;
|
|
188
209
|
case 'LCSSeason':
|
|
189
210
|
identifierProps.push('flexPLMSeasonName');
|
|
190
211
|
break;
|
|
@@ -203,7 +224,10 @@ class TypeDefaults {
|
|
|
203
224
|
static getDefaultInformationalPropertiesFromObject(object) {
|
|
204
225
|
const objectClass = TypeDefaults.getObjectClass(object);
|
|
205
226
|
let properties = [];
|
|
206
|
-
|
|
227
|
+
const itemClasses = TypeDefaults.processLCSMaterialAsItem
|
|
228
|
+
? ['LCSProduct', 'LCSMaterial']
|
|
229
|
+
: ['LCSProduct'];
|
|
230
|
+
if (itemClasses.includes(objectClass)) {
|
|
207
231
|
properties.push('name');
|
|
208
232
|
}
|
|
209
233
|
else if ('LCSSKU' === objectClass) {
|
|
@@ -222,3 +246,4 @@ exports.TypeDefaults = TypeDefaults;
|
|
|
222
246
|
TypeDefaults.NO_ENTITY_TYPE = 'Not able to determine the entity type of the entity object';
|
|
223
247
|
TypeDefaults.NO_OBJECT_CLASS = 'Please ensure that the flexPLMObjectClass property is provided.';
|
|
224
248
|
TypeDefaults.NO_TYPE_PATH = 'Please ensure that the flexPLMTypePath property is provided.';
|
|
249
|
+
TypeDefaults.processLCSMaterialAsItem = false;
|
|
@@ -369,12 +369,25 @@ describe('Type Defaults', () => {
|
|
|
369
369
|
const entityClass = type_defaults_1.TypeDefaults.getDefaultEntityClass(object);
|
|
370
370
|
expect(entityClass).toBe('custom-entity');
|
|
371
371
|
});
|
|
372
|
-
it('item - LCSMaterial', () => {
|
|
372
|
+
it('item - LCSMaterial - processAsItem=true', () => {
|
|
373
|
+
const object = {
|
|
374
|
+
flexPLMObjectClass: 'LCSMaterial'
|
|
375
|
+
};
|
|
376
|
+
type_defaults_1.TypeDefaults.applyConfig({ LCSMaterial: { processAsItem: true } });
|
|
377
|
+
try {
|
|
378
|
+
const entityClass = type_defaults_1.TypeDefaults.getDefaultEntityClass(object);
|
|
379
|
+
expect(entityClass).toBe('item');
|
|
380
|
+
}
|
|
381
|
+
finally {
|
|
382
|
+
type_defaults_1.TypeDefaults.applyConfig({});
|
|
383
|
+
}
|
|
384
|
+
});
|
|
385
|
+
it('custom-entity - LCSMaterial - processAsItem=false (default)', () => {
|
|
373
386
|
const object = {
|
|
374
387
|
flexPLMObjectClass: 'LCSMaterial'
|
|
375
388
|
};
|
|
376
389
|
const entityClass = type_defaults_1.TypeDefaults.getDefaultEntityClass(object);
|
|
377
|
-
expect(entityClass).toBe('
|
|
390
|
+
expect(entityClass).toBe('custom-entity');
|
|
378
391
|
});
|
|
379
392
|
});
|
|
380
393
|
describe('getDefaultEntityTypePath', () => {
|
|
@@ -427,12 +440,24 @@ describe('Type Defaults', () => {
|
|
|
427
440
|
const typePath = type_defaults_1.TypeDefaults.getDefaultEntityTypePath(object);
|
|
428
441
|
expect(typePath).toBe('assortment');
|
|
429
442
|
});
|
|
430
|
-
it('LCSMaterial', () => {
|
|
443
|
+
it('LCSMaterial - processAsItem=true', () => {
|
|
431
444
|
const object = {
|
|
432
445
|
flexPLMObjectClass: 'LCSMaterial'
|
|
433
446
|
};
|
|
434
|
-
|
|
435
|
-
|
|
447
|
+
type_defaults_1.TypeDefaults.applyConfig({ LCSMaterial: { processAsItem: true } });
|
|
448
|
+
try {
|
|
449
|
+
const typePath = type_defaults_1.TypeDefaults.getDefaultEntityTypePath(object);
|
|
450
|
+
expect(typePath).toBe('item:material');
|
|
451
|
+
}
|
|
452
|
+
finally {
|
|
453
|
+
type_defaults_1.TypeDefaults.applyConfig({});
|
|
454
|
+
}
|
|
455
|
+
});
|
|
456
|
+
it('LCSMaterial - processAsItem=false (default) throws', () => {
|
|
457
|
+
const object = {
|
|
458
|
+
flexPLMObjectClass: 'LCSMaterial'
|
|
459
|
+
};
|
|
460
|
+
expect(() => type_defaults_1.TypeDefaults.getDefaultEntityTypePath(object)).toThrowError(type_defaults_1.TypeDefaults.NO_TYPE_PATH);
|
|
436
461
|
});
|
|
437
462
|
});
|
|
438
463
|
describe('getDefaultIdentifierPropertiesFromObject', () => {
|
|
@@ -492,12 +517,26 @@ describe('Type Defaults', () => {
|
|
|
492
517
|
expect(defaultIdentifiers).toContain('name');
|
|
493
518
|
expect(defaultIdentifiers).toHaveLength(1);
|
|
494
519
|
});
|
|
495
|
-
it('LCSMaterial', () => {
|
|
520
|
+
it('LCSMaterial - processAsItem=true', () => {
|
|
521
|
+
const object = {
|
|
522
|
+
flexPLMObjectClass: 'LCSMaterial'
|
|
523
|
+
};
|
|
524
|
+
type_defaults_1.TypeDefaults.applyConfig({ LCSMaterial: { processAsItem: true } });
|
|
525
|
+
try {
|
|
526
|
+
const defaultIdentifiers = type_defaults_1.TypeDefaults.getDefaultIdentifierPropertiesFromObject(object);
|
|
527
|
+
expect(defaultIdentifiers).toContain('itemNumber');
|
|
528
|
+
expect(defaultIdentifiers).toHaveLength(1);
|
|
529
|
+
}
|
|
530
|
+
finally {
|
|
531
|
+
type_defaults_1.TypeDefaults.applyConfig({});
|
|
532
|
+
}
|
|
533
|
+
});
|
|
534
|
+
it('LCSMaterial - processAsItem=false (default)', () => {
|
|
496
535
|
const object = {
|
|
497
536
|
flexPLMObjectClass: 'LCSMaterial'
|
|
498
537
|
};
|
|
499
538
|
const defaultIdentifiers = type_defaults_1.TypeDefaults.getDefaultIdentifierPropertiesFromObject(object);
|
|
500
|
-
expect(defaultIdentifiers).toContain('
|
|
539
|
+
expect(defaultIdentifiers).toContain('name');
|
|
501
540
|
expect(defaultIdentifiers).toHaveLength(1);
|
|
502
541
|
});
|
|
503
542
|
});
|
|
@@ -534,13 +573,54 @@ describe('Type Defaults', () => {
|
|
|
534
573
|
expect(defaultIdentifiers).toContain('name');
|
|
535
574
|
expect(defaultIdentifiers).toHaveLength(1);
|
|
536
575
|
});
|
|
537
|
-
it('LCSMaterial', () => {
|
|
576
|
+
it('LCSMaterial - processAsItem=true', () => {
|
|
577
|
+
const object = {
|
|
578
|
+
flexPLMObjectClass: 'LCSMaterial'
|
|
579
|
+
};
|
|
580
|
+
type_defaults_1.TypeDefaults.applyConfig({ LCSMaterial: { processAsItem: true } });
|
|
581
|
+
try {
|
|
582
|
+
const defaultIdentifiers = type_defaults_1.TypeDefaults.getDefaultInformationalPropertiesFromObject(object);
|
|
583
|
+
expect(defaultIdentifiers).toContain('name');
|
|
584
|
+
expect(defaultIdentifiers).toHaveLength(1);
|
|
585
|
+
}
|
|
586
|
+
finally {
|
|
587
|
+
type_defaults_1.TypeDefaults.applyConfig({});
|
|
588
|
+
}
|
|
589
|
+
});
|
|
590
|
+
it('LCSMaterial - processAsItem=false (default) yields no informational props', () => {
|
|
538
591
|
const object = {
|
|
539
592
|
flexPLMObjectClass: 'LCSMaterial'
|
|
540
593
|
};
|
|
541
594
|
const defaultIdentifiers = type_defaults_1.TypeDefaults.getDefaultInformationalPropertiesFromObject(object);
|
|
542
|
-
expect(defaultIdentifiers).
|
|
543
|
-
|
|
595
|
+
expect(defaultIdentifiers).toHaveLength(0);
|
|
596
|
+
});
|
|
597
|
+
});
|
|
598
|
+
describe('applyConfig', () => {
|
|
599
|
+
afterEach(() => {
|
|
600
|
+
type_defaults_1.TypeDefaults.applyConfig({});
|
|
601
|
+
});
|
|
602
|
+
it('sets processLCSMaterialAsItem=true when processAsItem=true', () => {
|
|
603
|
+
type_defaults_1.TypeDefaults.applyConfig({ LCSMaterial: { processAsItem: true } });
|
|
604
|
+
expect(type_defaults_1.TypeDefaults.processLCSMaterialAsItem).toBe(true);
|
|
605
|
+
});
|
|
606
|
+
it('sets processLCSMaterialAsItem=true when processAsItem=\"true\" (string)', () => {
|
|
607
|
+
type_defaults_1.TypeDefaults.applyConfig({ LCSMaterial: { processAsItem: 'true' } });
|
|
608
|
+
expect(type_defaults_1.TypeDefaults.processLCSMaterialAsItem).toBe(true);
|
|
609
|
+
});
|
|
610
|
+
it('sets processLCSMaterialAsItem=false when processAsItem=false', () => {
|
|
611
|
+
type_defaults_1.TypeDefaults.processLCSMaterialAsItem = true;
|
|
612
|
+
type_defaults_1.TypeDefaults.applyConfig({ LCSMaterial: { processAsItem: false } });
|
|
613
|
+
expect(type_defaults_1.TypeDefaults.processLCSMaterialAsItem).toBe(false);
|
|
614
|
+
});
|
|
615
|
+
it('sets processLCSMaterialAsItem=false when LCSMaterial missing', () => {
|
|
616
|
+
type_defaults_1.TypeDefaults.processLCSMaterialAsItem = true;
|
|
617
|
+
type_defaults_1.TypeDefaults.applyConfig({});
|
|
618
|
+
expect(type_defaults_1.TypeDefaults.processLCSMaterialAsItem).toBe(false);
|
|
619
|
+
});
|
|
620
|
+
it('sets processLCSMaterialAsItem=false when config is null/undefined', () => {
|
|
621
|
+
type_defaults_1.TypeDefaults.processLCSMaterialAsItem = true;
|
|
622
|
+
type_defaults_1.TypeDefaults.applyConfig(undefined);
|
|
623
|
+
expect(type_defaults_1.TypeDefaults.processLCSMaterialAsItem).toBe(false);
|
|
544
624
|
});
|
|
545
625
|
});
|
|
546
626
|
});
|
package/package.json
CHANGED
|
@@ -3,6 +3,7 @@ import { IdentifierConversion } from "./identifier-conversion";
|
|
|
3
3
|
import { DataConverter } from "../util/data-converter";
|
|
4
4
|
import { FCConfig } from "../interfaces/interfaces";
|
|
5
5
|
import { Entities } from "@contrail/sdk";
|
|
6
|
+
import { TypeDefaults } from "../util/type-defaults";
|
|
6
7
|
|
|
7
8
|
const mapFile1Data = require('./identifier-conversion-spec-mockData');
|
|
8
9
|
const mapFile1Mappings = mapFile1Data?.mapping;
|
|
@@ -325,6 +326,7 @@ describe('getItemCriteriaFromObject', () => {
|
|
|
325
326
|
itemNumber: 'MAT-100'
|
|
326
327
|
};
|
|
327
328
|
let getEntityValuesSpyOn = undefined
|
|
329
|
+
TypeDefaults.applyConfig({ LCSMaterial: { processAsItem: true } });
|
|
328
330
|
try {
|
|
329
331
|
|
|
330
332
|
getEntityValuesSpyOn = jest.spyOn(dc, 'getEntityValues');
|
|
@@ -335,6 +337,7 @@ describe('getItemCriteriaFromObject', () => {
|
|
|
335
337
|
if (getEntityValuesSpyOn) {
|
|
336
338
|
getEntityValuesSpyOn.mockRestore();
|
|
337
339
|
}
|
|
340
|
+
TypeDefaults.applyConfig({});
|
|
338
341
|
}
|
|
339
342
|
});
|
|
340
343
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ConfigDefaults } from './config-defaults';
|
|
2
2
|
import { FCConfig } from '../interfaces/interfaces';
|
|
3
|
+
import { TypeDefaults } from './type-defaults';
|
|
3
4
|
|
|
4
5
|
let entityObject = {};
|
|
5
6
|
jest.mock('@contrail/sdk', () => {
|
|
@@ -392,6 +393,20 @@ describe('all tests', () => {
|
|
|
392
393
|
const fcConfig: any = await ConfigDefaults.setConfigDefaults(startConfig);
|
|
393
394
|
expect(fcConfig.LCSMaterial.processAsItem).toBe(true);
|
|
394
395
|
});
|
|
396
|
+
|
|
397
|
+
it('applies LCSMaterial.processAsItem to TypeDefaults', async () => {
|
|
398
|
+
try {
|
|
399
|
+
const startConfig: any = Object.assign({}, config, { LCSMaterial: { processAsItem: true } });
|
|
400
|
+
await ConfigDefaults.setConfigDefaults(startConfig);
|
|
401
|
+
expect(TypeDefaults.processLCSMaterialAsItem).toBe(true);
|
|
402
|
+
|
|
403
|
+
const defaultStart: any = Object.assign({}, config);
|
|
404
|
+
await ConfigDefaults.setConfigDefaults(defaultStart);
|
|
405
|
+
expect(TypeDefaults.processLCSMaterialAsItem).toBe(false);
|
|
406
|
+
} finally {
|
|
407
|
+
TypeDefaults.applyConfig({});
|
|
408
|
+
}
|
|
409
|
+
});
|
|
395
410
|
});
|
|
396
411
|
|
|
397
412
|
describe('getConfigFile', () => {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Entities } from '@contrail/sdk';
|
|
2
2
|
import { FCConfig } from '../interfaces/interfaces';
|
|
3
3
|
import { ObjectUtil } from '@contrail/util';
|
|
4
|
+
import { TypeDefaults } from './type-defaults';
|
|
4
5
|
|
|
5
6
|
export class ConfigDefaults {
|
|
6
7
|
static NEED_CONFIG_VALUES = 'To connect to FlexPLM all these APP values need to be set apiHost, userName, and password';
|
|
@@ -34,6 +35,8 @@ export class ConfigDefaults {
|
|
|
34
35
|
//Don't allow overwriting this.
|
|
35
36
|
outputConfig['OOBvibeEventEndpoint'] = '/rfa/vibeiq/vibeEvents';
|
|
36
37
|
|
|
38
|
+
TypeDefaults.applyConfig(outputConfig);
|
|
39
|
+
|
|
37
40
|
console.log('outputConfig: ' + JSON.stringify(outputConfig));
|
|
38
41
|
return outputConfig as FCConfig;
|
|
39
42
|
}
|