@contrail/flexplm 1.3.0-alpha.0 → 1.3.0-alpha.3

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 (123) hide show
  1. package/.github/pull_request_template.md +31 -31
  2. package/.github/workflows/flexplm-lib.yml +27 -27
  3. package/CHANGELOG.md +1 -1
  4. package/lib/entity-processor/base-entity-processor.d.ts +42 -0
  5. package/lib/entity-processor/base-entity-processor.js +377 -0
  6. package/lib/entity-processor/base-entity-processor.spec.d.ts +1 -0
  7. package/lib/entity-processor/base-entity-processor.spec.js +426 -0
  8. package/lib/flexplm-request.d.ts +3 -0
  9. package/lib/flexplm-request.js +34 -0
  10. package/lib/flexplm-utils.d.ts +5 -0
  11. package/lib/flexplm-utils.js +33 -0
  12. package/lib/flexplm-utils.spec.d.ts +1 -0
  13. package/lib/flexplm-utils.spec.js +26 -0
  14. package/lib/index.d.ts +22 -0
  15. package/lib/index.js +38 -0
  16. package/lib/interfaces/interfaces.d.ts +105 -0
  17. package/lib/interfaces/interfaces.js +2 -0
  18. package/lib/interfaces/item-family-changes.d.ts +20 -0
  19. package/lib/interfaces/item-family-changes.js +56 -0
  20. package/lib/interfaces/publish-change-data.d.ts +19 -0
  21. package/lib/interfaces/publish-change-data.js +32 -0
  22. package/lib/publish/base-process-publish-assortment-callback.d.ts +9 -0
  23. package/lib/publish/base-process-publish-assortment-callback.js +38 -0
  24. package/lib/publish/base-process-publish-assortment.d.ts +93 -0
  25. package/lib/publish/base-process-publish-assortment.js +944 -0
  26. package/lib/publish/base-process-publish-assortment.spec.d.ts +1 -0
  27. package/lib/publish/base-process-publish-assortment.spec.js +1670 -0
  28. package/lib/publish/mockData.d.ts +1389 -0
  29. package/lib/publish/mockData.js +4519 -0
  30. package/lib/transform/identifier-conversion-spec-mockData.d.ts +0 -0
  31. package/lib/transform/identifier-conversion-spec-mockData.js +444 -0
  32. package/lib/transform/identifier-conversion.d.ts +15 -0
  33. package/lib/transform/identifier-conversion.js +212 -0
  34. package/lib/transform/identifier-conversion.spec.d.ts +1 -0
  35. package/lib/transform/identifier-conversion.spec.js +339 -0
  36. package/lib/util/config-defaults.d.ts +8 -0
  37. package/lib/util/config-defaults.js +85 -0
  38. package/lib/util/config-defaults.spec.d.ts +1 -0
  39. package/lib/util/config-defaults.spec.js +293 -0
  40. package/lib/util/data-converter-spec-mockData.d.ts +0 -0
  41. package/lib/util/data-converter-spec-mockData.js +205 -0
  42. package/lib/util/data-converter.d.ts +39 -0
  43. package/lib/util/data-converter.js +592 -0
  44. package/lib/util/data-converter.spec.d.ts +1 -0
  45. package/lib/util/data-converter.spec.js +904 -0
  46. package/lib/util/error-response-object.d.ts +4 -0
  47. package/lib/util/error-response-object.js +47 -0
  48. package/lib/util/error-response-object.spec.d.ts +1 -0
  49. package/lib/util/error-response-object.spec.js +99 -0
  50. package/lib/util/event-short-message-status.d.ts +18 -0
  51. package/lib/util/event-short-message-status.js +22 -0
  52. package/lib/util/federation.d.ts +15 -0
  53. package/lib/util/federation.js +149 -0
  54. package/lib/util/flexplm-connect.d.ts +22 -0
  55. package/lib/util/flexplm-connect.js +176 -0
  56. package/lib/util/flexplm-connect.spec.d.ts +1 -0
  57. package/lib/util/flexplm-connect.spec.js +88 -0
  58. package/lib/util/logger-config.d.ts +1 -0
  59. package/lib/util/logger-config.js +26 -0
  60. package/lib/util/map-util-spec-mockData.d.ts +0 -0
  61. package/lib/util/map-util-spec-mockData.js +205 -0
  62. package/lib/util/map-utils.d.ts +6 -0
  63. package/lib/util/map-utils.js +15 -0
  64. package/lib/util/map-utils.spec.d.ts +1 -0
  65. package/lib/util/map-utils.spec.js +89 -0
  66. package/lib/util/mockData.d.ts +79 -0
  67. package/lib/util/mockData.js +99 -0
  68. package/lib/util/thumbnail-util.d.ts +28 -0
  69. package/lib/util/thumbnail-util.js +202 -0
  70. package/lib/util/thumbnail-util.spec.d.ts +1 -0
  71. package/lib/util/thumbnail-util.spec.js +398 -0
  72. package/lib/util/type-conversion-utils-spec-mockData.d.ts +0 -0
  73. package/lib/util/type-conversion-utils-spec-mockData.js +259 -0
  74. package/lib/util/type-conversion-utils.d.ts +23 -0
  75. package/lib/util/type-conversion-utils.js +266 -0
  76. package/lib/util/type-conversion-utils.spec.d.ts +1 -0
  77. package/lib/util/type-conversion-utils.spec.js +868 -0
  78. package/lib/util/type-defaults.d.ts +16 -0
  79. package/lib/util/type-defaults.js +221 -0
  80. package/lib/util/type-defaults.spec.d.ts +1 -0
  81. package/lib/util/type-defaults.spec.js +516 -0
  82. package/lib/util/type-utils.d.ts +13 -0
  83. package/lib/util/type-utils.js +114 -0
  84. package/lib/util/type-utils.spec.d.ts +1 -0
  85. package/lib/util/type-utils.spec.js +190 -0
  86. package/package.json +1 -1
  87. package/publish.bat +4 -4
  88. package/publish.sh +4 -4
  89. package/src/entity-processor/base-entity-processor.spec.ts +157 -0
  90. package/src/entity-processor/base-entity-processor.ts +21 -2
  91. package/src/flexplm-request.ts +28 -28
  92. package/src/flexplm-utils.spec.ts +27 -27
  93. package/src/flexplm-utils.ts +29 -29
  94. package/src/index.ts +21 -21
  95. package/src/interfaces/item-family-changes.ts +66 -66
  96. package/src/interfaces/publish-change-data.ts +42 -42
  97. package/src/publish/base-process-publish-assortment-callback.ts +50 -50
  98. package/src/transform/identifier-conversion-spec-mockData.ts +495 -495
  99. package/src/transform/identifier-conversion.spec.ts +353 -353
  100. package/src/transform/identifier-conversion.ts +281 -281
  101. package/src/util/config-defaults.spec.ts +350 -350
  102. package/src/util/config-defaults.ts +92 -92
  103. package/src/util/data-converter-spec-mockData.ts +230 -230
  104. package/src/util/error-response-object.spec.ts +115 -115
  105. package/src/util/error-response-object.ts +49 -49
  106. package/src/util/federation.ts +172 -172
  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 +97 -97
  112. package/src/util/thumbnail-util.spec.ts +190 -0
  113. package/src/util/thumbnail-util.ts +109 -1
  114. package/src/util/type-conversion-utils.spec.ts +25 -25
  115. package/src/util/type-conversion-utils.ts +10 -9
  116. package/src/util/type-defaults.spec.ts +668 -668
  117. package/src/util/type-defaults.ts +280 -280
  118. package/src/util/type-utils.spec.ts +227 -227
  119. package/src/util/type-utils.ts +144 -144
  120. package/tsconfig.json +28 -26
  121. package/tslint.json +57 -57
  122. package/scripts/output.png +0 -0
  123. package/scripts/test-get-request.ts +0 -35
