@5minds/node-red-contrib-processcube 0.13.0 → 0.14.0-develop-6cc1ff-lz03ui7c
Sign up to get free protection for your applications and to get access to all the features.
- package/Dockerfile +1 -1
- package/docker-compose.yml +12 -0
- package/examples/External-Task-Sample.json +252 -0
- package/externaltask-error.html +16 -2
- package/externaltask-error.js +11 -13
- package/externaltask-input.html +19 -2
- package/externaltask-input.js +97 -44
- package/externaltask-output.html +12 -2
- package/externaltask-output.js +3 -3
- package/message-event-trigger.js +26 -34
- package/nodered/node-red-contrib-processcube-flows.json +216 -132
- package/nodered/package.json +1 -0
- package/nodered/settings.js +1 -1
- package/package.json +2 -2
- package/process-start.js +23 -28
- package/processcube-engine-config.js +17 -2
- package/processdefinition-query.js +47 -45
- package/processes/External-Task-Sample.bpmn +94 -0
- package/processinstance-query.js +25 -27
- package/signal-event-trigger.js +26 -34
- package/usertask-finished-listener.js +52 -31
- package/usertask-input.js +48 -34
- package/usertask-new-listener.js +49 -32
- package/usertask-output.js +35 -31
- package/processes/CheckError.bpmn +0 -78
- package/processes/NodeRedExternalTask.bpmn +0 -77
- package/processes/SampleUserTask.bpmn +0 -95
@@ -1,31 +1,23 @@
|
|
1
|
-
const process = require(
|
2
|
-
const EventEmitter = require(
|
1
|
+
const process = require("process");
|
2
|
+
const EventEmitter = require("node:events");
|
3
3
|
|
4
|
-
const engine_client = require(
|
4
|
+
const engine_client = require("@5minds/processcube_engine_client");
|
5
5
|
|
6
|
-
module.exports = function(RED) {
|
6
|
+
module.exports = function (RED) {
|
7
7
|
function ProcessdefinitionQuery(config) {
|
8
|
-
RED.nodes.createNode(this,config);
|
8
|
+
RED.nodes.createNode(this, config);
|
9
9
|
var node = this;
|
10
10
|
var flowContext = node.context().flow;
|
11
|
-
var nodeContext = node.context();
|
12
11
|
|
13
12
|
this.engine = this.server = RED.nodes.getNode(config.engine);
|
14
13
|
|
15
|
-
const
|
14
|
+
const client = this.engine.getEngineClient();
|
16
15
|
|
17
|
-
var
|
18
|
-
|
19
|
-
if (!client) {
|
20
|
-
nodeContext.set('client', new engine_client.EngineClient(engineUrl));
|
21
|
-
client = nodeContext.get('client');
|
22
|
-
}
|
23
|
-
|
24
|
-
var eventEmitter = flowContext.get('emitter');
|
16
|
+
var eventEmitter = flowContext.get("emitter");
|
25
17
|
|
26
18
|
if (!eventEmitter) {
|
27
|
-
flowContext.set(
|
28
|
-
eventEmitter = flowContext.get(
|
19
|
+
flowContext.set("emitter", new EventEmitter());
|
20
|
+
eventEmitter = flowContext.get("emitter");
|
29
21
|
}
|
30
22
|
|
31
23
|
node.on("close", async () => {
|
@@ -33,38 +25,48 @@ module.exports = function(RED) {
|
|
33
25
|
client = null;
|
34
26
|
});
|
35
27
|
|
36
|
-
node.on(
|
37
|
-
let query = RED.util.evaluateNodeProperty(
|
28
|
+
node.on("input", function (msg) {
|
29
|
+
let query = RED.util.evaluateNodeProperty(
|
30
|
+
config.query,
|
31
|
+
config.query_type,
|
32
|
+
node,
|
33
|
+
msg
|
34
|
+
);
|
38
35
|
query = {
|
39
36
|
...query,
|
40
|
-
identity: node.server.identity
|
37
|
+
identity: node.server.identity,
|
41
38
|
};
|
42
|
-
|
43
|
-
client.processDefinitions.getAll(query).then((matchingProcessDefinitions) => {
|
44
|
-
|
45
|
-
|
46
|
-
if (config.models_only && matchingProcessDefinitions.totalCount > 0) {
|
47
|
-
let models = [];
|
48
|
-
|
49
|
-
matchingProcessDefinitions.processDefinitions.forEach(processDefinition => {
|
50
|
-
processDefinition.processModels.forEach(model => {
|
51
|
-
models.push(model);
|
52
|
-
});
|
53
|
-
});
|
54
|
-
|
55
|
-
msg.payload = {
|
56
|
-
models: models,
|
57
|
-
totalCount: models.length
|
58
|
-
};
|
59
|
-
|
60
|
-
} else {
|
61
|
-
msg.payload = matchingProcessDefinitions;
|
62
|
-
}
|
63
|
-
|
64
39
|
|
65
|
-
|
66
|
-
|
40
|
+
client.processDefinitions
|
41
|
+
.getAll(query)
|
42
|
+
.then((matchingProcessDefinitions) => {
|
43
|
+
if (
|
44
|
+
config.models_only &&
|
45
|
+
matchingProcessDefinitions.totalCount > 0
|
46
|
+
) {
|
47
|
+
let models = [];
|
48
|
+
|
49
|
+
matchingProcessDefinitions.processDefinitions.forEach(
|
50
|
+
(processDefinition) => {
|
51
|
+
processDefinition.processModels.forEach(
|
52
|
+
(model) => {
|
53
|
+
models.push(model);
|
54
|
+
}
|
55
|
+
);
|
56
|
+
}
|
57
|
+
);
|
58
|
+
|
59
|
+
msg.payload = {
|
60
|
+
models: models,
|
61
|
+
totalCount: models.length,
|
62
|
+
};
|
63
|
+
} else {
|
64
|
+
msg.payload = matchingProcessDefinitions;
|
65
|
+
}
|
66
|
+
|
67
|
+
node.send(msg);
|
68
|
+
});
|
67
69
|
});
|
68
70
|
}
|
69
71
|
RED.nodes.registerType("processdefinition-query", ProcessdefinitionQuery);
|
70
|
-
}
|
72
|
+
};
|
@@ -0,0 +1,94 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="External-Task-Sample_Definition" targetNamespace="http://bpmn.io/schema/bpmn" exporter="5Minds Studio" exporterVersion="1">
|
3
|
+
<bpmn:collaboration id="Collaboration_1cidyxu" name="">
|
4
|
+
<bpmn:participant id="Participant_0px403d" name="External-Task-Sample" processRef="External-Task-Sample_Process" />
|
5
|
+
<bpmn:textAnnotation id="TextAnnotation_0lbjt7p">
|
6
|
+
<bpmn:text>Will be executed at the boundary event</bpmn:text>
|
7
|
+
</bpmn:textAnnotation>
|
8
|
+
<bpmn:association id="Association_0ivfgz1" associationDirection="None" sourceRef="Activity_0ma3kzt" targetRef="TextAnnotation_0lbjt7p" />
|
9
|
+
</bpmn:collaboration>
|
10
|
+
<bpmn:process id="External-Task-Sample_Process" name="External-Task-Sample" isExecutable="true">
|
11
|
+
<bpmn:laneSet />
|
12
|
+
<bpmn:startEvent id="StartEvent_1" name="Start">
|
13
|
+
<bpmn:outgoing>Flow_0qmxzxk</bpmn:outgoing>
|
14
|
+
</bpmn:startEvent>
|
15
|
+
<bpmn:sequenceFlow id="Flow_0qmxzxk" sourceRef="StartEvent_1" targetRef="Activity_02ykwt2" />
|
16
|
+
<bpmn:sequenceFlow id="Flow_16dfeac" sourceRef="Activity_02ykwt2" targetRef="Activity_0ma3kzt" />
|
17
|
+
<bpmn:endEvent id="Event_05wpeos">
|
18
|
+
<bpmn:incoming>Flow_0mo4oek</bpmn:incoming>
|
19
|
+
</bpmn:endEvent>
|
20
|
+
<bpmn:sequenceFlow id="Flow_0mo4oek" sourceRef="Activity_0ma3kzt" targetRef="Event_05wpeos" />
|
21
|
+
<bpmn:endEvent id="Event_0yn9mzh">
|
22
|
+
<bpmn:incoming>Flow_0y6es1p</bpmn:incoming>
|
23
|
+
</bpmn:endEvent>
|
24
|
+
<bpmn:sequenceFlow id="Flow_0y6es1p" sourceRef="Event_0o7qlkd" targetRef="Event_0yn9mzh" />
|
25
|
+
<bpmn:serviceTask id="Activity_02ykwt2" name="Topic "Test"" camunda:type="external" camunda:topic="Test">
|
26
|
+
<bpmn:incoming>Flow_0qmxzxk</bpmn:incoming>
|
27
|
+
<bpmn:outgoing>Flow_16dfeac</bpmn:outgoing>
|
28
|
+
</bpmn:serviceTask>
|
29
|
+
<bpmn:serviceTask id="Activity_0ma3kzt" name="Topic "SampleError"" camunda:type="external" camunda:topic="SampleError">
|
30
|
+
<bpmn:incoming>Flow_16dfeac</bpmn:incoming>
|
31
|
+
<bpmn:outgoing>Flow_0mo4oek</bpmn:outgoing>
|
32
|
+
</bpmn:serviceTask>
|
33
|
+
<bpmn:boundaryEvent id="Event_0o7qlkd" attachedToRef="Activity_0ma3kzt">
|
34
|
+
<bpmn:outgoing>Flow_0y6es1p</bpmn:outgoing>
|
35
|
+
<bpmn:errorEventDefinition id="ErrorEventDefinition_1lr8fha" errorRef="Error_3O8wBFQi" />
|
36
|
+
</bpmn:boundaryEvent>
|
37
|
+
</bpmn:process>
|
38
|
+
<bpmn:error id="Error_3O8wBFQi" errorCode="MyErrorCode" />
|
39
|
+
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
|
40
|
+
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Collaboration_1cidyxu">
|
41
|
+
<bpmndi:BPMNShape id="Participant_0px403d_di" bpmnElement="Participant_0px403d" isHorizontal="true">
|
42
|
+
<dc:Bounds x="5" y="30" width="635" height="320" />
|
43
|
+
</bpmndi:BPMNShape>
|
44
|
+
<bpmndi:BPMNShape id="StartEvent_1_di" bpmnElement="StartEvent_1">
|
45
|
+
<dc:Bounds x="92" y="152" width="36" height="36" />
|
46
|
+
<bpmndi:BPMNLabel>
|
47
|
+
<dc:Bounds x="98" y="195" width="24" height="14" />
|
48
|
+
</bpmndi:BPMNLabel>
|
49
|
+
</bpmndi:BPMNShape>
|
50
|
+
<bpmndi:BPMNShape id="Event_05wpeos_di" bpmnElement="Event_05wpeos">
|
51
|
+
<dc:Bounds x="502" y="152" width="36" height="36" />
|
52
|
+
</bpmndi:BPMNShape>
|
53
|
+
<bpmndi:BPMNShape id="Event_0yn9mzh_di" bpmnElement="Event_0yn9mzh">
|
54
|
+
<dc:Bounds x="482" y="272" width="36" height="36" />
|
55
|
+
</bpmndi:BPMNShape>
|
56
|
+
<bpmndi:BPMNShape id="Activity_1vxcs04_di" bpmnElement="Activity_02ykwt2">
|
57
|
+
<dc:Bounds x="180" y="130" width="100" height="80" />
|
58
|
+
<bpmndi:BPMNLabel />
|
59
|
+
</bpmndi:BPMNShape>
|
60
|
+
<bpmndi:BPMNShape id="Activity_1b7fiqp_di" bpmnElement="Activity_0ma3kzt">
|
61
|
+
<dc:Bounds x="340" y="130" width="100" height="80" />
|
62
|
+
<bpmndi:BPMNLabel />
|
63
|
+
</bpmndi:BPMNShape>
|
64
|
+
<bpmndi:BPMNShape id="Event_134k5nt_di" bpmnElement="Event_0o7qlkd">
|
65
|
+
<dc:Bounds x="392" y="192" width="36" height="36" />
|
66
|
+
</bpmndi:BPMNShape>
|
67
|
+
<bpmndi:BPMNEdge id="Flow_0qmxzxk_di" bpmnElement="Flow_0qmxzxk">
|
68
|
+
<di:waypoint x="128" y="170" />
|
69
|
+
<di:waypoint x="180" y="170" />
|
70
|
+
</bpmndi:BPMNEdge>
|
71
|
+
<bpmndi:BPMNEdge id="Flow_16dfeac_di" bpmnElement="Flow_16dfeac">
|
72
|
+
<di:waypoint x="280" y="170" />
|
73
|
+
<di:waypoint x="340" y="170" />
|
74
|
+
</bpmndi:BPMNEdge>
|
75
|
+
<bpmndi:BPMNEdge id="Flow_0mo4oek_di" bpmnElement="Flow_0mo4oek">
|
76
|
+
<di:waypoint x="440" y="170" />
|
77
|
+
<di:waypoint x="502" y="170" />
|
78
|
+
</bpmndi:BPMNEdge>
|
79
|
+
<bpmndi:BPMNEdge id="Flow_0y6es1p_di" bpmnElement="Flow_0y6es1p">
|
80
|
+
<di:waypoint x="410" y="228" />
|
81
|
+
<di:waypoint x="410" y="290" />
|
82
|
+
<di:waypoint x="482" y="290" />
|
83
|
+
</bpmndi:BPMNEdge>
|
84
|
+
<bpmndi:BPMNShape id="TextAnnotation_0lbjt7p_di" bpmnElement="TextAnnotation_0lbjt7p">
|
85
|
+
<dc:Bounds x="370" y="50" width="169.99387960829492" height="39.99855990783411" />
|
86
|
+
<bpmndi:BPMNLabel />
|
87
|
+
</bpmndi:BPMNShape>
|
88
|
+
<bpmndi:BPMNEdge id="Association_0ivfgz1_di" bpmnElement="Association_0ivfgz1">
|
89
|
+
<di:waypoint x="401" y="130" />
|
90
|
+
<di:waypoint x="413" y="90" />
|
91
|
+
</bpmndi:BPMNEdge>
|
92
|
+
</bpmndi:BPMNPlane>
|
93
|
+
</bpmndi:BPMNDiagram>
|
94
|
+
</bpmn:definitions>
|
package/processinstance-query.js
CHANGED
@@ -1,31 +1,23 @@
|
|
1
|
-
const process = require(
|
2
|
-
const EventEmitter = require(
|
1
|
+
const process = require("process");
|
2
|
+
const EventEmitter = require("node:events");
|
3
3
|
|
4
|
-
const engine_client = require(
|
4
|
+
const engine_client = require("@5minds/processcube_engine_client");
|
5
5
|
|
6
|
-
module.exports = function(RED) {
|
6
|
+
module.exports = function (RED) {
|
7
7
|
function ProcessinstanceQuery(config) {
|
8
|
-
RED.nodes.createNode(this,config);
|
8
|
+
RED.nodes.createNode(this, config);
|
9
9
|
var node = this;
|
10
10
|
var flowContext = node.context().flow;
|
11
|
-
var nodeContext = node.context();
|
12
11
|
|
13
12
|
this.engine = this.server = RED.nodes.getNode(config.engine);
|
14
13
|
|
15
|
-
const
|
14
|
+
const client = this.engine.getEngineClient();
|
16
15
|
|
17
|
-
var
|
18
|
-
|
19
|
-
if (!client) {
|
20
|
-
nodeContext.set('client', new engine_client.EngineClient(engineUrl));
|
21
|
-
client = nodeContext.get('client');
|
22
|
-
}
|
23
|
-
|
24
|
-
var eventEmitter = flowContext.get('emitter');
|
16
|
+
var eventEmitter = flowContext.get("emitter");
|
25
17
|
|
26
18
|
if (!eventEmitter) {
|
27
|
-
flowContext.set(
|
28
|
-
eventEmitter = flowContext.get(
|
19
|
+
flowContext.set("emitter", new EventEmitter());
|
20
|
+
eventEmitter = flowContext.get("emitter");
|
29
21
|
}
|
30
22
|
|
31
23
|
node.on("close", async () => {
|
@@ -33,16 +25,22 @@ module.exports = function(RED) {
|
|
33
25
|
client = null;
|
34
26
|
});
|
35
27
|
|
36
|
-
node.on(
|
37
|
-
let query = RED.util.evaluateNodeProperty(
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
msg
|
42
|
-
|
43
|
-
|
44
|
-
|
28
|
+
node.on("input", function (msg) {
|
29
|
+
let query = RED.util.evaluateNodeProperty(
|
30
|
+
config.query,
|
31
|
+
config.query_type,
|
32
|
+
node,
|
33
|
+
msg
|
34
|
+
);
|
35
|
+
|
36
|
+
client.processInstances
|
37
|
+
.query(query, { identity: node.server.identity })
|
38
|
+
.then((matchingInstances) => {
|
39
|
+
msg.payload = matchingInstances;
|
40
|
+
|
41
|
+
node.send(msg);
|
42
|
+
});
|
45
43
|
});
|
46
44
|
}
|
47
45
|
RED.nodes.registerType("processinstance-query", ProcessinstanceQuery);
|
48
|
-
}
|
46
|
+
};
|
package/signal-event-trigger.js
CHANGED
@@ -1,45 +1,37 @@
|
|
1
|
-
const process = require(
|
1
|
+
const process = require("process");
|
2
2
|
|
3
|
-
const engine_client = require(
|
3
|
+
const engine_client = require("@5minds/processcube_engine_client");
|
4
4
|
|
5
|
-
module.exports = function(RED) {
|
5
|
+
module.exports = function (RED) {
|
6
6
|
function SignalEventTrigger(config) {
|
7
7
|
RED.nodes.createNode(this, config);
|
8
8
|
var node = this;
|
9
|
-
var nodeContext = node.context();
|
10
9
|
|
11
10
|
this.engine = this.server = RED.nodes.getNode(config.engine);
|
12
11
|
|
13
|
-
const
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
node.send(msg);
|
37
|
-
node.status({fill: "blue", shape: "dot", text: `signal event triggered`});
|
38
|
-
|
39
|
-
}).catch((error) => {
|
40
|
-
node.error(error);
|
41
|
-
});
|
12
|
+
const client = this.engine.getEngineClient();
|
13
|
+
|
14
|
+
node.on("input", function (msg) {
|
15
|
+
client.events
|
16
|
+
.triggerSignalEvent(config.signalname, {
|
17
|
+
processInstanceId: config.processinstanceid,
|
18
|
+
payload: msg.payload,
|
19
|
+
identity: node.server.identity,
|
20
|
+
})
|
21
|
+
.then((result) => {
|
22
|
+
msg.payload = result;
|
23
|
+
|
24
|
+
node.send(msg);
|
25
|
+
node.status({
|
26
|
+
fill: "blue",
|
27
|
+
shape: "dot",
|
28
|
+
text: `signal event triggered`,
|
29
|
+
});
|
30
|
+
})
|
31
|
+
.catch((error) => {
|
32
|
+
node.error(error);
|
33
|
+
});
|
42
34
|
});
|
43
35
|
}
|
44
36
|
RED.nodes.registerType("signal-event-trigger", SignalEventTrigger);
|
45
|
-
}
|
37
|
+
};
|
@@ -1,58 +1,79 @@
|
|
1
|
-
const process = require(
|
2
|
-
const EventEmitter = require(
|
1
|
+
const process = require("process");
|
2
|
+
const EventEmitter = require("node:events");
|
3
3
|
|
4
|
-
const engine_client = require(
|
4
|
+
const engine_client = require("@5minds/processcube_engine_client");
|
5
5
|
|
6
|
-
module.exports = function(RED) {
|
6
|
+
module.exports = function (RED) {
|
7
7
|
function UserTaskFinishedListener(config) {
|
8
8
|
RED.nodes.createNode(this, config);
|
9
9
|
var node = this;
|
10
10
|
var flowContext = node.context().flow;
|
11
|
-
var nodeContext = node.context();
|
12
11
|
|
13
12
|
this.engine = this.server = RED.nodes.getNode(config.engine);
|
14
13
|
|
15
|
-
const
|
14
|
+
const client = this.engine.getEngineClient();
|
16
15
|
|
17
|
-
var
|
18
|
-
|
19
|
-
if (!client) {
|
20
|
-
nodeContext.set('client', new engine_client.EngineClient(engineUrl));
|
21
|
-
client = nodeContext.get('client');
|
22
|
-
}
|
23
|
-
|
24
|
-
var eventEmitter = flowContext.get('emitter');
|
16
|
+
var eventEmitter = flowContext.get("emitter");
|
25
17
|
|
26
18
|
if (!eventEmitter) {
|
27
|
-
flowContext.set(
|
28
|
-
eventEmitter = flowContext.get(
|
19
|
+
flowContext.set("emitter", new EventEmitter());
|
20
|
+
eventEmitter = flowContext.get("emitter");
|
29
21
|
}
|
30
22
|
|
31
23
|
const register = async () => {
|
32
24
|
let currentIdentity = node.server.identity;
|
33
|
-
let subscription = await client.userTasks.onUserTaskFinished(
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
25
|
+
let subscription = await client.userTasks.onUserTaskFinished(
|
26
|
+
(userTaskFinishedNotification) => {
|
27
|
+
node.send({
|
28
|
+
payload: {
|
29
|
+
flowNodeInstanceId:
|
30
|
+
userTaskFinishedNotification.flowNodeInstanceId,
|
31
|
+
action: "finished",
|
32
|
+
type: "usertask",
|
33
|
+
},
|
34
|
+
});
|
35
|
+
},
|
36
|
+
{ identity: currentIdentity }
|
37
|
+
);
|
38
|
+
|
39
|
+
node.server.registerOnIdentityChanged(async (identity) => {
|
40
|
+
client.userTasks.removeSubscription(
|
41
|
+
subscription,
|
42
|
+
currentIdentity
|
43
|
+
);
|
39
44
|
currentIdentity = identity;
|
40
|
-
|
41
|
-
subscription = await client.userTasks.onUserTaskFinished(
|
42
|
-
|
43
|
-
|
45
|
+
|
46
|
+
subscription = await client.userTasks.onUserTaskFinished(
|
47
|
+
(userTaskFinishedNotification) => {
|
48
|
+
node.send({
|
49
|
+
payload: {
|
50
|
+
flowNodeInstanceId:
|
51
|
+
userTaskFinishedNotification.flowNodeInstanceId,
|
52
|
+
action: "finished",
|
53
|
+
type: "usertask",
|
54
|
+
},
|
55
|
+
});
|
56
|
+
},
|
57
|
+
{ identity: currentIdentity }
|
58
|
+
);
|
44
59
|
});
|
45
|
-
|
60
|
+
|
46
61
|
node.on("close", async () => {
|
47
|
-
client.userTasks.removeSubscription(
|
62
|
+
client.userTasks.removeSubscription(
|
63
|
+
subscription,
|
64
|
+
currentIdentity
|
65
|
+
);
|
48
66
|
client.dispose();
|
49
67
|
client = null;
|
50
68
|
});
|
51
|
-
}
|
69
|
+
};
|
52
70
|
|
53
71
|
if (node.server) {
|
54
72
|
register();
|
55
73
|
}
|
56
74
|
}
|
57
|
-
RED.nodes.registerType(
|
58
|
-
|
75
|
+
RED.nodes.registerType(
|
76
|
+
"usertask-finished-listener",
|
77
|
+
UserTaskFinishedListener
|
78
|
+
);
|
79
|
+
};
|
package/usertask-input.js
CHANGED
@@ -1,40 +1,40 @@
|
|
1
|
-
const process = require(
|
2
|
-
const EventEmitter = require(
|
1
|
+
const process = require("process");
|
2
|
+
const EventEmitter = require("node:events");
|
3
3
|
|
4
|
-
const engine_client = require(
|
4
|
+
const engine_client = require("@5minds/processcube_engine_client");
|
5
5
|
|
6
6
|
function showStatus(node, msgCounter) {
|
7
7
|
if (msgCounter >= 1) {
|
8
|
-
node.status({
|
8
|
+
node.status({
|
9
|
+
fill: "blue",
|
10
|
+
shape: "dot",
|
11
|
+
text: `handling tasks ${msgCounter}`,
|
12
|
+
});
|
9
13
|
} else {
|
10
|
-
node.status({
|
14
|
+
node.status({
|
15
|
+
fill: "blue",
|
16
|
+
shape: "ring",
|
17
|
+
text: `subcribed ${msgCounter}`,
|
18
|
+
});
|
11
19
|
}
|
12
20
|
}
|
13
21
|
|
14
|
-
module.exports = function(RED) {
|
22
|
+
module.exports = function (RED) {
|
15
23
|
function UserTaskInput(config) {
|
16
|
-
RED.nodes.createNode(this,config);
|
24
|
+
RED.nodes.createNode(this, config);
|
17
25
|
var node = this;
|
18
26
|
var msgCounter = 0;
|
19
27
|
var flowContext = node.context().flow;
|
20
|
-
var nodeContext = node.context();
|
21
28
|
|
22
29
|
this.engine = this.server = RED.nodes.getNode(config.engine);
|
23
30
|
|
24
|
-
const
|
25
|
-
|
26
|
-
var client = nodeContext.get('client');
|
27
|
-
|
28
|
-
if (!client) {
|
29
|
-
nodeContext.set('client', new engine_client.EngineClient(engineUrl));
|
30
|
-
client = nodeContext.get('client');
|
31
|
-
}
|
31
|
+
const client = this.engine.getEngineClient();
|
32
32
|
|
33
|
-
var eventEmitter = flowContext.get(
|
33
|
+
var eventEmitter = flowContext.get("emitter");
|
34
34
|
|
35
35
|
if (!eventEmitter) {
|
36
|
-
flowContext.set(
|
37
|
-
eventEmitter = flowContext.get(
|
36
|
+
flowContext.set("emitter", new EventEmitter());
|
37
|
+
eventEmitter = flowContext.get("emitter");
|
38
38
|
}
|
39
39
|
|
40
40
|
node.on("close", async () => {
|
@@ -42,40 +42,54 @@ module.exports = function(RED) {
|
|
42
42
|
client = null;
|
43
43
|
});
|
44
44
|
|
45
|
-
node.on(
|
46
|
-
let query = RED.util.evaluateNodeProperty(
|
45
|
+
node.on("input", function (msg) {
|
46
|
+
let query = RED.util.evaluateNodeProperty(
|
47
|
+
config.query,
|
48
|
+
config.query_type,
|
49
|
+
node,
|
50
|
+
msg
|
51
|
+
);
|
47
52
|
query = {
|
48
53
|
...query,
|
49
|
-
identity: node.server.identity
|
50
|
-
}
|
54
|
+
identity: node.server.identity,
|
55
|
+
};
|
51
56
|
client.userTasks.query(query).then((matchingFlowNodes) => {
|
52
|
-
|
53
|
-
|
57
|
+
if (
|
58
|
+
!config.force_send_array &&
|
59
|
+
matchingFlowNodes &&
|
60
|
+
matchingFlowNodes.userTasks &&
|
61
|
+
matchingFlowNodes.userTasks.length == 1
|
62
|
+
) {
|
54
63
|
userTask = matchingFlowNodes.userTasks[0];
|
55
64
|
|
56
65
|
msg.payload = { userTask: userTask };
|
57
66
|
node.send(msg);
|
58
67
|
} else {
|
59
68
|
if (!config.force_send_array) {
|
60
|
-
if (
|
69
|
+
if (
|
70
|
+
config.multisend &&
|
71
|
+
matchingFlowNodes.userTasks &&
|
72
|
+
matchingFlowNodes.userTasks.length > 1
|
73
|
+
) {
|
61
74
|
matchingFlowNodes.userTasks.forEach((userTask) => {
|
62
|
-
|
63
|
-
msg.payload = { userTask: userTask } ;
|
75
|
+
msg.payload = { userTask: userTask };
|
64
76
|
node.send(msg);
|
65
77
|
});
|
66
78
|
} else {
|
67
|
-
|
68
|
-
|
79
|
+
msg.payload = {
|
80
|
+
userTasks: matchingFlowNodes.userTasks,
|
81
|
+
};
|
69
82
|
node.send(msg);
|
70
83
|
}
|
71
84
|
} else {
|
72
|
-
|
73
|
-
|
85
|
+
msg.payload = {
|
86
|
+
userTasks: matchingFlowNodes.userTasks || [],
|
87
|
+
};
|
74
88
|
node.send(msg);
|
75
89
|
}
|
76
|
-
|
90
|
+
}
|
77
91
|
});
|
78
92
|
});
|
79
93
|
}
|
80
94
|
RED.nodes.registerType("usertask-input", UserTaskInput);
|
81
|
-
}
|
95
|
+
};
|