@contrail/flexplm 1.3.0 → 1.3.1-alpha.585afc1

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 (149) hide show
  1. package/lib/cli/commands/compile.d.ts +1 -0
  2. package/lib/cli/commands/compile.js +71 -0
  3. package/lib/cli/commands/compile.spec.d.ts +1 -0
  4. package/lib/cli/commands/compile.spec.js +80 -0
  5. package/lib/cli/commands/create.d.ts +1 -0
  6. package/lib/cli/commands/create.js +75 -0
  7. package/lib/cli/commands/create.spec.d.ts +1 -0
  8. package/lib/cli/commands/create.spec.js +78 -0
  9. package/lib/cli/commands/upload.d.ts +10 -0
  10. package/lib/cli/commands/upload.js +219 -0
  11. package/lib/cli/commands/upload.spec.d.ts +1 -0
  12. package/lib/cli/commands/upload.spec.js +88 -0
  13. package/lib/cli/index.d.ts +2 -0
  14. package/lib/cli/index.js +64 -0
  15. package/lib/cli/index.spec.d.ts +1 -0
  16. package/lib/cli/index.spec.js +79 -0
  17. package/lib/cli/template/mapping-template.ts.template +18 -0
  18. package/lib/entity-processor/base-entity-processor.d.ts +89 -42
  19. package/lib/entity-processor/base-entity-processor.js +438 -385
  20. package/lib/entity-processor/base-entity-processor.spec.d.ts +1 -1
  21. package/lib/entity-processor/base-entity-processor.spec.js +398 -397
  22. package/lib/flexplm-request.d.ts +3 -3
  23. package/lib/flexplm-request.js +34 -34
  24. package/lib/flexplm-utils.d.ts +5 -5
  25. package/lib/flexplm-utils.js +33 -33
  26. package/lib/flexplm-utils.spec.d.ts +1 -1
  27. package/lib/flexplm-utils.spec.js +26 -26
  28. package/lib/index.d.ts +23 -22
  29. package/lib/index.js +39 -38
  30. package/lib/interfaces/interfaces.d.ts +105 -105
  31. package/lib/interfaces/interfaces.js +2 -2
  32. package/lib/interfaces/item-family-changes.d.ts +20 -20
  33. package/lib/interfaces/item-family-changes.js +56 -56
  34. package/lib/interfaces/mapping-file.d.ts +429 -0
  35. package/lib/interfaces/mapping-file.js +2 -0
  36. package/lib/interfaces/publish-change-data.d.ts +19 -19
  37. package/lib/interfaces/publish-change-data.js +32 -32
  38. package/lib/publish/base-process-publish-assortment-callback.d.ts +9 -9
  39. package/lib/publish/base-process-publish-assortment-callback.js +38 -38
  40. package/lib/publish/base-process-publish-assortment.d.ts +118 -93
  41. package/lib/publish/base-process-publish-assortment.js +998 -944
  42. package/lib/publish/base-process-publish-assortment.spec.d.ts +1 -1
  43. package/lib/publish/base-process-publish-assortment.spec.js +1688 -1670
  44. package/lib/publish/mockData.d.ts +1389 -1389
  45. package/lib/publish/mockData.js +4524 -4519
  46. package/lib/transform/identifier-conversion-spec-mockData.js +472 -444
  47. package/lib/transform/identifier-conversion.d.ts +51 -15
  48. package/lib/transform/identifier-conversion.js +248 -212
  49. package/lib/transform/identifier-conversion.spec.d.ts +1 -1
  50. package/lib/transform/identifier-conversion.spec.js +343 -339
  51. package/lib/util/config-defaults.d.ts +8 -8
  52. package/lib/util/config-defaults.js +88 -85
  53. package/lib/util/config-defaults.spec.d.ts +1 -1
  54. package/lib/util/config-defaults.spec.js +302 -293
  55. package/lib/util/data-converter-spec-mockData.js +219 -205
  56. package/lib/util/data-converter.d.ts +136 -39
  57. package/lib/util/data-converter.js +718 -592
  58. package/lib/util/data-converter.spec.d.ts +1 -1
  59. package/lib/util/data-converter.spec.js +906 -904
  60. package/lib/util/error-response-object.d.ts +9 -4
  61. package/lib/util/error-response-object.js +54 -47
  62. package/lib/util/error-response-object.spec.d.ts +1 -1
  63. package/lib/util/error-response-object.spec.js +99 -99
  64. package/lib/util/event-short-message-status.d.ts +19 -19
  65. package/lib/util/event-short-message-status.js +24 -23
  66. package/lib/util/federation.d.ts +15 -15
  67. package/lib/util/federation.js +157 -149
  68. package/lib/util/flexplm-connect.d.ts +29 -22
  69. package/lib/util/flexplm-connect.js +190 -176
  70. package/lib/util/flexplm-connect.spec.d.ts +1 -1
  71. package/lib/util/flexplm-connect.spec.js +88 -88
  72. package/lib/util/logger-config.d.ts +1 -1
  73. package/lib/util/logger-config.js +27 -26
  74. package/lib/util/map-util-spec-mockData.js +219 -205
  75. package/lib/util/map-utils.d.ts +33 -6
  76. package/lib/util/map-utils.js +42 -15
  77. package/lib/util/map-utils.spec.d.ts +1 -1
  78. package/lib/util/map-utils.spec.js +89 -89
  79. package/lib/util/mockData.d.ts +80 -80
  80. package/lib/util/mockData.js +103 -103
  81. package/lib/util/thumbnail-util.d.ts +55 -34
  82. package/lib/util/thumbnail-util.js +242 -215
  83. package/lib/util/thumbnail-util.spec.d.ts +1 -1
  84. package/lib/util/thumbnail-util.spec.js +440 -434
  85. package/lib/util/type-conversion-utils-spec-mockData.js +259 -259
  86. package/lib/util/type-conversion-utils.d.ts +163 -23
  87. package/lib/util/type-conversion-utils.js +408 -265
  88. package/lib/util/type-conversion-utils.spec.d.ts +1 -1
  89. package/lib/util/type-conversion-utils.spec.js +868 -868
  90. package/lib/util/type-defaults.d.ts +74 -16
  91. package/lib/util/type-defaults.js +279 -221
  92. package/lib/util/type-defaults.spec.d.ts +1 -1
  93. package/lib/util/type-defaults.spec.js +516 -516
  94. package/lib/util/type-utils.d.ts +34 -13
  95. package/lib/util/type-utils.js +137 -114
  96. package/lib/util/type-utils.spec.d.ts +1 -1
  97. package/lib/util/type-utils.spec.js +192 -190
  98. package/package.json +21 -6
  99. package/scripts/copy-template.js +10 -0
  100. package/.claude/settings.local.json +0 -8
  101. package/.github/pull_request_template.md +0 -31
  102. package/.github/workflows/flexplm-lib.yml +0 -27
  103. package/.github/workflows/publish-to-npm.yml +0 -124
  104. package/CHANGELOG.md +0 -32
  105. package/publish.bat +0 -5
  106. package/publish.sh +0 -5
  107. package/src/entity-processor/base-entity-processor.spec.ts +0 -460
  108. package/src/entity-processor/base-entity-processor.ts +0 -515
  109. package/src/flexplm-request.ts +0 -28
  110. package/src/flexplm-utils.spec.ts +0 -27
  111. package/src/flexplm-utils.ts +0 -29
  112. package/src/index.ts +0 -22
  113. package/src/interfaces/interfaces.ts +0 -122
  114. package/src/interfaces/item-family-changes.ts +0 -67
  115. package/src/interfaces/publish-change-data.ts +0 -43
  116. package/src/publish/base-process-publish-assortment-callback.ts +0 -50
  117. package/src/publish/base-process-publish-assortment.spec.ts +0 -1992
  118. package/src/publish/base-process-publish-assortment.ts +0 -1134
  119. package/src/publish/mockData.ts +0 -4561
  120. package/src/transform/identifier-conversion-spec-mockData.ts +0 -496
  121. package/src/transform/identifier-conversion.spec.ts +0 -354
  122. package/src/transform/identifier-conversion.ts +0 -282
  123. package/src/util/config-defaults.spec.ts +0 -350
  124. package/src/util/config-defaults.ts +0 -93
  125. package/src/util/data-converter-spec-mockData.ts +0 -231
  126. package/src/util/data-converter.spec.ts +0 -1041
  127. package/src/util/data-converter.ts +0 -762
  128. package/src/util/error-response-object.spec.ts +0 -116
  129. package/src/util/error-response-object.ts +0 -50
  130. package/src/util/event-short-message-status.ts +0 -22
  131. package/src/util/federation.ts +0 -172
  132. package/src/util/flexplm-connect.spec.ts +0 -132
  133. package/src/util/flexplm-connect.ts +0 -208
  134. package/src/util/logger-config.ts +0 -20
  135. package/src/util/map-util-spec-mockData.ts +0 -231
  136. package/src/util/map-utils.spec.ts +0 -103
  137. package/src/util/map-utils.ts +0 -41
  138. package/src/util/mockData.ts +0 -101
  139. package/src/util/thumbnail-util.spec.ts +0 -508
  140. package/src/util/thumbnail-util.ts +0 -272
  141. package/src/util/type-conversion-utils-spec-mockData.ts +0 -271
  142. package/src/util/type-conversion-utils.spec.ts +0 -968
  143. package/src/util/type-conversion-utils.ts +0 -460
  144. package/src/util/type-defaults.spec.ts +0 -669
  145. package/src/util/type-defaults.ts +0 -281
  146. package/src/util/type-utils.spec.ts +0 -227
  147. package/src/util/type-utils.ts +0 -144
  148. package/tsconfig.json +0 -29
  149. package/tslint.json +0 -57