@@ -0,0 +1,190 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const type_utils_1 = require("./type-utils");
4
+ describe('TypeUtils.getEventObjectClass() tests', () => {
5
+ const tu = new type_utils_1.TypeUtils();
6
+ it('LCSProduct', () => {
7
+ const entityType = 'item';
8
+ const newData = {
9
+ roles: ['family']
10
+ };
11
+ const objectClass = tu.getEventObjectClass(entityType, newData);
12
+ expect(objectClass).toEqual('LCSProduct');
13
+ });
14
+ it('LCSSKU', () => {
15
+ const entityType = 'item';
16
+ const newData = {
17
+ roles: ['color']
18
+ };
19
+ const objectClass = tu.getEventObjectClass(entityType, newData);
20
+ expect(objectClass).toEqual('LCSSKU');
21
+ });
22
+ it('LCSProductSeasonLink', () => {
23
+ const entityType = 'project-item';
24
+ const newData = {
25
+ roles: ['family']
26
+ };
27
+ const objectClass = tu.getEventObjectClass(entityType, newData);
28
+ expect(objectClass).toEqual('LCSProductSeasonLink');
29
+ });
30
+ it('LCSSKUSeasonLink', () => {
31
+ const entityType = 'project-item';
32
+ const newData = {
33
+ roles: ['color']
34
+ };
35
+ const objectClass = tu.getEventObjectClass(entityType, newData);
36
+ expect(objectClass).toEqual('LCSSKUSeasonLink');
37
+ });
38
+ it('LCSColor', () => {
39
+ const entityType = 'color';
40
+ const newData = {};
41
+ const objectClass = tu.getEventObjectClass(entityType, newData);
42
+ expect(objectClass).toEqual('LCSColor');
43
+ });
44
+ it('LCSRevisableEntity', () => {
45
+ const entityType = 'custom-entity';
46
+ const newData = {};
47
+ const objectClass = tu.getEventObjectClass(entityType, newData);
48
+ expect(objectClass).toEqual('LCSRevisableEntity');
49
+ });
50
+ });
51
+ describe('filterProperties-item', () => {
52
+ const itemType = {
53
+ typePath: 'item'
54
+ };
55
+ itemType['typeProperties'] = [
56
+ {
57
+ id: 'H4NazLloHdUVhc71',
58
+ slug: 'null',
59
+ propertyLevel: null
60
+ },
61
+ {
62
+ id: 'H4NazLloHdUVhc71',
63
+ slug: 'family',
64
+ propertyLevel: 'family'
65
+ },
66
+ {
67
+ id: 'H4NazLloHdUVhc71',
68
+ slug: 'option',
69
+ propertyLevel: 'option'
70
+ },
71
+ {
72
+ id: 'H4NazLloHdUVhc71',
73
+ slug: 'overridable',
74
+ propertyLevel: 'overridable'
75
+ },
76
+ {
77
+ id: 'H4NazLloHdUVhc71',
78
+ slug: 'all',
79
+ propertyLevel: 'all'
80
+ },
81
+ ];
82
+ const tu = new type_utils_1.TypeUtils();
83
+ it('item-family', () => {
84
+ const len = 4;
85
+ const newData = {
86
+ roles: ['family']
87
+ };
88
+ const filteredProps = tu.filterTypeProperties(itemType, newData);
89
+ expect(filteredProps.length).toEqual(len);
90
+ });
91
+ it('item-option', () => {
92
+ const len = 4;
93
+ const newData = {
94
+ roles: ['option']
95
+ };
96
+ const filteredProps = tu.filterTypeProperties(itemType, newData);
97
+ expect(filteredProps.length).toEqual(len);
98
+ });
99
+ it('item-no-roles', () => {
100
+ const len = 5;
101
+ const newData = {};
102
+ const filteredProps = tu.filterTypeProperties(itemType, newData);
103
+ expect(filteredProps.length).toEqual(len);
104
+ });
105
+ });
106
+ describe('filterProperties-project-item', () => {
107
+ const projectItemType = {
108
+ typePath: 'project-item'
109
+ };
110
+ projectItemType['typeProperties'] = [
111
+ {
112
+ id: 'H4NazLloHdUVhc71',
113
+ slug: 'null',
114
+ propertyLevel: null
115
+ },
116
+ {
117
+ id: 'H4NazLloHdUVhc71',
118
+ slug: 'family',
119
+ propertyLevel: 'family'
120
+ },
121
+ {
122
+ id: 'H4NazLloHdUVhc71',
123
+ slug: 'option',
124
+ propertyLevel: 'option'
125
+ },
126
+ {
127
+ id: 'H4NazLloHdUVhc71',
128
+ slug: 'overridable',
129
+ propertyLevel: 'overridable'
130
+ },
131
+ {
132
+ id: 'H4NazLloHdUVhc71',
133
+ slug: 'all',
134
+ propertyLevel: 'all'
135
+ },
136
+ ];
137
+ const tu = new type_utils_1.TypeUtils();
138
+ it('item-family', () => {
139
+ const len = 4;
140
+ const newData = {
141
+ roles: ['family']
142
+ };
143
+ const filteredProps = tu.filterTypeProperties(projectItemType, newData);
144
+ expect(filteredProps.length).toEqual(len);
145
+ });
146
+ it('item-option', () => {
147
+ const len = 4;
148
+ const newData = {
149
+ roles: ['option']
150
+ };
151
+ const filteredProps = tu.filterTypeProperties(projectItemType, newData);
152
+ expect(filteredProps.length).toEqual(len);
153
+ });
154
+ });
155
+ describe('filterProperties-color', () => {
156
+ const colorType = {
157
+ typePath: 'color'
158
+ };
159
+ colorType['typeProperties'] = [
160
+ {
161
+ id: 'H4NazLloHdUVhc71',
162
+ slug: 'null',
163
+ },
164
+ {
165
+ id: 'H4NazLloHdUVhc71',
166
+ slug: 'family',
167
+ },
168
+ {
169
+ id: 'H4NazLloHdUVhc71',
170
+ slug: 'option',
171
+ },
172
+ {
173
+ id: 'H4NazLloHdUVhc71',
174
+ slug: 'overridable',
175
+ },
176
+ {
177
+ id: 'H4NazLloHdUVhc71',
178
+ slug: 'all',
179
+ },
180
+ ];
181
+ const tu = new type_utils_1.TypeUtils();
182
+ it('color', () => {
183
+ const len = 5;
184
+ const newData = {
185
+ roles: ['family']
186
+ };
187
+ const filteredProps = tu.filterTypeProperties(colorType, newData);
188
+ expect(filteredProps.length).toEqual(len);
189
+ });
190
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/flexplm",
3
- "version": "1.3.0-alpha.0",
3
+ "version": "1.3.0-alpha.3",
4
4
  "description": "Library used for integration with flexplm.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
package/publish.bat CHANGED
@@ -1,5 +1,5 @@
1
- rd /s /q lib
2
- call npm install
3
- call npm run build
4
- call npm version patch
1
+ rd /s /q lib
2
+ call npm install
3
+ call npm run build
4
+ call npm version patch
5
5
  call npm publish
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,159 @@ 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 updateEntity with thumbnail updates 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
+ const updateEntitySpy = jest.spyOn(btep, 'updateEntity').mockResolvedValue(mockCreatedEntity);
367
+ syncInboundImagesSpy.mockResolvedValue(true);
368
+ const thumbnailUpdates = { primaryViewableId: 'pv-new', primaryFileUrl: 'https://files/new.png' };
369
+ syncThumbnailSpy.mockResolvedValue(thumbnailUpdates);
370
+
371
+ const result = await btep.handleIncomingUpsert(mockEvent);
372
+
373
+ expect(syncThumbnailSpy).toBeCalledTimes(1);
374
+ expect(syncThumbnailSpy).toBeCalledWith({ entityId: 'created-1', primaryViewableId: 'pv-created', event: mockEvent, entityName: 'test' });
375
+ expect(updateEntitySpy).toBeCalledWith('test', mockCreatedEntity, thumbnailUpdates);
376
+ expect(result).toBe(mockCreatedEntity);
377
+ });
378
+
379
+ it('should not call updateEntity after create when syncThumbnailToVibeIQ returns undefined', async () =>{
380
+ jest.spyOn(btep, 'getIncomingEntity' as any).mockResolvedValue({ entity: null });
381
+ jest.spyOn(btep, 'getCreateEntity' as any).mockResolvedValue({ entity: { name: 'new' } });
382
+ jest.spyOn(btep, 'createEntity').mockResolvedValue(mockCreatedEntity);
383
+ const updateEntitySpy = jest.spyOn(btep, 'updateEntity');
384
+ syncInboundImagesSpy.mockResolvedValue(true);
385
+ syncThumbnailSpy.mockResolvedValue(undefined);
386
+
387
+ const result = await btep.handleIncomingUpsert(mockEvent);
388
+
389
+ expect(syncThumbnailSpy).toBeCalledTimes(1);
390
+ expect(updateEntitySpy).not.toHaveBeenCalled();
391
+ expect(result).toBe(mockCreatedEntity);
392
+ });
393
+
394
+ it('should not sync images after create when syncInboundImages returns false', async () =>{
395
+ jest.spyOn(btep, 'getIncomingEntity' as any).mockResolvedValue({ entity: null });
396
+ jest.spyOn(btep, 'getCreateEntity' as any).mockResolvedValue({ entity: { name: 'new' } });
397
+ jest.spyOn(btep, 'createEntity').mockResolvedValue(mockCreatedEntity);
398
+ syncInboundImagesSpy.mockResolvedValue(false);
399
+
400
+ const result = await btep.handleIncomingUpsert(mockEvent);
401
+
402
+ expect(syncInboundImagesSpy).toBeCalledTimes(1);
403
+ expect(syncThumbnailSpy).toBeCalledTimes(0);
404
+ expect(result).toBe(mockCreatedEntity);
405
+ });
406
+
407
+ it('should merge thumbnail updates with property diffs on update', async () =>{
408
+ jest.spyOn(btep, 'getIncomingEntity' as any).mockResolvedValue({ entity: mockExistingEntity });
409
+ jest.spyOn(btep, 'getUpdatesForEntity').mockResolvedValue({ name: 'changed' });
410
+ const updateEntitySpy = jest.spyOn(btep, 'updateEntity').mockResolvedValue(mockUpdatedEntity);
411
+ syncInboundImagesSpy.mockResolvedValue(true);
412
+ const thumbnailUpdates = { primaryViewableId: 'pv-new' };
413
+ syncThumbnailSpy.mockResolvedValue(thumbnailUpdates);
414
+
415
+ const result = await btep.handleIncomingUpsert(mockEvent);
416
+
417
+ expect(syncThumbnailSpy).toBeCalledTimes(1);
418
+ expect(syncThumbnailSpy).toBeCalledWith({ entityId: 'existing-1', primaryViewableId: undefined, event: mockEvent, entityName: 'test' });
419
+ expect(updateEntitySpy).toBeCalledWith('test', mockExistingEntity, { name: 'changed', primaryViewableId: 'pv-new' });
420
+ expect(result).toBe(mockUpdatedEntity);
421
+ });
422
+
423
+ it('should update entity with only thumbnail changes when no property diffs', async () =>{
424
+ jest.spyOn(btep, 'getIncomingEntity' as any).mockResolvedValue({ entity: mockExistingEntity });
425
+ jest.spyOn(btep, 'getUpdatesForEntity').mockResolvedValue({});
426
+ const updateEntitySpy = jest.spyOn(btep, 'updateEntity').mockResolvedValue(mockUpdatedEntity);
427
+ syncInboundImagesSpy.mockResolvedValue(true);
428
+ const thumbnailUpdates = { primaryViewableId: 'pv-new' };
429
+ syncThumbnailSpy.mockResolvedValue(thumbnailUpdates);
430
+
431
+ const result = await btep.handleIncomingUpsert(mockEvent);
432
+
433
+ expect(updateEntitySpy).toBeCalledWith('test', mockExistingEntity, { primaryViewableId: 'pv-new' });
434
+ expect(result).toBe(mockUpdatedEntity);
435
+ });
436
+
437
+ it('should not sync images on update when syncInboundImages returns false', async () =>{
438
+ jest.spyOn(btep, 'getIncomingEntity' as any).mockResolvedValue({ entity: mockExistingEntity });
439
+ jest.spyOn(btep, 'getUpdatesForEntity').mockResolvedValue({ name: 'changed' });
440
+ jest.spyOn(btep, 'updateEntity').mockResolvedValue(mockUpdatedEntity);
441
+ syncInboundImagesSpy.mockResolvedValue(false);
442
+
443
+ const result = await btep.handleIncomingUpsert(mockEvent);
444
+
445
+ expect(syncInboundImagesSpy).toBeCalledTimes(1);
446
+ expect(syncThumbnailSpy).toBeCalledTimes(0);
447
+ expect(result).toBe(mockUpdatedEntity);
448
+ });
449
+
450
+ it('should not sync images on early return from getIncomingEntity', async () =>{
451
+ jest.spyOn(btep, 'getIncomingEntity' as any).mockResolvedValue({
452
+ earlyReturn: { status: 400, data: { message: 'error' }, shortStatusMessage: 'FAIL' }
453
+ });
454
+
455
+ await btep.handleIncomingUpsert(mockEvent);
456
+
457
+ expect(syncInboundImagesSpy).toBeCalledTimes(0);
458
+ expect(syncThumbnailSpy).toBeCalledTimes(0);
459
+ });
460
+
461
+ it('should not sync images on early return from getCreateEntity', async () =>{
462
+ jest.spyOn(btep, 'getIncomingEntity' as any).mockResolvedValue({ entity: null });
463
+ jest.spyOn(btep, 'getCreateEntity' as any).mockResolvedValue({
464
+ earlyReturn: { status: 400, data: { message: 'not creatable' }, shortStatusMessage: 'NOT_CREATABLE' }
465
+ });
466
+
467
+ await btep.handleIncomingUpsert(mockEvent);
468
+
469
+ expect(syncInboundImagesSpy).toBeCalledTimes(0);
470
+ expect(syncThumbnailSpy).toBeCalledTimes(0);
471
+ });
472
+
473
+ it('should return no changes when no property diffs and no thumbnail updates', async () =>{
474
+ jest.spyOn(btep, 'getIncomingEntity' as any).mockResolvedValue({ entity: mockExistingEntity });
475
+ jest.spyOn(btep, 'getUpdatesForEntity').mockResolvedValue({});
476
+ syncInboundImagesSpy.mockResolvedValue(true);
477
+ syncThumbnailSpy.mockResolvedValue(undefined);
478
+
479
+ const result = await btep.handleIncomingUpsert(mockEvent);
480
+
481
+ expect(result).toEqual({ status: 200, data: { message: 'No Changes to persist for entity: existing-1' } });
482
+ });
483
+
484
+ it('should return no changes when syncInboundImages is false and no property diffs', async () =>{
485
+ jest.spyOn(btep, 'getIncomingEntity' as any).mockResolvedValue({ entity: mockExistingEntity });
486
+ jest.spyOn(btep, 'getUpdatesForEntity').mockResolvedValue({});
487
+ syncInboundImagesSpy.mockResolvedValue(false);
488
+
489
+ const result = await btep.handleIncomingUpsert(mockEvent);
490
+
491
+ expect(result).toEqual({ status: 200, data: { message: 'No Changes to persist for entity: existing-1' } });
492
+ });
493
+ });
494
+
338
495
  });
