@5minds/node-red-contrib-processcube 1.1.4-feature-f15f2e-m06hsqhu → 1.1.4-feature-ce7ef0-m0c3u8nd

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@5minds/node-red-contrib-processcube",
3
- "version": "1.1.4-feature-f15f2e-m06hsqhu",
3
+ "version": "1.1.4-feature-ce7ef0-m0c3u8nd",
4
4
  "license": "MIT",
5
5
  "description": "Node-RED nodes for ProcessCube",
6
6
  "scripts": {
@@ -6,7 +6,9 @@
6
6
  name: { value: '' },
7
7
  engine: { value: '', type: 'processcube-engine-config' },
8
8
  processmodel: { value: '', required: false },
9
- eventtype: { value: '', required: true}
9
+ eventtype: { value: '', required: true},
10
+ query: { value: '{}' },
11
+ query_type: { value: 'json' },
10
12
  },
11
13
  inputs: 0,
12
14
  outputs: 1,
@@ -14,6 +16,22 @@
14
16
  label: function () {
15
17
  return this.name || 'process-event-listener';
16
18
  },
19
+ oneditprepare: function () {
20
+ $('#node-input-query').typedInput({
21
+ default: 'json',
22
+ types: ['json'],
23
+ });
24
+
25
+ $('#node-input-query').typedInput('value', this.query);
26
+ $('#node-input-query').typedInput('type', this.query_type);
27
+ },
28
+ oneditsave: function () {
29
+ if ($('#node-input-query').typedInput('value') == '') {
30
+ $('#node-input-query').typedInput('value', '{}')
31
+ }
32
+ (this.query = $('#node-input-query').typedInput('value')),
33
+ (this.query_type = $('#node-input-query').typedInput('type'));
34
+ },
17
35
  });
18
36
  </script>
19
37
 
@@ -46,6 +64,10 @@
46
64
  <option value="undeployed">undeployed</option>
47
65
  </select>
48
66
  </div>
67
+ <div class="form-row">
68
+ <label for="node-input-query"><i class="fa fa-tag"></i> Query</label>
69
+ <input type="text" id="node-input-query" />
70
+ </div>
49
71
  </script>
50
72
 
51
73
  <script type="text/markdown" data-help-name="process-event-listener">