@@ -1,385 +1,438 @@
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 thumbnail_util_1 = require("../util/thumbnail-util");
10
- const event_short_message_status_1 = require("../util/event-short-message-status");
11
- const UNSUPPORTED_TYPE = 'Unsupported eventType.';
12
- class IncomingEntityResponse {
13
- }
14
- exports.IncomingEntityResponse = IncomingEntityResponse;
15
- class BaseEntityProcessor {
16
- constructor(config, dc, mapFileUtil, baseType) {
17
- this.config = config;
18
- this.dc = dc;
19
- this.mapFileUtil = mapFileUtil;
20
- this.baseType = baseType;
21
- this.typeUtil = new type_utils_1.TypeUtils();
22
- this.transformMapFile = this.config?.transformMapFile;
23
- this.entities = new sdk_1.Entities();
24
- this.orgSlug = this.config?.orgSlug || 'unset-orgSlug';
25
- }
26
- async inbound(event) {
27
- const eventType = event.eventType;
28
- console.log(`inbound entity: ${eventType}:${event.objectClass}`);
29
- switch (eventType) {
30
- case 'PERSIST':
31
- return await this.handleIncomingUpsert(event);
32
- case 'DELETE':
33
- return await this.handleIncomingDelete(event);
34
- default:
35
- console.error(UNSUPPORTED_TYPE);
36
- return {
37
- status: 500,
38
- data: { UNSUPPORTED_TYPE }
39
- };
40
- }
41
- }
42
- async handleIncomingUpsert(event) {
43
- const inboundData = await this.getTransformedData(event);
44
- const incomingEntityResponse = await this.getIncomingEntity(event, inboundData);
45
- if (incomingEntityResponse.earlyReturn) {
46
- const statusMsg = this.getInboundStatusMessage({
47
- status: event_short_message_status_1.EventShortMessageStatus.FAILURE,
48
- statusMessage: incomingEntityResponse.earlyReturn.shortStatusMessage || '',
49
- objectClass: event.objectClass,
50
- federatedId: event.federatedId
51
- });
52
- console.log(statusMsg);
53
- return incomingEntityResponse.earlyReturn;
54
- }
55
- const entity = incomingEntityResponse.entity;
56
- if (!entity) {
57
- const createEntityResponse = await this.getCreateEntity(inboundData);
58
- if (createEntityResponse.earlyReturn) {
59
- const status = (createEntityResponse.earlyReturn.shortStatusMessage === event_short_message_status_1.EventShortMessageStatus.NOT_CREATABLE)
60
- ? event_short_message_status_1.EventShortMessageStatus.SUCCESS
61
- : event_short_message_status_1.EventShortMessageStatus.FAILURE;
62
- const statusMsg = this.getInboundStatusMessage({
63
- status,
64
- statusMessage: createEntityResponse.earlyReturn.shortStatusMessage || '',
65
- objectClass: event.objectClass,
66
- federatedId: event.federatedId
67
- });
68
- console.log(statusMsg);
69
- return createEntityResponse.earlyReturn;
70
- }
71
- let createdEntity = await this.createEntity(this.baseType, createEntityResponse.entity);
72
- const shouldSyncThumbnail = await type_conversion_utils_1.TypeConversionUtils.syncInboundImages(this.transformMapFile, this.mapFileUtil, event.data);
73
- if (shouldSyncThumbnail) {
74
- createdEntity = await new thumbnail_util_1.ThumbnailUtil(this.config).syncThumbnailToVibeIQ({ entityId: createdEntity.id, primaryViewableId: createdEntity.primaryViewableId, event, entityName: this.baseType }) || createdEntity;
75
- }
76
- const statusMsg = this.getInboundStatusMessage({
77
- status: event_short_message_status_1.EventShortMessageStatus.SUCCESS,
78
- statusMessage: event_short_message_status_1.EventShortMessageStatus.CREATED,
79
- objectClass: event.objectClass,
80
- entityId: 'id',
81
- federatedId: event.federatedId
82
- });
83
- console.log(statusMsg);
84
- return createdEntity;
85
- }
86
- const diffs = await this.getUpdatesForEntity(entity, inboundData);
87
- const shouldSyncThumbnail = await type_conversion_utils_1.TypeConversionUtils.syncInboundImages(this.transformMapFile, this.mapFileUtil, event.data);
88
- let thumbnailEntity;
89
- if (shouldSyncThumbnail) {
90
- thumbnailEntity = await new thumbnail_util_1.ThumbnailUtil(this.config).syncThumbnailToVibeIQ({ entityId: entity.id, primaryViewableId: entity.primaryViewableId, event, entityName: this.baseType });
91
- }
92
- const hasPropertyChanges = Object.getOwnPropertyNames(diffs).length > 0;
93
- if (!hasPropertyChanges && thumbnailEntity) {
94
- const statusMsg = this.getInboundStatusMessage({
95
- status: event_short_message_status_1.EventShortMessageStatus.SUCCESS,
96
- statusMessage: event_short_message_status_1.EventShortMessageStatus.PRIMARY_CONTENT_UPDATED,
97
- objectClass: event.objectClass,
98
- entityId: entity.id,
99
- federatedId: event.federatedId
100
- });
101
- console.log(statusMsg);
102
- return thumbnailEntity;
103
- }
104
- if (!hasPropertyChanges) {
105
- const statusMsg = this.getInboundStatusMessage({
106
- status: event_short_message_status_1.EventShortMessageStatus.SUCCESS,
107
- statusMessage: event_short_message_status_1.EventShortMessageStatus.NO_CHANGES,
108
- objectClass: event.objectClass,
109
- entityId: entity.id,
110
- federatedId: event.federatedId
111
- });
112
- console.log(statusMsg);
113
- const message = 'No Changes to persist for entity: ' + entity.id;
114
- return {
115
- status: 200,
116
- data: { message }
117
- };
118
- }
119
- const updatedEntity = await this.updateEntity(this.baseType, entity, diffs);
120
- const statusMsg = this.getInboundStatusMessage({
121
- status: event_short_message_status_1.EventShortMessageStatus.SUCCESS,
122
- statusMessage: event_short_message_status_1.EventShortMessageStatus.UPDATED,
123
- objectClass: event.objectClass,
124
- entityId: entity.id,
125
- federatedId: event.federatedId
126
- });
127
- console.log(statusMsg);
128
- return updatedEntity;
129
- }
130
- getInboundStatusMessage(statusObject) {
131
- return 'BaseEntityProcessor: inbound: status: ' + statusObject.status
132
- + ', statusMessage: ' + statusObject.statusMessage
133
- + ', entityType: ' + this.baseType
134
- + ', entityId: ' + statusObject.entityId
135
- + ', objectClass: ' + statusObject.objectClass
136
- + ', federatedId: ' + statusObject.federatedId
137
- + ', orgSlug: ' + this.orgSlug;
138
- }
139
- async queryEntityWithSubTypeCriteria(entityType, entityTypePath, propertyCriteria) {
140
- if (!entityType || !entityTypePath) {
141
- throw new Error('type and entityTypePath must be defined');
142
- }
143
- if (!propertyCriteria || Object.getOwnPropertyNames(propertyCriteria).length == 0) {
144
- throw new Error('propertyCriteria must be defined and have at least one property');
145
- }
146
- const { rootTypeCriteria, subTypeCriteria } = await this.getCriteriaForEntity(entityType, entityTypePath, propertyCriteria);
147
- const returnedEntities = await this.dc.getAllObjectReferences(entityType, rootTypeCriteria, subTypeCriteria);
148
- return returnedEntities;
149
- }
150
- async getCriteriaForEntity(entityType, entityTypePath, propertyCriteria) {
151
- if (!entityType || !entityTypePath) {
152
- throw new Error('type and entityTypePath must be defined');
153
- }
154
- if (!propertyCriteria || Object.getOwnPropertyNames(propertyCriteria).length == 0) {
155
- throw new Error('propertyCriteria must be defined and have at least one property');
156
- }
157
- const rootType = await this.typeUtil.getByRootAndPath({ root: entityType });
158
- const rootTypePropertyKeys = await this.getRootTypePropertyKeys(rootType, propertyCriteria);
159
- const rootTypeCriteria = {};
160
- const subTypeCriteria = {};
161
- if (entityType !== entityTypePath) {
162
- subTypeCriteria['typePath'] = entityTypePath;
163
- }
164
- for (const key in propertyCriteria) {
165
- if (rootTypePropertyKeys.includes(key)) {
166
- rootTypeCriteria[key] = propertyCriteria[key];
167
- }
168
- else {
169
- subTypeCriteria[key] = propertyCriteria[key];
170
- }
171
- }
172
- return { rootTypeCriteria, subTypeCriteria };
173
- }
174
- getRootTypePropertyKeys(rootType, propertyCriteria = null) {
175
- const props = rootType['typeProperties'];
176
- const rootTypePropertyKeys = props.map(prop => prop.slug);
177
- return rootTypePropertyKeys;
178
- }
179
- async handleIncomingDelete(event) {
180
- console.warn('delete is not configured', event);
181
- }
182
- async getTransformedData(event) {
183
- let inboundData = event.data;
184
- console.debug('inboundData: ' + JSON.stringify(inboundData));
185
- const mapKey = await type_conversion_utils_1.TypeConversionUtils.getMapKeyFromObject(this.transformMapFile, this.mapFileUtil, inboundData, type_conversion_utils_1.TypeConversionUtils.FLEX2VIBE_DIRECTION);
186
- inboundData = await map_utils_1.MapUtil.applyTransformMap(this.transformMapFile, this.mapFileUtil, inboundData, mapKey, type_conversion_utils_1.TypeConversionUtils.FLEX2VIBE_DIRECTION);
187
- console.debug('Transformed-inboundData: ' + JSON.stringify(inboundData));
188
- return inboundData;
189
- }
190
- async getUpdatesForEntity(entity, inboundData) {
191
- const vibeOwningKeys = await this.getVibeOwningKeys(entity);
192
- let updates = {
193
- typeId: entity.typeId,
194
- roles: entity.roles,
195
- id: entity.id,
196
- };
197
- updates = await this.dc.setEntityValues(updates, inboundData, vibeOwningKeys);
198
- for (const prop of ['typeId', 'roles', 'id']) {
199
- delete updates[prop];
200
- }
201
- return this.dc.getPersistableChanges(entity, updates);
202
- }
203
- async getVibeOwningKeys(entity) {
204
- let vibeOwningKeys = [];
205
- if (this.transformMapFile && entity) {
206
- const mapKey = await type_conversion_utils_1.TypeConversionUtils.getMapKey(this.transformMapFile, this.mapFileUtil, entity, type_conversion_utils_1.TypeConversionUtils.VIBE2FLEX_DIRECTION);
207
- const mapSection = await map_utils_1.MapUtil.getFullMapSection(this.transformMapFile, this.mapFileUtil, mapKey);
208
- vibeOwningKeys = mapSection?.vibeOwningKeys || [];
209
- }
210
- console.debug('vibeOwningKeys: ' + vibeOwningKeys);
211
- return vibeOwningKeys;
212
- }
213
- async getVibeOwningKeysFromInbound(entity) {
214
- let vibeOwningKeys = [];
215
- if (this.transformMapFile && entity) {
216
- const mapKey = await type_conversion_utils_1.TypeConversionUtils.getMapKeyFromObject(this.transformMapFile, this.mapFileUtil, entity, type_conversion_utils_1.TypeConversionUtils.FLEX2VIBE_DIRECTION);
217
- const mapSection = await map_utils_1.MapUtil.getFullMapSection(this.transformMapFile, this.mapFileUtil, mapKey);
218
- vibeOwningKeys = mapSection?.vibeOwningKeys || [];
219
- }
220
- console.debug('vibeOwningKeys: ' + vibeOwningKeys);
221
- return vibeOwningKeys;
222
- }
223
- async createEntity(entityName, changes) {
224
- const options = {
225
- entityName: entityName,
226
- object: changes,
227
- };
228
- console.log("createEntity: " + JSON.stringify(options));
229
- return await new sdk_1.Entities().create(options);
230
- }
231
- async updateEntity(entityName, entity, diffs) {
232
- const options = {
233
- entityName: entityName,
234
- id: entity['id'],
235
- object: diffs
236
- };
237
- console.log('updateEntity: ' + JSON.stringify(options));
238
- return await new sdk_1.Entities().update(options);
239
- }
240
- async outbound(event) {
241
- const entityType = event.entityType;
242
- const eventType = event.eventType;
243
- const entityId = event.id;
244
- console.log(`outbound: ${entityType}:${entityId}`);
245
- switch (eventType) {
246
- case 'update':
247
- case 'create':
248
- return await this.handleOutgoingUpsert(entityType, event);
249
- case 'delete':
250
- return await this.handleOutgoingDelete(entityType, event);
251
- case 'sendUpsertToFlexPLM':
252
- return await this.sendUpsertToFlexPLM(event);
253
- default:
254
- console.log(UNSUPPORTED_TYPE);
255
- return {
256
- status: 500,
257
- data: { UNSUPPORTED_TYPE }
258
- };
259
- }
260
- }
261
- async handleOutgoingUpsert(entityType, event) {
262
- const objectClass = await type_conversion_utils_1.TypeConversionUtils.getObjectClass(this.transformMapFile, this.mapFileUtil, event.newData);
263
- if (!objectClass) {
264
- const message = 'ObjectClass must have a value.';
265
- console.log(message);
266
- return {
267
- status: 500,
268
- data: { message }
269
- };
270
- }
271
- try {
272
- const payload = await this.getOutgoingUpsertPayload(entityType, event);
273
- const flexResponse = await new flexplm_connect_1.FlexPLMConnect(this.config).sendToFlexPLM(payload);
274
- const outboundEntityUpdates = await this.getOutboundEntityUpdates(event, flexResponse);
275
- if (outboundEntityUpdates) {
276
- flexResponse['outboundEntityUpdates'] = outboundEntityUpdates;
277
- }
278
- const statusMsg = 'BaseEntityProcessor: outbound: status: ' + event_short_message_status_1.EventShortMessageStatus.SUCCESS
279
- + ', statusMessage: ' + flexResponse.status
280
- + ', entityType: ' + this.baseType
281
- + ', entityId: ' + event.id
282
- + ', objectClass: ' + payload.objectClass
283
- + ', updateFromResponse: ' + ((outboundEntityUpdates && Object.keys(outboundEntityUpdates).length > 0) ? 'true' : 'false')
284
- + ', orgSlug: ' + this.orgSlug;
285
- console.log(statusMsg);
286
- return flexResponse;
287
- }
288
- catch (e) {
289
- const statusMsg = 'BaseEntityProcessor: outbound: status: ' + event_short_message_status_1.EventShortMessageStatus.FAILURE
290
- + ', statusMessage: ' + e.httpResponseStatus
291
- + ', entityType: ' + this.baseType
292
- + ', entityId: ' + event.id
293
- + ', objectClass: ' + objectClass
294
- + ', updateFromResponse: ' + 'false'
295
- + ', orgSlug: ' + this.orgSlug;
296
- console.log(statusMsg);
297
- throw e;
298
- }
299
- }
300
- async getOutboundEntityUpdates(event, flexResponse) {
301
- const payload = flexResponse?.data?.payload;
302
- const flexPayload = (payload) ? payload[0] : undefined;
303
- let outboundEntityUpdates = undefined;
304
- if (flexPayload && 'OK' === flexPayload.status) {
305
- if (flexPayload.data && !flexPayload.data?.flexPLMObjectClass) {
306
- flexPayload.data.flexPLMObjectClass = flexPayload.objectClass;
307
- }
308
- const inboundData = await this.getTransformedData(flexPayload);
309
- outboundEntityUpdates = await this.getUpdatesForEntity(event.newData, inboundData);
310
- }
311
- return outboundEntityUpdates;
312
- }
313
- async handleOutgoingDelete(entityType, event) {
314
- console.warn('delete is not configured', entityType, event.oldData);
315
- }
316
- async triggerNewEvent(triggerKey, event) {
317
- const newEvent = {
318
- entityName: 'event-workflow-request',
319
- object: {
320
- triggerKey,
321
- event
322
- }
323
- };
324
- const response = await this.entities.create(newEvent);
325
- return response;
326
- }
327
- async sendUpsertToFlexPLM(event) {
328
- const payload = await this.getEntityCurrentStateUpsertPayload(event);
329
- if (!payload) {
330
- const message = 'No payload to send to FlexPLM';
331
- console.log(message);
332
- return {
333
- status: 500,
334
- data: { message }
335
- };
336
- }
337
- ;
338
- let objectClass = payload.objectClass;
339
- try {
340
- const flexResponse = await new flexplm_connect_1.FlexPLMConnect(this.config).sendToFlexPLM(payload);
341
- const outboundEntityUpdates = await this.getOutboundEntityUpdates(event, flexResponse);
342
- if (outboundEntityUpdates) {
343
- flexResponse['outboundEntityUpdates'] = outboundEntityUpdates;
344
- }
345
- const statusMsg = 'BaseEntityProcessor: outbound: status: ' + event_short_message_status_1.EventShortMessageStatus.SUCCESS
346
- + ', statusMessage: ' + flexResponse.status
347
- + ', entityType: ' + this.baseType
348
- + ', entityId: ' + event.id
349
- + ', objectClass: ' + objectClass
350
- + ', updateFromResponse: ' + ((outboundEntityUpdates && Object.keys(outboundEntityUpdates).length > 0) ? 'true' : 'false')
351
- + ', orgSlug: ' + this.orgSlug;
352
- console.log(statusMsg);
353
- return flexResponse;
354
- }
355
- catch (e) {
356
- const statusMsg = 'BaseEntityProcessor: outbound: status: ' + event_short_message_status_1.EventShortMessageStatus.FAILURE
357
- + ', statusMessage: ' + e.httpResponseStatus
358
- + ', entityType: ' + this.baseType
359
- + ', entityId: ' + event.id
360
- + ', objectClass: ' + objectClass
361
- + ', updateFromResponse: ' + 'false'
362
- + ', orgSlug: ' + this.orgSlug;
363
- console.log(statusMsg);
364
- throw e;
365
- }
366
- }
367
- async getEntityCurrentStateUpsertPayload(event) {
368
- const id = event.id;
369
- if (!id) {
370
- return undefined;
371
- }
372
- const entity = await this.entities.get({
373
- entityName: this.baseType,
374
- id
375
- });
376
- if (!entity) {
377
- return undefined;
378
- }
379
- event.newData = entity;
380
- event.oldData = entity;
381
- const payload = await this.getOutgoingUpsertPayload(this.baseType, event);
382
- return payload;
383
- }
384
- }
385
- exports.BaseEntityProcessor = BaseEntityProcessor;
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 thumbnail_util_1 = require("../util/thumbnail-util");
10
+ const event_short_message_status_1 = require("../util/event-short-message-status");
11
+ const UNSUPPORTED_TYPE = 'Unsupported eventType.';
12
+ class IncomingEntityResponse {
13
+ }
14
+ exports.IncomingEntityResponse = IncomingEntityResponse;
15
+ class BaseEntityProcessor {
16
+ constructor(config, dc, mapFileUtil, baseType) {
17
+ this.config = config;
18
+ this.dc = dc;
19
+ this.mapFileUtil = mapFileUtil;
20
+ this.baseType = baseType;
21
+ this.typeUtil = new type_utils_1.TypeUtils();
22
+ this.transformMapFile = this.config?.transformMapFile;
23
+ this.entities = new sdk_1.Entities();
24
+ this.orgSlug = this.config?.orgSlug || 'unset-orgSlug';
25
+ }
26
+ // inbound
27
+ async inbound(event) {
28
+ const eventType = event.eventType;
29
+ console.log(`inbound entity: ${eventType}:${event.objectClass}`);
30
+ switch (eventType) {
31
+ case 'PERSIST':
32
+ return await this.handleIncomingUpsert(event);
33
+ case 'DELETE':
34
+ return await this.handleIncomingDelete(event);
35
+ default:
36
+ console.error(UNSUPPORTED_TYPE);
37
+ return {
38
+ status: 500,
39
+ data: { UNSUPPORTED_TYPE }
40
+ };
41
+ }
42
+ }
43
+ async handleIncomingUpsert(event) {
44
+ const inboundData = await this.getTransformedData(event);
45
+ const incomingEntityResponse = await this.getIncomingEntity(event, inboundData);
46
+ // This case means there was an early return in the getIncomingEntity method
47
+ if (incomingEntityResponse.earlyReturn) {
48
+ const statusMsg = this.getInboundStatusMessage({
49
+ status: event_short_message_status_1.EventShortMessageStatus.FAILURE,
50
+ statusMessage: incomingEntityResponse.earlyReturn.shortStatusMessage || '',
51
+ objectClass: event.objectClass,
52
+ federatedId: event.federatedId
53
+ });
54
+ console.log(statusMsg);
55
+ return incomingEntityResponse.earlyReturn;
56
+ }
57
+ const entity = incomingEntityResponse.entity;
58
+ if (!entity) {
59
+ const createEntityResponse = await this.getCreateEntity(inboundData);
60
+ if (createEntityResponse.earlyReturn) {
61
+ const status = (createEntityResponse.earlyReturn.shortStatusMessage === event_short_message_status_1.EventShortMessageStatus.NOT_CREATABLE)
62
+ ? event_short_message_status_1.EventShortMessageStatus.SUCCESS
63
+ : event_short_message_status_1.EventShortMessageStatus.FAILURE;
64
+ const statusMsg = this.getInboundStatusMessage({
65
+ status,
66
+ statusMessage: createEntityResponse.earlyReturn.shortStatusMessage || '',
67
+ objectClass: event.objectClass,
68
+ federatedId: event.federatedId
69
+ });
70
+ console.log(statusMsg);
71
+ return createEntityResponse.earlyReturn;
72
+ }
73
+ let createdEntity = await this.createEntity(this.baseType, createEntityResponse.entity);
74
+ const shouldSyncThumbnail = await type_conversion_utils_1.TypeConversionUtils.syncInboundImages(this.transformMapFile, this.mapFileUtil, event.data);
75
+ if (shouldSyncThumbnail) {
76
+ createdEntity = await new thumbnail_util_1.ThumbnailUtil(this.config).syncThumbnailToVibeIQ({ entityId: createdEntity.id, primaryViewableId: createdEntity.primaryViewableId, event, entityName: this.baseType }) || createdEntity;
77
+ }
78
+ const statusMsg = this.getInboundStatusMessage({
79
+ status: event_short_message_status_1.EventShortMessageStatus.SUCCESS,
80
+ statusMessage: event_short_message_status_1.EventShortMessageStatus.CREATED,
81
+ objectClass: event.objectClass,
82
+ entityId: 'id',
83
+ federatedId: event.federatedId
84
+ });
85
+ console.log(statusMsg);
86
+ return createdEntity;
87
+ }
88
+ const diffs = await this.getUpdatesForEntity(entity, inboundData);
89
+ const shouldSyncThumbnail = await type_conversion_utils_1.TypeConversionUtils.syncInboundImages(this.transformMapFile, this.mapFileUtil, event.data);
90
+ let thumbnailEntity;
91
+ if (shouldSyncThumbnail) {
92
+ thumbnailEntity = await new thumbnail_util_1.ThumbnailUtil(this.config).syncThumbnailToVibeIQ({ entityId: entity.id, primaryViewableId: entity.primaryViewableId, event, entityName: this.baseType });
93
+ }
94
+ const hasPropertyChanges = Object.getOwnPropertyNames(diffs).length > 0;
95
+ if (!hasPropertyChanges && thumbnailEntity) {
96
+ const statusMsg = this.getInboundStatusMessage({
97
+ status: event_short_message_status_1.EventShortMessageStatus.SUCCESS,
98
+ statusMessage: event_short_message_status_1.EventShortMessageStatus.PRIMARY_CONTENT_UPDATED,
99
+ objectClass: event.objectClass,
100
+ entityId: entity.id,
101
+ federatedId: event.federatedId
102
+ });
103
+ console.log(statusMsg);
104
+ return thumbnailEntity;
105
+ }
106
+ if (!hasPropertyChanges) {
107
+ const statusMsg = this.getInboundStatusMessage({
108
+ status: event_short_message_status_1.EventShortMessageStatus.SUCCESS,
109
+ statusMessage: event_short_message_status_1.EventShortMessageStatus.NO_CHANGES,
110
+ objectClass: event.objectClass,
111
+ entityId: entity.id,
112
+ federatedId: event.federatedId
113
+ });
114
+ console.log(statusMsg);
115
+ const message = 'No Changes to persist for entity: ' + entity.id;
116
+ return {
117
+ status: 200,
118
+ data: { message }
119
+ };
120
+ }
121
+ const updatedEntity = await this.updateEntity(this.baseType, entity, diffs);
122
+ const statusMsg = this.getInboundStatusMessage({
123
+ status: event_short_message_status_1.EventShortMessageStatus.SUCCESS,
124
+ statusMessage: event_short_message_status_1.EventShortMessageStatus.UPDATED,
125
+ objectClass: event.objectClass,
126
+ entityId: entity.id,
127
+ federatedId: event.federatedId
128
+ });
129
+ console.log(statusMsg);
130
+ return updatedEntity;
131
+ }
132
+ getInboundStatusMessage(statusObject) {
133
+ return 'BaseEntityProcessor: inbound: status: ' + statusObject.status
134
+ + ', statusMessage: ' + statusObject.statusMessage
135
+ + ', entityType: ' + this.baseType
136
+ + ', entityId: ' + statusObject.entityId
137
+ + ', objectClass: ' + statusObject.objectClass
138
+ + ', federatedId: ' + statusObject.federatedId
139
+ + ', orgSlug: ' + this.orgSlug;
140
+ }
141
+ /**This will query for the entity, and handle post-processing
142
+ * of any critieria that is defined at the sub-type level.
143
+ * Because sub-type criteria can't be used in the search done
144
+ * on the server. This is expected to be called by getIncomingEntity().
145
+ *
146
+ * @param entityType: the root type of the entity
147
+ * @param entityTypePath: the full type path of the entity. Ex: custom-entity:sample
148
+ * @param propertyCriteria: all the criteria to search for the entity
149
+ * @returns the entities that match the criteria
150
+ */
151
+ async queryEntityWithSubTypeCriteria(entityType, entityTypePath, propertyCriteria) {
152
+ //allCriteria; identifierKeys; entityType; entityTypePath
153
+ if (!entityType || !entityTypePath) {
154
+ throw new Error('type and entityTypePath must be defined');
155
+ }
156
+ if (!propertyCriteria || Object.getOwnPropertyNames(propertyCriteria).length == 0) {
157
+ throw new Error('propertyCriteria must be defined and have at least one property');
158
+ }
159
+ const { rootTypeCriteria, subTypeCriteria } = await this.getCriteriaForEntity(entityType, entityTypePath, propertyCriteria);
160
+ const returnedEntities = await this.dc.getAllObjectReferences(entityType, rootTypeCriteria, subTypeCriteria);
161
+ return returnedEntities;
162
+ }
163
+ /** This is to get the criteria for the entity that is being processed.
164
+ * This is to be overridden for item & project-item because of the need for
165
+ * setting the roles criteria.
166
+ *
167
+ * @param entityType: the root type of the entity
168
+ * @param entityTypePath: the full type path of the entity. Ex: custom-entity:sample
169
+ * @param propertyCriteria: all the criteria to search for the entity
170
+ * @returns the criteria for the entity
171
+ */
172
+ async getCriteriaForEntity(entityType, entityTypePath, propertyCriteria) {
173
+ if (!entityType || !entityTypePath) {
174
+ throw new Error('type and entityTypePath must be defined');
175
+ }
176
+ if (!propertyCriteria || Object.getOwnPropertyNames(propertyCriteria).length == 0) {
177
+ throw new Error('propertyCriteria must be defined and have at least one property');
178
+ }
179
+ const rootType = await this.typeUtil.getByRootAndPath({ root: entityType });
180
+ const rootTypePropertyKeys = await this.getRootTypePropertyKeys(rootType, propertyCriteria);
181
+ const rootTypeCriteria = {};
182
+ const subTypeCriteria = {};
183
+ if (entityType !== entityTypePath) {
184
+ subTypeCriteria['typePath'] = entityTypePath;
185
+ }
186
+ for (const key in propertyCriteria) {
187
+ if (rootTypePropertyKeys.includes(key)) {
188
+ rootTypeCriteria[key] = propertyCriteria[key];
189
+ }
190
+ else {
191
+ subTypeCriteria[key] = propertyCriteria[key];
192
+ }
193
+ }
194
+ return { rootTypeCriteria, subTypeCriteria };
195
+ }
196
+ /** This is to get the properties that are owned by the root type
197
+ * This needs to be overridded for multi-level types, such as item
198
+ * and project-item. And for those types, the propertyCriteria
199
+ * will be needed to determine the correct level.
200
+ *
201
+ * @param rootType: the full root type entity for the processed entity
202
+ * @param propertyCriteria: the criteria to determine the correct level (unused for single level types)
203
+ * @returns: string[] of the property keys
204
+ */
205
+ getRootTypePropertyKeys(rootType, propertyCriteria = null) {
206
+ const props = rootType['typeProperties'];
207
+ const rootTypePropertyKeys = props.map(prop => prop.slug);
208
+ return rootTypePropertyKeys;
209
+ }
210
+ async handleIncomingDelete(event) {
211
+ console.warn('delete is not configured', event);
212
+ }
213
+ async getTransformedData(event) {
214
+ let inboundData = event.data;
215
+ console.debug('inboundData: ' + JSON.stringify(inboundData));
216
+ const mapKey = await type_conversion_utils_1.TypeConversionUtils.getMapKeyFromObject(this.transformMapFile, this.mapFileUtil, inboundData, type_conversion_utils_1.TypeConversionUtils.FLEX2VIBE_DIRECTION);
217
+ inboundData = await map_utils_1.MapUtil.applyTransformMap(this.transformMapFile, this.mapFileUtil, inboundData, mapKey, type_conversion_utils_1.TypeConversionUtils.FLEX2VIBE_DIRECTION);
218
+ console.debug('Transformed-inboundData: ' + JSON.stringify(inboundData));
219
+ return inboundData;
220
+ }
221
+ async getUpdatesForEntity(entity, inboundData) {
222
+ const vibeOwningKeys = await this.getVibeOwningKeys(entity);
223
+ let updates = {
224
+ typeId: entity.typeId,
225
+ roles: entity.roles,
226
+ id: entity.id,
227
+ };
228
+ updates = await this.dc.setEntityValues(updates, inboundData, vibeOwningKeys);
229
+ for (const prop of ['typeId', 'roles', 'id']) {
230
+ delete updates[prop];
231
+ }
232
+ return this.dc.getPersistableChanges(entity, updates);
233
+ }
234
+ async getVibeOwningKeys(entity) {
235
+ let vibeOwningKeys = [];
236
+ if (this.transformMapFile && entity) {
237
+ //Technically the transform is flex->vibe. But the vibe entity being updated was passed in,
238
+ // so we use VIBE2FLEX_DIRECTION to get the mapKey
239
+ const mapKey = await type_conversion_utils_1.TypeConversionUtils.getMapKey(this.transformMapFile, this.mapFileUtil, entity, type_conversion_utils_1.TypeConversionUtils.VIBE2FLEX_DIRECTION);
240
+ const mapSection = await map_utils_1.MapUtil.getFullMapSection(this.transformMapFile, this.mapFileUtil, mapKey);
241
+ vibeOwningKeys = mapSection?.vibeOwningKeys || [];
242
+ }
243
+ console.debug('vibeOwningKeys: ' + vibeOwningKeys);
244
+ return vibeOwningKeys;
245
+ }
246
+ async getVibeOwningKeysFromInbound(entity) {
247
+ let vibeOwningKeys = [];
248
+ if (this.transformMapFile && entity) {
249
+ const mapKey = await type_conversion_utils_1.TypeConversionUtils.getMapKeyFromObject(this.transformMapFile, this.mapFileUtil, entity, type_conversion_utils_1.TypeConversionUtils.FLEX2VIBE_DIRECTION);
250
+ const mapSection = await map_utils_1.MapUtil.getFullMapSection(this.transformMapFile, this.mapFileUtil, mapKey);
251
+ vibeOwningKeys = mapSection?.vibeOwningKeys || [];
252
+ }
253
+ console.debug('vibeOwningKeys: ' + vibeOwningKeys);
254
+ return vibeOwningKeys;
255
+ }
256
+ async createEntity(entityName, changes) {
257
+ const options = {
258
+ entityName: entityName,
259
+ object: changes,
260
+ };
261
+ console.log("createEntity: " + JSON.stringify(options));
262
+ return await new sdk_1.Entities().create(options);
263
+ }
264
+ async updateEntity(entityName, entity, diffs) {
265
+ const options = {
266
+ entityName: entityName,
267
+ id: entity['id'],
268
+ object: diffs
269
+ };
270
+ console.log('updateEntity: ' + JSON.stringify(options));
271
+ return await new sdk_1.Entities().update(options);
272
+ }
273
+ // outbound
274
+ async outbound(event) {
275
+ const entityType = event.entityType;
276
+ const eventType = event.eventType;
277
+ const entityId = event.id;
278
+ console.log(`outbound: ${entityType}:${entityId}`);
279
+ switch (eventType) {
280
+ case 'update':
281
+ case 'create':
282
+ return await this.handleOutgoingUpsert(entityType, event);
283
+ case 'delete':
284
+ return await this.handleOutgoingDelete(entityType, event);
285
+ case 'sendUpsertToFlexPLM':
286
+ return await this.sendUpsertToFlexPLM(event);
287
+ default:
288
+ console.log(UNSUPPORTED_TYPE);
289
+ return {
290
+ status: 500,
291
+ data: { UNSUPPORTED_TYPE }
292
+ };
293
+ }
294
+ }
295
+ async handleOutgoingUpsert(entityType, event) {
296
+ const objectClass = await type_conversion_utils_1.TypeConversionUtils.getObjectClass(this.transformMapFile, this.mapFileUtil, event.newData);
297
+ if (!objectClass) {
298
+ const message = 'ObjectClass must have a value.';
299
+ console.log(message);
300
+ return {
301
+ status: 500,
302
+ data: { message }
303
+ };
304
+ }
305
+ try {
306
+ const payload = await this.getOutgoingUpsertPayload(entityType, event);
307
+ const flexResponse = await new flexplm_connect_1.FlexPLMConnect(this.config).sendToFlexPLM(payload);
308
+ const outboundEntityUpdates = await this.getOutboundEntityUpdates(event, flexResponse);
309
+ if (outboundEntityUpdates) {
310
+ flexResponse['outboundEntityUpdates'] = outboundEntityUpdates;
311
+ }
312
+ const statusMsg = 'BaseEntityProcessor: outbound: status: ' + event_short_message_status_1.EventShortMessageStatus.SUCCESS
313
+ + ', statusMessage: ' + flexResponse.status
314
+ + ', entityType: ' + this.baseType
315
+ + ', entityId: ' + event.id
316
+ + ', objectClass: ' + payload.objectClass
317
+ + ', updateFromResponse: ' + ((outboundEntityUpdates && Object.keys(outboundEntityUpdates).length > 0) ? 'true' : 'false')
318
+ + ', orgSlug: ' + this.orgSlug;
319
+ console.log(statusMsg);
320
+ return flexResponse;
321
+ }
322
+ catch (e) {
323
+ const statusMsg = 'BaseEntityProcessor: outbound: status: ' + event_short_message_status_1.EventShortMessageStatus.FAILURE
324
+ + ', statusMessage: ' + e.httpResponseStatus
325
+ + ', entityType: ' + this.baseType
326
+ + ', entityId: ' + event.id
327
+ + ', objectClass: ' + objectClass
328
+ + ', updateFromResponse: ' + 'false'
329
+ + ', orgSlug: ' + this.orgSlug;
330
+ console.log(statusMsg);
331
+ throw e;
332
+ }
333
+ }
334
+ async getOutboundEntityUpdates(event, flexResponse) {
335
+ const payload = flexResponse?.data?.payload;
336
+ const flexPayload = (payload) ? payload[0] : undefined;
337
+ let outboundEntityUpdates = undefined;
338
+ if (flexPayload && 'OK' === flexPayload.status) {
339
+ if (flexPayload.data && !flexPayload.data?.flexPLMObjectClass) {
340
+ flexPayload.data.flexPLMObjectClass = flexPayload.objectClass;
341
+ }
342
+ const inboundData = await this.getTransformedData(flexPayload);
343
+ outboundEntityUpdates = await this.getUpdatesForEntity(event.newData, inboundData);
344
+ }
345
+ return outboundEntityUpdates;
346
+ }
347
+ async handleOutgoingDelete(entityType, event) {
348
+ console.warn('delete is not configured', entityType, event.oldData);
349
+ }
350
+ /** Create a new event-workflow-request to rerun sending the entity to FlexPLM
351
+ * The event must contain any information needed to ensure it is put in the correct queue for the entity
352
+ *
353
+ * @param triggerKey Ex: event.entityType + '|sendUpsertToFlexPLM'
354
+ * @param event
355
+ * @returns
356
+ */
357
+ async triggerNewEvent(triggerKey, event) {
358
+ const newEvent = {
359
+ entityName: 'event-workflow-request',
360
+ object: {
361
+ triggerKey,
362
+ event
363
+ }
364
+ };
365
+ const response = await this.entities.create(newEvent);
366
+ return response;
367
+ }
368
+ /** Sends the current state of the entity to FlexPLM.
369
+ * So any changes made in Vibe between the event being generated and the event being processed are sent to FlexPLM.
370
+ *
371
+ * @param event must contain entityType, id; which are used to query for the entity
372
+ * @returns results of sending the entity to FlexPLM
373
+ */
374
+ async sendUpsertToFlexPLM(event) {
375
+ const payload = await this.getEntityCurrentStateUpsertPayload(event);
376
+ if (!payload) {
377
+ const message = 'No payload to send to FlexPLM';
378
+ console.log(message);
379
+ return {
380
+ status: 500,
381
+ data: { message }
382
+ };
383
+ }
384
+ ;
385
+ let objectClass = payload.objectClass;
386
+ try {
387
+ const flexResponse = await new flexplm_connect_1.FlexPLMConnect(this.config).sendToFlexPLM(payload);
388
+ const outboundEntityUpdates = await this.getOutboundEntityUpdates(event, flexResponse);
389
+ if (outboundEntityUpdates) {
390
+ flexResponse['outboundEntityUpdates'] = outboundEntityUpdates;
391
+ }
392
+ const statusMsg = 'BaseEntityProcessor: outbound: status: ' + event_short_message_status_1.EventShortMessageStatus.SUCCESS
393
+ + ', statusMessage: ' + flexResponse.status
394
+ + ', entityType: ' + this.baseType
395
+ + ', entityId: ' + event.id
396
+ + ', objectClass: ' + objectClass
397
+ + ', updateFromResponse: ' + ((outboundEntityUpdates && Object.keys(outboundEntityUpdates).length > 0) ? 'true' : 'false')
398
+ + ', orgSlug: ' + this.orgSlug;
399
+ console.log(statusMsg);
400
+ return flexResponse;
401
+ }
402
+ catch (e) {
403
+ const statusMsg = 'BaseEntityProcessor: outbound: status: ' + event_short_message_status_1.EventShortMessageStatus.FAILURE
404
+ + ', statusMessage: ' + e.httpResponseStatus
405
+ + ', entityType: ' + this.baseType
406
+ + ', entityId: ' + event.id
407
+ + ', objectClass: ' + objectClass
408
+ + ', updateFromResponse: ' + 'false'
409
+ + ', orgSlug: ' + this.orgSlug;
410
+ console.log(statusMsg);
411
+ throw e;
412
+ }
413
+ }
414
+ /** Generates the payload to send to FlexPLM, based on the current state of the entity.
415
+ * The current state of the entity are used as the newData and oldData; which is passed
416
+ * to getOutgoingUpsertPayload to generate the payload.
417
+ * @param event information about the item to send to FlexPLM
418
+ * @returns The payload to send to FlexPLM
419
+ */
420
+ async getEntityCurrentStateUpsertPayload(event) {
421
+ const id = event.id;
422
+ if (!id) {
423
+ return undefined;
424
+ }
425
+ const entity = await this.entities.get({
426
+ entityName: this.baseType,
427
+ id
428
+ });
429
+ if (!entity) {
430
+ return undefined;
431
+ }
432
+ event.newData = entity;
433
+ event.oldData = entity;
434
+ const payload = await this.getOutgoingUpsertPayload(this.baseType, event);
435
+ return payload;
436
+ }
437
+ }
438
+ exports.BaseEntityProcessor = BaseEntityProcessor;