-
Notifications
You must be signed in to change notification settings - Fork 188
/
TaskTabsVisibility.java
261 lines (219 loc) · 10.7 KB
/
TaskTabsVisibility.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
/*
* Copyright (c) 2010-2019 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/
package com.evolveum.midpoint.web.page.admin.server;
import com.evolveum.midpoint.gui.api.prism.ItemWrapper;
import com.evolveum.midpoint.gui.api.prism.PrismContainerWrapper;
import com.evolveum.midpoint.gui.api.prism.PrismObjectWrapper;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.model.api.ModelPublicConstants;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.statistics.StatisticsUtil;
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import java.io.Serializable;
/**
* Used to determine whether tabs have to be refreshed - by comparing instances of this class before and after task update.
*
* @author mederly
*/
class TaskTabsVisibility implements Serializable {
private static final transient Trace LOGGER = TraceManager.getTrace(TaskTabsVisibility.class);
private boolean basicVisible;
private boolean schedulingVisible;
private boolean workManagementVisible;
private boolean subtasksAndThreadsVisible;
private boolean cleanupPolicyVisible;
private boolean progressVisible;
private boolean environmentalPerformanceVisible;
private boolean internalPerformanceVisible;
private boolean operationVisible;
private boolean resultVisible;
private boolean errorsVisible;
public boolean computeBasicVisible(PageTask parentPage, TaskType task) {
basicVisible = !WebComponentUtil.isWorkflowTask(task);
return basicVisible;
}
public boolean computeSchedulingVisible(PageTask parentPage, TaskType task) {
schedulingVisible = !WebComponentUtil.isWorkflowTask(task);
return schedulingVisible;
}
public boolean computeWorkManagementVisible(){
workManagementVisible = true; //todo when work management should be visible?
return workManagementVisible;
}
public boolean computeCleanupPolicyVisible(){
cleanupPolicyVisible = true; //todo when cleanup policy should be visible?
return cleanupPolicyVisible;
}
public boolean computeSubtasksAndThreadsVisible(PageTask parentPage, PrismObjectWrapper<TaskType> taskWrapper) {
return subtasksAndThreadsVisible = taskWrapper.getObject().findReference(TaskType.F_SUBTASK_REF) != null;
// TODO we want to show subtasks always when subtasks exist. Following should be the behavior for tables on subtasks tab.
// boolean isThreadsReadable = isTaskItemReadable(taskWrapper, ItemPath.create(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_WORKER_THREADS));
// TaskType task = taskWrapper.getObject().asObjectable();
//
// if (parentPage.isEditingFocus()) {
// subtasksAndThreadsVisible = configuresWorkerThreads(task) && isThreadsReadable;
// } else if (!parentPage.isAdd() && !WebComponentUtil.isWorkflowTask(taskWrapper.getObject().asObjectable())) {
// subtasksAndThreadsVisible = configuresWorkerThreads(task) && isThreadsReadable
// || !CollectionUtils.isNotEmpty(task.getSubtaskRef());
// } else {
// subtasksAndThreadsVisible = false;
// }
// return subtasksAndThreadsVisible;
}
public boolean configuresWorkerThreads(TaskType task) {
return WebComponentUtil.isReconciliation(task) || WebComponentUtil.isImport(task) || WebComponentUtil.isRecomputation(task) || isExecuteChanges(task.getHandlerUri())
|| isShadowIntegrityCheck(task.getHandlerUri()) || isFocusValidityScanner(task.getHandlerUri()) || isTriggerScanner(task.getHandlerUri());
}
public boolean computeEnvironmentalPerformanceVisible(PageTask parentPage, PrismObjectWrapper<TaskType> taskWrapper) {
final OperationStatsType operationStats = taskWrapper.getObject().asObjectable().getOperationStats();
environmentalPerformanceVisible = parentPage.isEditingFocus();
return environmentalPerformanceVisible;
}
public boolean computeInternalPerformanceVisible(PageTask parentPage, PrismObjectWrapper<TaskType> taskWrapper) {
internalPerformanceVisible = parentPage.isEditingFocus();
return internalPerformanceVisible;
}
public boolean computeOperationVisible(PageTask parentPage, PrismObjectWrapper<TaskType> taskWrapper) {
PrismContainerWrapper lensContext = null;
try{
lensContext = taskWrapper.findContainer(TaskType.F_MODEL_OPERATION_CONTEXT);
} catch (SchemaException ex){
LOGGER.warn("Unable to find modelOperationContext in task {}", taskWrapper.getObject().asObjectable());
}
operationVisible = parentPage.isEditingFocus()
&& isTaskItemReadable(taskWrapper, TaskType.F_MODEL_OPERATION_CONTEXT)
&& lensContext != null && !lensContext.isEmpty()
&& !WebComponentUtil.isWorkflowTask(taskWrapper.getObject().asObjectable());
return operationVisible;
}
public boolean computeResultVisible(PageTask parentPage, PrismObjectWrapper<TaskType> taskWrapper) {
resultVisible = parentPage.isEditingFocus()
&& isTaskItemReadable(taskWrapper, TaskType.F_RESULT)
&& !WebComponentUtil.isWorkflowTask(taskWrapper.getObject().asObjectable());
return resultVisible;
}
public boolean computeErrorsVisible(PageTask parentPage, TaskType task) {
errorsVisible = parentPage.isEditingFocus()
&& !WebComponentUtil.isWorkflowTask(task);
return errorsVisible;
}
public void computeAll(PageTask parentPage, PrismObjectWrapper<TaskType> taskWrapper) {
computeBasicVisible(parentPage, taskWrapper.getObject().asObjectable());
computeSchedulingVisible(parentPage, taskWrapper.getObject().asObjectable());
computeWorkManagementVisible();
computeCleanupPolicyVisible();
computeSubtasksAndThreadsVisible(parentPage, taskWrapper);
computeProgressVisible(parentPage);
computeEnvironmentalPerformanceVisible(parentPage, taskWrapper);
computeInternalPerformanceVisible(parentPage, taskWrapper);
computeOperationVisible(parentPage, taskWrapper);
computeResultVisible(parentPage, taskWrapper);
computeErrorsVisible(parentPage, taskWrapper.getObject().asObjectable());
}
public boolean computeProgressVisible(PageTask parentPage) {
progressVisible = parentPage.isEditingFocus();
return progressVisible;
}
private boolean isShadowIntegrityCheck(String handlerUri) {
return ModelPublicConstants.SHADOW_INTEGRITY_CHECK_TASK_HANDLER_URI.equals(handlerUri);
}
private boolean isFocusValidityScanner(String handlerUri) {
return ModelPublicConstants.FOCUS_VALIDITY_SCANNER_TASK_HANDLER_URI.equals(handlerUri)
|| ModelPublicConstants.DEPRECATED_FOCUS_VALIDITY_SCANNER_TASK_HANDLER_URI.equals(handlerUri);
}
private boolean isTriggerScanner(String handlerUri) {
return ModelPublicConstants.TRIGGER_SCANNER_TASK_HANDLER_URI.equals(handlerUri);
}
private boolean isExecuteChanges(String handlerUri) {
return ModelPublicConstants.EXECUTE_CHANGES_TASK_HANDLER_URI.equals(handlerUri);
}
private boolean isTaskItemReadable(PrismObjectWrapper<TaskType> taskWrapper, ItemPath itemPath){
ItemWrapper taskProperty = null;
try {
taskProperty = taskWrapper.findProperty(itemPath);
} catch (SchemaException ex){
LOGGER.warn("Unable to find {} property in task object {}, {}", itemPath,
taskWrapper.getObject().asObjectable(), ex.getLocalizedMessage());
}
return taskProperty != null && taskProperty.canRead();
}
public boolean isBasicVisible() {
return basicVisible;
}
public boolean isSchedulingVisible() {
return schedulingVisible;
}
public boolean isWorkManagementVisible() {
return workManagementVisible;
}
public boolean isCleanupPolicyVisible() {
return cleanupPolicyVisible;
}
public boolean isSubtasksAndThreadsVisible() {
return subtasksAndThreadsVisible;
}
public boolean isProgressVisible() {
return progressVisible;
}
public boolean isEnvironmentalPerformanceVisible() {
return environmentalPerformanceVisible;
}
public boolean isInternalPerformanceVisible() {
return internalPerformanceVisible;
}
public boolean isOperationVisible() {
return operationVisible;
}
public boolean isResultVisible() {
return resultVisible;
}
public boolean isErrorsVisible() {
return errorsVisible;
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
TaskTabsVisibility that = (TaskTabsVisibility) o;
if (basicVisible != that.basicVisible)
return false;
if (schedulingVisible != that.schedulingVisible)
return false;
if (subtasksAndThreadsVisible != that.subtasksAndThreadsVisible)
return false;
if (progressVisible != that.progressVisible)
return false;
if (environmentalPerformanceVisible != that.environmentalPerformanceVisible)
return false;
if (operationVisible != that.operationVisible)
return false;
if (errorsVisible != that.errorsVisible)
return false;
return resultVisible == that.resultVisible;
}
@Override
public int hashCode() {
int result = (basicVisible ? 1 : 0);
result = 31 * result + (schedulingVisible ? 1 : 0);
result = 31 * result + (subtasksAndThreadsVisible ? 1 : 0);
result = 31 * result + (progressVisible ? 1 : 0);
result = 31 * result + (environmentalPerformanceVisible ? 1 : 0);
result = 31 * result + (operationVisible ? 1 : 0);
result = 31 * result + (resultVisible ? 1 : 0);
result = 31 * result + (errorsVisible ? 1 : 0);
return result;
}
}