@contrail/flexplm 1.1.36 → 1.1.37

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 triggerSendEvent(triggerKey: string, event: any): Promise<any>;
35
+ protected sendUpsertToFlexPLM(event: any): Promise<any>;
36
+ protected getEntityUpsertPayload(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,38 @@ class BaseEntityProcessor {
171
173
  async handleOutgoingDelete(entityType, event) {
172
174
  console.warn('delete is not configured', entityType, event.oldData);
173
175
  }
176
+ async triggerSendEvent(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.getEntityUpsertPayload(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 getEntityUpsertPayload(event) {
206
+ console.warn('getEntityUpsertPayload is not configured', JSON.stringify(event));
207
+ return undefined;
208
+ }
174
209
  }
175
210
  exports.BaseEntityProcessor = BaseEntityProcessor;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/flexplm",
3
- "version": "1.1.36",
3
+ "version": "1.1.37",
4
4
  "description": "Library used for integration with flexplm.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -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,57 @@ 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 triggerSendEvent(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.getEntityUpsertPayload(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
+ protected async getEntityUpsertPayload(event: any): Promise<EntityPayloadType> {
278
+ console.warn('getEntityUpsertPayload is not configured', JSON.stringify(event));
279
+ return undefined;
280
+ }
226
281
  }