@contrail/flexplm 1.1.41 → 1.1.42
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.
|
@@ -31,4 +31,7 @@ export declare abstract class BaseEntityProcessor {
|
|
|
31
31
|
getOutboundEntityUpdates(event: any, flexResponse: any): Promise<any>;
|
|
32
32
|
handleOutgoingDelete(entityType: any, event: any): Promise<void>;
|
|
33
33
|
protected abstract getOutgoingUpsertPayload(entityType: any, event: any): Promise<EntityPayloadType>;
|
|
34
|
+
protected triggerNewEvent(triggerKey: string, event: any): Promise<any>;
|
|
35
|
+
protected sendUpsertToFlexPLM(event: any): Promise<any>;
|
|
36
|
+
protected getEntityCurrentStateUpsertPayload(event: any): Promise<EntityPayloadType>;
|
|
34
37
|
}
|
|
@@ -133,6 +133,8 @@ class BaseEntityProcessor {
|
|
|
133
133
|
return await this.handleOutgoingUpsert(entityType, event);
|
|
134
134
|
case 'delete':
|
|
135
135
|
return await this.handleOutgoingDelete(entityType, event);
|
|
136
|
+
case 'sendUpsertToFlexPLM':
|
|
137
|
+
return await this.sendUpsertToFlexPLM(event);
|
|
136
138
|
default:
|
|
137
139
|
console.log(UNSUPPORTED_TYPE);
|
|
138
140
|
return {
|
|
@@ -171,5 +173,51 @@ class BaseEntityProcessor {
|
|
|
171
173
|
async handleOutgoingDelete(entityType, event) {
|
|
172
174
|
console.warn('delete is not configured', entityType, event.oldData);
|
|
173
175
|
}
|
|
176
|
+
async triggerNewEvent(triggerKey, event) {
|
|
177
|
+
const newEvent = {
|
|
178
|
+
entityName: 'event-workflow-request',
|
|
179
|
+
object: {
|
|
180
|
+
triggerKey,
|
|
181
|
+
event
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
const response = await this.entities.create(newEvent);
|
|
185
|
+
return response;
|
|
186
|
+
}
|
|
187
|
+
async sendUpsertToFlexPLM(event) {
|
|
188
|
+
const payload = await this.getEntityCurrentStateUpsertPayload(event);
|
|
189
|
+
if (!payload) {
|
|
190
|
+
const message = 'No payload to send to FlexPLM';
|
|
191
|
+
console.log(message);
|
|
192
|
+
return {
|
|
193
|
+
status: 500,
|
|
194
|
+
data: { message }
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
;
|
|
198
|
+
const flexResponse = await new flexplm_connect_1.FlexPLMConnect(this.config).sendToFlexPLM(payload);
|
|
199
|
+
const outboundEntityUpdates = await this.getOutboundEntityUpdates(event, flexResponse);
|
|
200
|
+
if (outboundEntityUpdates) {
|
|
201
|
+
flexResponse['outboundEntityUpdates'] = outboundEntityUpdates;
|
|
202
|
+
}
|
|
203
|
+
return flexResponse;
|
|
204
|
+
}
|
|
205
|
+
async getEntityCurrentStateUpsertPayload(event) {
|
|
206
|
+
const id = event.id;
|
|
207
|
+
if (!id) {
|
|
208
|
+
return undefined;
|
|
209
|
+
}
|
|
210
|
+
const entity = await this.entities.get({
|
|
211
|
+
entityName: this.baseType,
|
|
212
|
+
id
|
|
213
|
+
});
|
|
214
|
+
if (!entity) {
|
|
215
|
+
return undefined;
|
|
216
|
+
}
|
|
217
|
+
event.newData = entity;
|
|
218
|
+
event.oldData = entity;
|
|
219
|
+
const payload = await this.getOutgoingUpsertPayload(this.baseType, event);
|
|
220
|
+
return payload;
|
|
221
|
+
}
|
|
174
222
|
}
|
|
175
223
|
exports.BaseEntityProcessor = BaseEntityProcessor;
|
package/package.json
CHANGED
|
@@ -176,6 +176,8 @@ export abstract class BaseEntityProcessor {
|
|
|
176
176
|
return await this.handleOutgoingUpsert(entityType, event);
|
|
177
177
|
case 'delete':
|
|
178
178
|
return await this.handleOutgoingDelete(entityType, event);
|
|
179
|
+
case 'sendUpsertToFlexPLM':
|
|
180
|
+
return await this.sendUpsertToFlexPLM(event);
|
|
179
181
|
default:
|
|
180
182
|
console.log(UNSUPPORTED_TYPE);
|
|
181
183
|
return {
|
|
@@ -223,4 +225,82 @@ export abstract class BaseEntityProcessor {
|
|
|
223
225
|
|
|
224
226
|
// This method must be implemented by derived classes
|
|
225
227
|
protected abstract getOutgoingUpsertPayload(entityType, event): Promise<EntityPayloadType>;
|
|
228
|
+
|
|
229
|
+
/** Create a new event-workflow-request to rerun sending the entity to FlexPLM
|
|
230
|
+
* The event must contain any information needed to ensure it is put in the correct queue for the entity
|
|
231
|
+
*
|
|
232
|
+
* @param triggerKey Ex: event.entityType + '|sendUpsertToFlexPLM'
|
|
233
|
+
* @param event
|
|
234
|
+
* @returns
|
|
235
|
+
*/
|
|
236
|
+
|
|
237
|
+
protected async triggerNewEvent(triggerKey: string, event: any) {
|
|
238
|
+
const newEvent = {
|
|
239
|
+
entityName: 'event-workflow-request',
|
|
240
|
+
object: {
|
|
241
|
+
triggerKey,
|
|
242
|
+
event
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
const response = await this.entities.create(newEvent);
|
|
246
|
+
|
|
247
|
+
return response;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/** Sends the current state of the entity to FlexPLM.
|
|
251
|
+
* So any changes made in Vibe between the event being generated and the event being processed are sent to FlexPLM.
|
|
252
|
+
*
|
|
253
|
+
* @param event must contain entityType, id; which are used to query for the entity
|
|
254
|
+
* @returns results of sending the entity to FlexPLM
|
|
255
|
+
*/
|
|
256
|
+
protected async sendUpsertToFlexPLM(event) {
|
|
257
|
+
const payload = await this.getEntityCurrentStateUpsertPayload(event);
|
|
258
|
+
if(!payload){
|
|
259
|
+
const message = 'No payload to send to FlexPLM';
|
|
260
|
+
console.log(message);
|
|
261
|
+
return {
|
|
262
|
+
status: 500,
|
|
263
|
+
data: {message}
|
|
264
|
+
};
|
|
265
|
+
};
|
|
266
|
+
const flexResponse: any = await new FlexPLMConnect(this.config).sendToFlexPLM(payload);
|
|
267
|
+
|
|
268
|
+
const outboundEntityUpdates = await this.getOutboundEntityUpdates(event, flexResponse);
|
|
269
|
+
if(outboundEntityUpdates){
|
|
270
|
+
flexResponse['outboundEntityUpdates'] = outboundEntityUpdates;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
return flexResponse;
|
|
274
|
+
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/** Generates the payload to send to FlexPLM, based on the current state of the entity.
|
|
278
|
+
* The current state of the entity are used as the newData and oldData; which is passed
|
|
279
|
+
* to getOutgoingUpsertPayload to generate the payload.
|
|
280
|
+
* @param event information about the item to send to FlexPLM
|
|
281
|
+
* @returns The payload to send to FlexPLM
|
|
282
|
+
*/
|
|
283
|
+
protected async getEntityCurrentStateUpsertPayload(event: any): Promise<EntityPayloadType> {
|
|
284
|
+
|
|
285
|
+
const id = event.id;
|
|
286
|
+
if(!id){
|
|
287
|
+
return undefined;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
const entity = await this.entities.get({
|
|
291
|
+
entityName: this.baseType,
|
|
292
|
+
id
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
if(!entity){
|
|
296
|
+
return undefined;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
event.newData = entity;
|
|
300
|
+
event.oldData = entity;
|
|
301
|
+
|
|
302
|
+
const payload = await this.getOutgoingUpsertPayload(this.baseType, event);
|
|
303
|
+
|
|
304
|
+
return payload;
|
|
305
|
+
}
|
|
226
306
|
}
|