@contrail/flexplm 2.0.0-alpha.9af4b96 → 2.0.0-alpha.baca70f
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/lib/entity-processor/base-entity-processor.d.ts +0 -29
- package/lib/entity-processor/base-entity-processor.js +143 -238
- package/lib/entity-processor/base-entity-processor.spec.js +0 -212
- package/lib/index.d.ts +0 -2
- package/lib/index.js +0 -2
- package/lib/interfaces/interfaces.d.ts +1 -1
- package/lib/publish/base-process-publish-assortment-callback.js +0 -30
- package/lib/publish/base-process-publish-assortment.d.ts +0 -24
- package/lib/publish/base-process-publish-assortment.js +132 -243
- package/lib/publish/base-process-publish-assortment.spec.js +0 -188
- package/lib/util/config-defaults.js +0 -2
- package/lib/util/error-response-object.js +0 -2
- package/lib/util/flexplm-connect.d.ts +9 -4
- package/lib/util/flexplm-connect.js +172 -202
- package/lib/util/flexplm-connect.spec.js +166 -2
- package/lib/util/thumbnail-util.d.ts +1 -2
- package/lib/util/thumbnail-util.js +6 -34
- package/lib/util/thumbnail-util.spec.js +0 -42
- package/lib/util/type-utils.d.ts +3 -3
- package/package.json +10 -12
- package/lib/__tests__/telemetry-test-utils.d.ts +0 -8
- package/lib/__tests__/telemetry-test-utils.js +0 -30
- package/lib/flexplm-request.d.ts +0 -3
- package/lib/flexplm-request.js +0 -34
- package/lib/publish/base-process-publish-assortment-callback.spec.d.ts +0 -1
- package/lib/publish/base-process-publish-assortment-callback.spec.js +0 -62
- package/lib/util/flexplm-connect.telemetry.spec.d.ts +0 -1
- package/lib/util/flexplm-connect.telemetry.spec.js +0 -212
- package/lib/util/telemetry-attributes.d.ts +0 -68
- package/lib/util/telemetry-attributes.js +0 -73
- package/lib/util/telemetry-utils.d.ts +0 -3
- package/lib/util/telemetry-utils.js +0 -10
|
@@ -2,28 +2,10 @@ import { FCConfig, EntityPayloadType } from '../interfaces/interfaces';
|
|
|
2
2
|
import { DataConverter } from '../util/data-converter';
|
|
3
3
|
import { TypeUtils } from '../util/type-utils';
|
|
4
4
|
import { MapFileUtil } from '@contrail/transform-data';
|
|
5
|
-
import { EventShortMessageStatus } from '../util/event-short-message-status';
|
|
6
5
|
export declare class IncomingEntityResponse {
|
|
7
6
|
entity: any;
|
|
8
7
|
earlyReturn: any;
|
|
9
8
|
}
|
|
10
|
-
export interface InboundStatus {
|
|
11
|
-
status: EventShortMessageStatus;
|
|
12
|
-
statusMessage: string;
|
|
13
|
-
objectClass: string;
|
|
14
|
-
entityId?: string;
|
|
15
|
-
federatedId?: string;
|
|
16
|
-
}
|
|
17
|
-
export interface OutboundStatus {
|
|
18
|
-
status: EventShortMessageStatus;
|
|
19
|
-
entityId: string;
|
|
20
|
-
objectClass: string;
|
|
21
|
-
httpStatus?: number;
|
|
22
|
-
updatedFromResponse: boolean;
|
|
23
|
-
/** FlexPLM's per-item status from the response payload, when it returned one. */
|
|
24
|
-
itemStatus?: string;
|
|
25
|
-
error?: unknown;
|
|
26
|
-
}
|
|
27
9
|
export declare abstract class BaseEntityProcessor {
|
|
28
10
|
protected config: FCConfig;
|
|
29
11
|
protected dc: DataConverter;
|
|
@@ -36,18 +18,7 @@ export declare abstract class BaseEntityProcessor {
|
|
|
36
18
|
constructor(config: FCConfig, dc: DataConverter, mapFileUtil: MapFileUtil, baseType: string);
|
|
37
19
|
inbound(event: EntityPayloadType): Promise<any>;
|
|
38
20
|
handleIncomingUpsert(event: EntityPayloadType): Promise<any>;
|
|
39
|
-
/** @deprecated Use {@link recordInboundStatus}, which logs structured fields and sets span attributes. */
|
|
40
21
|
getInboundStatusMessage(statusObject: any): string;
|
|
41
|
-
/** Records the result of one inbound event: attributes on the active span plus one structured log.
|
|
42
|
-
* A Failure here is a handled early return, so it is a warning and the span stays OK.
|
|
43
|
-
*/
|
|
44
|
-
protected recordInboundStatus(statusObject: InboundStatus): void;
|
|
45
|
-
/** Records the result of sending one entity to FlexPLM: attributes on the active span plus one structured log.
|
|
46
|
-
* On failure the caller still rethrows; the log keeps the entity context that the action's error log lacks.
|
|
47
|
-
* A Success whose response item status is not 'OK' is recorded as a Failure: FlexPLM accepted the request
|
|
48
|
-
* but rejected the item. Nothing is thrown for it, so it is a warning and the span stays OK.
|
|
49
|
-
*/
|
|
50
|
-
protected recordOutboundStatus(statusObject: OutboundStatus): void;
|
|
51
22
|
/** Looks up an identity record from the identity service based on the passed in criteria.
|
|
52
23
|
* If no identity record is found, returns undefined. If multiple are found, throws an error.
|
|
53
24
|
*
|
|
@@ -8,17 +8,10 @@ const sdk_1 = require("@contrail/sdk");
|
|
|
8
8
|
const type_conversion_utils_1 = require("../util/type-conversion-utils");
|
|
9
9
|
const thumbnail_util_1 = require("../util/thumbnail-util");
|
|
10
10
|
const event_short_message_status_1 = require("../util/event-short-message-status");
|
|
11
|
-
const telemetry_1 = require("@contrail/telemetry");
|
|
12
|
-
const telemetry_utils_1 = require("../util/telemetry-utils");
|
|
13
|
-
const telemetry_attributes_1 = require("../util/telemetry-attributes");
|
|
14
11
|
const UNSUPPORTED_TYPE = 'Unsupported eventType.';
|
|
15
12
|
class IncomingEntityResponse {
|
|
16
13
|
}
|
|
17
14
|
exports.IncomingEntityResponse = IncomingEntityResponse;
|
|
18
|
-
const FLEXPLM_ITEM_STATUS_OK = 'OK';
|
|
19
|
-
const hasUpdates = (updates) => !!updates && Object.keys(updates).length > 0;
|
|
20
|
-
const getResponseItemStatus = (flexResponse) => flexResponse?.data?.payload?.[0]?.status;
|
|
21
|
-
const countProperties = (object) => (object && typeof object === 'object') ? Object.keys(object).length : 0;
|
|
22
15
|
class BaseEntityProcessor {
|
|
23
16
|
constructor(config, dc, mapFileUtil, baseType) {
|
|
24
17
|
this.config = config;
|
|
@@ -32,37 +25,33 @@ class BaseEntityProcessor {
|
|
|
32
25
|
}
|
|
33
26
|
// inbound
|
|
34
27
|
async inbound(event) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
status: 500,
|
|
50
|
-
data: { UNSUPPORTED_TYPE }
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
});
|
|
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
|
+
}
|
|
54
42
|
}
|
|
55
43
|
async handleIncomingUpsert(event) {
|
|
56
44
|
const inboundData = await this.getTransformedData(event);
|
|
57
45
|
const incomingEntityResponse = await this.getIncomingEntity(event, inboundData);
|
|
58
46
|
// This case means there was an early return in the getIncomingEntity method
|
|
59
47
|
if (incomingEntityResponse.earlyReturn) {
|
|
60
|
-
this.
|
|
48
|
+
const statusMsg = this.getInboundStatusMessage({
|
|
61
49
|
status: event_short_message_status_1.EventShortMessageStatus.FAILURE,
|
|
62
50
|
statusMessage: incomingEntityResponse.earlyReturn.shortStatusMessage || '',
|
|
63
51
|
objectClass: event.objectClass,
|
|
64
52
|
federatedId: event.federatedId
|
|
65
53
|
});
|
|
54
|
+
console.log(statusMsg);
|
|
66
55
|
return incomingEntityResponse.earlyReturn;
|
|
67
56
|
}
|
|
68
57
|
const entity = incomingEntityResponse.entity;
|
|
@@ -72,12 +61,13 @@ class BaseEntityProcessor {
|
|
|
72
61
|
const status = (createEntityResponse.earlyReturn.shortStatusMessage === event_short_message_status_1.EventShortMessageStatus.NOT_CREATABLE)
|
|
73
62
|
? event_short_message_status_1.EventShortMessageStatus.SUCCESS
|
|
74
63
|
: event_short_message_status_1.EventShortMessageStatus.FAILURE;
|
|
75
|
-
this.
|
|
64
|
+
const statusMsg = this.getInboundStatusMessage({
|
|
76
65
|
status,
|
|
77
66
|
statusMessage: createEntityResponse.earlyReturn.shortStatusMessage || '',
|
|
78
67
|
objectClass: event.objectClass,
|
|
79
68
|
federatedId: event.federatedId
|
|
80
69
|
});
|
|
70
|
+
console.log(statusMsg);
|
|
81
71
|
return createEntityResponse.earlyReturn;
|
|
82
72
|
}
|
|
83
73
|
let createdEntity = await this.createEntity(this.baseType, createEntityResponse.entity);
|
|
@@ -85,13 +75,14 @@ class BaseEntityProcessor {
|
|
|
85
75
|
if (shouldSyncThumbnail) {
|
|
86
76
|
createdEntity = await new thumbnail_util_1.ThumbnailUtil(this.config).syncThumbnailToVibeIQ({ entityId: createdEntity.id, primaryViewableId: createdEntity.primaryViewableId, event, entityName: this.baseType }) || createdEntity;
|
|
87
77
|
}
|
|
88
|
-
this.
|
|
78
|
+
const statusMsg = this.getInboundStatusMessage({
|
|
89
79
|
status: event_short_message_status_1.EventShortMessageStatus.SUCCESS,
|
|
90
80
|
statusMessage: event_short_message_status_1.EventShortMessageStatus.CREATED,
|
|
91
81
|
objectClass: event.objectClass,
|
|
92
|
-
entityId:
|
|
82
|
+
entityId: 'id',
|
|
93
83
|
federatedId: event.federatedId
|
|
94
84
|
});
|
|
85
|
+
console.log(statusMsg);
|
|
95
86
|
return createdEntity;
|
|
96
87
|
}
|
|
97
88
|
const diffs = await this.getUpdatesForEntity(entity, inboundData, event.data);
|
|
@@ -102,23 +93,25 @@ class BaseEntityProcessor {
|
|
|
102
93
|
}
|
|
103
94
|
const hasPropertyChanges = Object.getOwnPropertyNames(diffs).length > 0;
|
|
104
95
|
if (!hasPropertyChanges && thumbnailEntity) {
|
|
105
|
-
this.
|
|
96
|
+
const statusMsg = this.getInboundStatusMessage({
|
|
106
97
|
status: event_short_message_status_1.EventShortMessageStatus.SUCCESS,
|
|
107
98
|
statusMessage: event_short_message_status_1.EventShortMessageStatus.PRIMARY_CONTENT_UPDATED,
|
|
108
99
|
objectClass: event.objectClass,
|
|
109
100
|
entityId: entity.id,
|
|
110
101
|
federatedId: event.federatedId
|
|
111
102
|
});
|
|
103
|
+
console.log(statusMsg);
|
|
112
104
|
return thumbnailEntity;
|
|
113
105
|
}
|
|
114
106
|
if (!hasPropertyChanges) {
|
|
115
|
-
this.
|
|
107
|
+
const statusMsg = this.getInboundStatusMessage({
|
|
116
108
|
status: event_short_message_status_1.EventShortMessageStatus.SUCCESS,
|
|
117
109
|
statusMessage: event_short_message_status_1.EventShortMessageStatus.NO_CHANGES,
|
|
118
110
|
objectClass: event.objectClass,
|
|
119
111
|
entityId: entity.id,
|
|
120
112
|
federatedId: event.federatedId
|
|
121
113
|
});
|
|
114
|
+
console.log(statusMsg);
|
|
122
115
|
const message = 'No Changes to persist for entity: ' + entity.id;
|
|
123
116
|
return {
|
|
124
117
|
status: 200,
|
|
@@ -126,16 +119,16 @@ class BaseEntityProcessor {
|
|
|
126
119
|
};
|
|
127
120
|
}
|
|
128
121
|
const updatedEntity = await this.updateEntity(this.baseType, entity, diffs);
|
|
129
|
-
this.
|
|
122
|
+
const statusMsg = this.getInboundStatusMessage({
|
|
130
123
|
status: event_short_message_status_1.EventShortMessageStatus.SUCCESS,
|
|
131
124
|
statusMessage: event_short_message_status_1.EventShortMessageStatus.UPDATED,
|
|
132
125
|
objectClass: event.objectClass,
|
|
133
126
|
entityId: entity.id,
|
|
134
127
|
federatedId: event.federatedId
|
|
135
128
|
});
|
|
129
|
+
console.log(statusMsg);
|
|
136
130
|
return updatedEntity;
|
|
137
131
|
}
|
|
138
|
-
/** @deprecated Use {@link recordInboundStatus}, which logs structured fields and sets span attributes. */
|
|
139
132
|
getInboundStatusMessage(statusObject) {
|
|
140
133
|
return 'BaseEntityProcessor: inbound: status: ' + statusObject.status
|
|
141
134
|
+ ', statusMessage: ' + statusObject.statusMessage
|
|
@@ -145,60 +138,6 @@ class BaseEntityProcessor {
|
|
|
145
138
|
+ ', federatedId: ' + statusObject.federatedId
|
|
146
139
|
+ ', orgSlug: ' + this.orgSlug;
|
|
147
140
|
}
|
|
148
|
-
/** Records the result of one inbound event: attributes on the active span plus one structured log.
|
|
149
|
-
* A Failure here is a handled early return, so it is a warning and the span stays OK.
|
|
150
|
-
*/
|
|
151
|
-
recordInboundStatus(statusObject) {
|
|
152
|
-
const { status, statusMessage, objectClass, entityId, federatedId } = statusObject;
|
|
153
|
-
(0, telemetry_utils_1.setActiveSpanAttributes)({
|
|
154
|
-
[telemetry_attributes_1.ATTR_FLEXPLM_STATUS]: status,
|
|
155
|
-
[telemetry_attributes_1.ATTR_FLEXPLM_OUTCOME]: statusMessage,
|
|
156
|
-
[telemetry_attributes_1.ATTR_FLEXPLM_ENTITY_TYPE]: this.baseType,
|
|
157
|
-
[telemetry_attributes_1.ATTR_FLEXPLM_EVENT_OBJECT_CLASS]: objectClass,
|
|
158
|
-
[telemetry_attributes_1.ATTR_FLEXPLM_ENTITY_ID]: entityId,
|
|
159
|
-
[telemetry_attributes_1.ATTR_FLEXPLM_FEDERATED_ID]: federatedId,
|
|
160
|
-
});
|
|
161
|
-
const fields = { flexplm: {
|
|
162
|
-
direction: 'inbound', status, outcome: statusMessage, entity_type: this.baseType,
|
|
163
|
-
entity_id: entityId, object_class: objectClass, federated_id: federatedId,
|
|
164
|
-
} };
|
|
165
|
-
if (status === event_short_message_status_1.EventShortMessageStatus.FAILURE) {
|
|
166
|
-
telemetry_1.logger.warn(fields, 'FlexPLM inbound entity not processed: %j', fields.flexplm);
|
|
167
|
-
}
|
|
168
|
-
else {
|
|
169
|
-
telemetry_1.logger.info(fields, 'FlexPLM inbound entity processed: %j', fields.flexplm);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
/** Records the result of sending one entity to FlexPLM: attributes on the active span plus one structured log.
|
|
173
|
-
* On failure the caller still rethrows; the log keeps the entity context that the action's error log lacks.
|
|
174
|
-
* A Success whose response item status is not 'OK' is recorded as a Failure: FlexPLM accepted the request
|
|
175
|
-
* but rejected the item. Nothing is thrown for it, so it is a warning and the span stays OK.
|
|
176
|
-
*/
|
|
177
|
-
recordOutboundStatus(statusObject) {
|
|
178
|
-
const { entityId, objectClass, httpStatus, updatedFromResponse, itemStatus, error } = statusObject;
|
|
179
|
-
const rejected = statusObject.status === event_short_message_status_1.EventShortMessageStatus.SUCCESS && !!itemStatus && itemStatus !== FLEXPLM_ITEM_STATUS_OK;
|
|
180
|
-
const status = rejected ? event_short_message_status_1.EventShortMessageStatus.FAILURE : statusObject.status;
|
|
181
|
-
(0, telemetry_utils_1.setActiveSpanAttributes)({
|
|
182
|
-
[telemetry_attributes_1.ATTR_FLEXPLM_STATUS]: status,
|
|
183
|
-
[telemetry_attributes_1.ATTR_FLEXPLM_ENTITY_ID]: entityId,
|
|
184
|
-
[telemetry_attributes_1.ATTR_FLEXPLM_EVENT_OBJECT_CLASS]: objectClass,
|
|
185
|
-
[telemetry_attributes_1.ATTR_FLEXPLM_UPDATED_FROM_RESPONSE]: updatedFromResponse,
|
|
186
|
-
[telemetry_attributes_1.ATTR_FLEXPLM_RESPONSE_ITEM_STATUS]: itemStatus,
|
|
187
|
-
});
|
|
188
|
-
const flexplm = {
|
|
189
|
-
direction: 'outbound', status, entity_type: this.baseType, entity_id: entityId,
|
|
190
|
-
object_class: objectClass, http_status: httpStatus, item_status: itemStatus, updated_from_response: updatedFromResponse,
|
|
191
|
-
};
|
|
192
|
-
if (rejected) {
|
|
193
|
-
telemetry_1.logger.warn({ flexplm }, 'FlexPLM outbound entity rejected: %j', flexplm);
|
|
194
|
-
}
|
|
195
|
-
else if (status === event_short_message_status_1.EventShortMessageStatus.FAILURE) {
|
|
196
|
-
telemetry_1.logger.error({ error, flexplm }, 'FlexPLM outbound entity failed: %j', flexplm);
|
|
197
|
-
}
|
|
198
|
-
else {
|
|
199
|
-
telemetry_1.logger.info({ flexplm }, 'FlexPLM outbound entity sent: %j', flexplm);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
141
|
/** Looks up an identity record from the identity service based on the passed in criteria.
|
|
203
142
|
* If no identity record is found, returns undefined. If multiple are found, throws an error.
|
|
204
143
|
*
|
|
@@ -239,29 +178,25 @@ class BaseEntityProcessor {
|
|
|
239
178
|
* @throws error if multiple identity entities are found, or if required parameters are missing
|
|
240
179
|
*/
|
|
241
180
|
async getEntityUsingIdentityService(params) {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
entityName,
|
|
260
|
-
id
|
|
261
|
-
});
|
|
262
|
-
span.setAttribute(telemetry_attributes_1.ATTR_FLEXPLM_ENTITY_FOUND, !!entity);
|
|
263
|
-
return entity;
|
|
181
|
+
const identityEntity = await this.getIdentityEntity(params);
|
|
182
|
+
if (!identityEntity) {
|
|
183
|
+
return undefined;
|
|
184
|
+
}
|
|
185
|
+
const entityReference = identityEntity.entityReference;
|
|
186
|
+
if (typeof entityReference !== 'string' || !entityReference.includes(':')) {
|
|
187
|
+
throw new Error(`Invalid identity entityReference: ${String(entityReference)}`);
|
|
188
|
+
}
|
|
189
|
+
const firstColonIndex = entityReference.indexOf(':');
|
|
190
|
+
if (firstColonIndex === 0 || firstColonIndex === entityReference.length - 1) {
|
|
191
|
+
throw new Error('Invalid identity entityReference: ' + entityReference);
|
|
192
|
+
}
|
|
193
|
+
const entityName = entityReference.slice(0, firstColonIndex);
|
|
194
|
+
const id = entityReference.slice(firstColonIndex + 1);
|
|
195
|
+
const entity = await this.entities.get({
|
|
196
|
+
entityName,
|
|
197
|
+
id
|
|
264
198
|
});
|
|
199
|
+
return entity;
|
|
265
200
|
}
|
|
266
201
|
/**This will query for the entity, and handle post-processing
|
|
267
202
|
* of any critieria that is defined at the sub-type level.
|
|
@@ -281,12 +216,9 @@ class BaseEntityProcessor {
|
|
|
281
216
|
if (!propertyCriteria || Object.getOwnPropertyNames(propertyCriteria).length == 0) {
|
|
282
217
|
throw new Error('propertyCriteria must be defined and have at least one property');
|
|
283
218
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
span.setAttribute(telemetry_attributes_1.ATTR_FLEXPLM_ENTITY_RESULT_COUNT, Array.isArray(returnedEntities) ? returnedEntities.length : 0);
|
|
288
|
-
return returnedEntities;
|
|
289
|
-
});
|
|
219
|
+
const { rootTypeCriteria, subTypeCriteria } = await this.getCriteriaForEntity(entityType, entityTypePath, propertyCriteria);
|
|
220
|
+
const returnedEntities = await this.dc.getAllObjectReferences(entityType, rootTypeCriteria, subTypeCriteria);
|
|
221
|
+
return returnedEntities;
|
|
290
222
|
}
|
|
291
223
|
/** This is to get the criteria for the entity that is being processed.
|
|
292
224
|
* This is to be overridden for item & project-item because of the need for
|
|
@@ -336,11 +268,7 @@ class BaseEntityProcessor {
|
|
|
336
268
|
return rootTypePropertyKeys;
|
|
337
269
|
}
|
|
338
270
|
async handleIncomingDelete(event) {
|
|
339
|
-
|
|
340
|
-
telemetry_1.logger.warn({ flexplm: {
|
|
341
|
-
direction: 'inbound', event_type: event?.eventType, entity_type: this.baseType,
|
|
342
|
-
object_class: event?.objectClass, federated_id: event?.federatedId,
|
|
343
|
-
} }, 'FlexPLM delete is not configured');
|
|
271
|
+
console.warn('delete is not configured', event);
|
|
344
272
|
}
|
|
345
273
|
async getTransformedData(event) {
|
|
346
274
|
let inboundData = event.data;
|
|
@@ -399,15 +327,7 @@ class BaseEntityProcessor {
|
|
|
399
327
|
object: changes,
|
|
400
328
|
};
|
|
401
329
|
console.log("createEntity: " + JSON.stringify(options));
|
|
402
|
-
return
|
|
403
|
-
[telemetry_attributes_1.ATTR_FLEXPLM_ENTITY_TYPE]: entityName,
|
|
404
|
-
[telemetry_attributes_1.ATTR_FLEXPLM_CHANGED_PROPERTY_COUNT]: countProperties(changes),
|
|
405
|
-
}, async (span) => {
|
|
406
|
-
const created = await new sdk_1.Entities().create(options);
|
|
407
|
-
if (created?.id)
|
|
408
|
-
span.setAttribute(telemetry_attributes_1.ATTR_FLEXPLM_ENTITY_ID, created.id);
|
|
409
|
-
return created;
|
|
410
|
-
});
|
|
330
|
+
return await new sdk_1.Entities().create(options);
|
|
411
331
|
}
|
|
412
332
|
async updateEntity(entityName, entity, diffs) {
|
|
413
333
|
const options = {
|
|
@@ -416,78 +336,68 @@ class BaseEntityProcessor {
|
|
|
416
336
|
object: diffs
|
|
417
337
|
};
|
|
418
338
|
console.log('updateEntity: ' + JSON.stringify(options));
|
|
419
|
-
return
|
|
420
|
-
[telemetry_attributes_1.ATTR_FLEXPLM_ENTITY_TYPE]: entityName,
|
|
421
|
-
[telemetry_attributes_1.ATTR_FLEXPLM_ENTITY_ID]: entity?.['id'],
|
|
422
|
-
[telemetry_attributes_1.ATTR_FLEXPLM_CHANGED_PROPERTY_COUNT]: countProperties(diffs),
|
|
423
|
-
}, () => new sdk_1.Entities().update(options));
|
|
339
|
+
return await new sdk_1.Entities().update(options);
|
|
424
340
|
}
|
|
425
341
|
// outbound
|
|
426
342
|
async outbound(event) {
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
return await this.sendUpsertToFlexPLM(event);
|
|
442
|
-
default:
|
|
443
|
-
telemetry_1.logger.warn({ flexplm: { direction: 'outbound', event_type: eventType, entity_type: this.baseType, entity_id: event.id } }, 'Unsupported FlexPLM event type');
|
|
444
|
-
return {
|
|
445
|
-
status: 500,
|
|
446
|
-
data: { UNSUPPORTED_TYPE }
|
|
447
|
-
};
|
|
448
|
-
}
|
|
449
|
-
});
|
|
450
|
-
}
|
|
451
|
-
async handleOutgoingUpsert(entityType, event) {
|
|
452
|
-
return (0, telemetry_1.traceSection)('upsert_entity_in_flexplm', { [telemetry_attributes_1.ATTR_FLEXPLM_ENTITY_TYPE]: this.baseType }, async () => {
|
|
453
|
-
const objectClass = await type_conversion_utils_1.TypeConversionUtils.getObjectClass(this.transformMapFile, this.mapFileUtil, event.newData);
|
|
454
|
-
if (!objectClass) {
|
|
455
|
-
const message = 'ObjectClass must have a value.';
|
|
456
|
-
telemetry_1.logger.warn({ flexplm: { direction: 'outbound', entity_type: this.baseType, entity_id: event.id } }, message);
|
|
343
|
+
const entityType = event.entityType;
|
|
344
|
+
const eventType = event.eventType;
|
|
345
|
+
const entityId = event.id;
|
|
346
|
+
console.log(`outbound: ${entityType}:${entityId}`);
|
|
347
|
+
switch (eventType) {
|
|
348
|
+
case 'update':
|
|
349
|
+
case 'create':
|
|
350
|
+
return await this.handleOutgoingUpsert(entityType, event);
|
|
351
|
+
case 'delete':
|
|
352
|
+
return await this.handleOutgoingDelete(entityType, event);
|
|
353
|
+
case 'sendUpsertToFlexPLM':
|
|
354
|
+
return await this.sendUpsertToFlexPLM(event);
|
|
355
|
+
default:
|
|
356
|
+
console.log(UNSUPPORTED_TYPE);
|
|
457
357
|
return {
|
|
458
358
|
status: 500,
|
|
459
|
-
data: {
|
|
359
|
+
data: { UNSUPPORTED_TYPE }
|
|
460
360
|
};
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
async handleOutgoingUpsert(entityType, event) {
|
|
364
|
+
const objectClass = await type_conversion_utils_1.TypeConversionUtils.getObjectClass(this.transformMapFile, this.mapFileUtil, event.newData);
|
|
365
|
+
if (!objectClass) {
|
|
366
|
+
const message = 'ObjectClass must have a value.';
|
|
367
|
+
console.log(message);
|
|
368
|
+
return {
|
|
369
|
+
status: 500,
|
|
370
|
+
data: { message }
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
try {
|
|
374
|
+
const payload = await this.getOutgoingUpsertPayload(entityType, event);
|
|
375
|
+
const flexResponse = await new flexplm_connect_1.FlexPLMConnect(this.config).sendToFlexPLM(payload);
|
|
376
|
+
const outboundEntityUpdates = await this.getOutboundEntityUpdates(event, flexResponse);
|
|
377
|
+
if (outboundEntityUpdates) {
|
|
378
|
+
flexResponse['outboundEntityUpdates'] = outboundEntityUpdates;
|
|
461
379
|
}
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
objectClass,
|
|
484
|
-
httpStatus: e.httpResponseStatus,
|
|
485
|
-
updatedFromResponse: false,
|
|
486
|
-
error: e,
|
|
487
|
-
});
|
|
488
|
-
throw e;
|
|
489
|
-
}
|
|
490
|
-
});
|
|
380
|
+
const statusMsg = 'BaseEntityProcessor: outbound: status: ' + event_short_message_status_1.EventShortMessageStatus.SUCCESS
|
|
381
|
+
+ ', statusMessage: ' + flexResponse.status
|
|
382
|
+
+ ', entityType: ' + this.baseType
|
|
383
|
+
+ ', entityId: ' + event.id
|
|
384
|
+
+ ', objectClass: ' + payload.objectClass
|
|
385
|
+
+ ', updateFromResponse: ' + ((outboundEntityUpdates && Object.keys(outboundEntityUpdates).length > 0) ? 'true' : 'false')
|
|
386
|
+
+ ', orgSlug: ' + this.orgSlug;
|
|
387
|
+
console.log(statusMsg);
|
|
388
|
+
return flexResponse;
|
|
389
|
+
}
|
|
390
|
+
catch (e) {
|
|
391
|
+
const statusMsg = 'BaseEntityProcessor: outbound: status: ' + event_short_message_status_1.EventShortMessageStatus.FAILURE
|
|
392
|
+
+ ', statusMessage: ' + e.httpResponseStatus
|
|
393
|
+
+ ', entityType: ' + this.baseType
|
|
394
|
+
+ ', entityId: ' + event.id
|
|
395
|
+
+ ', objectClass: ' + objectClass
|
|
396
|
+
+ ', updateFromResponse: ' + 'false'
|
|
397
|
+
+ ', orgSlug: ' + this.orgSlug;
|
|
398
|
+
console.log(statusMsg);
|
|
399
|
+
throw e;
|
|
400
|
+
}
|
|
491
401
|
}
|
|
492
402
|
async getOutboundEntityUpdates(event, flexResponse) {
|
|
493
403
|
const payload = flexResponse?.data?.payload;
|
|
@@ -503,10 +413,7 @@ class BaseEntityProcessor {
|
|
|
503
413
|
return outboundEntityUpdates;
|
|
504
414
|
}
|
|
505
415
|
async handleOutgoingDelete(entityType, event) {
|
|
506
|
-
|
|
507
|
-
telemetry_1.logger.warn({ flexplm: {
|
|
508
|
-
direction: 'outbound', event_type: event?.eventType, entity_type: entityType, entity_id: event?.id,
|
|
509
|
-
} }, 'FlexPLM delete is not configured');
|
|
416
|
+
console.warn('delete is not configured', entityType, event.oldData);
|
|
510
417
|
}
|
|
511
418
|
/** Create a new event-workflow-request to rerun sending the entity to FlexPLM
|
|
512
419
|
* The event must contain any information needed to ensure it is put in the correct queue for the entity
|
|
@@ -533,46 +440,44 @@ class BaseEntityProcessor {
|
|
|
533
440
|
* @returns results of sending the entity to FlexPLM
|
|
534
441
|
*/
|
|
535
442
|
async sendUpsertToFlexPLM(event) {
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
flexResponse['outboundEntityUpdates'] = outboundEntityUpdates;
|
|
553
|
-
}
|
|
554
|
-
this.recordOutboundStatus({
|
|
555
|
-
status: event_short_message_status_1.EventShortMessageStatus.SUCCESS,
|
|
556
|
-
entityId: event.id,
|
|
557
|
-
objectClass,
|
|
558
|
-
httpStatus: flexResponse.status,
|
|
559
|
-
updatedFromResponse: hasUpdates(outboundEntityUpdates),
|
|
560
|
-
itemStatus: getResponseItemStatus(flexResponse),
|
|
561
|
-
});
|
|
562
|
-
return flexResponse;
|
|
563
|
-
}
|
|
564
|
-
catch (e) {
|
|
565
|
-
this.recordOutboundStatus({
|
|
566
|
-
status: event_short_message_status_1.EventShortMessageStatus.FAILURE,
|
|
567
|
-
entityId: event.id,
|
|
568
|
-
objectClass,
|
|
569
|
-
httpStatus: e.httpResponseStatus,
|
|
570
|
-
updatedFromResponse: false,
|
|
571
|
-
error: e,
|
|
572
|
-
});
|
|
573
|
-
throw e;
|
|
443
|
+
const payload = await this.getEntityCurrentStateUpsertPayload(event);
|
|
444
|
+
if (!payload) {
|
|
445
|
+
const message = 'No payload to send to FlexPLM';
|
|
446
|
+
console.log(message);
|
|
447
|
+
return {
|
|
448
|
+
status: 500,
|
|
449
|
+
data: { message }
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
;
|
|
453
|
+
let objectClass = payload.objectClass;
|
|
454
|
+
try {
|
|
455
|
+
const flexResponse = await new flexplm_connect_1.FlexPLMConnect(this.config).sendToFlexPLM(payload);
|
|
456
|
+
const outboundEntityUpdates = await this.getOutboundEntityUpdates(event, flexResponse);
|
|
457
|
+
if (outboundEntityUpdates) {
|
|
458
|
+
flexResponse['outboundEntityUpdates'] = outboundEntityUpdates;
|
|
574
459
|
}
|
|
575
|
-
|
|
460
|
+
const statusMsg = 'BaseEntityProcessor: outbound: status: ' + event_short_message_status_1.EventShortMessageStatus.SUCCESS
|
|
461
|
+
+ ', statusMessage: ' + flexResponse.status
|
|
462
|
+
+ ', entityType: ' + this.baseType
|
|
463
|
+
+ ', entityId: ' + event.id
|
|
464
|
+
+ ', objectClass: ' + objectClass
|
|
465
|
+
+ ', updateFromResponse: ' + ((outboundEntityUpdates && Object.keys(outboundEntityUpdates).length > 0) ? 'true' : 'false')
|
|
466
|
+
+ ', orgSlug: ' + this.orgSlug;
|
|
467
|
+
console.log(statusMsg);
|
|
468
|
+
return flexResponse;
|
|
469
|
+
}
|
|
470
|
+
catch (e) {
|
|
471
|
+
const statusMsg = 'BaseEntityProcessor: outbound: status: ' + event_short_message_status_1.EventShortMessageStatus.FAILURE
|
|
472
|
+
+ ', statusMessage: ' + e.httpResponseStatus
|
|
473
|
+
+ ', entityType: ' + this.baseType
|
|
474
|
+
+ ', entityId: ' + event.id
|
|
475
|
+
+ ', objectClass: ' + objectClass
|
|
476
|
+
+ ', updateFromResponse: ' + 'false'
|
|
477
|
+
+ ', orgSlug: ' + this.orgSlug;
|
|
478
|
+
console.log(statusMsg);
|
|
479
|
+
throw e;
|
|
480
|
+
}
|
|
576
481
|
}
|
|
577
482
|
/** Generates the payload to send to FlexPLM, based on the current state of the entity.
|
|
578
483
|
* The current state of the entity are used as the newData and oldData; which is passed
|