-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocessdefinition-query.js
47 lines (39 loc) · 1.68 KB
/
processdefinition-query.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
module.exports = function (RED) {
function ProcessdefinitionQuery(config) {
RED.nodes.createNode(this, config);
var node = this;
node.on('input', function (msg) {
node.engine = RED.nodes.getNode(config.engine);
const client = node.engine.engineClient;
if (!client) {
node.error('No engine configured.');
return;
}
let query = RED.util.evaluateNodeProperty(config.query, config.query_type, node, msg);
node.log(`Querying process definitions with query: ${JSON.stringify(query)}`);
client.processDefinitions
.getAll(query)
.then((matchingProcessDefinitions) => {
if (config.models_only && matchingProcessDefinitions.totalCount > 0) {
let models = [];
matchingProcessDefinitions.processDefinitions.forEach((processDefinition) => {
processDefinition.processModels.forEach((model) => {
models.push(model);
});
});
msg.payload = {
models: models,
totalCount: models.length,
};
} else {
msg.payload = matchingProcessDefinitions;
}
node.send(msg);
})
.catch((error) => {
node.error(JSON.stringify(error));
});
});
}
RED.nodes.registerType('processdefinition-query', ProcessdefinitionQuery);
};