@contrail/flexplm 1.2.1 → 1.3.0-alpha.04c91a9

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.
Files changed (125) hide show
  1. package/.github/pull_request_template.md +31 -31
  2. package/.github/workflows/flexplm-lib.yml +27 -27
  3. package/.github/workflows/publish-to-npm.yml +131 -0
  4. package/CHANGELOG.md +10 -0
  5. package/lib/entity-processor/base-entity-processor.d.ts +42 -42
  6. package/lib/entity-processor/base-entity-processor.js +385 -363
  7. package/lib/entity-processor/base-entity-processor.spec.d.ts +1 -1
  8. package/lib/entity-processor/base-entity-processor.spec.js +397 -302
  9. package/lib/flexplm-request.d.ts +3 -3
  10. package/lib/flexplm-request.js +34 -34
  11. package/lib/flexplm-utils.d.ts +5 -5
  12. package/lib/flexplm-utils.js +33 -33
  13. package/lib/flexplm-utils.spec.d.ts +1 -1
  14. package/lib/flexplm-utils.spec.js +26 -26
  15. package/lib/index.d.ts +22 -22
  16. package/lib/index.js +38 -38
  17. package/lib/interfaces/interfaces.d.ts +105 -105
  18. package/lib/interfaces/interfaces.js +2 -2
  19. package/lib/interfaces/item-family-changes.d.ts +20 -20
  20. package/lib/interfaces/item-family-changes.js +56 -56
  21. package/lib/interfaces/publish-change-data.d.ts +19 -19
  22. package/lib/interfaces/publish-change-data.js +32 -32
  23. package/lib/publish/base-process-publish-assortment-callback.d.ts +9 -9
  24. package/lib/publish/base-process-publish-assortment-callback.js +38 -38
  25. package/lib/publish/base-process-publish-assortment.d.ts +93 -93
  26. package/lib/publish/base-process-publish-assortment.js +944 -944
  27. package/lib/publish/base-process-publish-assortment.spec.d.ts +1 -1
  28. package/lib/publish/base-process-publish-assortment.spec.js +1670 -1670
  29. package/lib/publish/mockData.d.ts +1389 -1389
  30. package/lib/publish/mockData.js +4519 -4519
  31. package/lib/transform/identifier-conversion-spec-mockData.js +444 -444
  32. package/lib/transform/identifier-conversion.d.ts +15 -15
  33. package/lib/transform/identifier-conversion.js +212 -212
  34. package/lib/transform/identifier-conversion.spec.d.ts +1 -1
  35. package/lib/transform/identifier-conversion.spec.js +339 -339
  36. package/lib/util/config-defaults.d.ts +8 -8
  37. package/lib/util/config-defaults.js +85 -85
  38. package/lib/util/config-defaults.spec.d.ts +1 -1
  39. package/lib/util/config-defaults.spec.js +293 -293
  40. package/lib/util/data-converter-spec-mockData.js +205 -205
  41. package/lib/util/data-converter.d.ts +39 -39
  42. package/lib/util/data-converter.js +592 -592
  43. package/lib/util/data-converter.spec.d.ts +1 -1
  44. package/lib/util/data-converter.spec.js +904 -904
  45. package/lib/util/error-response-object.d.ts +4 -4
  46. package/lib/util/error-response-object.js +47 -47
  47. package/lib/util/error-response-object.spec.d.ts +1 -1
  48. package/lib/util/error-response-object.spec.js +99 -99
  49. package/lib/util/event-short-message-status.d.ts +19 -18
  50. package/lib/util/event-short-message-status.js +23 -22
  51. package/lib/util/federation.d.ts +15 -15
  52. package/lib/util/federation.js +149 -149
  53. package/lib/util/flexplm-connect.d.ts +22 -18
  54. package/lib/util/flexplm-connect.js +176 -171
  55. package/lib/util/flexplm-connect.spec.d.ts +1 -0
  56. package/lib/util/flexplm-connect.spec.js +88 -0
  57. package/lib/util/logger-config.d.ts +1 -1
  58. package/lib/util/logger-config.js +26 -26
  59. package/lib/util/map-util-spec-mockData.js +205 -205
  60. package/lib/util/map-utils.d.ts +6 -6
  61. package/lib/util/map-utils.js +15 -15
  62. package/lib/util/map-utils.spec.d.ts +1 -1
  63. package/lib/util/map-utils.spec.js +89 -89
  64. package/lib/util/mockData.d.ts +80 -79
  65. package/lib/util/mockData.js +103 -99
  66. package/lib/util/thumbnail-util.d.ts +34 -19
  67. package/lib/util/thumbnail-util.js +215 -114
  68. package/lib/util/thumbnail-util.spec.d.ts +1 -1
  69. package/lib/util/thumbnail-util.spec.js +434 -242
  70. package/lib/util/type-conversion-utils-spec-mockData.js +259 -241
  71. package/lib/util/type-conversion-utils.d.ts +23 -21
  72. package/lib/util/type-conversion-utils.js +265 -223
  73. package/lib/util/type-conversion-utils.spec.d.ts +1 -1
  74. package/lib/util/type-conversion-utils.spec.js +868 -708
  75. package/lib/util/type-defaults.d.ts +16 -16
  76. package/lib/util/type-defaults.js +221 -221
  77. package/lib/util/type-defaults.spec.d.ts +1 -1
  78. package/lib/util/type-defaults.spec.js +516 -516
  79. package/lib/util/type-utils.d.ts +13 -13
  80. package/lib/util/type-utils.js +114 -114
  81. package/lib/util/type-utils.spec.d.ts +1 -1
  82. package/lib/util/type-utils.spec.js +190 -190
  83. package/package.json +1 -1
  84. package/publish.bat +4 -4
  85. package/publish.sh +4 -4
  86. package/src/entity-processor/base-entity-processor.spec.ts +122 -0
  87. package/src/entity-processor/base-entity-processor.ts +31 -2
  88. package/src/flexplm-request.ts +28 -28
  89. package/src/flexplm-utils.spec.ts +27 -27
  90. package/src/flexplm-utils.ts +29 -29
  91. package/src/index.ts +21 -21
  92. package/src/interfaces/item-family-changes.ts +66 -66
  93. package/src/interfaces/publish-change-data.ts +42 -42
  94. package/src/publish/base-process-publish-assortment-callback.ts +50 -50
  95. package/src/transform/identifier-conversion-spec-mockData.ts +495 -495
  96. package/src/transform/identifier-conversion.spec.ts +353 -353
  97. package/src/transform/identifier-conversion.ts +281 -281
  98. package/src/util/config-defaults.spec.ts +350 -350
  99. package/src/util/config-defaults.ts +92 -92
  100. package/src/util/data-converter-spec-mockData.ts +230 -230
  101. package/src/util/error-response-object.spec.ts +115 -115
  102. package/src/util/error-response-object.ts +49 -49
  103. package/src/util/event-short-message-status.ts +1 -0
  104. package/src/util/federation.ts +172 -172
  105. package/src/util/flexplm-connect.spec.ts +132 -0
  106. package/src/util/flexplm-connect.ts +14 -5
  107. package/src/util/logger-config.ts +19 -19
  108. package/src/util/map-util-spec-mockData.ts +230 -230
  109. package/src/util/map-utils.spec.ts +102 -102
  110. package/src/util/map-utils.ts +40 -40
  111. package/src/util/mockData.ts +101 -97
  112. package/src/util/thumbnail-util.spec.ts +239 -0
  113. package/src/util/thumbnail-util.ts +140 -5
  114. package/src/util/type-conversion-utils-spec-mockData.ts +18 -0
  115. package/src/util/type-conversion-utils.spec.ts +184 -0
  116. package/src/util/type-conversion-utils.ts +75 -1
  117. package/src/util/type-defaults.spec.ts +668 -668
  118. package/src/util/type-defaults.ts +280 -280
  119. package/src/util/type-utils.spec.ts +227 -227
  120. package/src/util/type-utils.ts +144 -144
  121. package/tsconfig.json +23 -26
  122. package/tslint.json +57 -57
  123. package/.claude/settings.local.json +0 -8
  124. package/scripts/output.png +0 -0
  125. package/scripts/test-get-request.ts +0 -35