@@ -15,148 +15,311 @@ module.exports = function (RED) {
15
15
  let currentIdentity = node.engine.identity;
16
16
 
17
17
  let subscription;
18
+ const query = RED.util.evaluateNodeProperty(config.query, config.query_type, node);
18
19
 
19
20
  async function subscribe(eventType) {
20
21
  switch (eventType) {
21
- case "starting":
22
+ case 'starting':
22
23
  return await client.notification.onProcessStarting(
23
- (processNotification) => {
24
- if (config.processmodel != '' && config.processmodel != processNotification.processModelId)
24
+ async (processNotification) => {
25
+ if (
26
+ config.processmodel != '' &&
27
+ config.processmodel != processNotification.processModelId
28
+ )
25
29
  return;
26
- node.send({
27
- payload: {
28
- processInstanceId: processNotification.processInstanceId,
29
- processModelId: processNotification.processModelId,
30
- action: 'starting',
31
- type: 'processInstance',
32
- },
30
+ const newQuery = {
31
+ processInstanceId: processNotification.processInstanceId,
32
+ ...query,
33
+ };
34
+
35
+ const matchingInstances = await client.processInstances.query(newQuery, {
36
+ identity: currentIdentity,
33
37
  });
38
+
39
+ if (
40
+ matchingInstances.processInstances &&
41
+ matchingInstances.processInstances.length == 1
42
+ ) {
43
+ const processInstance = matchingInstances.processInstances[0];
44
+
45
+ node.send({
46
+ payload: {
47
+ processInstanceId: processNotification.processInstanceId,
48
+ processModelId: processNotification.processModelId,
49
+ processInstance: processInstance,
50
+ action: 'starting',
51
+ type: 'processInstance',
52
+ },
53
+ });
54
+ }
34
55
  },
35
56
  { identity: currentIdentity }
36
57
  );
37
58
  case 'started':
38
59
  return await client.notification.onProcessStarted(
39
- (processNotification) => {
40
- if (config.processmodel != '' && config.processmodel != processNotification.processModelId)
60
+ async (processNotification) => {
61
+ if (
62
+ config.processmodel != '' &&
63
+ config.processmodel != processNotification.processModelId
64
+ )
41
65
  return;
42
- node.send({
43
- payload: {
44
- processInstanceId: processNotification.processInstanceId,
45
- processModelId: processNotification.processModelId,
46
- flowNodeId: processNotification.flowNodeId,
47
- token: processNotification.currentToken,
48
- action: 'started',
49
- type: 'processInstance',
50
- },
66
+ const newQuery = {
67
+ processInstanceId: processNotification.processInstanceId,
68
+ ...query,
69
+ };
70
+
71
+ const matchingInstances = await client.processInstances.query(newQuery, {
72
+ identity: currentIdentity,
51
73
  });
74
+
75
+ if (
76
+ matchingInstances.processInstances &&
77
+ matchingInstances.processInstances.length == 1
78
+ ) {
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
+ });
91
+ }
52
92
  },
53
93
  { identity: currentIdentity }
54
94
  );
55
95
  case 'resumed':
56
96
  return await client.notification.onProcessResumed(
57
- (processNotification) => {
58
- if (config.processmodel != '' && config.processmodel != processNotification.processModelId)
97
+ async (processNotification) => {
98
+ if (
99
+ config.processmodel != '' &&
100
+ config.processmodel != processNotification.processModelId
101
+ )
59
102
  return;
60
- node.send({
61
- payload: {
62
- processInstanceId: processNotification.processInstanceId,
63
- processModelId: processNotification.processModelId,
64
- token: processNotification.currentToken,
65
- action: 'resumed',
66
- type: 'processInstance',
67
- },
103
+
104
+ const newQuery = {
105
+ processInstanceId: processNotification.processInstanceId,
106
+ ...query,
107
+ };
108
+
109
+ const matchingInstances = await client.processInstances.query(newQuery, {
110
+ identity: currentIdentity,
68
111
  });
112
+
113
+ if (
114
+ matchingInstances.processInstances &&
115
+ matchingInstances.processInstances.length == 1
116
+ ) {
117
+ const processInstance = matchingInstances.processInstances[0];
118
+ node.send({
119
+ payload: {
120
+ processInstanceId: processNotification.processInstanceId,
121
+ processModelId: processNotification.processModelId,
122
+ token: processNotification.currentToken,
123
+ processInstance: processInstance,
124
+ action: 'resumed',
125
+ type: 'processInstance',
126
+ },
127
+ });
128
+ }
69
129
  },
70
- { identity: currentIdentity }
130
+ { identity: currentIdentity }
71
131
  );
72
132
  case 'finished':
73
133
  return await client.notification.onProcessEnded(
74
- (processNotification) => {
75
- if (config.processmodel != '' && config.processmodel != processNotification.processModelId)
134
+ async (processNotification) => {
135
+ if (
136
+ config.processmodel != '' &&
137
+ config.processmodel != processNotification.processModelId
138
+ )
76
139
  return;
77
- node.send({
78
- payload: {
79
- processInstanceId: processNotification.processInstanceId,
80
- processModelId: processNotification.processModelId,
81
- flowNodeId: processNotification.flowNodeId,
82
- token: processNotification.currentToken,
83
- action: 'finished',
84
- type: 'processInstance',
85
- },
140
+
141
+ const newQuery = {
142
+ processInstanceId: processNotification.processInstanceId,
143
+ ...query,
144
+ };
145
+
146
+ const matchingInstances = await client.processInstances.query(newQuery, {
147
+ identity: currentIdentity,
86
148
  });
149
+
150
+ if (
151
+ matchingInstances.processInstances &&
152
+ matchingInstances.processInstances.length == 1
153
+ ) {
154
+ const processInstance = matchingInstances.processInstances[0];
155
+ node.send({
156
+ payload: {
157
+ processInstanceId: processNotification.processInstanceId,
158
+ processModelId: processNotification.processModelId,
159
+ flowNodeId: processNotification.flowNodeId,
160
+ token: processNotification.currentToken,
161
+ processInstance: processInstance,
162
+ action: 'finished',
163
+ type: 'processInstance',
164
+ },
165
+ });
166
+ }
87
167
  },
88
168
  { identity: currentIdentity }
89
169
  );
90
170
  case 'terminated':
91
171
  return await client.notification.onProcessTerminated(
92
- (processNotification) => {
93
- if (config.processmodel != '' && config.processmodel != processNotification.processModelId)
172
+ async (processNotification) => {
173
+ if (
174
+ config.processmodel != '' &&
175
+ config.processmodel != processNotification.processModelId
176
+ )
94
177
  return;
95
- node.send({
96
- payload: {
97
- processInstanceId: processNotification.processInstanceId,
98
- processModelId: processNotification.processModelId,
99
- token: processNotification.currentToken,
100
- action: 'terminated',
101
- type: 'processInstance',
102
- },
178
+
179
+ const newQuery = {
180
+ processInstanceId: processNotification.processInstanceId,
181
+ ...query,
182
+ };
183
+
184
+ const matchingInstances = await client.processInstances.query(newQuery, {
185
+ identity: currentIdentity,
103
186
  });
187
+
188
+ if (
189
+ matchingInstances.processInstances &&
190
+ matchingInstances.processInstances.length == 1
191
+ ) {
192
+ const processInstance = matchingInstances.processInstances[0];
193
+ node.send({
194
+ payload: {
195
+ processInstanceId: processNotification.processInstanceId,
196
+ processModelId: processNotification.processModelId,
197
+ token: processNotification.currentToken,
198
+ processInstance: processInstance,
199
+ action: 'terminated',
200
+ type: 'processInstance',
201
+ },
202
+ });
203
+ }
104
204
  },
105
205
  { identity: currentIdentity }
106
206
  );
107
- case "error":
207
+ case 'error':
108
208
  return await client.notification.onProcessError(
109
- (processNotification) => {
110
- if (config.processmodel != '' && config.processmodel != processNotification.processModelId)
209
+ async (processNotification) => {
210
+ if (
211
+ config.processmodel != '' &&
212
+ config.processmodel != processNotification.processModelId
213
+ )
111
214
  return;
112
- node.send({
113
- payload: {
114
- processInstanceId: processNotification.processInstanceId,
115
- processModelId: processNotification.processModelId,
116
- token: processNotification.currentToken,
117
- action: 'error',
118
- type: 'processInstance',
119
- },
215
+
216
+ const newQuery = {
217
+ processInstanceId: processNotification.processInstanceId,
218
+ ...query,
219
+ };
220
+
221
+ const matchingInstances = await client.processInstances.query(newQuery, {
222
+ identity: currentIdentity,
120
223
  });
224
+
225
+ if (
226
+ matchingInstances.processInstances &&
227
+ matchingInstances.processInstances.length == 1
228
+ ) {
229
+ const processInstance = matchingInstances.processInstances[0];
230
+ node.send({
231
+ payload: {
232
+ processInstanceId: processNotification.processInstanceId,
233
+ processModelId: processNotification.processModelId,
234
+ token: processNotification.currentToken,
235
+ processInstance: processInstance,
236
+ action: 'error',
237
+ type: 'processInstance',
238
+ },
239
+ });
240
+ }
121
241
  },
122
242
  { identity: currentIdentity }
123
243
  );
124
- case "owner-changed":
244
+ case 'owner-changed':
125
245
  return await client.notification.onProcessOwnerChanged(
126
- (processNotification) => {
127
- if (config.processmodel != '' && config.processmodel != processNotification.processModelId)
246
+ async (processNotification) => {
247
+ if (
248
+ config.processmodel != '' &&
249
+ config.processmodel != processNotification.processModelId
250
+ )
128
251
  return;
129
- node.send({
130
- payload: {
131
- processInstanceId: processNotification.processInstanceId,
132
- processModelId: processNotification.processModelId,
133
- action: 'owner-changed',
134
- type: 'processInstance',
135
- },
252
+
253
+ const newQuery = {
254
+ processInstanceId: processNotification.processInstanceId,
255
+ ...query,
256
+ };
257
+
258
+ const matchingInstances = await client.processInstances.query(newQuery, {
259
+ identity: currentIdentity,
136
260
  });
261
+
262
+ if (
263
+ matchingInstances.processInstances &&
264
+ matchingInstances.processInstances.length == 1
265
+ ) {
266
+ const processInstance = matchingInstances.processInstances[0];
267
+ node.send({
268
+ payload: {
269
+ processInstanceId: processNotification.processInstanceId,
270
+ processModelId: processNotification.processModelId,
271
+ processInstance: processInstance,
272
+ action: 'owner-changed',
273
+ type: 'processInstance',
274
+ },
275
+ });
276
+ }
137
277
  },
138
278
  { identity: currentIdentity }
139
279
  );
140
- case "instances-deleted":
280
+ case 'instances-deleted':
141
281
  return await client.notification.onProcessInstancesDeleted(
142
- (processNotification) => {
143
- if (config.processmodel != '' && config.processmodel != processNotification.processModelId)
282
+ async (processNotification) => {
283
+ if (
284
+ config.processmodel != '' &&
285
+ config.processmodel != processNotification.processModelId
286
+ )
144
287
  return;
145
- node.send({
146
- payload: {
147
- processInstanceId: processNotification.processInstanceId,
148
- processModelId: processNotification.processModelId,
149
- action: 'instances-deleted',
150
- type: 'processInstance',
151
- },
288
+
289
+ const newQuery = {
290
+ processInstanceId: processNotification.processInstanceId,
291
+ ...query,
292
+ };
293
+
294
+ const matchingInstances = await client.processInstances.query(newQuery, {
295
+ identity: currentIdentity,
152
296
  });
297
+
298
+ if (
299
+ matchingInstances.processInstances &&
300
+ matchingInstances.processInstances.length == 1
301
+ ) {
302
+ const processInstance = matchingInstances.processInstances[0];
303
+ node.send({
304
+ payload: {
305
+ processInstanceId: processNotification.processInstanceId,
306
+ processModelId: processNotification.processModelId,
307
+ processInstance: processInstance,
308
+ action: 'instances-deleted',
309
+ type: 'processInstance',
310
+ },
311
+ });
312
+ }
153
313
  },
154
314
  { identity: currentIdentity }
155
315
  );
156
- case "is-executable-changed":
316
+ case 'is-executable-changed':
157
317
  return await client.notification.onProcessIsExecutableChanged(
158
318
  (processNotification) => {
159
- if (config.processmodel != '' && config.processmodel != processNotification.processModelId)
319
+ if (
320
+ config.processmodel != '' &&
321
+ config.processmodel != processNotification.processModelId
322
+ )
160
323
  return;
161
324
  node.send({
162
325
  payload: {
@@ -168,10 +331,13 @@ module.exports = function (RED) {
168
331
  },
169
332
  { identity: currentIdentity }
170
333
  );
171
- case "deployed":
334
+ case 'deployed':
172
335
  return await client.notification.onProcessDeployed(
173
336
  (processNotification) => {
174
- if (config.processmodel != '' && config.processmodel != processNotification.processModelId)
337
+ if (
338
+ config.processmodel != '' &&
339
+ config.processmodel != processNotification.processModelId
340
+ )
175
341
  return;
176
342
  node.send({
177
343
  payload: {
@@ -183,10 +349,13 @@ module.exports = function (RED) {
183
349
  },
184
350
  { identity: currentIdentity }
185
351
  );
186
- case "undeployed":
352
+ case 'undeployed':
187
353
  return await client.notification.onProcessUndeployed(
188
354
  (processNotification) => {
189
- if (config.processmodel != '' && config.processmodel != processNotification.processModelId)
355
+ if (
356
+ config.processmodel != '' &&
357
+ config.processmodel != processNotification.processModelId
358
+ )
190
359
  return;
191
360
  node.send({
192
361
  payload: {
@@ -199,13 +368,13 @@ module.exports = function (RED) {
199
368
  { identity: currentIdentity }
200
369
  );
201
370
  default:
202
- console.error("no such event: " + eventType)
371
+ console.error('no such event: ' + eventType);
203
372
  break;
204
373
  }
205
374
  }
206
375
 
207
376
  if (node.engine.isIdentityReady()) {
208
- subscription = await subscribe(config.eventtype)
377
+ subscription = await subscribe(config.eventtype);
209
378
  }
210
379
 
211
380
  node.engine.registerOnIdentityChanged(async (identity) => {
@@ -7,6 +7,8 @@
7
7
  engine: { value: '', type: 'processcube-engine-config' },
8
8
  usertask: { value: '', required: false },
9
9
  eventtype: { value: '', required: true },
10
+ query: { value: '{}' },
11
+ query_type: { value: 'json' },
10
12
  },
11
13
  inputs: 0,
12
14
  outputs: 1,
@@ -14,6 +16,22 @@
14
16
  label: function () {
15
17
  return this.name || 'usertask-event-listener';
16
18
  },
19
+ oneditprepare: function () {
20
+ $('#node-input-query').typedInput({
21
+ default: 'json',
22
+ types: ['json'],
23
+ });
24
+
25
+ $('#node-input-query').typedInput('value', this.query);
26
+ $('#node-input-query').typedInput('type', this.query_type);
27
+ },
28
+ oneditsave: function () {
29
+ if ($('#node-input-query').typedInput('value') == '') {
30
+ $('#node-input-query').typedInput('value', '{}')
31
+ }
32
+ (this.query = $('#node-input-query').typedInput('value')),
33
+ (this.query_type = $('#node-input-query').typedInput('type'));
34
+ },
17
35
  });
18
36
  </script>
19
37
 
@@ -39,6 +57,10 @@
39
57
  <option value="reservation-canceled">reservation-canceled</option>
40
58
  </select>
41
59
  </div>
60
+ <div class="form-row">
61
+ <label for="node-input-query"><i class="fa fa-tag"></i> Query</label>
62
+ <input type="text" id="node-input-query" />
63
+ </div>
42
64
  </script>
43
65
 
44
66
  <script type="text/markdown" data-help-name="usertask-event-listener">
@@ -15,66 +15,123 @@ module.exports = function (RED) {
15
15
  }
16
16
 
17
17
  let subscription;
18
+ const query = RED.util.evaluateNodeProperty(config.query, config.query_type, node);
18
19
 
19
20
  async function subscribe() {
20
21
  switch (config.eventtype) {
21
22
  case 'new':
22
23
  return await client.userTasks.onUserTaskWaiting(
23
- (userTaskNotification) => {
24
+ async (userTaskNotification) => {
24
25
  if (config.usertask != '' && config.usertask != userTaskNotification.flowNodeId) return;
25
- node.send({
26
- payload: {
27
- flowNodeInstanceId: userTaskNotification.flowNodeInstanceId,
28
- userTaskEvent: userTaskNotification,
29
- action: 'new',
30
- type: 'usertask',
31
- },
26
+ const newQuery = {
27
+ flowNodeInstanceId: userTaskNotification.flowNodeInstanceId,
28
+ ...query,
29
+ };
30
+
31
+ const matchingFlowNodes = await client.userTasks.query(newQuery, {
32
+ identity: currentIdentity,
32
33
  });
34
+
35
+ if (matchingFlowNodes.userTasks && matchingFlowNodes.userTasks.length == 1) {
36
+ const userTask = matchingFlowNodes.userTasks[0];
37
+
38
+ node.send({
39
+ payload: {
40
+ flowNodeInstanceId: userTaskNotification.flowNodeInstanceId,
41
+ userTaskEvent: userTaskNotification,
42
+ userTask: userTask,
43
+ action: 'new',
44
+ type: 'usertask',
45
+ },
46
+ });
47
+ }
33
48
  },
34
49
  { identity: currentIdentity }
35
50
  );
36
51
  case 'finished':
37
52
  return await client.userTasks.onUserTaskFinished(
38
- (userTaskNotification) => {
53
+ async (userTaskNotification) => {
39
54
  if (config.usertask != '' && config.usertask != userTaskNotification.flowNodeId) return;
40
- node.send({
41
- payload: {
42
- flowNodeInstanceId: userTaskNotification.flowNodeInstanceId,
43
- userTaskEvent: userTaskNotification,
44
- action: 'finished',
45
- type: 'usertask',
46
- },
55
+ const newQuery = {
56
+ flowNodeInstanceId: userTaskNotification.flowNodeInstanceId,
57
+ ...query,
58
+ };
59
+
60
+ const matchingFlowNodes = await client.userTasks.query(newQuery, {
61
+ identity: currentIdentity,
47
62
  });
63
+
64
+ if (matchingFlowNodes.userTasks && matchingFlowNodes.userTasks.length == 1) {
65
+ const userTask = matchingFlowNodes.userTasks[0];
66
+
67
+ node.send({
68
+ payload: {
69
+ flowNodeInstanceId: userTaskNotification.flowNodeInstanceId,
70
+ userTaskEvent: userTaskNotification,
71
+ userTask: userTask,
72
+ action: 'finished',
73
+ type: 'usertask',
74
+ },
75
+ });
76
+ }
48
77
  },
49
78
  { identity: currentIdentity }
50
79
  );
51
80
  case 'reserved':
52
81
  return await client.userTasks.onUserTaskReserved(
53
- (userTaskNotification) => {
82
+ async (userTaskNotification) => {
54
83
  if (config.usertask != '' && config.usertask != userTaskNotification.flowNodeId) return;
55
- node.send({
56
- payload: {
57
- flowNodeInstanceId: userTaskNotification.flowNodeInstanceId,
58
- userTaskEvent: userTaskNotification,
59
- action: 'reserved',
60
- type: 'usertask',
61
- },
84
+ const newQuery = {
85
+ flowNodeInstanceId: userTaskNotification.flowNodeInstanceId,
86
+ ...query,
87
+ };
88
+
89
+ const matchingFlowNodes = await client.userTasks.query(newQuery, {
90
+ identity: currentIdentity,
62
91
  });
92
+
93
+ if (matchingFlowNodes.userTasks && matchingFlowNodes.userTasks.length == 1) {
94
+ const userTask = matchingFlowNodes.userTasks[0];
95
+
96
+ node.send({
97
+ payload: {
98
+ flowNodeInstanceId: userTaskNotification.flowNodeInstanceId,
99
+ userTaskEvent: userTaskNotification,
100
+ userTask: userTask,
101
+ action: 'reserved',
102
+ type: 'usertask',
103
+ },
104
+ });
105
+ }
63
106
  },
64
107
  { identity: currentIdentity }
65
108
  );
66
109
  case 'reservation-canceled':
67
110
  return await client.userTasks.onUserTaskReservationCanceled(
68
- (userTaskNotification) => {
111
+ async (userTaskNotification) => {
69
112
  if (config.usertask != '' && config.usertask != userTaskNotification.flowNodeId) return;
70
- node.send({
71
- payload: {
72
- flowNodeInstanceId: userTaskNotification.flowNodeInstanceId,
73
- userTaskEvent: userTaskNotification,
74
- action: 'reservation-canceled',
75
- type: 'usertask',
76
- },
113
+ const newQuery = {
114
+ flowNodeInstanceId: userTaskNotification.flowNodeInstanceId,
115
+ ...query,
116
+ };
117
+
118
+ const matchingFlowNodes = await client.userTasks.query(newQuery, {
119
+ identity: currentIdentity,
77
120
  });
121
+
122
+ if (matchingFlowNodes.userTasks && matchingFlowNodes.userTasks.length == 1) {
123
+ const userTask = matchingFlowNodes.userTasks[0];
124
+
125
+ node.send({
126
+ payload: {
127
+ flowNodeInstanceId: userTaskNotification.flowNodeInstanceId,
128
+ userTaskEvent: userTaskNotification,
129
+ userTask: userTask,
130
+ action: 'reservation-canceled',
131
+ type: 'usertask',
132
+ },
133
+ });
134
+ }
78
135
  },
79
136
  { identity: currentIdentity }
80
137
  );