/
TaskServiceImpl.java
379 lines (302 loc) · 14.7 KB
/
TaskServiceImpl.java
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.engine.impl;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.activiti.engine.ActivitiIllegalArgumentException;
import org.activiti.engine.TaskService;
import org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.activiti.engine.impl.cmd.AddCommentCmd;
import org.activiti.engine.impl.cmd.AddIdentityLinkCmd;
import org.activiti.engine.impl.cmd.ClaimTaskCmd;
import org.activiti.engine.impl.cmd.CompleteTaskCmd;
import org.activiti.engine.impl.cmd.CreateAttachmentCmd;
import org.activiti.engine.impl.cmd.DelegateTaskCmd;
import org.activiti.engine.impl.cmd.DeleteAttachmentCmd;
import org.activiti.engine.impl.cmd.DeleteCommentCmd;
import org.activiti.engine.impl.cmd.DeleteIdentityLinkCmd;
import org.activiti.engine.impl.cmd.DeleteTaskCmd;
import org.activiti.engine.impl.cmd.GetAttachmentCmd;
import org.activiti.engine.impl.cmd.GetAttachmentContentCmd;
import org.activiti.engine.impl.cmd.GetCommentCmd;
import org.activiti.engine.impl.cmd.GetIdentityLinksForTaskCmd;
import org.activiti.engine.impl.cmd.GetProcessInstanceAttachmentsCmd;
import org.activiti.engine.impl.cmd.GetProcessInstanceCommentsCmd;
import org.activiti.engine.impl.cmd.GetSubTasksCmd;
import org.activiti.engine.impl.cmd.GetTaskAttachmentsCmd;
import org.activiti.engine.impl.cmd.GetTaskCommentsByTypeCmd;
import org.activiti.engine.impl.cmd.GetTaskCommentsCmd;
import org.activiti.engine.impl.cmd.GetTaskEventCmd;
import org.activiti.engine.impl.cmd.GetTaskEventsCmd;
import org.activiti.engine.impl.cmd.GetTaskVariableCmd;
import org.activiti.engine.impl.cmd.GetTaskVariablesCmd;
import org.activiti.engine.impl.cmd.GetTypeCommentsCmd;
import org.activiti.engine.impl.cmd.HasTaskVariableCmd;
import org.activiti.engine.impl.cmd.NewTaskCmd;
import org.activiti.engine.impl.cmd.RemoveTaskVariablesCmd;
import org.activiti.engine.impl.cmd.ResolveTaskCmd;
import org.activiti.engine.impl.cmd.SaveAttachmentCmd;
import org.activiti.engine.impl.cmd.SaveTaskCmd;
import org.activiti.engine.impl.cmd.SetTaskDueDateCmd;
import org.activiti.engine.impl.cmd.SetTaskPriorityCmd;
import org.activiti.engine.impl.cmd.SetTaskVariablesCmd;
import org.activiti.engine.task.Attachment;
import org.activiti.engine.task.Comment;
import org.activiti.engine.task.Event;
import org.activiti.engine.task.IdentityLink;
import org.activiti.engine.task.IdentityLinkType;
import org.activiti.engine.task.NativeTaskQuery;
import org.activiti.engine.task.Task;
import org.activiti.engine.task.TaskQuery;
/**
* @author Tom Baeyens
* @author Joram Barrez
*/
public class TaskServiceImpl extends ServiceImpl implements TaskService {
public TaskServiceImpl() {
}
public TaskServiceImpl(ProcessEngineConfigurationImpl processEngineConfiguration) {
super(processEngineConfiguration);
}
public Task newTask() {
return newTask(null);
}
public Task newTask(String taskId) {
return commandExecutor.execute(new NewTaskCmd(taskId));
}
public void saveTask(Task task) {
commandExecutor.execute(new SaveTaskCmd(task));
}
public void deleteTask(String taskId) {
commandExecutor.execute(new DeleteTaskCmd(taskId, null, false));
}
public void deleteTasks(Collection<String> taskIds) {
commandExecutor.execute(new DeleteTaskCmd(taskIds, null, false));
}
public void deleteTask(String taskId, boolean cascade) {
commandExecutor.execute(new DeleteTaskCmd(taskId, null, cascade));
}
public void deleteTasks(Collection<String> taskIds, boolean cascade) {
commandExecutor.execute(new DeleteTaskCmd(taskIds, null, cascade));
}
@Override
public void deleteTask(String taskId, String deleteReason) {
commandExecutor.execute(new DeleteTaskCmd(taskId, deleteReason, false));
}
@Override
public void deleteTasks(Collection<String> taskIds, String deleteReason) {
commandExecutor.execute(new DeleteTaskCmd(taskIds, deleteReason, false));
}
public void setAssignee(String taskId, String userId) {
commandExecutor.execute(new AddIdentityLinkCmd(taskId, userId, null, IdentityLinkType.ASSIGNEE));
}
public void setOwner(String taskId, String userId) {
commandExecutor.execute(new AddIdentityLinkCmd(taskId, userId, null, IdentityLinkType.OWNER));
}
public void addCandidateUser(String taskId, String userId) {
commandExecutor.execute(new AddIdentityLinkCmd(taskId, userId, null, IdentityLinkType.CANDIDATE));
}
public void addCandidateGroup(String taskId, String groupId) {
commandExecutor.execute(new AddIdentityLinkCmd(taskId, null, groupId, IdentityLinkType.CANDIDATE));
}
public void addUserIdentityLink(String taskId, String userId, String identityLinkType) {
commandExecutor.execute(new AddIdentityLinkCmd(taskId, userId, null, identityLinkType));
}
public void addGroupIdentityLink(String taskId, String groupId, String identityLinkType) {
commandExecutor.execute(new AddIdentityLinkCmd(taskId, null, groupId, identityLinkType));
}
public void deleteCandidateGroup(String taskId, String groupId) {
commandExecutor.execute(new DeleteIdentityLinkCmd(taskId, null, groupId, IdentityLinkType.CANDIDATE));
}
public void deleteCandidateUser(String taskId, String userId) {
commandExecutor.execute(new DeleteIdentityLinkCmd(taskId, userId, null, IdentityLinkType.CANDIDATE));
}
public void deleteGroupIdentityLink(String taskId, String groupId, String identityLinkType) {
commandExecutor.execute(new DeleteIdentityLinkCmd(taskId, null, groupId, identityLinkType));
}
public void deleteUserIdentityLink(String taskId, String userId, String identityLinkType) {
commandExecutor.execute(new DeleteIdentityLinkCmd(taskId, userId, null, identityLinkType));
}
public List<IdentityLink> getIdentityLinksForTask(String taskId) {
return commandExecutor.execute(new GetIdentityLinksForTaskCmd(taskId));
}
public void claim(String taskId, String userId) {
commandExecutor.execute(new ClaimTaskCmd(taskId, userId));
}
public void unclaim(String taskId) {
commandExecutor.execute(new ClaimTaskCmd(taskId, null));
}
public void complete(String taskId) {
commandExecutor.execute(new CompleteTaskCmd(taskId, null));
}
public void complete(String taskId, Map<String, Object> variables) {
commandExecutor.execute(new CompleteTaskCmd(taskId, variables));
}
public void complete(String taskId, Map<String, Object> variables,boolean localScope) {
commandExecutor.execute(new CompleteTaskCmd(taskId, variables, localScope));
}
public void delegateTask(String taskId, String userId) {
commandExecutor.execute(new DelegateTaskCmd(taskId, userId));
}
public void resolveTask(String taskId) {
commandExecutor.execute(new ResolveTaskCmd(taskId, null));
}
public void resolveTask(String taskId, Map<String, Object> variables) {
commandExecutor.execute(new ResolveTaskCmd(taskId, variables));
}
public void setPriority(String taskId, int priority) {
commandExecutor.execute(new SetTaskPriorityCmd(taskId, priority) );
}
public void setDueDate(String taskId, Date dueDate) {
commandExecutor.execute(new SetTaskDueDateCmd(taskId, dueDate) );
}
public TaskQuery createTaskQuery() {
return new TaskQueryImpl(commandExecutor, processEngineConfiguration.getDatabaseType());
}
public NativeTaskQuery createNativeTaskQuery() {
return new NativeTaskQueryImpl(commandExecutor);
}
public Map<String, Object> getVariables(String executionId) {
return commandExecutor.execute(new GetTaskVariablesCmd(executionId, null, false));
}
public Map<String, Object> getVariablesLocal(String executionId) {
return commandExecutor.execute(new GetTaskVariablesCmd(executionId, null, true));
}
public Map<String, Object> getVariables(String executionId, Collection<String> variableNames) {
return commandExecutor.execute(new GetTaskVariablesCmd(executionId, variableNames, false));
}
public Map<String, Object> getVariablesLocal(String executionId, Collection<String> variableNames) {
return commandExecutor.execute(new GetTaskVariablesCmd(executionId, variableNames, true));
}
public Object getVariable(String executionId, String variableName) {
return commandExecutor.execute(new GetTaskVariableCmd(executionId, variableName, false));
}
public boolean hasVariable(String taskId, String variableName) {
return commandExecutor.execute(new HasTaskVariableCmd(taskId, variableName, false));
}
public Object getVariableLocal(String executionId, String variableName) {
return commandExecutor.execute(new GetTaskVariableCmd(executionId, variableName, true));
}
public boolean hasVariableLocal(String taskId, String variableName) {
return commandExecutor.execute(new HasTaskVariableCmd(taskId, variableName, true));
}
public void setVariable(String executionId, String variableName, Object value) {
if(variableName == null) {
throw new ActivitiIllegalArgumentException("variableName is null");
}
Map<String, Object> variables = new HashMap<String, Object>();
variables.put(variableName, value);
commandExecutor.execute(new SetTaskVariablesCmd(executionId, variables, false));
}
public void setVariableLocal(String executionId, String variableName, Object value) {
if(variableName == null) {
throw new ActivitiIllegalArgumentException("variableName is null");
}
Map<String, Object> variables = new HashMap<String, Object>();
variables.put(variableName, value);
commandExecutor.execute(new SetTaskVariablesCmd(executionId, variables, true));
}
public void setVariables(String executionId, Map<String, ? extends Object> variables) {
commandExecutor.execute(new SetTaskVariablesCmd(executionId, variables, false));
}
public void setVariablesLocal(String executionId, Map<String, ? extends Object> variables) {
commandExecutor.execute(new SetTaskVariablesCmd(executionId, variables, true));
}
public void removeVariable(String taskId, String variableName) {
Collection<String> variableNames = new ArrayList<String>();
variableNames.add(variableName);
commandExecutor.execute(new RemoveTaskVariablesCmd(taskId, variableNames, false));
}
public void removeVariableLocal(String taskId, String variableName) {
Collection<String> variableNames = new ArrayList<String>(1);
variableNames.add(variableName);
commandExecutor.execute(new RemoveTaskVariablesCmd(taskId, variableNames, true));
}
public void removeVariables(String taskId, Collection<String> variableNames) {
commandExecutor.execute(new RemoveTaskVariablesCmd(taskId, variableNames, false));
}
public void removeVariablesLocal(String taskId, Collection<String> variableNames) {
commandExecutor.execute(new RemoveTaskVariablesCmd(taskId, variableNames, true));
}
public Comment addComment(String taskId, String processInstance, String message) {
return commandExecutor.execute(new AddCommentCmd(taskId, processInstance, message));
}
public Comment addComment(String taskId, String processInstance, String type, String message) {
return commandExecutor.execute(new AddCommentCmd(taskId, processInstance, type, message));
}
@Override
public Comment getComment(String commentId) {
return commandExecutor.execute(new GetCommentCmd(commentId));
}
@Override
public Event getEvent(String eventId) {
return commandExecutor.execute(new GetTaskEventCmd(eventId));
}
public List<Comment> getTaskComments(String taskId) {
return commandExecutor.execute(new GetTaskCommentsCmd(taskId));
}
public List<Comment> getTaskComments(String taskId, String type) {
return commandExecutor.execute(new GetTaskCommentsByTypeCmd(taskId, type));
}
public List<Comment> getCommentsByType(String type) {
return commandExecutor.execute(new GetTypeCommentsCmd(type));
}
public List<Event> getTaskEvents(String taskId) {
return commandExecutor.execute(new GetTaskEventsCmd(taskId));
}
public List<Comment> getProcessInstanceComments(String processInstanceId) {
return commandExecutor.execute(new GetProcessInstanceCommentsCmd(processInstanceId));
}
public List<Comment> getProcessInstanceComments(String processInstanceId, String type) {
return commandExecutor.execute(new GetProcessInstanceCommentsCmd(processInstanceId, type));
}
public Attachment createAttachment(String attachmentType, String taskId, String processInstanceId, String attachmentName, String attachmentDescription, InputStream content) {
return commandExecutor.execute(new CreateAttachmentCmd(attachmentType, taskId, processInstanceId, attachmentName, attachmentDescription, content, null));
}
public Attachment createAttachment(String attachmentType, String taskId, String processInstanceId, String attachmentName, String attachmentDescription, String url) {
return commandExecutor.execute(new CreateAttachmentCmd(attachmentType, taskId, processInstanceId, attachmentName, attachmentDescription, null, url));
}
public InputStream getAttachmentContent(String attachmentId) {
return commandExecutor.execute(new GetAttachmentContentCmd(attachmentId));
}
public void deleteAttachment(String attachmentId) {
commandExecutor.execute(new DeleteAttachmentCmd(attachmentId));
}
public void deleteComments(String taskId, String processInstanceId) {
commandExecutor.execute(new DeleteCommentCmd(taskId, processInstanceId, null));
}
@Override
public void deleteComment(String commentId) {
commandExecutor.execute(new DeleteCommentCmd(null, null, commentId));
}
public Attachment getAttachment(String attachmentId) {
return commandExecutor.execute(new GetAttachmentCmd(attachmentId));
}
public List<Attachment> getTaskAttachments(String taskId) {
return commandExecutor.execute(new GetTaskAttachmentsCmd(taskId));
}
public List<Attachment> getProcessInstanceAttachments(String processInstanceId) {
return commandExecutor.execute(new GetProcessInstanceAttachmentsCmd(processInstanceId));
}
public void saveAttachment(Attachment attachment) {
commandExecutor.execute(new SaveAttachmentCmd(attachment));
}
public List<Task> getSubTasks(String parentTaskId) {
return commandExecutor.execute(new GetSubTasksCmd(parentTaskId));
}
}