/
WorkItemDto.java
323 lines (276 loc) · 11.2 KB
/
WorkItemDto.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
/*
* Copyright (c) 2010-2013 Evolveum
*
* 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 com.evolveum.midpoint.web.page.admin.workflow.dto;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.model.api.ModelInteractionService;
import com.evolveum.midpoint.model.api.visualizer.Scene;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.prism.xml.XmlTypeConverter;
import com.evolveum.midpoint.schema.ObjectTreeDeltas;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.WfContextUtil;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.web.component.DateLabelComponent;
import com.evolveum.midpoint.web.component.prism.show.SceneDto;
import com.evolveum.midpoint.web.component.prism.show.SceneUtil;
import com.evolveum.midpoint.web.component.util.Selectable;
import com.evolveum.midpoint.web.page.admin.server.dto.TaskChangesDto;
import com.evolveum.midpoint.web.page.admin.server.dto.TaskDto;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.Nullable;
import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.List;
import java.util.Date;
/**
* @author lazyman
* @author mederly
*/
public class WorkItemDto extends Selectable {
public static final String F_WORK_ITEM = "workItem";
public static final String F_NAME = "name";
public static final String F_CREATED_FORMATTED = "createdFormatted";
public static final String F_CREATED_FORMATTED_FULL = "createdFormattedFull";
public static final String F_STARTED_FORMATTED_FULL = "startedFormattedFull";
public static final String F_ASSIGNEE_OR_CANDIDATES = "assigneeOrCandidates";
public static final String F_ASSIGNEE = "assignee";
public static final String F_CANDIDATES = "candidates";
public static final String F_STAGE_INFO = "stageInfo";
public static final String F_APPROVER_INSTRUCTION = "approverInstruction";
public static final String F_OTHER_WORK_ITEMS = "otherWorkItems";
public static final String F_RELATED_WORKFLOW_REQUESTS = "relatedWorkflowRequests";
public static final String F_OBJECT_NAME = "objectName";
public static final String F_TARGET_NAME = "targetName";
public static final String F_REQUESTER_NAME = "requesterName";
public static final String F_REQUESTER_FULL_NAME = "requesterFullName";
public static final String F_APPROVER_COMMENT = "approverComment";
public static final String F_WORKFLOW_CONTEXT = "workflowContext"; // use with care
@Deprecated public static final String F_DELTAS = "deltas";
public static final String F_PROCESS_INSTANCE_ID = "processInstanceId";
public static final String F_CHANGES = "changes";
// workItem may or may not contain resolved taskRef;
// and this task may or may not contain filled-in workflowContext -> and then requesterRef object
//
// Depending on expected use (work item list vs. work item details)
protected WorkItemType workItem;
protected TaskType taskType;
protected List<TaskType> relatedTasks;
@Deprecated protected SceneDto deltas;
protected TaskChangesDto changes;
protected String approverComment;
public WorkItemDto(WorkItemType workItem) {
this(workItem, null, null);
}
public WorkItemDto(WorkItemType workItem, TaskType taskType, List<TaskType> relatedTasks) {
this.workItem = workItem;
this.taskType = taskType;
this.relatedTasks = relatedTasks;
}
public void prepareDeltaVisualization(String sceneNameKey, PrismContext prismContext,
ModelInteractionService modelInteractionService, Task opTask, OperationResult result) throws SchemaException {
TaskType task = getTaskType();
if (task == null || task.getWorkflowContext() == null) {
return;
}
if (!(task.getWorkflowContext().getProcessorSpecificState() instanceof WfPrimaryChangeProcessorStateType)) {
return;
}
WfPrimaryChangeProcessorStateType state = (WfPrimaryChangeProcessorStateType) task.getWorkflowContext().getProcessorSpecificState();
Scene deltasScene = SceneUtil.visualizeObjectTreeDeltas(state.getDeltasToProcess(), sceneNameKey, prismContext, modelInteractionService, opTask, result);
deltas = new SceneDto(deltasScene);
ObjectTreeDeltas deltas = ObjectTreeDeltas.fromObjectTreeDeltasType(state.getDeltasToProcess(), prismContext);
changes = TaskDto.createChangesToBeApproved(deltas, modelInteractionService,
prismContext, opTask, result);
}
@Nullable
protected TaskType getTaskType() {
if (taskType == null) {
taskType = WebComponentUtil.getObjectFromReference(workItem.getTaskRef(), TaskType.class);
}
return taskType;
}
public String getWorkItemId() {
return workItem.getWorkItemId();
}
public String getName() {
return workItem.getName();
}
public String getCreatedFormatted() {
return WebComponentUtil.getLocalizedDate(workItem.getWorkItemCreatedTimestamp(), DateLabelComponent.MEDIUM_MEDIUM_STYLE);
}
public String getCreatedFormattedFull() {
return WebComponentUtil.getLocalizedDate(workItem.getWorkItemCreatedTimestamp(), DateLabelComponent.FULL_MEDIUM_STYLE);
}
public Date getCreatedDate() {
return XmlTypeConverter.toDate(workItem.getWorkItemCreatedTimestamp());
}
public Date getStartedDate() {
return XmlTypeConverter.toDate(workItem.getProcessStartedTimestamp());
}
public String getStartedFormattedFull() {
return WebComponentUtil.getLocalizedDate(workItem.getProcessStartedTimestamp(), DateLabelComponent.FULL_MEDIUM_STYLE);
}
public String getAssigneeOrCandidates() {
String assignee = getAssignee();
if (assignee != null) {
return assignee;
} else {
return getCandidates();
}
}
public String getAssignee() {
return WebComponentUtil.getName(workItem.getAssigneeRef());
}
public String getCandidates() {
StringBuilder sb = new StringBuilder();
boolean first = true;
for (ObjectReferenceType roleRef : workItem.getCandidateRolesRef()) {
if (!first) {
sb.append(", ");
} else {
first = false;
}
sb.append(WebComponentUtil.getName(roleRef));
if (RoleType.COMPLEX_TYPE.equals(roleRef.getType())) {
sb.append(" (role)");
} else if (OrgType.COMPLEX_TYPE.equals(roleRef.getType())) {
sb.append(" (org)");
}
}
for (ObjectReferenceType userRef : workItem.getCandidateUsersRef()) {
if (!first) {
sb.append(", ");
} else {
first = false;
}
sb.append(WebComponentUtil.getName(userRef));
sb.append(" (user)");
}
return sb.toString();
}
public String getObjectName() {
return WebComponentUtil.getName(workItem.getObjectRef());
}
public ObjectReferenceType getObjectRef() {
return workItem.getObjectRef();
}
public ObjectReferenceType getTargetRef() {
return workItem.getTargetRef();
}
public String getTargetName() {
return WebComponentUtil.getName(workItem.getTargetRef());
}
public WfContextType getWorkflowContext() {
TaskType task = getTaskType();
if (task == null || task.getWorkflowContext() == null) {
return null;
} else {
return task.getWorkflowContext();
}
}
public String getRequesterName() {
WfContextType workflowContext = getWorkflowContext();
return workflowContext != null ? WebComponentUtil.getName(workflowContext.getRequesterRef()) : null;
}
public String getRequesterFullName() {
UserType requester = getRequester();
return requester != null ? PolyString.getOrig(requester.getFullName()) : null;
}
public UserType getRequester() {
WfContextType wfContext = getWorkflowContext();
if (wfContext == null) {
return null;
}
return WebComponentUtil.getObjectFromReference(wfContext.getRequesterRef(), UserType.class);
}
public String getApproverComment() {
return approverComment;
}
public void setApproverComment(String approverComment) {
this.approverComment = approverComment;
}
public WorkItemType getWorkItem() {
return workItem;
}
@Deprecated
public SceneDto getDeltas() {
return deltas;
}
public QName getTargetType() {
return workItem.getTargetRef() != null ? workItem.getTargetRef().getType() : null;
}
public QName getObjectType() {
return workItem.getObjectRef() != null ? workItem.getObjectRef().getType() : null;
}
// all except the current one
public List<WorkItemDto> getOtherWorkItems() {
final List<WorkItemDto> rv = new ArrayList<>();
final TaskType task = getTaskType();
if (task == null || task.getWorkflowContext() == null) {
return rv;
}
for (WorkItemType workItemType : task.getWorkflowContext().getWorkItem()) {
if (workItemType.getWorkItemId() == null || workItemType.getWorkItemId().equals(getWorkItemId())) {
continue;
}
rv.add(new WorkItemDto(workItemType));
}
return rv;
}
// all excluding the current task
public List<ProcessInstanceDto> getRelatedWorkflowRequests() {
final List<ProcessInstanceDto> rv = new ArrayList<>();
if (relatedTasks == null) {
return rv;
}
for (TaskType task : relatedTasks) {
if (task.getWorkflowContext() == null || task.getWorkflowContext().getProcessInstanceId() == null) {
continue;
}
if (StringUtils.equals(getProcessInstanceId(), task.getWorkflowContext().getProcessInstanceId())) {
continue;
}
rv.add(new ProcessInstanceDto(task));
}
return rv;
}
public String getProcessInstanceId() {
final TaskType task = getTaskType();
return task != null && task.getWorkflowContext() != null ? task.getWorkflowContext().getProcessInstanceId() : null;
}
public String getTaskOid() {
final TaskType task = getTaskType();
return task != null ? task.getOid() : null;
}
public boolean hasHistory() {
WfContextType wfc = getWorkflowContext();
if (wfc == null || !(wfc.getProcessSpecificState() instanceof ItemApprovalProcessStateType)) {
return false;
}
ItemApprovalProcessStateType instanceState = (ItemApprovalProcessStateType) wfc.getProcessSpecificState();
return CollectionUtils.isNotEmpty(instanceState.getDecisions());
}
public String getStageInfo() {
return WfContextUtil.getStageInfo(getWorkflowContext());
}
public String getApproverInstruction() {
return workItem.getApproverInstruction();
}
}