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

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 (88) hide show
  1. package/package.json +1 -1
  2. package/scripts/output.png +0 -0
  3. package/scripts/test-get-request.ts +35 -0
  4. package/src/util/flexplm-connect.spec.ts +132 -0
  5. package/src/util/flexplm-connect.ts +14 -5
  6. package/src/util/type-conversion-utils-spec-mockData.ts +18 -0
  7. package/src/util/type-conversion-utils.spec.ts +184 -0
  8. package/src/util/type-conversion-utils.ts +74 -0
  9. package/lib/entity-processor/base-entity-processor.d.ts +0 -42
  10. package/lib/entity-processor/base-entity-processor.js +0 -363
  11. package/lib/entity-processor/base-entity-processor.spec.d.ts +0 -1
  12. package/lib/entity-processor/base-entity-processor.spec.js +0 -302
  13. package/lib/flexplm-request.d.ts +0 -3
  14. package/lib/flexplm-request.js +0 -34
  15. package/lib/flexplm-utils.d.ts +0 -5
  16. package/lib/flexplm-utils.js +0 -33
  17. package/lib/flexplm-utils.spec.d.ts +0 -1
  18. package/lib/flexplm-utils.spec.js +0 -26
  19. package/lib/index.d.ts +0 -22
  20. package/lib/index.js +0 -38
  21. package/lib/interfaces/interfaces.d.ts +0 -105
  22. package/lib/interfaces/interfaces.js +0 -2
  23. package/lib/interfaces/item-family-changes.d.ts +0 -20
  24. package/lib/interfaces/item-family-changes.js +0 -56
  25. package/lib/interfaces/publish-change-data.d.ts +0 -19
  26. package/lib/interfaces/publish-change-data.js +0 -32
  27. package/lib/publish/base-process-publish-assortment-callback.d.ts +0 -9
  28. package/lib/publish/base-process-publish-assortment-callback.js +0 -38
  29. package/lib/publish/base-process-publish-assortment.d.ts +0 -93
  30. package/lib/publish/base-process-publish-assortment.js +0 -944
  31. package/lib/publish/base-process-publish-assortment.spec.d.ts +0 -1
  32. package/lib/publish/base-process-publish-assortment.spec.js +0 -1670
  33. package/lib/publish/mockData.d.ts +0 -1389
  34. package/lib/publish/mockData.js +0 -4519
  35. package/lib/transform/identifier-conversion-spec-mockData.d.ts +0 -0
  36. package/lib/transform/identifier-conversion-spec-mockData.js +0 -444
  37. package/lib/transform/identifier-conversion.d.ts +0 -15
  38. package/lib/transform/identifier-conversion.js +0 -212
  39. package/lib/transform/identifier-conversion.spec.d.ts +0 -1
  40. package/lib/transform/identifier-conversion.spec.js +0 -339
  41. package/lib/util/config-defaults.d.ts +0 -8
  42. package/lib/util/config-defaults.js +0 -85
  43. package/lib/util/config-defaults.spec.d.ts +0 -1
  44. package/lib/util/config-defaults.spec.js +0 -293
  45. package/lib/util/data-converter-spec-mockData.d.ts +0 -0
  46. package/lib/util/data-converter-spec-mockData.js +0 -205
  47. package/lib/util/data-converter.d.ts +0 -39
  48. package/lib/util/data-converter.js +0 -592
  49. package/lib/util/data-converter.spec.d.ts +0 -1
  50. package/lib/util/data-converter.spec.js +0 -904
  51. package/lib/util/error-response-object.d.ts +0 -4
  52. package/lib/util/error-response-object.js +0 -47
  53. package/lib/util/error-response-object.spec.d.ts +0 -1
  54. package/lib/util/error-response-object.spec.js +0 -99
  55. package/lib/util/event-short-message-status.d.ts +0 -18
  56. package/lib/util/event-short-message-status.js +0 -22
  57. package/lib/util/federation.d.ts +0 -15
  58. package/lib/util/federation.js +0 -149
  59. package/lib/util/flexplm-connect.d.ts +0 -18
  60. package/lib/util/flexplm-connect.js +0 -171
  61. package/lib/util/logger-config.d.ts +0 -1
  62. package/lib/util/logger-config.js +0 -26
  63. package/lib/util/map-util-spec-mockData.d.ts +0 -0
  64. package/lib/util/map-util-spec-mockData.js +0 -205
  65. package/lib/util/map-utils.d.ts +0 -6
  66. package/lib/util/map-utils.js +0 -15
  67. package/lib/util/map-utils.spec.d.ts +0 -1
  68. package/lib/util/map-utils.spec.js +0 -89
  69. package/lib/util/mockData.d.ts +0 -79
  70. package/lib/util/mockData.js +0 -99
  71. package/lib/util/thumbnail-util.d.ts +0 -19
  72. package/lib/util/thumbnail-util.js +0 -114
  73. package/lib/util/thumbnail-util.spec.d.ts +0 -1
  74. package/lib/util/thumbnail-util.spec.js +0 -242
  75. package/lib/util/type-conversion-utils-spec-mockData.d.ts +0 -0
  76. package/lib/util/type-conversion-utils-spec-mockData.js +0 -241
  77. package/lib/util/type-conversion-utils.d.ts +0 -21
  78. package/lib/util/type-conversion-utils.js +0 -223
  79. package/lib/util/type-conversion-utils.spec.d.ts +0 -1
  80. package/lib/util/type-conversion-utils.spec.js +0 -708
  81. package/lib/util/type-defaults.d.ts +0 -16
  82. package/lib/util/type-defaults.js +0 -221
  83. package/lib/util/type-defaults.spec.d.ts +0 -1
  84. package/lib/util/type-defaults.spec.js +0 -516
  85. package/lib/util/type-utils.d.ts +0 -13
  86. package/lib/util/type-utils.js +0 -114
  87. package/lib/util/type-utils.spec.d.ts +0 -1
  88. package/lib/util/type-utils.spec.js +0 -190
