@5minds/node-red-contrib-processcube 1.5.11-develop-0a7a7c-m4r8trh2 → 1.5.11-feature-e8accd-m4sa259r

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.
@@ -6,17 +6,6 @@ module.exports = function (RED) {
6
6
 
7
7
  let subscription;
8
8
 
9
- const engineEventEmitter = node.engine.eventEmitter;
10
-
11
- engineEventEmitter.on('engine-client-dispose', () => {
12
- node.engine.engineClient.notification.removeSubscription(subscription, node.engine.identity);
13
- });
14
-
15
- engineEventEmitter.on('engine-client-changed', () => {
16
- node.log('new engineClient received');
17
- register();
18
- });
19
-
20
9
  const register = async () => {
21
10
  const client = node.engine.engineClient;
22
11
 
@@ -25,442 +14,336 @@ module.exports = function (RED) {
25
14
  return;
26
15
  }
27
16
 
28
- let currentIdentity = node.engine.identity;
29
-
30
17
  const query = RED.util.evaluateNodeProperty(config.query, config.query_type, node);
31
18
 
32
19
  async function subscribe(eventType) {
33
20
  switch (eventType) {
34
21
  case 'starting':
35
- return await client.notification.onProcessStarting(
36
- async (processNotification) => {
37
- if (
38
- config.processmodel != '' &&
39
- config.processmodel != processNotification.processModelId
40
- ) {
41
- return;
42
- }
22
+ return await client.notification.onProcessStarting(async (processNotification) => {
23
+ if (
24
+ config.processmodel != '' &&
25
+ config.processmodel != processNotification.processModelId
26
+ ) {
27
+ return;
28
+ }
29
+
30
+ const newQuery = {
31
+ processInstanceId: processNotification.processInstanceId,
32
+ ...query,
33
+ };
43
34
 
44
- const newQuery = {
45
- processInstanceId: processNotification.processInstanceId,
46
- ...query,
47
- };
35
+ try {
36
+ const matchingInstances = await client.processInstances.query(newQuery);
48
37
 
49
- try {
50
- const matchingInstances = await client.processInstances.query(newQuery, {
51
- identity: currentIdentity,
38
+ if (
39
+ matchingInstances.processInstances &&
40
+ matchingInstances.processInstances.length == 1
41
+ ) {
42
+ const processInstance = matchingInstances.processInstances[0];
43
+ node.send({
44
+ payload: {
45
+ processInstanceId: processNotification.processInstanceId,
46
+ processModelId: processNotification.processModelId,
47
+ processInstance: processInstance,
48
+ action: 'starting',
49
+ type: 'processInstance',
50
+ },
52
51
  });
53
-
54
- if (
55
- matchingInstances.processInstances &&
56
- matchingInstances.processInstances.length == 1
57
- ) {
58
- const processInstance = matchingInstances.processInstances[0];
59
-
60
- node.send({
61
- payload: {
62
- processInstanceId: processNotification.processInstanceId,
63
- processModelId: processNotification.processModelId,
64
- processInstance: processInstance,
65
- action: 'starting',
66
- type: 'processInstance',
67
- },
68
- });
69
- }
70
- } catch (error) {
71
- node.error(JSON.stringify(error));
72
52
  }
73
- },
74
- { identity: currentIdentity }
75
- );
53
+ } catch (error) {
54
+ node.error(JSON.stringify(error));
55
+ }
56
+
57
+ });
76
58
  case 'started':
77
- return await client.notification.onProcessStarted(
78
- async (processNotification) => {
59
+ return await client.notification.onProcessStarted(async (processNotification) => {
60
+ if (
61
+ config.processmodel != '' &&
62
+ config.processmodel != processNotification.processModelId
63
+ ) {
64
+ return;
65
+ }
66
+
67
+ const newQuery = {
68
+ processInstanceId: processNotification.processInstanceId,
69
+ ...query,
70
+ };
71
+
72
+ try {
73
+ const matchingInstances = await client.processInstances.query(newQuery);
74
+
79
75
  if (
80
- config.processmodel != '' &&
81
- config.processmodel != processNotification.processModelId
76
+ matchingInstances.processInstances &&
77
+ matchingInstances.processInstances.length == 1
82
78
  ) {
83
- return;
79
+ const processInstance = matchingInstances.processInstances[0];
80
+ node.send({
81
+ payload: {
82
+ processInstanceId: processNotification.processInstanceId,
83
+ processModelId: processNotification.processModelId,
84
+ flowNodeId: processNotification.flowNodeId,
85
+ token: processNotification.currentToken,
86
+ processInstance: processInstance,
87
+ action: 'started',
88
+ type: 'processInstance',
89
+ },
90
+ });
84
91
  }
92
+ } catch (error) {
93
+ node.error(JSON.stringify(error));
94
+ }
95
+ });
96
+ case 'resumed':
97
+ return await client.notification.onProcessResumed(async (processNotification) => {
98
+ if (config.processmodel != '' && config.processmodel != processNotification.processModelId)
99
+ return;
85
100
 
86
- const newQuery = {
87
- processInstanceId: processNotification.processInstanceId,
88
- ...query,
89
- };
101
+ const newQuery = {
102
+ processInstanceId: processNotification.processInstanceId,
103
+ ...query,
104
+ };
90
105
 
91
- try {
92
- const matchingInstances = await client.processInstances.query(newQuery, {
93
- identity: currentIdentity,
94
- });
106
+ try {
107
+ const matchingInstances = await client.processInstances.query(newQuery);
95
108
 
96
- if (
97
- matchingInstances.processInstances &&
98
- matchingInstances.processInstances.length == 1
99
- ) {
100
- const processInstance = matchingInstances.processInstances[0];
101
- node.send({
102
- payload: {
103
- processInstanceId: processNotification.processInstanceId,
104
- processModelId: processNotification.processModelId,
105
- flowNodeId: processNotification.flowNodeId,
106
- token: processNotification.currentToken,
107
- processInstance: processInstance,
108
- action: 'started',
109
- type: 'processInstance',
110
- },
111
- });
112
- }
113
- } catch (error) {
114
- node.error(JSON.stringify(error));
115
- }
116
- },
117
- { identity: currentIdentity }
118
- );
119
- case 'resumed':
120
- return await client.notification.onProcessResumed(
121
- async (processNotification) => {
122
109
  if (
123
- config.processmodel != '' &&
124
- config.processmodel != processNotification.processModelId
125
- )
126
- return;
127
-
128
- const newQuery = {
129
- processInstanceId: processNotification.processInstanceId,
130
- ...query,
131
- };
132
-
133
- try {
134
- const matchingInstances = await client.processInstances.query(newQuery, {
135
- identity: currentIdentity,
110
+ matchingInstances.processInstances &&
111
+ matchingInstances.processInstances.length == 1
112
+ ) {
113
+ const processInstance = matchingInstances.processInstances[0];
114
+ node.send({
115
+ payload: {
116
+ processInstanceId: processNotification.processInstanceId,
117
+ processModelId: processNotification.processModelId,
118
+ token: processNotification.currentToken,
119
+ processInstance: processInstance,
120
+ action: 'resumed',
121
+ type: 'processInstance',
122
+ },
136
123
  });
137
-
138
- if (
139
- matchingInstances.processInstances &&
140
- matchingInstances.processInstances.length == 1
141
- ) {
142
- const processInstance = matchingInstances.processInstances[0];
143
- node.send({
144
- payload: {
145
- processInstanceId: processNotification.processInstanceId,
146
- processModelId: processNotification.processModelId,
147
- token: processNotification.currentToken,
148
- processInstance: processInstance,
149
- action: 'resumed',
150
- type: 'processInstance',
151
- },
152
- });
153
- }
154
- } catch (error) {
155
- node.error(JSON.stringify(error));
156
124
  }
157
- },
158
- { identity: currentIdentity }
159
- );
125
+ } catch (error) {
126
+ node.error(JSON.stringify(error));
127
+ }
128
+ });
160
129
  case 'finished':
161
- return await client.notification.onProcessEnded(
162
- async (processNotification) => {
130
+ return await client.notification.onProcessEnded(async (processNotification) => {
131
+ if (config.processmodel != '' && config.processmodel != processNotification.processModelId)
132
+ return;
133
+
134
+ const newQuery = {
135
+ processInstanceId: processNotification.processInstanceId,
136
+ ...query,
137
+ };
138
+
139
+ try {
140
+ const matchingInstances = await client.processInstances.query(newQuery);
141
+
163
142
  if (
164
- config.processmodel != '' &&
165
- config.processmodel != processNotification.processModelId
166
- )
167
- return;
168
-
169
- const newQuery = {
170
- processInstanceId: processNotification.processInstanceId,
171
- ...query,
172
- };
173
-
174
- try {
175
- const matchingInstances = await client.processInstances.query(newQuery, {
176
- identity: currentIdentity,
143
+ matchingInstances.processInstances &&
144
+ matchingInstances.processInstances.length == 1
145
+ ) {
146
+ const processInstance = matchingInstances.processInstances[0];
147
+ node.send({
148
+ payload: {
149
+ processInstanceId: processNotification.processInstanceId,
150
+ processModelId: processNotification.processModelId,
151
+ flowNodeId: processNotification.flowNodeId,
152
+ token: processNotification.currentToken,
153
+ processInstance: processInstance,
154
+ action: 'finished',
155
+ type: 'processInstance',
156
+ },
177
157
  });
178
-
179
- if (
180
- matchingInstances.processInstances &&
181
- matchingInstances.processInstances.length == 1
182
- ) {
183
- const processInstance = matchingInstances.processInstances[0];
184
- node.send({
185
- payload: {
186
- processInstanceId: processNotification.processInstanceId,
187
- processModelId: processNotification.processModelId,
188
- flowNodeId: processNotification.flowNodeId,
189
- token: processNotification.currentToken,
190
- processInstance: processInstance,
191
- action: 'finished',
192
- type: 'processInstance',
193
- },
194
- });
195
- }
196
- } catch (error) {
197
- node.error(JSON.stringify(error));
198
158
  }
199
- },
200
- { identity: currentIdentity }
201
- );
159
+ } catch (error) {
160
+ node.error(JSON.stringify(error));
161
+ }
162
+ });
202
163
  case 'terminated':
203
- return await client.notification.onProcessTerminated(
204
- async (processNotification) => {
164
+ return await client.notification.onProcessTerminated(async (processNotification) => {
165
+ if (config.processmodel != '' && config.processmodel != processNotification.processModelId)
166
+ return;
167
+
168
+ const newQuery = {
169
+ processInstanceId: processNotification.processInstanceId,
170
+ ...query,
171
+ };
172
+
173
+ try {
174
+ const matchingInstances = await client.processInstances.query(newQuery);
205
175
  if (
206
- config.processmodel != '' &&
207
- config.processmodel != processNotification.processModelId
208
- )
209
- return;
210
-
211
- const newQuery = {
212
- processInstanceId: processNotification.processInstanceId,
213
- ...query,
214
- };
215
-
216
- try {
217
- const matchingInstances = await client.processInstances.query(newQuery, {
218
- identity: currentIdentity,
176
+ matchingInstances.processInstances &&
177
+ matchingInstances.processInstances.length == 1
178
+ ) {
179
+ const processInstance = matchingInstances.processInstances[0];
180
+ node.send({
181
+ payload: {
182
+ processInstanceId: processNotification.processInstanceId,
183
+ processModelId: processNotification.processModelId,
184
+ token: processNotification.currentToken,
185
+ processInstance: processInstance,
186
+ action: 'terminated',
187
+ type: 'processInstance',
188
+ },
219
189
  });
220
- if (
221
- matchingInstances.processInstances &&
222
- matchingInstances.processInstances.length == 1
223
- ) {
224
- const processInstance = matchingInstances.processInstances[0];
225
- node.send({
226
- payload: {
227
- processInstanceId: processNotification.processInstanceId,
228
- processModelId: processNotification.processModelId,
229
- token: processNotification.currentToken,
230
- processInstance: processInstance,
231
- action: 'terminated',
232
- type: 'processInstance',
233
- },
234
- });
235
- }
236
- } catch (error) {
237
- node.error(JSON.stringify(error));
238
190
  }
239
- },
240
- { identity: currentIdentity }
241
- );
191
+ } catch (error) {
192
+ node.error(JSON.stringify(error));
193
+ }
194
+ });
242
195
  case 'error':
243
- return await client.notification.onProcessError(
244
- async (processNotification) => {
196
+ return await client.notification.onProcessError(async (processNotification) => {
197
+ if (config.processmodel != '' && config.processmodel != processNotification.processModelId)
198
+ return;
199
+
200
+ const newQuery = {
201
+ processInstanceId: processNotification.processInstanceId,
202
+ ...query,
203
+ };
204
+
205
+ try {
206
+ const matchingInstances = await client.processInstances.query(newQuery);
207
+
245
208
  if (
246
- config.processmodel != '' &&
247
- config.processmodel != processNotification.processModelId
248
- )
249
- return;
250
-
251
- const newQuery = {
252
- processInstanceId: processNotification.processInstanceId,
253
- ...query,
254
- };
255
-
256
- try {
257
- const matchingInstances = await client.processInstances.query(newQuery, {
258
- identity: currentIdentity,
209
+ matchingInstances.processInstances &&
210
+ matchingInstances.processInstances.length == 1
211
+ ) {
212
+ const processInstance = matchingInstances.processInstances[0];
213
+ node.send({
214
+ payload: {
215
+ processInstanceId: processNotification.processInstanceId,
216
+ processModelId: processNotification.processModelId,
217
+ token: processNotification.currentToken,
218
+ processInstance: processInstance,
219
+ action: 'error',
220
+ type: 'processInstance',
221
+ },
259
222
  });
260
-
261
- if (
262
- matchingInstances.processInstances &&
263
- matchingInstances.processInstances.length == 1
264
- ) {
265
- const processInstance = matchingInstances.processInstances[0];
266
- node.send({
267
- payload: {
268
- processInstanceId: processNotification.processInstanceId,
269
- processModelId: processNotification.processModelId,
270
- token: processNotification.currentToken,
271
- processInstance: processInstance,
272
- action: 'error',
273
- type: 'processInstance',
274
- },
275
- });
276
- }
277
- } catch (error) {
278
- node.error(JSON.stringify(error));
279
223
  }
280
- },
281
- { identity: currentIdentity }
282
- );
224
+ } catch (error) {
225
+ node.error(JSON.stringify(error));
226
+ }
227
+ });
283
228
  case 'owner-changed':
284
- return await client.notification.onProcessOwnerChanged(
285
- async (processNotification) => {
229
+ return await client.notification.onProcessOwnerChanged(async (processNotification) => {
230
+ if (config.processmodel != '' && config.processmodel != processNotification.processModelId)
231
+ return;
232
+
233
+ const newQuery = {
234
+ processInstanceId: processNotification.processInstanceId,
235
+ ...query,
236
+ };
237
+
238
+ try {
239
+ const matchingInstances = await client.processInstances.query(newQuery);
240
+
286
241
  if (
287
- config.processmodel != '' &&
288
- config.processmodel != processNotification.processModelId
289
- )
290
- return;
291
-
292
- const newQuery = {
293
- processInstanceId: processNotification.processInstanceId,
294
- ...query,
295
- };
296
-
297
- try {
298
- const matchingInstances = await client.processInstances.query(newQuery, {
299
- identity: currentIdentity,
242
+ matchingInstances.processInstances &&
243
+ matchingInstances.processInstances.length == 1
244
+ ) {
245
+ const processInstance = matchingInstances.processInstances[0];
246
+ node.send({
247
+ payload: {
248
+ processInstanceId: processNotification.processInstanceId,
249
+ processModelId: processNotification.processModelId,
250
+ processInstance: processInstance,
251
+ action: 'owner-changed',
252
+ type: 'processInstance',
253
+ },
300
254
  });
301
-
302
- if (
303
- matchingInstances.processInstances &&
304
- matchingInstances.processInstances.length == 1
305
- ) {
306
- const processInstance = matchingInstances.processInstances[0];
307
- node.send({
308
- payload: {
309
- processInstanceId: processNotification.processInstanceId,
310
- processModelId: processNotification.processModelId,
311
- processInstance: processInstance,
312
- action: 'owner-changed',
313
- type: 'processInstance',
314
- },
315
- });
316
- }
317
- } catch (error) {
318
- node.error(JSON.stringify(error));
319
255
  }
320
- },
321
- { identity: currentIdentity }
322
- );
256
+ } catch (error) {
257
+ node.error(JSON.stringify(error));
258
+ }
259
+ });
323
260
  case 'instances-deleted':
324
- return await client.notification.onProcessInstancesDeleted(
325
- async (processNotification) => {
326
- if (
327
- config.processmodel != '' &&
328
- config.processmodel != processNotification.processModelId
329
- )
330
- return;
331
-
332
- const newQuery = {
333
- processInstanceId: processNotification.processInstanceId,
334
- ...query,
335
- };
336
-
337
- try {
338
- const matchingInstances = await client.processInstances.query(newQuery, {
339
- identity: currentIdentity,
340
- });
261
+ return await client.notification.onProcessInstancesDeleted(async (processNotification) => {
262
+ if (config.processmodel != '' && config.processmodel != processNotification.processModelId)
263
+ return;
341
264
 
342
- if (
343
- matchingInstances.processInstances &&
344
- matchingInstances.processInstances.length == 1
345
- ) {
346
- const processInstance = matchingInstances.processInstances[0];
347
- node.send({
348
- payload: {
349
- processInstanceId: processNotification.processInstanceId,
350
- processModelId: processNotification.processModelId,
351
- processInstance: processInstance,
352
- action: 'instances-deleted',
353
- type: 'processInstance',
354
- },
355
- });
356
- }
357
- } catch (error) {
358
- node.error(JSON.stringify(error));
359
- }
360
- },
361
- { identity: currentIdentity }
362
- );
363
- case 'is-executable-changed':
364
- return await client.notification.onProcessIsExecutableChanged(
365
- (processNotification) => {
265
+ const newQuery = {
266
+ processInstanceId: processNotification.processInstanceId,
267
+ ...query,
268
+ };
366
269
 
367
- node.log('processNotification (is-executable-changed): ' + JSON.stringify(processNotification));
270
+ try {
271
+ const matchingInstances = await client.processInstances.query(newQuery);
368
272
 
369
273
  if (
370
- config.processmodel != '' &&
371
- config.processmodel != processNotification.processModelId
372
- )
373
- return;
374
- node.send({
375
- payload: {
376
- processModelId: processNotification.processModelId,
377
- action: 'is-executable-changed',
378
- type: 'processModel',
379
- },
380
- });
381
- },
382
- { identity: currentIdentity }
383
- );
274
+ matchingInstances.processInstances &&
275
+ matchingInstances.processInstances.length == 1
276
+ ) {
277
+ const processInstance = matchingInstances.processInstances[0];
278
+ node.send({
279
+ payload: {
280
+ processInstanceId: processNotification.processInstanceId,
281
+ processModelId: processNotification.processModelId,
282
+ processInstance: processInstance,
283
+ action: 'instances-deleted',
284
+ type: 'processInstance',
285
+ },
286
+ });
287
+ }
288
+ } catch (error) {
289
+ node.error(JSON.stringify(error));
290
+ }
291
+ });
292
+ case 'is-executable-changed':
293
+ return await client.notification.onProcessIsExecutableChanged((processNotification) => {
294
+ node.log(
295
+ 'processNotification (is-executable-changed): ' + JSON.stringify(processNotification)
296
+ );
297
+
298
+ if (config.processmodel != '' && config.processmodel != processNotification.processModelId)
299
+ return;
300
+ node.send({
301
+ payload: {
302
+ processModelId: processNotification.processModelId,
303
+ action: 'is-executable-changed',
304
+ type: 'processModel',
305
+ },
306
+ });
307
+ });
384
308
  case 'deployed':
385
- return await client.notification.onProcessDeployed(
386
- (processNotification) => {
387
-
388
- node.log('processNotification (deployed): ' + JSON.stringify(processNotification));
389
-
390
- if (
391
- config.processmodel != '' &&
392
- config.processmodel != processNotification.processModelId
393
- )
394
- return;
395
- node.send({
396
- payload: {
397
- processModelId: processNotification.processModelId,
398
- action: 'deployed',
399
- type: 'processModel',
400
- },
401
- });
402
- },
403
- { identity: currentIdentity }
404
- );
309
+ return await client.notification.onProcessDeployed((processNotification) => {
310
+ node.log('processNotification (deployed): ' + JSON.stringify(processNotification));
311
+
312
+ if (config.processmodel != '' && config.processmodel != processNotification.processModelId)
313
+ return;
314
+ node.send({
315
+ payload: {
316
+ processModelId: processNotification.processModelId,
317
+ action: 'deployed',
318
+ type: 'processModel',
319
+ },
320
+ });
321
+ });
405
322
  case 'undeployed':
406
- return await client.notification.onProcessUndeployed(
407
- (processNotification) => {
408
-
409
- node.log('processNotification (undeployed): ' + JSON.stringify(processNotification));
410
-
411
- if (
412
- config.processmodel != '' &&
413
- config.processmodel != processNotification.processModelId
414
- )
415
- return;
416
- node.send({
417
- payload: {
418
- processModelId: processNotification.processModelId,
419
- action: 'undeployed',
420
- type: 'processModel',
421
- },
422
- });
423
- },
424
- { identity: currentIdentity }
425
- );
323
+ return await client.notification.onProcessUndeployed((processNotification) => {
324
+ node.log('processNotification (undeployed): ' + JSON.stringify(processNotification));
325
+
326
+ if (config.processmodel != '' && config.processmodel != processNotification.processModelId)
327
+ return;
328
+ node.send({
329
+ payload: {
330
+ processModelId: processNotification.processModelId,
331
+ action: 'undeployed',
332
+ type: 'processModel',
333
+ },
334
+ });
335
+ });
426
336
  default:
427
337
  console.error('no such event: ' + eventType);
428
338
  break;
429
339
  }
430
340
  }
431
341
 
432
- if (node.engine.isIdentityReady()) {
433
- subscription = await subscribe(config.eventtype);
434
- }
435
-
436
- node.engine.registerOnIdentityChanged(async (identity) => {
437
- if (subscription) {
438
- client.notification.removeSubscription(subscription, currentIdentity);
439
- }
440
-
441
- currentIdentity = identity;
442
-
443
- subscription = await client.notification.onProcessResumed(
444
- (processNotification) => {
445
- if (config.processmodel != '' && config.processmodel != processNotification.processModelId)
446
- return;
447
- node.send({
448
- payload: {
449
- processInstanceId: processNotification.processInstanceId,
450
- processModelId: processNotification.processModelId,
451
- token: processNotification.currentToken,
452
- action: 'resumed',
453
- type: 'processInstance',
454
- },
455
- });
456
- },
457
- { identity: currentIdentity }
458
- );
459
- });
342
+ subscription = await subscribe(config.eventtype);
460
343
 
461
344
  node.on('close', () => {
462
345
  if (node.engine && node.engine.engineClient && client) {
463
- client.notification.removeSubscription(subscription, currentIdentity);
346
+ client.notification.removeSubscription(subscription);
464
347
  }
465
348
  });
466
349
  };