@contrail/flexplm 1.3.0 → 1.3.1-alpha.eae3d9f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/flexplm-lib.yml +1 -1
- package/.github/workflows/publish-to-npm.yml +35 -38
- package/lib/entity-processor/base-entity-processor.d.ts +42 -42
- package/lib/entity-processor/base-entity-processor.js +385 -385
- package/lib/entity-processor/base-entity-processor.spec.d.ts +1 -1
- package/lib/entity-processor/base-entity-processor.spec.js +397 -397
- package/lib/flexplm-request.d.ts +3 -3
- package/lib/flexplm-request.js +34 -34
- package/lib/flexplm-utils.d.ts +5 -5
- package/lib/flexplm-utils.js +33 -33
- package/lib/flexplm-utils.spec.d.ts +1 -1
- package/lib/flexplm-utils.spec.js +26 -26
- package/lib/index.d.ts +22 -22
- package/lib/index.js +38 -38
- package/lib/interfaces/interfaces.d.ts +105 -105
- package/lib/interfaces/interfaces.js +2 -2
- package/lib/interfaces/item-family-changes.d.ts +20 -20
- package/lib/interfaces/item-family-changes.js +56 -56
- package/lib/interfaces/publish-change-data.d.ts +19 -19
- package/lib/interfaces/publish-change-data.js +32 -32
- package/lib/publish/base-process-publish-assortment-callback.d.ts +9 -9
- package/lib/publish/base-process-publish-assortment-callback.js +38 -38
- package/lib/publish/base-process-publish-assortment.d.ts +93 -93
- package/lib/publish/base-process-publish-assortment.js +944 -944
- package/lib/publish/base-process-publish-assortment.spec.d.ts +1 -1
- package/lib/publish/base-process-publish-assortment.spec.js +1670 -1670
- package/lib/publish/mockData.d.ts +1389 -1389
- package/lib/publish/mockData.js +4519 -4519
- package/lib/transform/identifier-conversion-spec-mockData.js +444 -444
- package/lib/transform/identifier-conversion.d.ts +15 -15
- package/lib/transform/identifier-conversion.js +212 -212
- package/lib/transform/identifier-conversion.spec.d.ts +1 -1
- package/lib/transform/identifier-conversion.spec.js +339 -339
- package/lib/util/config-defaults.d.ts +8 -8
- package/lib/util/config-defaults.js +85 -85
- package/lib/util/config-defaults.spec.d.ts +1 -1
- package/lib/util/config-defaults.spec.js +293 -293
- package/lib/util/data-converter-spec-mockData.js +205 -205
- package/lib/util/data-converter.d.ts +39 -39
- package/lib/util/data-converter.js +592 -592
- package/lib/util/data-converter.spec.d.ts +1 -1
- package/lib/util/data-converter.spec.js +904 -904
- package/lib/util/error-response-object.d.ts +4 -4
- package/lib/util/error-response-object.js +47 -47
- package/lib/util/error-response-object.spec.d.ts +1 -1
- package/lib/util/error-response-object.spec.js +99 -99
- package/lib/util/event-short-message-status.d.ts +19 -19
- package/lib/util/event-short-message-status.js +23 -23
- package/lib/util/federation.d.ts +15 -15
- package/lib/util/federation.js +149 -149
- package/lib/util/flexplm-connect.d.ts +22 -22
- package/lib/util/flexplm-connect.js +176 -176
- package/lib/util/flexplm-connect.spec.d.ts +1 -1
- package/lib/util/flexplm-connect.spec.js +88 -88
- package/lib/util/logger-config.d.ts +1 -1
- package/lib/util/logger-config.js +26 -26
- package/lib/util/map-util-spec-mockData.js +205 -205
- package/lib/util/map-utils.d.ts +6 -6
- package/lib/util/map-utils.js +15 -15
- package/lib/util/map-utils.spec.d.ts +1 -1
- package/lib/util/map-utils.spec.js +89 -89
- package/lib/util/mockData.d.ts +80 -80
- package/lib/util/mockData.js +103 -103
- package/lib/util/thumbnail-util.d.ts +34 -34
- package/lib/util/thumbnail-util.js +215 -215
- package/lib/util/thumbnail-util.spec.d.ts +1 -1
- package/lib/util/thumbnail-util.spec.js +434 -434
- package/lib/util/type-conversion-utils-spec-mockData.js +259 -259
- package/lib/util/type-conversion-utils.d.ts +23 -23
- package/lib/util/type-conversion-utils.js +265 -265
- package/lib/util/type-conversion-utils.spec.d.ts +1 -1
- package/lib/util/type-conversion-utils.spec.js +868 -868
- package/lib/util/type-defaults.d.ts +16 -16
- package/lib/util/type-defaults.js +221 -221
- package/lib/util/type-defaults.spec.d.ts +1 -1
- package/lib/util/type-defaults.spec.js +516 -516
- package/lib/util/type-utils.d.ts +13 -13
- package/lib/util/type-utils.js +114 -114
- package/lib/util/type-utils.spec.d.ts +1 -1
- package/lib/util/type-utils.spec.js +190 -190
- package/package.json +1 -1
- package/publish.sh +0 -0
- package/tsconfig.json +1 -6
- package/.claude/settings.local.json +0 -8
|
@@ -1,385 +1,385 @@
|
|
|
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
|
+
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;
|