@@ -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.';
@@ -84,6 +85,15 @@ export abstract class BaseEntityProcessor {
84
85
  return createEntityResponse.earlyReturn;
85
86
  }
86
87
  const 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
+ const thumbnailUpdates = await new ThumbnailUtil(this.config).syncThumbnailToVibeIQ({ entityId: createdEntity.id, primaryViewableId: createdEntity.primaryViewableId, event, entityName: this.baseType });
93
+ if (thumbnailUpdates) {
94
+ await this.updateEntity(this.baseType, createdEntity, thumbnailUpdates);
95
+ }
96
+ }
87
97
  const statusMsg = this.getInboundStatusMessage({
88
98
  status: EventShortMessageStatus.SUCCESS,
89
99
  statusMessage: EventShortMessageStatus.CREATED,
@@ -96,7 +106,16 @@ export abstract class BaseEntityProcessor {
96
106
  }
97
107
 
98
108
  const diffs = await this.getUpdatesForEntity(entity, inboundData);
99
- if(Object.getOwnPropertyNames(diffs).length == 0){
109
+ const shouldSyncThumbnail = await TypeConversionUtils.syncInboundImages(
110
+ this.transformMapFile, this.mapFileUtil, event.data
111
+ );
112
+ let thumbnailUpdates;
113
+ if (shouldSyncThumbnail) {
114
+ thumbnailUpdates = await new ThumbnailUtil(this.config).syncThumbnailToVibeIQ({ entityId: entity.id, primaryViewableId: entity.primaryViewableId, event, entityName: this.baseType });
115
+ }
116
+
117
+ const allUpdates = { ...diffs, ...thumbnailUpdates };
118
+ if(Object.getOwnPropertyNames(allUpdates).length == 0){
100
119
  const statusMsg = this.getInboundStatusMessage({
101
120
  status: EventShortMessageStatus.SUCCESS,
102
121
  statusMessage: EventShortMessageStatus.NO_CHANGES,
@@ -112,7 +131,7 @@ export abstract class BaseEntityProcessor {
112
131
  };
113
132
  }
114
133
 
115
- const updatedEntity = await this.updateEntity(this.baseType, entity, diffs);
134
+ const updatedEntity = await this.updateEntity(this.baseType, entity, allUpdates);
116
135
  const statusMsg = this.getInboundStatusMessage({
117
136
  status: EventShortMessageStatus.SUCCESS,
118
137
  statusMessage: EventShortMessageStatus.UPDATED,
@@ -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';