package/publish.sh CHANGED
@@ -1,5 +1,5 @@
1
- rm -rf lib;
2
- npm install;
3
- npm run build;
4
- npm version patch;
1
+ rm -rf lib;
2
+ npm install;
3
+ npm run build;
4
+ npm version patch;
5
5
  npm publish;
@@ -3,6 +3,8 @@ import { MapFileUtil } from "@contrail/transform-data";
3
3
  import { EntityPayloadType, FCConfig } from "../interfaces/interfaces";
4
4
  import { DataConverter } from "../util/data-converter";
5
5
  import { BaseEntityProcessor, IncomingEntityResponse } from "./base-entity-processor";
6
+ import { TypeConversionUtils } from "../util/type-conversion-utils";
7
+ import { ThumbnailUtil } from "../util/thumbnail-util";
6
8
 
7
9
  const mockRootType = {
8
10
  typeProperties: [
@@ -335,4 +337,124 @@ describe('BaseEntityProcessor', () =>{
335
337
 
336
338
  });
337
339
 
340
+ describe('handleIncomingUpsert - inbound image sync', () =>{
341
+ const config = {} as FCConfig;
342
+ const mapFileUtil = new MapFileUtil(new Entities());
343
+ const dc = new DataConverter(config, mapFileUtil);
344
+ const mockEvent = { objectClass: 'TestClass', federatedId: 'fed-123', data: { name: 'test' }, entityReference: 'ref-1', eventType: 'PERSIST' } as EntityPayloadType;
345
+ const mockInboundData = { name: 'transformed-test' };
346
+ const mockCreatedEntity = { id: 'created-1', name: 'created', primaryViewableId: 'pv-created' };
347
+ const mockUpdatedEntity = { id: 'updated-1', name: 'updated', primaryViewableId: 'pv-updated' };
348
+ const mockExistingEntity = { id: 'existing-1', name: 'existing', typeId: 'type-1', roles: [] };
349
+
350
+ let btep: TestBaseEntityProcessor;
351
+ let syncInboundImagesSpy: jest.SpyInstance;
352
+ let syncThumbnailSpy: jest.SpyInstance;
353
+
354
+ beforeEach(() =>{
355
+ jest.clearAllMocks();
356
+ btep = new TestBaseEntityProcessor(config, dc, mapFileUtil, 'test');
357
+ jest.spyOn(btep, 'getTransformedData').mockResolvedValue(mockInboundData);
358
+ syncInboundImagesSpy = jest.spyOn(TypeConversionUtils, 'syncInboundImages');
359
+ syncThumbnailSpy = jest.spyOn(ThumbnailUtil.prototype, 'syncThumbnailToVibeIQ').mockResolvedValue(undefined);
360
+ });
361
+
362
+ it('should call syncThumbnailToVibeIQ with entity after create when syncInboundImages returns true', async () =>{
363
+ jest.spyOn(btep, 'getIncomingEntity' as any).mockResolvedValue({ entity: null });
364
+ jest.spyOn(btep, 'getCreateEntity' as any).mockResolvedValue({ entity: { name: 'new' } });
365
+ jest.spyOn(btep, 'createEntity').mockResolvedValue(mockCreatedEntity);
366
+ syncInboundImagesSpy.mockResolvedValue(true);
367
+
368
+ const result = await btep.handleIncomingUpsert(mockEvent);
369
+
370
+ expect(syncThumbnailSpy).toBeCalledTimes(1);
371
+ expect(syncThumbnailSpy).toBeCalledWith({ entityId: 'created-1', primaryViewableId: 'pv-created', event: mockEvent, entityName: 'test' });
372
+ expect(result).toBe(mockCreatedEntity);
373
+ });
374
+
375
+ it('should not sync images after create when syncInboundImages returns false', async () =>{
376
+ jest.spyOn(btep, 'getIncomingEntity' as any).mockResolvedValue({ entity: null });
377
+ jest.spyOn(btep, 'getCreateEntity' as any).mockResolvedValue({ entity: { name: 'new' } });
378
+ jest.spyOn(btep, 'createEntity').mockResolvedValue(mockCreatedEntity);
379
+ syncInboundImagesSpy.mockResolvedValue(false);
380
+
381
+ const result = await btep.handleIncomingUpsert(mockEvent);
382
+
383
+ expect(syncInboundImagesSpy).toBeCalledTimes(1);
384
+ expect(syncThumbnailSpy).toBeCalledTimes(0);
385
+ expect(result).toBe(mockCreatedEntity);
386
+ });
387
+
388
+ it('should call syncThumbnailToVibeIQ with entity and update with property diffs on update', async () =>{
389
+ jest.spyOn(btep, 'getIncomingEntity' as any).mockResolvedValue({ entity: mockExistingEntity });
390
+ jest.spyOn(btep, 'getUpdatesForEntity').mockResolvedValue({ name: 'changed' });
391
+ const updateEntitySpy = jest.spyOn(btep, 'updateEntity').mockResolvedValue(mockUpdatedEntity);
392
+ syncInboundImagesSpy.mockResolvedValue(true);
393
+
394
+ const result = await btep.handleIncomingUpsert(mockEvent);
395
+
396
+ expect(syncThumbnailSpy).toBeCalledTimes(1);
397
+ expect(syncThumbnailSpy).toBeCalledWith({ entityId: 'existing-1', primaryViewableId: undefined, event: mockEvent, entityName: 'test' });
398
+ expect(updateEntitySpy).toBeCalledWith('test', mockExistingEntity, { name: 'changed' });
399
+ expect(result).toBe(mockUpdatedEntity);
400
+ });
401
+
402
+ it('should not sync images on update when syncInboundImages returns false', async () =>{
403
+ jest.spyOn(btep, 'getIncomingEntity' as any).mockResolvedValue({ entity: mockExistingEntity });
404
+ jest.spyOn(btep, 'getUpdatesForEntity').mockResolvedValue({ name: 'changed' });
405
+ jest.spyOn(btep, 'updateEntity').mockResolvedValue(mockUpdatedEntity);
406
+ syncInboundImagesSpy.mockResolvedValue(false);
407
+
408
+ const result = await btep.handleIncomingUpsert(mockEvent);
409
+
410
+ expect(syncInboundImagesSpy).toBeCalledTimes(1);
411
+ expect(syncThumbnailSpy).toBeCalledTimes(0);
412
+ expect(result).toBe(mockUpdatedEntity);
413
+ });
414
+
415
+ it('should not sync images on early return from getIncomingEntity', async () =>{
416
+ jest.spyOn(btep, 'getIncomingEntity' as any).mockResolvedValue({
417
+ earlyReturn: { status: 400, data: { message: 'error' }, shortStatusMessage: 'FAIL' }
418
+ });
419
+
420
+ await btep.handleIncomingUpsert(mockEvent);
421
+
422
+ expect(syncInboundImagesSpy).toBeCalledTimes(0);
423
+ expect(syncThumbnailSpy).toBeCalledTimes(0);
424
+ });
425
+
426
+ it('should not sync images on early return from getCreateEntity', async () =>{
427
+ jest.spyOn(btep, 'getIncomingEntity' as any).mockResolvedValue({ entity: null });
428
+ jest.spyOn(btep, 'getCreateEntity' as any).mockResolvedValue({
429
+ earlyReturn: { status: 400, data: { message: 'not creatable' }, shortStatusMessage: 'NOT_CREATABLE' }
430
+ });
431
+
432
+ await btep.handleIncomingUpsert(mockEvent);
433
+
434
+ expect(syncInboundImagesSpy).toBeCalledTimes(0);
435
+ expect(syncThumbnailSpy).toBeCalledTimes(0);
436
+ });
437
+
438
+ it('should return no changes when no property diffs and no thumbnail updates', async () =>{
439
+ jest.spyOn(btep, 'getIncomingEntity' as any).mockResolvedValue({ entity: mockExistingEntity });
440
+ jest.spyOn(btep, 'getUpdatesForEntity').mockResolvedValue({});
441
+ syncInboundImagesSpy.mockResolvedValue(true);
442
+ syncThumbnailSpy.mockResolvedValue(undefined);
443
+
444
+ const result = await btep.handleIncomingUpsert(mockEvent);
445
+
446
+ expect(result).toEqual({ status: 200, data: { message: 'No Changes to persist for entity: existing-1' } });
447
+ });
448
+
449
+ it('should return no changes when syncInboundImages is false and no property diffs', async () =>{
450
+ jest.spyOn(btep, 'getIncomingEntity' as any).mockResolvedValue({ entity: mockExistingEntity });
451
+ jest.spyOn(btep, 'getUpdatesForEntity').mockResolvedValue({});
452
+ syncInboundImagesSpy.mockResolvedValue(false);
453
+
454
+ const result = await btep.handleIncomingUpsert(mockEvent);
455
+
456
+ expect(result).toEqual({ status: 200, data: { message: 'No Changes to persist for entity: existing-1' } });
457
+ });
458
+ });
459
+
338
460
  });
