-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
173 lines (158 loc) · 5.28 KB
/
Copy pathindex.js
File metadata and controls
173 lines (158 loc) · 5.28 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
'use strict';
const Request = require('request');
//API documentation for Activiti can be found at http://activiti.org/userguide/index.html#_rest_api
module.exports = class ActivitiClient {
//Here auth needs to be an object with properties user and pass
constructor(baseUrl, auth) {
this.baseUrl = baseUrl;
this.auth = auth;
}
getProcessInstancesByDefinitionKey(processDefinitionKey, start, size, callback) {
Request({
url: this.baseUrl + "/runtime/process-instances?processDefinitionKey=" + processDefinitionKey + "&size=" + size + "&start=" + start + "&excludeSubprocesses=true",
method: "GET",
json: true,
auth: this.auth
}, function(err, httpResponse, body) {
if(err) {
return callback(err, null);
}
if (httpResponse.statusCode == 200) {
return callback(null, body);
}
else {
return callback(body, null);
}
});
}
getProcessInstancesByBusinessKey(businessKey, start, size, callback) {
Request({
url: this.baseUrl + "/runtime/process-instances?businessKey=" + businessKey + "&size=" + size + "&start=" + start + "&excludeSubprocesses=true",
method: "GET",
json: true,
auth: this.auth
}, function(err, httpResponse, body) {
if(err) {
return callback(err, null);
}
if (httpResponse.statusCode == 200) {
return callback(null, body);
}
else {
return callback(body, null);
}
});
}
getProcessStatus(processInstanceId, callback) {
Request({
url: this.baseUrl + "/runtime/executions/" + processInstanceId + "/activities",
method: "GET",
json: true,
auth: this.auth
}, function(err, httpResponse, body) {
if(err) {
return callback(err, null);
}
if (httpResponse.statusCode == 200) {
return callback(null, body);
}
else {
return callback(body, null);
}
});
}
getProcessStatusByBusinessKey(businessKey, callback) {
var that = this;
this.getProcessInstancesByBusinessKey(businessKey, 0, 1, function(err, response) {
if(err) {
return callback(err);
}
that.getProcessStatus(response.data[0].id, callback);
});
}
//Here variables is a list of objects with properties name, value and type, of which type is optional
startProcessInstance(processDefinitionKey, businessKey, variables, callback) {
var params = {
processDefinitionKey: processDefinitionKey,
businessKey: businessKey,
variables: variables
};
Request({
url: this.baseUrl + "/runtime/process-instances",
method: "POST",
body: params,
json: true,
auth: this.auth
}, function(err, httpResponse, body) {
if(err) {
return callback(err, null);
}
if (httpResponse.statusCode == 201) {
return callback(null, body);
}
else {
return callback(body, null);
}
});
}
getProcessTasks(businessKey, callback) {
Request({
url: this.baseUrl + "/runtime/tasks?assignee=" + this.auth.user + "&processInstanceBusinessKey=" + businessKey,
method: "GET",
json: true,
auth: this.auth
}, function(err, httpResponse, body) {
if(err) {
return callback(err, null);
}
if (httpResponse.statusCode == 200) {
return callback(null, body);
}
else {
return callback(body, null);
}
});
}
getTaskVariables(taskId, callback) {
Request({
url: this.baseUrl + "/runtime/tasks/" + taskId + "/variables",
method: "GET",
json: true,
auth: this.auth
}, function(err, httpResponse, body) {
if(err) {
return callback(err, null);
}
if (httpResponse.statusCode == 200) {
return callback(null, body);
}
else {
return callback(body, null);
}
});
}
//Here variables is a list of objects with properties name, value, type of which type is optional
completeTask(taskId, variables, callback) {
var params = {
action: "complete",
variables: variables
};
Request({
url: this.baseUrl + "/runtime/tasks/" + taskId,
method: "POST",
body: params,
json: true,
auth: this.auth
}, function(err, httpResponse, body) {
if(err) {
return callback(err, null);
}
if (httpResponse.statusCode == 200) {
return callback(null, body);
}
else {
return callback(body, null);
}
});
}
};