forked from kiegroup/jbpm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TaskImpl.java
457 lines (369 loc) · 13.7 KB
/
TaskImpl.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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
/*
* Copyright 2017 Red Hat, Inc. and/or its affiliates.
*
* 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.jbpm.services.task.impl.model;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.Version;
import org.jbpm.services.task.utils.CollectionUtils;
import org.kie.api.task.model.I18NText;
import org.kie.api.task.model.PeopleAssignments;
import org.kie.api.task.model.TaskData;
import org.kie.internal.task.api.model.Deadlines;
import org.kie.internal.task.api.model.Delegation;
import org.kie.internal.task.api.model.InternalTask;
import org.kie.internal.task.api.model.SubTasksStrategy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Entity
@Table(name="Task",
indexes = {@Index(name = "IDX_Task_Initiator", columnList="taskInitiator_id"),
@Index(name = "IDX_Task_ActualOwner", columnList="actualOwner_id"),
@Index(name = "IDX_Task_CreatedBy", columnList="createdBy_id"),
@Index(name = "IDX_Task_processInstanceId", columnList="processInstanceId"),
@Index(name = "IDX_Task_processId", columnList="processId"),
@Index(name = "IDX_Task_status", columnList="status"),
@Index(name = "IDX_Task_archived", columnList="archived"),
@Index(name = "IDX_Task_workItemId", columnList="workItemId")})
@SequenceGenerator(name="taskIdSeq", sequenceName="TASK_ID_SEQ", allocationSize=1)
public class TaskImpl implements InternalTask {
/**
* WSHT uses a name for the unique identifier, for now we use a generated ID which is also the key, which can be
* mapped to the name or a unique name field added later.
*/
private static final Logger logger = LoggerFactory.getLogger(TaskImpl.class);
@Transient
private static final int TASK_DESCRIPTION_LENGTH = Integer.parseInt(System.getProperty("org.jbpm.ht.task.description.length", "255"));
@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator="taskIdSeq")
@Column(name = "id")
private Long id = 0L;
@Version
@Column(name = "OPTLOCK")
private int version;
/**
* While WSHT says this is an expression, it always resolves to an integer, so resolve before setting
* default value is 0.
*/
private int priority;
private String name;
private String subject;
private String description;
@OneToMany(cascade = CascadeType.ALL, targetEntity=I18NTextImpl.class)
@JoinColumn(name = "Task_Names_Id", nullable = true)
private List<I18NText> names = Collections.emptyList();
@OneToMany(cascade = CascadeType.ALL, targetEntity=I18NTextImpl.class)
@JoinColumn(name = "Task_Subjects_Id", nullable = true)
private List<I18NText> subjects = Collections.emptyList();
@OneToMany(cascade = CascadeType.ALL, targetEntity=I18NTextImpl.class)
@JoinColumn(name = "Task_Descriptions_Id", nullable = true)
private List<I18NText> descriptions = Collections.emptyList();
@Embedded
private PeopleAssignmentsImpl peopleAssignments;
@Embedded
private DelegationImpl delegation;
@Embedded
private TaskDataImpl taskData;
@Embedded
private DeadlinesImpl deadlines;
@Enumerated(EnumType.STRING)
// Default Behaviour
private SubTasksStrategy subTaskStrategy = SubTasksStrategy.NoAction;
private String taskType;
private String formName;
@Basic
private Short archived = 0;
public TaskImpl() {
}
public void writeExternal(ObjectOutput out) throws IOException {
out.writeLong( id );
out.writeInt( priority );
out.writeShort( archived );
if (taskType != null) {
out.writeUTF(taskType);
} else {
out.writeUTF("");
}
if (formName != null) {
out.writeUTF(formName);
} else {
out.writeUTF("");
}
if (name != null) {
out.writeUTF(name);
} else {
out.writeUTF("");
}
if (subject != null) {
out.writeUTF(subject);
} else {
out.writeUTF("");
}
if (description != null) {
out.writeUTF(description);
} else {
out.writeUTF("");
}
CollectionUtils.writeI18NTextList( names, out );
CollectionUtils.writeI18NTextList( subjects, out );
CollectionUtils.writeI18NTextList( descriptions, out );
if (subTaskStrategy != null) {
out.writeBoolean(true);
out.writeUTF(subTaskStrategy.toString());
} else {
out.writeBoolean(false);
}
if ( peopleAssignments != null ) {
out.writeBoolean( true );
peopleAssignments.writeExternal( out );
} else {
out.writeBoolean( false );
}
if ( delegation != null ) {
out.writeBoolean( true );
delegation.writeExternal( out );
} else {
out.writeBoolean( false );
}
if ( taskData != null ) {
out.writeBoolean( true );
taskData.writeExternal( out );
} else {
out.writeBoolean( false );
}
if ( deadlines != null ) {
out.writeBoolean( true );
deadlines.writeExternal( out );
} else {
out.writeBoolean( false );
}
}
public void readExternal(ObjectInput in) throws IOException,
ClassNotFoundException {
id = in.readLong();
priority = in.readInt();
archived = in.readShort();
taskType = in.readUTF();
formName = in.readUTF();
name = in.readUTF();
subject = in.readUTF();
description = in.readUTF();
names = CollectionUtils.readI18NTextList( in );
subjects = CollectionUtils.readI18NTextList( in );
descriptions = CollectionUtils.readI18NTextList( in );
if (in.readBoolean()) {
subTaskStrategy = SubTasksStrategy.valueOf(in.readUTF());
}
if ( in.readBoolean() ) {
peopleAssignments = new PeopleAssignmentsImpl();
peopleAssignments.readExternal( in );
}
if ( in.readBoolean() ) {
delegation = new DelegationImpl();
delegation.readExternal( in );
}
if ( in.readBoolean() ) {
taskData = new TaskDataImpl();
taskData.readExternal( in );
}
if ( in.readBoolean() ) {
deadlines = new DeadlinesImpl();
deadlines.readExternal( in );
}
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Boolean isArchived() {
if (archived == null) {
return null;
}
return (archived == 1) ? Boolean.TRUE : Boolean.FALSE;
}
public void setArchived(Boolean archived) {
if (archived == null) {
this.archived = null;
} else {
this.archived = (archived == true) ? new Short("1") : new Short("0");
}
}
public Integer getVersion() {
return this.version;
}
public Integer getPriority() {
return priority;
}
public void setPriority(Integer priority) {
this.priority = priority;
}
public List<I18NText> getNames() {
return names;
}
public void setNames(List<I18NText> names) {
this.names = names;
}
public List<I18NText> getSubjects() {
return subjects;
}
public void setSubjects(List<I18NText> subjects) {
this.subjects = subjects;
}
public List<I18NText> getDescriptions() {
return descriptions;
}
public void setDescriptions(List<I18NText> descriptions) {
this.descriptions = descriptions;
}
public PeopleAssignments getPeopleAssignments() {
return peopleAssignments;
}
public void setPeopleAssignments(PeopleAssignments peopleAssignments) {
this.peopleAssignments = (PeopleAssignmentsImpl) peopleAssignments;
}
public Delegation getDelegation() {
return delegation;
}
public void setDelegation(Delegation delegation) {
this.delegation = (DelegationImpl) delegation;
}
public TaskData getTaskData() {
return taskData;
}
public void setTaskData(TaskData taskData) {
this.taskData = (TaskDataImpl) taskData;
}
public Deadlines getDeadlines() {
return deadlines;
}
public void setDeadlines(Deadlines deadlines) {
this.deadlines = (DeadlinesImpl) deadlines;
}
public String getTaskType() {
return taskType;
}
public void setTaskType(String taskType) {
this.taskType = taskType;
}
public String getFormName() {
return formName;
}
public void setFormName(String formName) {
this.formName = formName;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + version;
result = prime * result + priority;
result = prime * result + archived.hashCode();
result = prime * result + ((taskType == null) ? 0 : taskType.hashCode());
result = prime * result + CollectionUtils.hashCode( descriptions );
result = prime * result + CollectionUtils.hashCode( names );
result = prime * result + CollectionUtils.hashCode( subjects );
result = prime * result + ((peopleAssignments == null) ? 0 : peopleAssignments.hashCode());
result = prime * result + ((delegation == null) ? 0 : delegation.hashCode());
result = prime * result + ((taskData == null) ? 0 : taskData.hashCode());
result = prime * result + ((deadlines == null) ? 0 : deadlines.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if ( this == obj ) return true;
if ( obj == null ) return false;
if ( !(obj instanceof TaskImpl) ) return false;
TaskImpl other = (TaskImpl) obj;
if ( this.version != other.version ) {
return false;
}
if (!Objects.equals(this.archived, other.archived)) {
return false;
}
if (taskType == null) {
if (other.taskType != null) return false;
} else if (!taskType.equals(other.taskType)) return false;
if ( deadlines == null ) {
if ( other.deadlines != null ) {
}
} else if ( !deadlines.equals( other.deadlines ) ) return false;
if ( delegation == null ) {
if ( other.delegation != null ) return false;
} else if ( !delegation.equals( other.delegation ) ) return false;
if ( peopleAssignments == null ) {
if ( other.peopleAssignments != null ) return false;
} else if ( !peopleAssignments.equals( other.peopleAssignments ) ) return false;
if ( priority != other.priority ) return false;
if ( taskData == null ) {
if ( other.taskData != null ) return false;
} else if ( !taskData.equals( other.taskData ) ) return false;
return ( CollectionUtils.equals( descriptions, other.descriptions ) && CollectionUtils.equals( names, other.names )
&& CollectionUtils.equals( subjects, other.subjects ));
}
public SubTasksStrategy getSubTaskStrategy() {
return subTaskStrategy;
}
public void setSubTaskStrategy(SubTasksStrategy subTaskStrategy) {
this.subTaskStrategy = subTaskStrategy;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
if (description != null && description.length() > TASK_DESCRIPTION_LENGTH) {
description = description.substring(0, TASK_DESCRIPTION_LENGTH);
logger.warn("Task Description content was trimmed as it was too long (more than {} characters)", TASK_DESCRIPTION_LENGTH);
}
this.description = description;
}
@Override
public String toString() {
return "TaskImpl [id=" + id + ", name=" + name + "]";
}
}