@@ -7,6 +7,7 @@ import { MapFileUtil } from '@contrail/transform-data';
7
7
  import { Entities } from '@contrail/sdk';
8
8
  import { TypeProperty } from '@contrail/types';
9
9
  import { TypeConversionUtils } from '../util/type-conversion-utils';
10
+ import { ThumbnailUtil } from '../util/thumbnail-util';
10
11
  import { EventShortMessageStatus } from '../util/event-short-message-status';
11
12
 
12
13
  const UNSUPPORTED_TYPE = 'Unsupported eventType.';
@@ -83,7 +84,13 @@ export abstract class BaseEntityProcessor {
83
84
  console.log(statusMsg);
84
85
  return createEntityResponse.earlyReturn;
85
86
  }
86
- const createdEntity = await this.createEntity(this.baseType, createEntityResponse.entity);
87
+ let createdEntity = await this.createEntity(this.baseType, createEntityResponse.entity);
88
+ const shouldSyncThumbnail = await TypeConversionUtils.syncInboundImages(
89
+ this.transformMapFile, this.mapFileUtil, event.data
90
+ );
91
+ if (shouldSyncThumbnail) {
92
+ createdEntity = await new ThumbnailUtil(this.config).syncThumbnailToVibeIQ({ entityId: createdEntity.id, primaryViewableId: createdEntity.primaryViewableId, event, entityName: this.baseType }) || createdEntity;
93
+ }
87
94
  const statusMsg = this.getInboundStatusMessage({
88
95
  status: EventShortMessageStatus.SUCCESS,
89
96
  statusMessage: EventShortMessageStatus.CREATED,
@@ -96,7 +103,29 @@ export abstract class BaseEntityProcessor {
96
103
  }
97
104
 
98
105
  const diffs = await this.getUpdatesForEntity(entity, inboundData);
99
- if(Object.getOwnPropertyNames(diffs).length == 0){
106
+ const shouldSyncThumbnail = await TypeConversionUtils.syncInboundImages(
107
+ this.transformMapFile, this.mapFileUtil, event.data
108
+ );
109
+ let thumbnailEntity;
110
+ if (shouldSyncThumbnail) {
111
+ thumbnailEntity = await new ThumbnailUtil(this.config).syncThumbnailToVibeIQ({ entityId: entity.id, primaryViewableId: entity.primaryViewableId, event, entityName: this.baseType });
112
+ }
113
+
114
+ const hasPropertyChanges = Object.getOwnPropertyNames(diffs).length > 0;
115
+
116
+ if (!hasPropertyChanges && thumbnailEntity) {
117
+ const statusMsg = this.getInboundStatusMessage({
118
+ status: EventShortMessageStatus.SUCCESS,
119
+ statusMessage: EventShortMessageStatus.PRIMARY_CONTENT_UPDATED,
120
+ objectClass: event.objectClass,
121
+ entityId: entity.id,
122
+ federatedId: event.federatedId
123
+ });
124
+ console.log(statusMsg);
125
+ return thumbnailEntity;
126
+ }
127
+
128
+ if (!hasPropertyChanges) {
100
129
  const statusMsg = this.getInboundStatusMessage({
101
130
  status: EventShortMessageStatus.SUCCESS,
102
131
  statusMessage: EventShortMessageStatus.NO_CHANGES,
@@ -1,28 +1,28 @@
1
- import axios, { AxiosRequestConfig } from 'axios';
2
-
3
- const BASE_URL: string = 'https://PP-2006031951wo.portal.ptc.io/Windchill/servlet/rest/cdee';
4
- const BASE_CONFIG: AxiosRequestConfig = {
5
- method: 'POST',
6
- headers: {
7
- 'Accept': 'application/json',
8
- 'Content-Type': 'application/json',
9
- 'CSRF_NONCE': '2OaLp+0dWNBtrkTwtdDC491zaacu6Hykvqi/lpl6bZgJ/QXBrK/B1J5FErMkmAmktr/I3thcbO1Xn3HJ7Ne/l9kpaedUmn7H75Xey4ZbNLsenW+anM3vxIZ7ELosk3k=',
10
- 'Authorization': 'Basic d2NhZG1pbjpSZXRhaWwyMDIwLQ==',
11
- 'Cookie': 'JSESSIONID=36D5B3C74C1F963C6C73E9AF5B6BDA78.tomcat1; JSESSIONID=B8090C802D8548EA773C97F5886FAB79.tomcat1',
12
- },
13
- };
14
-
15
- export class FlexPLMRequest {
16
- static async request(path: string, data: any){
17
- const config = Object.assign({}, BASE_CONFIG);
18
- config.url = BASE_URL + path;
19
- config.data = data;
20
- try {
21
- const resp = await axios(config);
22
- return Promise.resolve(resp.data);
23
- } catch (error) {
24
- console.error(`${FlexPLMRequest} error: ${error.message}`);
25
- return Promise.resolve(null);
26
- }
27
- }
28
- }
1
+ import axios, { AxiosRequestConfig } from 'axios';
2
+
3
+ const BASE_URL: string = 'https://PP-2006031951wo.portal.ptc.io/Windchill/servlet/rest/cdee';
4
+ const BASE_CONFIG: AxiosRequestConfig = {
5
+ method: 'POST',
6
+ headers: {
7
+ 'Accept': 'application/json',
8
+ 'Content-Type': 'application/json',
9
+ 'CSRF_NONCE': '2OaLp+0dWNBtrkTwtdDC491zaacu6Hykvqi/lpl6bZgJ/QXBrK/B1J5FErMkmAmktr/I3thcbO1Xn3HJ7Ne/l9kpaedUmn7H75Xey4ZbNLsenW+anM3vxIZ7ELosk3k=',
10
+ 'Authorization': 'Basic d2NhZG1pbjpSZXRhaWwyMDIwLQ==',
11
+ 'Cookie': 'JSESSIONID=36D5B3C74C1F963C6C73E9AF5B6BDA78.tomcat1; JSESSIONID=B8090C802D8548EA773C97F5886FAB79.tomcat1',
12
+ },
13
+ };
14
+
15
+ export class FlexPLMRequest {
16
+ static async request(path: string, data: any){
17
+ const config = Object.assign({}, BASE_CONFIG);
18
+ config.url = BASE_URL + path;
19
+ config.data = data;
20
+ try {
21
+ const resp = await axios(config);
22
+ return Promise.resolve(resp.data);
23
+ } catch (error) {
24
+ console.error(`${FlexPLMRequest} error: ${error.message}`);
25
+ return Promise.resolve(null);
26
+ }
27
+ }
28
+ }
@@ -1,27 +1,27 @@
1
- import { FlexPLMUtils } from './flexplm-utils';
2
-
3
- describe('Types Controller', () => {
4
-
5
- beforeEach(async () => {
6
- });
7
-
8
- it('should convert a type path', () => {
9
- expect(FlexPLMUtils.convertTypePath('Product')).toEqual('product');
10
- expect(FlexPLMUtils.convertTypePath('Product\\Apparel')).toEqual('product:apparel');
11
- expect(FlexPLMUtils.convertTypePath('Product\\Skin Care')).toEqual('product:skin_care');
12
- expect(FlexPLMUtils.convertTypePath('Product\\Apparel\\Shirt')).toEqual('product:apparel:shirt');
13
- expect(FlexPLMUtils.convertTypePath('Product\\Apparel\\[Shirt]')).toEqual('product:apparel:*shirt*');
14
- expect(FlexPLMUtils.convertTypePath('')).toBeNull();
15
- });
16
- it('should compute level in tree', () => {
17
- expect(FlexPLMUtils.computeLevelFromPath('product')).toEqual(1);
18
- expect(FlexPLMUtils.computeLevelFromPath('product:apparel')).toEqual(2);
19
- expect(FlexPLMUtils.computeLevelFromPath('product:apparel:dress:mini')).toEqual(4);
20
- });
21
- it('should get a parent type path', () => {
22
- expect(FlexPLMUtils.getParentTypePath('product')).toBeNull();
23
- expect(FlexPLMUtils.getParentTypePath('product:apparel')).toEqual('product');
24
- expect(FlexPLMUtils.getParentTypePath('product:apparel:stuff')).toEqual('product:apparel');
25
- expect(FlexPLMUtils.getParentTypePath('Product\\Apparel')).toEqual('product');
26
- });
27
- });
1
+ import { FlexPLMUtils } from './flexplm-utils';
2
+
3
+ describe('Types Controller', () => {
4
+
5
+ beforeEach(async () => {
6
+ });
7
+
8
+ it('should convert a type path', () => {
9
+ expect(FlexPLMUtils.convertTypePath('Product')).toEqual('product');
10
+ expect(FlexPLMUtils.convertTypePath('Product\\Apparel')).toEqual('product:apparel');
11
+ expect(FlexPLMUtils.convertTypePath('Product\\Skin Care')).toEqual('product:skin_care');
12
+ expect(FlexPLMUtils.convertTypePath('Product\\Apparel\\Shirt')).toEqual('product:apparel:shirt');
13
+ expect(FlexPLMUtils.convertTypePath('Product\\Apparel\\[Shirt]')).toEqual('product:apparel:*shirt*');
14
+ expect(FlexPLMUtils.convertTypePath('')).toBeNull();
15
+ });
16
+ it('should compute level in tree', () => {
17
+ expect(FlexPLMUtils.computeLevelFromPath('product')).toEqual(1);
18
+ expect(FlexPLMUtils.computeLevelFromPath('product:apparel')).toEqual(2);
19
+ expect(FlexPLMUtils.computeLevelFromPath('product:apparel:dress:mini')).toEqual(4);
20
+ });
21
+ it('should get a parent type path', () => {
22
+ expect(FlexPLMUtils.getParentTypePath('product')).toBeNull();
23
+ expect(FlexPLMUtils.getParentTypePath('product:apparel')).toEqual('product');
24
+ expect(FlexPLMUtils.getParentTypePath('product:apparel:stuff')).toEqual('product:apparel');
25
+ expect(FlexPLMUtils.getParentTypePath('Product\\Apparel')).toEqual('product');
26
+ });
27
+ });
@@ -1,29 +1,29 @@
1
- export class FlexPLMUtils {
2
- static convertTypePath = (path: string): string => {
3
- if (!path) { return null; }
4
- let newPath = path;
5
- while (newPath.indexOf('\\') > 1) {
6
- newPath = newPath.replace('\\', ':');
7
- }
8
- while (newPath.indexOf('[') > 1) {
9
- newPath = newPath.replace('[', '*');
10
- }
11
- while (newPath.indexOf(']') > 1) {
12
- newPath = newPath.replace(']', '*');
13
- }
14
- while (newPath.indexOf(' ') > 1) {
15
- newPath = newPath.replace(' ', '_');
16
- }
17
- newPath = newPath.toLowerCase();
18
- return newPath;
19
- }
20
-
21
- static getParentTypePath = (path: string): string => {
22
- const newPath = FlexPLMUtils.convertTypePath(path);
23
- return (!newPath || newPath.indexOf(':') < 0) ? null : newPath.substring(0, newPath.lastIndexOf(':'));
24
- }
25
-
26
- static computeLevelFromPath(path: string) {
27
- return (path.match(/:/g) || []).length + 1;
28
- }
29
- }
1
+ export class FlexPLMUtils {
2
+ static convertTypePath = (path: string): string => {
3
+ if (!path) { return null; }
4
+ let newPath = path;
5
+ while (newPath.indexOf('\\') > 1) {
6
+ newPath = newPath.replace('\\', ':');
7
+ }
8
+ while (newPath.indexOf('[') > 1) {
9
+ newPath = newPath.replace('[', '*');
10
+ }
11
+ while (newPath.indexOf(']') > 1) {
12
+ newPath = newPath.replace(']', '*');
13
+ }
14
+ while (newPath.indexOf(' ') > 1) {
15
+ newPath = newPath.replace(' ', '_');
16
+ }
17
+ newPath = newPath.toLowerCase();
18
+ return newPath;
19
+ }
20
+
21
+ static getParentTypePath = (path: string): string => {
22
+ const newPath = FlexPLMUtils.convertTypePath(path);
23
+ return (!newPath || newPath.indexOf(':') < 0) ? null : newPath.substring(0, newPath.lastIndexOf(':'));
24
+ }
25
+
26
+ static computeLevelFromPath(path: string) {
27
+ return (path.match(/:/g) || []).length + 1;
28
+ }
29
+ }
package/src/index.ts CHANGED
@@ -1,22 +1,22 @@
1
- export * from './flexplm-request';
2
- export * from './flexplm-utils';
3
- export * from './util/config-defaults';
4
- export * from './util/data-converter';
5
- export * from './util/error-response-object';
6
- export * from './util/event-short-message-status';
7
- export * from './util/federation';
8
- export * from './util/flexplm-connect';
9
- export * from './interfaces/interfaces';
10
- export * from './util/logger-config';
11
- export * from './util/thumbnail-util';
12
- export * from './util/type-conversion-utils';
13
- export * from './util/type-defaults';
14
- export * from './util/type-utils';
15
- export * from './util/map-utils';
16
- export * from './interfaces/interfaces';
17
- export * from './interfaces/item-family-changes';
18
- export * from './interfaces/publish-change-data';
19
- export * from './publish/base-process-publish-assortment';
20
- export * from './publish/base-process-publish-assortment-callback';
21
- export * from './entity-processor/base-entity-processor';
1
+ export * from './flexplm-request';
2
+ export * from './flexplm-utils';
3
+ export * from './util/config-defaults';
4
+ export * from './util/data-converter';
5
+ export * from './util/error-response-object';
6
+ export * from './util/event-short-message-status';
7
+ export * from './util/federation';
8
+ export * from './util/flexplm-connect';
9
+ export * from './interfaces/interfaces';
10
+ export * from './util/logger-config';
11
+ export * from './util/thumbnail-util';
12
+ export * from './util/type-conversion-utils';
13
+ export * from './util/type-defaults';
14
+ export * from './util/type-utils';
15
+ export * from './util/map-utils';
16
+ export * from './interfaces/interfaces';
17
+ export * from './interfaces/item-family-changes';
18
+ export * from './interfaces/publish-change-data';
19
+ export * from './publish/base-process-publish-assortment';
20
+ export * from './publish/base-process-publish-assortment-callback';
21
+ export * from './entity-processor/base-entity-processor';
22
22
  export * from './transform/identifier-conversion';
@@ -1,67 +1,67 @@
1
- export class ItemFamilyChanges {
2
- private _itemFamilyId:string;
3
- public get itemFamilyId(){ return this._itemFamilyId; }
4
- private _sinceDate:Date;
5
- public get sinceDate(){ return this._sinceDate; }
6
-
7
- familyAdd = false;
8
- familyDelete = false;
9
- familyUpdate = false;
10
- familyItemRemoved = false;
11
- itemFamilyObject = undefined;
12
-
13
- colorAdds: string[] = [];
14
- colorDeletes: string[] = [];
15
- colorUpdates: string[] = [];
16
- colorUnchanged: string[] = [];
17
-
18
- assortmentItemFullChangeMap = new Map<string, any>();
19
- assortmentItemDeleteMap = new Map<string, any>();
20
- itemToFederatedIdMapping = new Map<string, string>();
21
- constructor(itemFamilyId: string, sinceDate: Date){
22
- this._itemFamilyId = itemFamilyId;
23
- this._sinceDate = sinceDate;
24
- }
25
-
26
- public toString(): string{
27
- let s = 'ItemFamilyChanges\n'
28
- + ' itemFamilyId: ' + this._itemFamilyId + '\n'
29
- + ' sinceDate: ' + this._sinceDate + '\n'
30
- + ' familyAdd: ' + this.familyAdd + '\n'
31
- + ' familyDelete: ' + this.familyDelete + '\n'
32
- + ' familyUpdate: ' + this.familyUpdate + '\n'
33
- + ' familyItemRemoved: ' + this.familyItemRemoved + '\n'
34
- ;
35
-
36
- s += ' colorAdds: ['+ this.colorAdds + ']\n';
37
-
38
- s += ' colorDeletes: ['+ this.colorDeletes + ']\n';
39
-
40
- s += ' colorUpdates: ['+ this.colorUpdates + ']\n';
41
-
42
- s += ' colorUnchanged: ['+ this.colorUnchanged + ']\n';
43
-
44
- s += 'assortmentItemFullChangeMap:\n';
45
- s += 'size: ' + this.assortmentItemFullChangeMap.size +'\n[';
46
- for(const key of this.assortmentItemFullChangeMap.keys()){
47
- s += key + ', ';
48
- }
49
- s += ']\n';
50
-
51
- s += 'assortmentItemDeleteMap:\n';
52
- s += 'size: ' + this.assortmentItemDeleteMap.size +'\n[';
53
- for(const key of this.assortmentItemDeleteMap.keys()){
54
- s += key + ', ';
55
- }
56
- s += ']\n';
57
-
58
- s += 'itemToFederatedIdMapping:\n';
59
- s += 'size: ' + this.itemToFederatedIdMapping.size +'\n[';
60
- for(const key of this.itemToFederatedIdMapping.keys()){
61
- s += key + ', ';
62
- }
63
- s += ']\n';
64
-
65
- return s;
66
- }
1
+ export class ItemFamilyChanges {
2
+ private _itemFamilyId:string;
3
+ public get itemFamilyId(){ return this._itemFamilyId; }
4
+ private _sinceDate:Date;
5
+ public get sinceDate(){ return this._sinceDate; }
6
+
7
+ familyAdd = false;
8
+ familyDelete = false;
9
+ familyUpdate = false;
10
+ familyItemRemoved = false;
11
+ itemFamilyObject = undefined;
12
+
13
+ colorAdds: string[] = [];
14
+ colorDeletes: string[] = [];
15
+ colorUpdates: string[] = [];
16
+ colorUnchanged: string[] = [];
17
+
18
+ assortmentItemFullChangeMap = new Map<string, any>();
19
+ assortmentItemDeleteMap = new Map<string, any>();
20
+ itemToFederatedIdMapping = new Map<string, string>();
21
+ constructor(itemFamilyId: string, sinceDate: Date){
22
+ this._itemFamilyId = itemFamilyId;
23
+ this._sinceDate = sinceDate;
24
+ }
25
+
26
+ public toString(): string{
27
+ let s = 'ItemFamilyChanges\n'
28
+ + ' itemFamilyId: ' + this._itemFamilyId + '\n'
29
+ + ' sinceDate: ' + this._sinceDate + '\n'
30
+ + ' familyAdd: ' + this.familyAdd + '\n'
31
+ + ' familyDelete: ' + this.familyDelete + '\n'
32
+ + ' familyUpdate: ' + this.familyUpdate + '\n'
33
+ + ' familyItemRemoved: ' + this.familyItemRemoved + '\n'
34
+ ;
35
+
36
+ s += ' colorAdds: ['+ this.colorAdds + ']\n';
37
+
38
+ s += ' colorDeletes: ['+ this.colorDeletes + ']\n';
39
+
40
+ s += ' colorUpdates: ['+ this.colorUpdates + ']\n';
41
+
42
+ s += ' colorUnchanged: ['+ this.colorUnchanged + ']\n';
43
+
44
+ s += 'assortmentItemFullChangeMap:\n';
45
+ s += 'size: ' + this.assortmentItemFullChangeMap.size +'\n[';
46
+ for(const key of this.assortmentItemFullChangeMap.keys()){
47
+ s += key + ', ';
48
+ }
49
+ s += ']\n';
50
+
51
+ s += 'assortmentItemDeleteMap:\n';
52
+ s += 'size: ' + this.assortmentItemDeleteMap.size +'\n[';
53
+ for(const key of this.assortmentItemDeleteMap.keys()){
54
+ s += key + ', ';
55
+ }
56
+ s += ']\n';
57
+
58
+ s += 'itemToFederatedIdMapping:\n';
59
+ s += 'size: ' + this.itemToFederatedIdMapping.size +'\n[';
60
+ for(const key of this.itemToFederatedIdMapping.keys()){
61
+ s += key + ', ';
62
+ }
63
+ s += ']\n';
64
+
65
+ return s;
66
+ }
67
67
  }
@@ -1,43 +1,43 @@
1
- import { SeasonFederation } from './interfaces';
2
- import { ItemFamilyChanges } from './item-family-changes';
3
-
4
- export class PublishChangeData {
5
-
6
- private _assortmentId: string;
7
- public get assortmentId(){ return this._assortmentId; }
8
- private _seasonFed: SeasonFederation;
9
- public get seasonFed() { return Object.assign({}, this._seasonFed); }
10
- private _assortmentPublishChangeId: string;
11
- public get assortmentPublishChangeId() { return this._assortmentPublishChangeId; }
12
- private _sinceDate: Date;
13
- public get sinceDate(){ return this._sinceDate; }
14
- private _publisher: object;
15
- public get publisher(){ return this._publisher; }
16
-
17
- itemToFederatedIdMapping: Map<string, string>;
18
- releasedForDevelopmentItemIds: string[] = [];
19
- itemFamilyChanges = new Map<string, ItemFamilyChanges>();
20
- constructor(_assortmentId: string, _seasonFed: SeasonFederation, _assortmentPublishChangeId: string, _sinceDate: Date, _publisher = {}) {
21
- this._assortmentId = _assortmentId;
22
- this._seasonFed = _seasonFed;
23
- this._assortmentPublishChangeId = _assortmentPublishChangeId;
24
- this._sinceDate = _sinceDate;
25
- this._publisher = _publisher;
26
- }
27
-
28
- toString(){
29
- let s = 'PublishChangeData\n'
30
- + 'assortmentId: ' + this._assortmentId + '\n'
31
- + 'seasonFed: ' + JSON.stringify(this._seasonFed) + '\n'
32
- + 'assortmentPublishChangeId: ' + this._assortmentPublishChangeId + '\n'
33
- ;
34
-
35
- s += ' itemToFederatedIdMapping: ' + JSON.stringify(Object.fromEntries(this.itemToFederatedIdMapping)) + '\n';
36
- s += 'itemFamilyChanges:\n';
37
- for(const [key, value] of this.itemFamilyChanges){
38
- s += ' ' + key + ' => ' + value.toString();
39
- }
40
- return s;
41
- }
42
-
1
+ import { SeasonFederation } from './interfaces';
2
+ import { ItemFamilyChanges } from './item-family-changes';
3
+
4
+ export class PublishChangeData {
5
+
6
+ private _assortmentId: string;
7
+ public get assortmentId(){ return this._assortmentId; }
8
+ private _seasonFed: SeasonFederation;
9
+ public get seasonFed() { return Object.assign({}, this._seasonFed); }
10
+ private _assortmentPublishChangeId: string;
11
+ public get assortmentPublishChangeId() { return this._assortmentPublishChangeId; }
12
+ private _sinceDate: Date;
13
+ public get sinceDate(){ return this._sinceDate; }
14
+ private _publisher: object;
15
+ public get publisher(){ return this._publisher; }
16
+
17
+ itemToFederatedIdMapping: Map<string, string>;
18
+ releasedForDevelopmentItemIds: string[] = [];
19
+ itemFamilyChanges = new Map<string, ItemFamilyChanges>();
20
+ constructor(_assortmentId: string, _seasonFed: SeasonFederation, _assortmentPublishChangeId: string, _sinceDate: Date, _publisher = {}) {
21
+ this._assortmentId = _assortmentId;
22
+ this._seasonFed = _seasonFed;
23
+ this._assortmentPublishChangeId = _assortmentPublishChangeId;
24
+ this._sinceDate = _sinceDate;
25
+ this._publisher = _publisher;
26
+ }
27
+
28
+ toString(){
29
+ let s = 'PublishChangeData\n'
30
+ + 'assortmentId: ' + this._assortmentId + '\n'
31
+ + 'seasonFed: ' + JSON.stringify(this._seasonFed) + '\n'
32
+ + 'assortmentPublishChangeId: ' + this._assortmentPublishChangeId + '\n'
33
+ ;
34
+
35
+ s += ' itemToFederatedIdMapping: ' + JSON.stringify(Object.fromEntries(this.itemToFederatedIdMapping)) + '\n';
36
+ s += 'itemFamilyChanges:\n';
37
+ for(const [key, value] of this.itemFamilyChanges){
38
+ s += ' ' + key + ' => ' + value.toString();
39
+ }
40
+ return s;
41
+ }
42
+
43
43
  }