@@ -1,363 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BaseEntityProcessor = exports.IncomingEntityResponse = void 0;
4
- const type_utils_1 = require("../util/type-utils");
5
- const flexplm_connect_1 = require("../util/flexplm-connect");
6
- const map_utils_1 = require("../util/map-utils");
7
- const sdk_1 = require("@contrail/sdk");
8
- const type_conversion_utils_1 = require("../util/type-conversion-utils");
9
- const event_short_message_status_1 = require("../util/event-short-message-status");
10
- const UNSUPPORTED_TYPE = 'Unsupported eventType.';
11
- class IncomingEntityResponse {
12
- }
13
- exports.IncomingEntityResponse = IncomingEntityResponse;
14
- class BaseEntityProcessor {
15
- constructor(config, dc, mapFileUtil, baseType) {
16
- this.config = config;
17
- this.dc = dc;
18
- this.mapFileUtil = mapFileUtil;
19
- this.baseType = baseType;
20
- this.typeUtil = new type_utils_1.TypeUtils();
21
- this.transformMapFile = this.config?.transformMapFile;
22
- this.entities = new sdk_1.Entities();
23
- this.orgSlug = this.config?.orgSlug || 'unset-orgSlug';
24
- }
25
- async inbound(event) {
26
- const eventType = event.eventType;
27
- console.log(`inbound entity: ${eventType}:${event.objectClass}`);
28
- switch (eventType) {
29
- case 'PERSIST':
30
- return await this.handleIncomingUpsert(event);
31
- case 'DELETE':
32
- return await this.handleIncomingDelete(event);
33
- default:
34
- console.error(UNSUPPORTED_TYPE);
35
- return {
36
- status: 500,
37
- data: { UNSUPPORTED_TYPE }
38
- };
39
- }
40
- }
41
- async handleIncomingUpsert(event) {
42
- const inboundData = await this.getTransformedData(event);
43
- const incomingEntityResponse = await this.getIncomingEntity(event, inboundData);
44
- if (incomingEntityResponse.earlyReturn) {
45
- const statusMsg = this.getInboundStatusMessage({
46
- status: event_short_message_status_1.EventShortMessageStatus.FAILURE,
47
- statusMessage: incomingEntityResponse.earlyReturn.shortStatusMessage || '',
48
- objectClass: event.objectClass,
49
- federatedId: event.federatedId
50
- });
51
- console.log(statusMsg);
52
- return incomingEntityResponse.earlyReturn;
53
- }
54
- const entity = incomingEntityResponse.entity;
55
- if (!entity) {
56
- const createEntityResponse = await this.getCreateEntity(inboundData);
57
- if (createEntityResponse.earlyReturn) {
58
- const status = (createEntityResponse.earlyReturn.shortStatusMessage === event_short_message_status_1.EventShortMessageStatus.NOT_CREATABLE)
59
- ? event_short_message_status_1.EventShortMessageStatus.SUCCESS
60
- : event_short_message_status_1.EventShortMessageStatus.FAILURE;
61
- const statusMsg = this.getInboundStatusMessage({
62
- status,
63
- statusMessage: createEntityResponse.earlyReturn.shortStatusMessage || '',
64
- objectClass: event.objectClass,
65
- federatedId: event.federatedId
66
- });
67
- console.log(statusMsg);
68
- return createEntityResponse.earlyReturn;
69
- }
70
- const createdEntity = await this.createEntity(this.baseType, createEntityResponse.entity);
71
- const statusMsg = this.getInboundStatusMessage({
72
- status: event_short_message_status_1.EventShortMessageStatus.SUCCESS,
73
- statusMessage: event_short_message_status_1.EventShortMessageStatus.CREATED,
74
- objectClass: event.objectClass,
75
- entityId: 'id',
76
- federatedId: event.federatedId
77
- });
78
- console.log(statusMsg);
79
- return createdEntity;
80
- }
81
- const diffs = await this.getUpdatesForEntity(entity, inboundData);
82
- if (Object.getOwnPropertyNames(diffs).length == 0) {
83
- const statusMsg = this.getInboundStatusMessage({
84
- status: event_short_message_status_1.EventShortMessageStatus.SUCCESS,
85
- statusMessage: event_short_message_status_1.EventShortMessageStatus.NO_CHANGES,
86
- objectClass: event.objectClass,
87
- entityId: entity.id,
88
- federatedId: event.federatedId
89
- });
90
- console.log(statusMsg);
91
- const message = 'No Changes to persist for entity: ' + entity.id;
92
- return {
93
- status: 200,
94
- data: { message }
95
- };
96
- }
97
- const updatedEntity = await this.updateEntity(this.baseType, entity, diffs);
98
- const statusMsg = this.getInboundStatusMessage({
99
- status: event_short_message_status_1.EventShortMessageStatus.SUCCESS,
100
- statusMessage: event_short_message_status_1.EventShortMessageStatus.UPDATED,
101
- objectClass: event.objectClass,
102
- entityId: entity.id,
103
- federatedId: event.federatedId
104
- });
105
- console.log(statusMsg);
106
- return updatedEntity;
107
- }
108
- getInboundStatusMessage(statusObject) {
109
- return 'BaseEntityProcessor: inbound: status: ' + statusObject.status
110
- + ', statusMessage: ' + statusObject.statusMessage
111
- + ', entityType: ' + this.baseType
112
- + ', entityId: ' + statusObject.entityId
113
- + ', objectClass: ' + statusObject.objectClass
114
- + ', federatedId: ' + statusObject.federatedId
115
- + ', orgSlug: ' + this.orgSlug;
116
- }
117
- async queryEntityWithSubTypeCriteria(entityType, entityTypePath, propertyCriteria) {
118
- if (!entityType || !entityTypePath) {
119
- throw new Error('type and entityTypePath must be defined');
120
- }
121
- if (!propertyCriteria || Object.getOwnPropertyNames(propertyCriteria).length == 0) {
122
- throw new Error('propertyCriteria must be defined and have at least one property');
123
- }
124
- const { rootTypeCriteria, subTypeCriteria } = await this.getCriteriaForEntity(entityType, entityTypePath, propertyCriteria);
125
- const returnedEntities = await this.dc.getAllObjectReferences(entityType, rootTypeCriteria, subTypeCriteria);
126
- return returnedEntities;
127
- }
128
- async getCriteriaForEntity(entityType, entityTypePath, propertyCriteria) {
129
- if (!entityType || !entityTypePath) {
130
- throw new Error('type and entityTypePath must be defined');
131
- }
132
- if (!propertyCriteria || Object.getOwnPropertyNames(propertyCriteria).length == 0) {
133
- throw new Error('propertyCriteria must be defined and have at least one property');
134
- }
135
- const rootType = await this.typeUtil.getByRootAndPath({ root: entityType });
136
- const rootTypePropertyKeys = await this.getRootTypePropertyKeys(rootType, propertyCriteria);
137
- const rootTypeCriteria = {};
138
- const subTypeCriteria = {};
139
- if (entityType !== entityTypePath) {
140
- subTypeCriteria['typePath'] = entityTypePath;
141
- }
142
- for (const key in propertyCriteria) {
143
- if (rootTypePropertyKeys.includes(key)) {
144
- rootTypeCriteria[key] = propertyCriteria[key];
145
- }
146
- else {
147
- subTypeCriteria[key] = propertyCriteria[key];
148
- }
149
- }
150
- return { rootTypeCriteria, subTypeCriteria };
151
- }
152
- getRootTypePropertyKeys(rootType, propertyCriteria = null) {
153
- const props = rootType['typeProperties'];
154
- const rootTypePropertyKeys = props.map(prop => prop.slug);
155
- return rootTypePropertyKeys;
156
- }
157
- async handleIncomingDelete(event) {
158
- console.warn('delete is not configured', event);
159
- }
160
- async getTransformedData(event) {
161
- let inboundData = event.data;
162
- console.debug('inboundData: ' + JSON.stringify(inboundData));
163
- const mapKey = await type_conversion_utils_1.TypeConversionUtils.getMapKeyFromObject(this.transformMapFile, this.mapFileUtil, inboundData, type_conversion_utils_1.TypeConversionUtils.FLEX2VIBE_DIRECTION);
164
- inboundData = await map_utils_1.MapUtil.applyTransformMap(this.transformMapFile, this.mapFileUtil, inboundData, mapKey, type_conversion_utils_1.TypeConversionUtils.FLEX2VIBE_DIRECTION);
165
- console.debug('Transformed-inboundData: ' + JSON.stringify(inboundData));
166
- return inboundData;
167
- }
168
- async getUpdatesForEntity(entity, inboundData) {
169
- const vibeOwningKeys = await this.getVibeOwningKeys(entity);
170
- let updates = {
171
- typeId: entity.typeId,
172
- roles: entity.roles,
173
- id: entity.id,
174
- };
175
- updates = await this.dc.setEntityValues(updates, inboundData, vibeOwningKeys);
176
- for (const prop of ['typeId', 'roles', 'id']) {
177
- delete updates[prop];
178
- }
179
- return this.dc.getPersistableChanges(entity, updates);
180
- }
181
- async getVibeOwningKeys(entity) {
182
- let vibeOwningKeys = [];
183
- if (this.transformMapFile && entity) {
184
- const mapKey = await type_conversion_utils_1.TypeConversionUtils.getMapKey(this.transformMapFile, this.mapFileUtil, entity, type_conversion_utils_1.TypeConversionUtils.VIBE2FLEX_DIRECTION);
185
- const mapSection = await map_utils_1.MapUtil.getFullMapSection(this.transformMapFile, this.mapFileUtil, mapKey);
186
- vibeOwningKeys = mapSection?.vibeOwningKeys || [];
187
- }
188
- console.debug('vibeOwningKeys: ' + vibeOwningKeys);
189
- return vibeOwningKeys;
190
- }
191
- async getVibeOwningKeysFromInbound(entity) {
192
- let vibeOwningKeys = [];
193
- if (this.transformMapFile && entity) {
194
- const mapKey = await type_conversion_utils_1.TypeConversionUtils.getMapKeyFromObject(this.transformMapFile, this.mapFileUtil, entity, type_conversion_utils_1.TypeConversionUtils.FLEX2VIBE_DIRECTION);
195
- const mapSection = await map_utils_1.MapUtil.getFullMapSection(this.transformMapFile, this.mapFileUtil, mapKey);
196
- vibeOwningKeys = mapSection?.vibeOwningKeys || [];
197
- }
198
- console.debug('vibeOwningKeys: ' + vibeOwningKeys);
199
- return vibeOwningKeys;
200
- }
201
- async createEntity(entityName, changes) {
202
- const options = {
203
- entityName: entityName,
204
- object: changes,
205
- };
206
- console.log("createEntity: " + JSON.stringify(options));
207
- return await new sdk_1.Entities().create(options);
208
- }
209
- async updateEntity(entityName, entity, diffs) {
210
- const options = {
211
- entityName: entityName,
212
- id: entity['id'],
213
- object: diffs
214
- };
215
- console.log('updateEntity: ' + JSON.stringify(options));
216
- return await new sdk_1.Entities().update(options);
217
- }
218
- async outbound(event) {
219
- const entityType = event.entityType;
220
- const eventType = event.eventType;
221
- const entityId = event.id;
222
- console.log(`outbound: ${entityType}:${entityId}`);
223
- switch (eventType) {
224
- case 'update':
225
- case 'create':
226
- return await this.handleOutgoingUpsert(entityType, event);
227
- case 'delete':
228
- return await this.handleOutgoingDelete(entityType, event);
229
- case 'sendUpsertToFlexPLM':
230
- return await this.sendUpsertToFlexPLM(event);
231
- default:
232
- console.log(UNSUPPORTED_TYPE);
233
- return {
234
- status: 500,
235
- data: { UNSUPPORTED_TYPE }
236
- };
237
- }
238
- }
239
- async handleOutgoingUpsert(entityType, event) {
240
- const objectClass = await type_conversion_utils_1.TypeConversionUtils.getObjectClass(this.transformMapFile, this.mapFileUtil, event.newData);
241
- if (!objectClass) {
242
- const message = 'ObjectClass must have a value.';
243
- console.log(message);
244
- return {
245
- status: 500,
246
- data: { message }
247
- };
248
- }
249
- try {
250
- const payload = await this.getOutgoingUpsertPayload(entityType, event);
251
- const flexResponse = await new flexplm_connect_1.FlexPLMConnect(this.config).sendToFlexPLM(payload);
252
- const outboundEntityUpdates = await this.getOutboundEntityUpdates(event, flexResponse);
253
- if (outboundEntityUpdates) {
254
- flexResponse['outboundEntityUpdates'] = outboundEntityUpdates;
255
- }
256
- const statusMsg = 'BaseEntityProcessor: outbound: status: ' + event_short_message_status_1.EventShortMessageStatus.SUCCESS
257
- + ', statusMessage: ' + flexResponse.status
258
- + ', entityType: ' + this.baseType
259
- + ', entityId: ' + event.id
260
- + ', objectClass: ' + payload.objectClass
261
- + ', updateFromResponse: ' + ((outboundEntityUpdates && Object.keys(outboundEntityUpdates).length > 0) ? 'true' : 'false')
262
- + ', orgSlug: ' + this.orgSlug;
263
- console.log(statusMsg);
264
- return flexResponse;
265
- }
266
- catch (e) {
267
- const statusMsg = 'BaseEntityProcessor: outbound: status: ' + event_short_message_status_1.EventShortMessageStatus.FAILURE
268
- + ', statusMessage: ' + e.httpResponseStatus
269
- + ', entityType: ' + this.baseType
270
- + ', entityId: ' + event.id
271
- + ', objectClass: ' + objectClass
272
- + ', updateFromResponse: ' + 'false'
273
- + ', orgSlug: ' + this.orgSlug;
274
- console.log(statusMsg);
275
- throw e;
276
- }
277
- }
278
- async getOutboundEntityUpdates(event, flexResponse) {
279
- const payload = flexResponse?.data?.payload;
280
- const flexPayload = (payload) ? payload[0] : undefined;
281
- let outboundEntityUpdates = undefined;
282
- if (flexPayload && 'OK' === flexPayload.status) {
283
- if (flexPayload.data && !flexPayload.data?.flexPLMObjectClass) {
284
- flexPayload.data.flexPLMObjectClass = flexPayload.objectClass;
285
- }
286
- const inboundData = await this.getTransformedData(flexPayload);
287
- outboundEntityUpdates = await this.getUpdatesForEntity(event.newData, inboundData);
288
- }
289
- return outboundEntityUpdates;
290
- }
291
- async handleOutgoingDelete(entityType, event) {
292
- console.warn('delete is not configured', entityType, event.oldData);
293
- }
294
- async triggerNewEvent(triggerKey, event) {
295
- const newEvent = {
296
- entityName: 'event-workflow-request',
297
- object: {
298
- triggerKey,
299
- event
300
- }
301
- };
302
- const response = await this.entities.create(newEvent);
303
- return response;
304
- }
305
- async sendUpsertToFlexPLM(event) {
306
- const payload = await this.getEntityCurrentStateUpsertPayload(event);
307
- if (!payload) {
308
- const message = 'No payload to send to FlexPLM';
309
- console.log(message);
310
- return {
311
- status: 500,
312
- data: { message }
313
- };
314
- }
315
- ;
316
- let objectClass = payload.objectClass;
317
- try {
318
- const flexResponse = await new flexplm_connect_1.FlexPLMConnect(this.config).sendToFlexPLM(payload);
319
- const outboundEntityUpdates = await this.getOutboundEntityUpdates(event, flexResponse);
320
- if (outboundEntityUpdates) {
321
- flexResponse['outboundEntityUpdates'] = outboundEntityUpdates;
322
- }
323
- const statusMsg = 'BaseEntityProcessor: outbound: status: ' + event_short_message_status_1.EventShortMessageStatus.SUCCESS
324
- + ', statusMessage: ' + flexResponse.status
325
- + ', entityType: ' + this.baseType
326
- + ', entityId: ' + event.id
327
- + ', objectClass: ' + objectClass
328
- + ', updateFromResponse: ' + ((outboundEntityUpdates && Object.keys(outboundEntityUpdates).length > 0) ? 'true' : 'false')
329
- + ', orgSlug: ' + this.orgSlug;
330
- console.log(statusMsg);
331
- return flexResponse;
332
- }
333
- catch (e) {
334
- const statusMsg = 'BaseEntityProcessor: outbound: status: ' + event_short_message_status_1.EventShortMessageStatus.FAILURE
335
- + ', statusMessage: ' + e.httpResponseStatus
336
- + ', entityType: ' + this.baseType
337
- + ', entityId: ' + event.id
338
- + ', objectClass: ' + objectClass
339
- + ', updateFromResponse: ' + 'false'
340
- + ', orgSlug: ' + this.orgSlug;
341
- console.log(statusMsg);
342
- throw e;
343
- }
344
- }
345
- async getEntityCurrentStateUpsertPayload(event) {
346
- const id = event.id;
347
- if (!id) {
348
- return undefined;
349
- }
350
- const entity = await this.entities.get({
351
- entityName: this.baseType,
352
- id
353
- });
354
- if (!entity) {
355
- return undefined;
356
- }
357
- event.newData = entity;
358
- event.oldData = entity;
359
- const payload = await this.getOutgoingUpsertPayload(this.baseType, event);
360
- return payload;
361
- }
362
- }
363
- exports.BaseEntityProcessor = BaseEntityProcessor;
@@ -1 +0,0 @@
1
- export {};
@@ -1,302 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const sdk_1 = require("@contrail/sdk");
4
- const transform_data_1 = require("@contrail/transform-data");
5
- const data_converter_1 = require("../util/data-converter");
6
- const base_entity_processor_1 = require("./base-entity-processor");
7
- const mockRootType = {
8
- typeProperties: [
9
- { slug: 'rootText' }
10
- ]
11
- };
12
- const mockTypeUtilGetByRootAndPath = jest.fn((options) => {
13
- return Promise.resolve(mockRootType);
14
- });
15
- jest.mock('@contrail/sdk', () => {
16
- const origModule = jest.requireActual('@contrail/sdk');
17
- return {
18
- __esModule: true,
19
- ...origModule,
20
- Types: jest.fn().mockImplementation(() => {
21
- return {
22
- getByRootAndPath: mockTypeUtilGetByRootAndPath
23
- };
24
- })
25
- };
26
- });
27
- class TestBaseEntityProcessor extends base_entity_processor_1.BaseEntityProcessor {
28
- getIncomingEntity(event, inboundData) {
29
- throw new Error("Method not implemented.");
30
- }
31
- getCreateEntity(inboundData) {
32
- throw new Error("Method not implemented.");
33
- }
34
- getOutgoingUpsertPayload(entityType, event) {
35
- throw new Error("Method not implemented.");
36
- }
37
- }
38
- describe('BaseEntityProcessor', () => {
39
- describe('getOutboundEntityUpdates', () => {
40
- const config = {};
41
- const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
42
- const dc = new data_converter_1.DataConverter(config, mapFileUtil);
43
- it('no payload', async () => {
44
- const btep = new TestBaseEntityProcessor(config, dc, mapFileUtil, 'test');
45
- const event = {};
46
- const flexResponse = {};
47
- const updates = await btep.getOutboundEntityUpdates(event, flexResponse);
48
- expect(updates).toBeUndefined();
49
- });
50
- it('flexPayload.status === OK', async () => {
51
- const btep = new TestBaseEntityProcessor(config, dc, mapFileUtil, 'test');
52
- const event = {};
53
- const flexResponse = {
54
- data: {
55
- payload: [
56
- {
57
- status: 'OK'
58
- }
59
- ]
60
- }
61
- };
62
- const getTransformedDataSpy = jest.spyOn(btep, 'getTransformedData').mockReturnValue(Promise.resolve({}));
63
- const returnValue = {
64
- name: 'Test'
65
- };
66
- const getUpdatesForEntitySpy = jest.spyOn(btep, 'getUpdatesForEntity').mockReturnValue(Promise.resolve(returnValue));
67
- const updates = await btep.getOutboundEntityUpdates(event, flexResponse);
68
- expect(getTransformedDataSpy).toBeCalledTimes(1);
69
- expect(getUpdatesForEntitySpy).toBeCalledTimes(1);
70
- expect(updates).toBe(returnValue);
71
- });
72
- it('flexPayload.status === FAIL', async () => {
73
- const btep = new TestBaseEntityProcessor(config, dc, mapFileUtil, 'test');
74
- const event = {};
75
- const flexResponse = {
76
- data: {
77
- payload: [
78
- {
79
- status: 'FAIL'
80
- }
81
- ]
82
- }
83
- };
84
- const getTransformedDataSpy = jest.spyOn(btep, 'getTransformedData').mockReturnValue(Promise.resolve({}));
85
- const returnValue = {
86
- name: 'Test'
87
- };
88
- const getUpdatesForEntitySpy = jest.spyOn(btep, 'getUpdatesForEntity').mockReturnValue(Promise.resolve(returnValue));
89
- const updates = await btep.getOutboundEntityUpdates(event, flexResponse);
90
- expect(getTransformedDataSpy).toBeCalledTimes(0);
91
- expect(getUpdatesForEntitySpy).toBeCalledTimes(0);
92
- expect(updates).toBeUndefined();
93
- });
94
- it('should set flexPLMObjectClass when data exists but flexPLMObjectClass is missing', async () => {
95
- const btep = new TestBaseEntityProcessor(config, dc, mapFileUtil, 'test');
96
- const event = { newData: { id: '123' } };
97
- const flexResponse = {
98
- data: {
99
- payload: [
100
- {
101
- status: 'OK',
102
- objectClass: 'Material',
103
- data: {
104
- name: 'Test Material'
105
- }
106
- }
107
- ]
108
- }
109
- };
110
- const getTransformedDataSpy = jest.spyOn(btep, 'getTransformedData').mockReturnValue(Promise.resolve({}));
111
- const returnValue = {
112
- name: 'Test'
113
- };
114
- const getUpdatesForEntitySpy = jest.spyOn(btep, 'getUpdatesForEntity').mockReturnValue(Promise.resolve(returnValue));
115
- await btep.getOutboundEntityUpdates(event, flexResponse);
116
- expect(flexResponse.data.payload[0].data['flexPLMObjectClass']).toBe('Material');
117
- expect(getTransformedDataSpy).toBeCalledTimes(1);
118
- expect(getTransformedDataSpy).toBeCalledWith(flexResponse.data.payload[0]);
119
- expect(getUpdatesForEntitySpy).toBeCalledTimes(1);
120
- });
121
- it('should not override existing flexPLMObjectClass', async () => {
122
- const btep = new TestBaseEntityProcessor(config, dc, mapFileUtil, 'test');
123
- const event = { newData: { id: '123' } };
124
- const flexResponse = {
125
- data: {
126
- payload: [
127
- {
128
- status: 'OK',
129
- objectClass: 'Material',
130
- data: {
131
- name: 'Test Material',
132
- flexPLMObjectClass: 'ExistingClass'
133
- }
134
- }
135
- ]
136
- }
137
- };
138
- const getTransformedDataSpy = jest.spyOn(btep, 'getTransformedData').mockReturnValue(Promise.resolve({}));
139
- const returnValue = {
140
- name: 'Test'
141
- };
142
- const getUpdatesForEntitySpy = jest.spyOn(btep, 'getUpdatesForEntity').mockReturnValue(Promise.resolve(returnValue));
143
- await btep.getOutboundEntityUpdates(event, flexResponse);
144
- expect(flexResponse.data.payload[0].data.flexPLMObjectClass).toBe('ExistingClass');
145
- expect(getTransformedDataSpy).toBeCalledTimes(1);
146
- expect(getTransformedDataSpy).toBeCalledWith(flexResponse.data.payload[0]);
147
- expect(getUpdatesForEntitySpy).toBeCalledTimes(1);
148
- });
149
- it('should skip setting flexPLMObjectClass when data is null or undefined', async () => {
150
- const btep = new TestBaseEntityProcessor(config, dc, mapFileUtil, 'test');
151
- const event = { newData: { id: '123' } };
152
- const flexResponse = {
153
- data: {
154
- payload: [
155
- {
156
- status: 'OK',
157
- objectClass: 'Material',
158
- data: null
159
- }
160
- ]
161
- }
162
- };
163
- const getTransformedDataSpy = jest.spyOn(btep, 'getTransformedData').mockReturnValue(Promise.resolve({}));
164
- const returnValue = {
165
- name: 'Test'
166
- };
167
- const getUpdatesForEntitySpy = jest.spyOn(btep, 'getUpdatesForEntity').mockReturnValue(Promise.resolve(returnValue));
168
- await btep.getOutboundEntityUpdates(event, flexResponse);
169
- expect(getTransformedDataSpy).toBeCalledTimes(1);
170
- expect(getTransformedDataSpy).toBeCalledWith(flexResponse.data.payload[0]);
171
- expect(getUpdatesForEntitySpy).toBeCalledTimes(1);
172
- });
173
- });
174
- describe('queryEntityWithSubType', () => {
175
- const config = {};
176
- const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
177
- beforeEach(() => {
178
- jest.clearAllMocks();
179
- });
180
- it('entity parameter not set', async () => {
181
- const btep = new TestBaseEntityProcessor({}, {}, {}, 'test');
182
- const entity = '';
183
- const subType = 'test';
184
- const propertyCriteria = { a: 'val' };
185
- expect(async () => { await btep.queryEntityWithSubTypeCriteria(entity, subType, propertyCriteria); }).rejects.toThrow();
186
- });
187
- it('entityTypePath not set', async () => {
188
- const btep = new TestBaseEntityProcessor({}, {}, {}, 'test');
189
- const entity = 'test';
190
- const subType = '';
191
- const propertyCriteria = {};
192
- expect(async () => { await btep.queryEntityWithSubTypeCriteria(entity, subType, propertyCriteria); }).rejects.toThrow();
193
- });
194
- it('propertyCriteria not set', async () => {
195
- const btep = new TestBaseEntityProcessor({}, {}, {}, 'test');
196
- const entity = 'test';
197
- const subType = 'test';
198
- const propertyCriteria = {};
199
- expect(async () => { await btep.queryEntityWithSubTypeCriteria(entity, subType, propertyCriteria); }).rejects.toThrow();
200
- });
201
- it('basic queryEntityWithSubTypeCriteria test', async () => {
202
- const dc = new data_converter_1.DataConverter(config, mapFileUtil);
203
- const btep = new TestBaseEntityProcessor(config, dc, mapFileUtil, 'test');
204
- const entityType = 'custom-entity';
205
- const entityTypePath = 'custom-entity:sample';
206
- const rootCriteria = {
207
- rootText: 'root'
208
- };
209
- const subCriteria = {
210
- sampleText: 'sample',
211
- typePath: entityTypePath
212
- };
213
- const propertyCriteria = Object.assign({}, rootCriteria, subCriteria);
214
- const rootCriteriaResults = Object.assign({}, rootCriteria);
215
- const mockGetByRootTypeProperties = jest.spyOn(btep, 'getRootTypePropertyKeys').mockReturnValue(['rootText']);
216
- const mockDCgetAllObjectReferences = jest.spyOn(dc, 'getAllObjectReferences').mockReturnValue(Promise.resolve([]));
217
- const results = await btep.queryEntityWithSubTypeCriteria(entityType, entityTypePath, propertyCriteria);
218
- expect(results).toEqual([]);
219
- expect(mockTypeUtilGetByRootAndPath).toBeCalledTimes(1);
220
- expect(mockTypeUtilGetByRootAndPath).toBeCalledWith({ root: entityType });
221
- expect(mockGetByRootTypeProperties).toBeCalledTimes(1);
222
- expect(mockGetByRootTypeProperties).toBeCalledWith(mockRootType, propertyCriteria);
223
- expect(mockDCgetAllObjectReferences).toBeCalledTimes(1);
224
- expect(mockDCgetAllObjectReferences).toBeCalledWith(entityType, rootCriteriaResults, subCriteria);
225
- });
226
- });
227
- describe('getCriteriaForEntity', () => {
228
- const config = {};
229
- const mapFileUtil = new transform_data_1.MapFileUtil(new sdk_1.Entities());
230
- beforeEach(() => {
231
- jest.clearAllMocks();
232
- });
233
- it('entity parameter not set', async () => {
234
- const btep = new TestBaseEntityProcessor({}, {}, {}, 'test');
235
- const entity = '';
236
- const subType = 'test';
237
- const propertyCriteria = { a: 'val' };
238
- expect(async () => { await btep.getCriteriaForEntity(entity, subType, propertyCriteria); }).rejects.toThrow();
239
- });
240
- it('entityTypePath not set', async () => {
241
- const btep = new TestBaseEntityProcessor({}, {}, {}, 'test');
242
- const entity = 'test';
243
- const subType = '';
244
- const propertyCriteria = {};
245
- expect(async () => { await btep.getCriteriaForEntity(entity, subType, propertyCriteria); }).rejects.toThrow();
246
- });
247
- it('propertyCriteria not set', async () => {
248
- const btep = new TestBaseEntityProcessor({}, {}, {}, 'test');
249
- const entity = 'test';
250
- const subType = 'test';
251
- const propertyCriteria = {};
252
- expect(async () => { await btep.getCriteriaForEntity(entity, subType, propertyCriteria); }).rejects.toThrow();
253
- });
254
- it('basic getCriteriaForEntity test', async () => {
255
- const dc = new data_converter_1.DataConverter(config, mapFileUtil);
256
- const btep = new TestBaseEntityProcessor(config, dc, mapFileUtil, 'test');
257
- const entityType = 'custom-entity';
258
- const entityTypePath = 'custom-entity:sample';
259
- const rootCriteria = {
260
- rootText: 'root'
261
- };
262
- const subCriteria = {
263
- sampleText: 'sample',
264
- typePath: entityTypePath
265
- };
266
- const propertyCriteria = Object.assign({}, rootCriteria, subCriteria);
267
- const rootCriteriaResults = Object.assign({}, rootCriteria);
268
- const subCriteriaResults = Object.assign({}, subCriteria);
269
- const mockGetByRootTypeProperties = jest.spyOn(btep, 'getRootTypePropertyKeys').mockReturnValue(['rootText']);
270
- const { rootTypeCriteria, subTypeCriteria } = await btep.getCriteriaForEntity(entityType, entityTypePath, propertyCriteria);
271
- expect(mockTypeUtilGetByRootAndPath).toBeCalledTimes(1);
272
- expect(mockTypeUtilGetByRootAndPath).toBeCalledWith({ root: entityType });
273
- expect(mockGetByRootTypeProperties).toBeCalledTimes(1);
274
- expect(mockGetByRootTypeProperties).toBeCalledWith(mockRootType, propertyCriteria);
275
- expect(rootTypeCriteria).toEqual(rootCriteriaResults);
276
- expect(subTypeCriteria).toEqual(subCriteriaResults);
277
- });
278
- });
279
- describe('getRootTypePropertyKeys', () => {
280
- it('rootType parameter not set', async () => {
281
- const btep = new TestBaseEntityProcessor({}, {}, {}, 'test');
282
- const rootType = '';
283
- expect(async () => { await btep.getRootTypePropertyKeys(rootType); }).rejects.toThrow();
284
- });
285
- it('get keys from rootType.typeProperties', async () => {
286
- const btep = new TestBaseEntityProcessor({}, {}, {}, 'test');
287
- const rootType = {
288
- typeProperties: ['a', 'b']
289
- };
290
- const keys = await btep.getRootTypePropertyKeys(rootType);
291
- expect(keys).not.toEqual(['a', 'b']);
292
- });
293
- it('get keys from rootType.typeProperties', async () => {
294
- const btep = new TestBaseEntityProcessor({}, {}, {}, 'test');
295
- const rootType = {
296
- typeProperties: [{ slug: 'a' }, { slug: 'b' }]
297
- };
298
- const keys = await btep.getRootTypePropertyKeys(rootType);
299
- expect(keys).toEqual(['a', 'b']);
300
- });
301
- });
302
- });
@@ -1,3 +0,0 @@
1
- export declare class FlexPLMRequest {
2
- static request(path: string, data: any): Promise<any>;
3
- }