-
Notifications
You must be signed in to change notification settings - Fork 188
/
PageCaseWorkItem.java
276 lines (245 loc) · 11.4 KB
/
PageCaseWorkItem.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
/*
* Copyright (c) 2010-2018 Evolveum et al.
*
* 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.cases;
import com.evolveum.midpoint.gui.api.model.LoadableModel;
import com.evolveum.midpoint.gui.api.util.WebModelServiceUtils;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.schema.GetOperationOptionsBuilder;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.WorkItemId;
import com.evolveum.midpoint.security.api.AuthorizationConstants;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.exception.*;
import com.evolveum.midpoint.util.logging.LoggingUtils;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.application.AuthorizationAction;
import com.evolveum.midpoint.web.application.PageDescriptor;
import com.evolveum.midpoint.web.application.Url;
import com.evolveum.midpoint.web.component.AjaxButton;
import com.evolveum.midpoint.web.component.util.VisibleBehaviour;
import com.evolveum.midpoint.web.page.admin.workflow.CaseWorkItemSummaryPanel;
import com.evolveum.midpoint.web.page.admin.workflow.PageAttorneySelection;
import com.evolveum.midpoint.web.page.admin.workflow.PageWorkItems;
import com.evolveum.midpoint.web.page.admin.workflow.WorkItemDetailsPanel;
import com.evolveum.midpoint.web.util.OnePageParameterEncoder;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.wicket.Component;
import org.apache.wicket.RestartResponseException;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.model.Model;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import static com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType.F_OBJECT_REF;
/**
* @author mederly
*/
@PageDescriptor(
urls = {
@Url(mountUrl = "/admin/caseWorkItem", matchUrlForSecurity = "/admin/caseWorkItem")
},
encoder = OnePageParameterEncoder.class,
action = {
@AuthorizationAction(actionUri = PageAdminCaseWorkItems.AUTH_CASE_WORK_ITEMS_ALL,
label = PageAdminCaseWorkItems.AUTH_CASE_WORK_ITEMS_ALL_LABEL,
description = PageAdminCaseWorkItems.AUTH_CASE_WORK_ITEMS_ALL_DESCRIPTION),
@AuthorizationAction(actionUri = AuthorizationConstants.AUTZ_UI_CASE_WORK_ITEM_URL,
label = "PageCaseWorkItem.auth.caseWorkItem.label",
description = "PageCaseWorkItem.auth.caseWorkItem.description")})
public class PageCaseWorkItem extends PageAdminCaseWorkItems {
private static final long serialVersionUID = 1L;
private static final String DOT_CLASS = PageCaseWorkItem.class.getName() + ".";
private static final String OPERATION_LOAD_CASE = DOT_CLASS + "loadCase";
private static final String OPERATION_LOAD_DONOR = DOT_CLASS + "loadPowerDonor";
private static final String OPERATION_SAVE_CASE_WORK_ITEM = DOT_CLASS + "closeCaseWorkItem";
private static final String PARAMETER_CASE_ID = "caseId";
private static final String PARAMETER_CASE_WORK_ITEM_ID = "caseWorkItemId";
private static final Trace LOGGER = TraceManager.getTrace(PageCaseWorkItem.class);
private static final String ID_WORK_ITEM_DETAILS = "workItemDetails";
private static final String ID_SUMMARY_PANEL = "summaryPanel";
private static final String ID_CASE_WORK_ITEM_ACTIONS_PANEL = "caseWorkItemActionsPanel";
private static final String ID_DELTA_PANEL = "deltaPanel";
private static final String ID_MAIN_FORM = "mainForm";
private static final String ID_CASE_WORK_ITEM_FORM = "caseWorkItemForm";
private static final String ID_CASE_NAME = "caseName";
private static final String ID_CASE_DESCRIPTION = "caseDescription";
private static final String ID_CASE_RESOURCE = "caseResource";
private static final String ID_CASE_TARGET = "caseTarget";
private static final String ID_CASE_EVENT = "caseEvent";
private static final String ID_CASE_OUTCOME = "caseOutcome";
private static final String ID_CASE_OPEN_TIMESTAMP = "caseOpenTimestamp";
private static final String ID_CASE_CLOSE_TIMESTAMP = "caseCloseTimestamp";
private static final String ID_CASE_STATE = "caseState";
private static final String ID_CASE_WORK_ITEM_NAME = "caseWorkItemName";
private static final String ID_CASE_WORK_ITEM_ASSIGNEES = "caseWorkItemAssignees";
private static final String ID_CASE_WORK_ITEM_ORIGINAL_ASSIGNEE = "caseWorkItemOriginalAssignee";
private static final String ID_CASE_WORK_ITEM_CLOSE_TIMESTAMP = "caseWorkItemCloseTimestamp";
private static final String ID_CASE_WORK_ITEM_DEADLINE = "caseWorkItemDeadline";
private static final String ID_CASE_WORK_ITEM_OUTCOME = "caseWorkItemOutcome";
private static final String ID_CASE_WORK_ITEM_COMMENT = "caseWorkItemComment";
private static final String ID_CASE_WORK_ITEM_FORM_COMMENT = "caseWorkItemFormComment";
private static final String ID_CASE_WORK_ITEM_FORM_EVIDENCE = "caseWorkItemFormEvidence";
private static final String ID_CASE_WORK_ITEM_EVIDENCE = "caseWorkItemEvidence";
private static final String ID_BACK_BUTTON = "backButton";
private static final String ID_CLOSE_CASE_BUTTON = "closeCaseButton";
private LoadableModel<CaseType> caseModel;
private LoadableModel<CaseWorkItemType> caseWorkItemModel;
private WorkItemId workItemId;
private PageParameters pageParameters;
public PageCaseWorkItem(PageParameters parameters) {
this.pageParameters = parameters;
String caseId = parameters.get(OnePageParameterEncoder.PARAMETER).toString();
if (StringUtils.isEmpty(caseId)) {
throw new IllegalStateException("Case ID not specified.");
}
workItemId = WorkItemId.create(caseId);
if (workItemId == null || StringUtils.isEmpty(workItemId.getCaseOid())) {
throw new IllegalStateException("Case oid not specified.");
}
caseModel = new LoadableModel<CaseType>(false) {
@Override
protected CaseType load() {
return loadCaseIfNecessary();
}
};
caseWorkItemModel = new LoadableModel<CaseWorkItemType>(false) {
@Override
protected CaseWorkItemType load() {
return loadCaseWorkItemIfNecessary();
}
};
// initLayout();
}
@Override
protected void onInitialize(){
super.onInitialize();
initLayout();
}
@Override
protected void createBreadcrumb() {
createInstanceBreadcrumb(); // to preserve page state (e.g. approver's comment)
}
private CaseType loadCaseIfNecessary() {
if (caseModel.isLoaded()) {
return caseModel.getObject();
}
Task task = createSimpleTask(OPERATION_LOAD_CASE);
OperationResult result = task.getResult();
CaseType caseInstance = null;
try {
GetOperationOptionsBuilder optionsBuilder = getOperationOptionsBuilder().item(F_OBJECT_REF).resolve();
PrismObject<CaseType> caseObject = WebModelServiceUtils.loadObject(CaseType.class, workItemId.getCaseOid(), optionsBuilder.build(),
PageCaseWorkItem.this, task, result);
caseInstance = caseObject.asObjectable();
result.recordSuccessIfUnknown();
} catch (RestartResponseException e) {
throw e; // already processed
} catch (NullPointerException ex) {
result.recordFatalError(getString("PageCaseWorkItem.couldNotGetCase"), ex);
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't get case because it does not exist. (It might have been already completed or deleted.)", ex);
} catch (RuntimeException ex) {
result.recordFatalError(getString("PageCaseWorkItem.couldNotGetCase.runtime"), ex);
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't get case.", ex);
}
showResult(result, false);
if (!result.isSuccess()) {
throw redirectBackViaRestartResponseException();
}
return caseInstance;
}
private CaseWorkItemType loadCaseWorkItemIfNecessary() {
if (caseWorkItemModel.isLoaded()) {
return caseWorkItemModel.getObject();
}
try {
List<CaseWorkItemType> caseWorkItemList = caseModel.getObject().getWorkItem();
if (caseWorkItemList == null) {
throw new ObjectNotFoundException("No case work item found for case " + workItemId.getCaseOid() + " with id " + workItemId.getId());
}
for (CaseWorkItemType caseWorkItemType : caseWorkItemList){
if (caseWorkItemType.getId().equals(workItemId.getId())){
return caseWorkItemType;
}
}
} catch (ObjectNotFoundException ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't get case work item because it does not exist. (It might have been already completed or deleted.)", ex);
} catch (NumberFormatException ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't parse case work item id.", ex);
}
return null;
}
private void initLayout(){
CaseWorkItemSummaryPanel summaryPanel = new CaseWorkItemSummaryPanel(ID_SUMMARY_PANEL, caseWorkItemModel);
summaryPanel.setOutputMarkupId(true);
add(summaryPanel);
WorkItemDetailsPanel workItemDetailsPanel = new WorkItemDetailsPanel(ID_WORK_ITEM_DETAILS, caseWorkItemModel);
workItemDetailsPanel.setOutputMarkupId(true);
add(workItemDetailsPanel);
AjaxButton back = new AjaxButton(ID_BACK_BUTTON, createStringResource("pageCase.button.back")) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
cancelPerformed();
}
};
back.setOutputMarkupId(true);
add(back);
CaseWorkItemActionsPanel actionsPanel = new CaseWorkItemActionsPanel(ID_CASE_WORK_ITEM_ACTIONS_PANEL, caseWorkItemModel){
private static final long serialVersionUID = 1L;
@Override
protected AbstractWorkItemOutputType getWorkItemOutput(boolean approved){
return super.getWorkItemOutput(approved)
.comment(workItemDetailsPanel.getApproverComment())
.evidence(workItemDetailsPanel.getWorkItemEvidence());
}
@Override
protected Component getCustomForm(){
return workItemDetailsPanel.getCustomForm();
}
@Override
public PrismObject<UserType> getPowerDonor() {
return PageCaseWorkItem.this.getPowerDonor();
}
};
actionsPanel.setOutputMarkupId(true);
actionsPanel.add(new VisibleBehaviour(() -> caseWorkItemModel.getObject().getCloseTimestamp() == null));
add(actionsPanel);
}
private void cancelPerformed() {
redirectBack();
}
protected PrismObject<UserType> getPowerDonor(){
if (pageParameters != null && pageParameters.get(PageAttorneySelection.PARAMETER_DONOR_OID) != null &&
StringUtils.isNotEmpty(pageParameters.get(PageAttorneySelection.PARAMETER_DONOR_OID).toString())){
String powerDonorOid = pageParameters.get(PageAttorneySelection.PARAMETER_DONOR_OID).toString();
if (StringUtils.isEmpty(powerDonorOid)){
return null;
}
Task task = createSimpleTask(OPERATION_LOAD_DONOR);
OperationResult result = task.getResult();
PrismObject<UserType> donor = WebModelServiceUtils.loadObject(UserType.class, powerDonorOid,
new ArrayList<>(), PageCaseWorkItem.this, task, result);
return donor;
}
return null;
}
}