@5minds/node-red-contrib-processcube 1.5.10-feature-b754b9-m4mtb82p → 1.5.10-feature-1657ec-m4r2pgad

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,6 +6,17 @@ 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
+
9
20
  const register = async () => {
10
21
  const client = node.engine.engineClient;
11
22
 
@@ -14,336 +25,442 @@ module.exports = function (RED) {
14
25
  return;
15
26
  }
16
27
 
28
+ let currentIdentity = node.engine.identity;
29
+
17
30
  const query = RED.util.evaluateNodeProperty(config.query, config.query_type, node);
18
31
 
19
32
  async function subscribe(eventType) {
20
33
  switch (eventType) {
21
34
  case 'starting':
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
- };
34
-
35
- try {
36
- const matchingInstances = await client.processInstances.query(newQuery);
37
-
35
+ return await client.notification.onProcessStarting(
36
+ async (processNotification) => {
38
37
  if (
39
- matchingInstances.processInstances &&
40
- matchingInstances.processInstances.length == 1
38
+ config.processmodel != '' &&
39
+ config.processmodel != processNotification.processModelId
41
40
  ) {
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
- },
51
- });
41
+ return;
52
42
  }
53
- } catch (error) {
54
- node.error(JSON.stringify(error));
55
- }
56
-
57
- });
58
- case 'started':
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
43
 
72
- try {
73
- const matchingInstances = await client.processInstances.query(newQuery);
44
+ const newQuery = {
45
+ processInstanceId: processNotification.processInstanceId,
46
+ ...query,
47
+ };
74
48
 
49
+ try {
50
+ const matchingInstances = await client.processInstances.query(newQuery, {
51
+ identity: currentIdentity,
52
+ });
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
+ }
73
+ },
74
+ { identity: currentIdentity }
75
+ );
76
+ case 'started':
77
+ return await client.notification.onProcessStarted(
78
+ async (processNotification) => {
75
79
  if (
76
- matchingInstances.processInstances &&
77
- matchingInstances.processInstances.length == 1
80
+ config.processmodel != '' &&
81
+ config.processmodel != processNotification.processModelId
78
82
  ) {
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
- });
83
+ return;
91
84
  }
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;
100
85
 
101
- const newQuery = {
102
- processInstanceId: processNotification.processInstanceId,
103
- ...query,
104
- };
86
+ const newQuery = {
87
+ processInstanceId: processNotification.processInstanceId,
88
+ ...query,
89
+ };
105
90
 
106
- try {
107
- const matchingInstances = await client.processInstances.query(newQuery);
91
+ try {
92
+ const matchingInstances = await client.processInstances.query(newQuery, {
93
+ identity: currentIdentity,
94
+ });
108
95
 
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) => {
109
122
  if (
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
- },
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,
123
136
  });
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));
124
156
  }
125
- } catch (error) {
126
- node.error(JSON.stringify(error));
127
- }
128
- });
157
+ },
158
+ { identity: currentIdentity }
159
+ );
129
160
  case 'finished':
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
-
161
+ return await client.notification.onProcessEnded(
162
+ async (processNotification) => {
142
163
  if (
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
- },
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,
157
177
  });
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));
158
198
  }
159
- } catch (error) {
160
- node.error(JSON.stringify(error));
161
- }
162
- });
199
+ },
200
+ { identity: currentIdentity }
201
+ );
163
202
  case 'terminated':
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);
203
+ return await client.notification.onProcessTerminated(
204
+ async (processNotification) => {
175
205
  if (
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
- },
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,
189
219
  });
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));
190
238
  }
191
- } catch (error) {
192
- node.error(JSON.stringify(error));
193
- }
194
- });
239
+ },
240
+ { identity: currentIdentity }
241
+ );
195
242
  case 'error':
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
-
243
+ return await client.notification.onProcessError(
244
+ async (processNotification) => {
208
245
  if (
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
- },
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,
222
259
  });
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));
223
279
  }
224
- } catch (error) {
225
- node.error(JSON.stringify(error));
226
- }
227
- });
280
+ },
281
+ { identity: currentIdentity }
282
+ );
228
283
  case 'owner-changed':
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
-
284
+ return await client.notification.onProcessOwnerChanged(
285
+ async (processNotification) => {
241
286
  if (
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
- },
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,
254
300
  });
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));
255
319
  }
256
- } catch (error) {
257
- node.error(JSON.stringify(error));
258
- }
259
- });
320
+ },
321
+ { identity: currentIdentity }
322
+ );
260
323
  case 'instances-deleted':
261
- return await client.notification.onProcessInstancesDeleted(async (processNotification) => {
262
- if (config.processmodel != '' && config.processmodel != processNotification.processModelId)
263
- return;
264
-
265
- const newQuery = {
266
- processInstanceId: processNotification.processInstanceId,
267
- ...query,
268
- };
269
-
270
- try {
271
- const matchingInstances = await client.processInstances.query(newQuery);
272
-
324
+ return await client.notification.onProcessInstancesDeleted(
325
+ async (processNotification) => {
273
326
  if (
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
- },
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,
286
340
  });
341
+
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));
287
359
  }
288
- } catch (error) {
289
- node.error(JSON.stringify(error));
290
- }
291
- });
360
+ },
361
+ { identity: currentIdentity }
362
+ );
292
363
  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
- });
364
+ return await client.notification.onProcessIsExecutableChanged(
365
+ (processNotification) => {
366
+
367
+ node.log('processNotification (is-executable-changed): ' + JSON.stringify(processNotification));
368
+
369
+ 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
+ );
308
384
  case 'deployed':
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
- });
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
+ );
322
405
  case 'undeployed':
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
- });
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
+ );
336
426
  default:
337
427
  console.error('no such event: ' + eventType);
338
428
  break;
339
429
  }
340
430
  }
341
431
 
342
- subscription = await subscribe(config.eventtype);
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
+ });
343
460
 
344
461
  node.on('close', () => {
345
462
  if (node.engine && node.engine.engineClient && client) {
346
- client.notification.removeSubscription(subscription);
463
+ client.notification.removeSubscription(subscription, currentIdentity);
347
464
  }
348
465
  });
349
466
  };