-
Notifications
You must be signed in to change notification settings - Fork 188
/
PageReport.java
424 lines (360 loc) · 17.9 KB
/
PageReport.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
/*
* Copyright (c) 2010-2015 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.reports;
import java.util.*;
import com.evolveum.midpoint.gui.api.component.tabs.PanelTab;
import com.evolveum.midpoint.gui.api.factory.wrapper.PrismObjectWrapperFactory;
import com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext;
import com.evolveum.midpoint.gui.api.page.PageBase;
import com.evolveum.midpoint.gui.api.prism.wrapper.*;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.prism.ItemDefinition;
import com.evolveum.midpoint.prism.PrismContainer;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.path.ItemName;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.schema.ObjectDeltaOperation;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.DisplayableValue;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.web.component.AjaxButton;
import com.evolveum.midpoint.web.component.ObjectSummaryPanel;
import com.evolveum.midpoint.web.component.TabbedPanel;
import com.evolveum.midpoint.web.component.input.DropDownChoicePanel;
import com.evolveum.midpoint.web.component.prism.ValueStatus;
import com.evolveum.midpoint.web.component.search.SearchValue;
import com.evolveum.midpoint.web.component.util.VisibleBehaviour;
import com.evolveum.midpoint.web.page.admin.PageAdminObjectDetails;
import com.evolveum.midpoint.web.page.admin.reports.component.*;
import com.evolveum.midpoint.web.page.admin.server.TaskBasicTabPanel;
import com.evolveum.midpoint.web.util.OnePageParameterEncoder;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import org.apache.wicket.Component;
import org.apache.wicket.Page;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.repeater.RepeatingView;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.StringResourceModel;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.security.api.AuthorizationConstants;
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.page.admin.configuration.PageAdminConfiguration;
/**
* @author lazyman
*/
@PageDescriptor(url = "/admin/report", encoder = OnePageParameterEncoder.class, action = {
@AuthorizationAction(actionUri = AuthorizationConstants.AUTZ_UI_REPORTS_ALL_URL,
label = PageAdminConfiguration.AUTH_CONFIGURATION_ALL_LABEL,
description = PageAdminConfiguration.AUTH_CONFIGURATION_ALL_DESCRIPTION),
@AuthorizationAction(actionUri = AuthorizationConstants.AUTZ_UI_REPORT_URL,
label = "PageReport.auth.report.label",
description = "PageReport.auth.report.description") })
public class PageReport extends PageAdminObjectDetails<ReportType> {
private static final Trace LOGGER = TraceManager.getTrace(PageReport.class);
private static final String ID_TABLE_CONTAINER = "tableContainer";
private static final String ID_TABLE_BOX = "tableBox";
private static final String ID_REPORT_TABLE = "reportTable";
private static final List<DisplayableValue<String>> TYPE_OF_REPORTS;
private static final String DOT_CLASS = PageReports.class.getName() + ".";
private static final String OPERATION_UPDATE_WRAPPER = DOT_CLASS + "updateReportWrapper";
private static final String OPERATION_RUN_REPORT = DOT_CLASS + "runReport";
private static final String OPERATION_IMPORT_REPORT = DOT_CLASS + "importReport";
static {
TYPE_OF_REPORTS = Arrays.asList(
new SearchValue<>(SystemObjectsType.ARCHETYPE_COLLECTION_REPORT.value(), "CollectionReports.title"),
new SearchValue<>(SystemObjectsType.ARCHETYPE_DASHBOARD_REPORT.value(), "DashboardReports.title"));
}
private Boolean runReport = false;
private IModel<Boolean> isShowingPreview = Model.of(Boolean.FALSE);
public PageReport() {
initialize(null);
}
public PageReport(PageParameters parameters) {
getPageParameters().overwriteWith(parameters);
initialize(null);
}
public PageReport(final PrismObject<ReportType> userToEdit) {
initialize(userToEdit);
}
public PageReport(final PrismObject<ReportType> unitToEdit, boolean isNewObject) {
initialize(unitToEdit, isNewObject);
}
public PageReport(final PrismObject<ReportType> unitToEdit, boolean isNewObject, boolean isReadonly) {
initialize(unitToEdit, isNewObject, isReadonly);
}
@Override
protected void initLayout() {
super.initLayout();
WebMarkupContainer tableContainer = new WebMarkupContainer(ID_TABLE_CONTAINER);
tableContainer.setOutputMarkupId(true);
add(tableContainer);
ReportObjectsListPanel reportTable = new ReportObjectsListPanel(ID_REPORT_TABLE, Model.of(getReport()));
reportTable.setOutputMarkupId(true);
WebMarkupContainer tableBox = new WebMarkupContainer(ID_TABLE_BOX);
tableBox.add(new VisibleBehaviour(() -> isShowingPreview.getObject() && reportTable.hasView()));
tableBox.setOutputMarkupId(true);
tableContainer.add(tableBox);
tableBox.add(reportTable);
}
@Override
public Class<ReportType> getCompileTimeClass() {
return ReportType.class;
}
@Override
protected ReportType createNewObject() {
return new ReportType(getPrismContext());
}
@Override
protected ObjectSummaryPanel<ReportType> createSummaryPanel(IModel<ReportType> summaryModel) {
return new ReportSummaryPanel(ID_SUMMARY_PANEL, summaryModel, this);
}
@Override
protected Class<? extends Page> getRestartResponsePage() {
return PageReport.class;
}
@Override
public void continueEditing(AjaxRequestTarget target) {
}
@Override
public void finishProcessing(AjaxRequestTarget target, Collection<ObjectDeltaOperation<? extends ObjectType>> executedDeltas, boolean returningFromAsync, OperationResult result) {
if (runReport && !result.isError()) {
showResult(result);
Task task = createSimpleTask("run_task");
PrismObject<ReportType> report;
if (getObjectModel().getObject().getOid() != null) {
report = getObjectModel().getObject().getObject();
} else {
report = (PrismObject<ReportType>) executedDeltas.iterator().next().getObjectDelta().getObjectToAdd();
}
if (hasParameters(report.asObjectable())) {
try {
getReportManager().runReport(report, null, task, result);
} catch (Exception ex) {
result.recordFatalError(ex);
} finally {
result.computeStatusIfUnknown();
}
showResult(result);
if (!isKeepDisplayingResults()) {
redirectBack();
} else {
target.add(getFeedbackPanel());
}
} else {
RunReportPopupPanel runReportPopupPanel = new RunReportPopupPanel(getMainPopupBodyId(), report.asObjectable()) {
private static final long serialVersionUID = 1L;
protected void runConfirmPerformed(AjaxRequestTarget target, ReportType reportType, PrismContainer<ReportParameterType> reportParam) {
try {
getReportManager().runReport(reportType.asPrismObject(), reportParam, task, result);
} catch (Exception ex) {
result.recordFatalError(ex);
} finally {
result.computeStatusIfUnknown();
}
hideMainPopup(target);
showResult(result);
if (!isKeepDisplayingResults()) {
redirectBack();
} else {
target.add(getFeedbackPanel());
}
}
};
showMainPopup(runReportPopupPanel, target);
}
this.runReport = false;
} else if (!isKeepDisplayingResults()) {
showResult(result);
redirectBack();
}
}
private static boolean hasParameters(ReportType report) {
return report.getObjectCollection() == null || report.getObjectCollection().getParameter().isEmpty();
}
@Override
protected ReportMainPanel createMainPanel(String id) {
return new ReportMainPanel(id, getObjectModel(), this);
}
public void saveAndRunPerformed(AjaxRequestTarget target) {
this.runReport = true;
savePerformed(target);
}
protected boolean isChangeArchetypeAllowed() {
return false;
}
@Override
protected void initOperationalButtons(RepeatingView repeatingView) {
String refreshId = repeatingView.newChildId();
String showPreviewId = repeatingView.newChildId();
String showPreviewInPopupId = repeatingView.newChildId();
AjaxButton refresh = new AjaxButton(refreshId, createStringResource("pageCreateCollectionReport.button.refresh")) {
@Override
public void onClick(AjaxRequestTarget target) {
ReportObjectsListPanel table = getReportTable();
table.getPageStorage().setSearch(null);
table.resetSearchModel();
table.resetTable(target);
table.refreshTable(target);
table.checkView();
target.add(table);
target.add(getTableBox());
target.add(getTableContainer());
target.add(getFeedbackPanel());
}
};
refresh.add(new VisibleBehaviour(() -> isShowingPreview.getObject()));
refresh.add(AttributeAppender.append("class", "btn-info btn-sm"));
refresh.setOutputMarkupId(true);
repeatingView.add(refresh);
AjaxButton showPreview = new AjaxButton(showPreviewId, createStringResource("pageCreateCollectionReport.button.showPreview.${}", isShowingPreview)) {
@Override
public void onClick(AjaxRequestTarget target) {
isShowingPreview.setObject(!isShowingPreview.getObject());
ReportObjectsListPanel table = getReportTable();
if (isShowingPreview.getObject()) {
table.getPageStorage().setSearch(null);
table.resetSearchModel();
table.resetTable(target);
table.refreshTable(target);
table.checkView();
}
target.add(getTableBox());
if (isShowingPreview.getObject() && table.hasView()) {
info(createStringResource("PageReport.message.shownedReportPreview").getString());
}
target.add(getTableContainer());
target.add(this);
target.add(repeatingView.get(showPreviewInPopupId));
target.add(repeatingView.get(refreshId));
target.add(getOperationalButtonsPanel());
target.add(getFeedbackPanel());
}
};
showPreview.add(new VisibleBehaviour(() -> isCollectionReport()));
showPreview.add(AttributeAppender.append("class", "btn-default btn-sm"));
showPreview.setOutputMarkupId(true);
repeatingView.add(showPreview);
AjaxButton showPreviewInPopup = new AjaxButton(showPreviewInPopupId, createStringResource("pageCreateCollectionReport.button.showPreviewInPopup")) {
@Override
public void onClick(AjaxRequestTarget target) {
RunReportPopupPanel reportPopup = new RunReportPopupPanel(getMainPopupBodyId(), getReport(), false) {
@Override
public StringResourceModel getTitle() {
return createStringResource("PageReport.reportPreview");
}
};
showMainPopup(reportPopup, target);
target.add(getOperationalButtonsPanel());
}
};
showPreviewInPopup.add(new VisibleBehaviour(() -> isCollectionReport() && !isShowingPreview.getObject()));
showPreviewInPopup.add(AttributeAppender.append("class", "btn-default btn-sm"));
showPreviewInPopup.setOutputMarkupId(true);
repeatingView.add(showPreviewInPopup);
AjaxButton runReport = new AjaxButton(repeatingView.newChildId(), createStringResource("pageCreateCollectionReport.button.runOriginalReport")) {
@Override
public void onClick(AjaxRequestTarget target) {
runReportPerformed(target, getOriginalReport(), PageReport.this);
}
};
runReport.add(new VisibleBehaviour(() -> isEditingFocus() && !WebComponentUtil.isImportReport(getOriginalReport())));
runReport.add(AttributeAppender.append("class", "btn-info btn-sm"));
runReport.setOutputMarkupId(true);
repeatingView.add(runReport);
AjaxButton importReport = new AjaxButton(repeatingView.newChildId(), createStringResource("pageCreateCollectionReport.button.importOriginalReport")) {
@Override
public void onClick(AjaxRequestTarget target) {
importReportPerformed(target, getOriginalReport(), PageReport.this);
}
};
importReport.add(new VisibleBehaviour(() -> isEditingFocus() && WebComponentUtil.isImportReport(getOriginalReport())));
importReport.add(AttributeAppender.append("class", "btn-info btn-sm"));
importReport.setOutputMarkupId(true);
repeatingView.add(importReport);
}
private ReportType getOriginalReport() {
return getObjectWrapper().getObjectOld().asObjectable();
}
public static void importReportPerformed(AjaxRequestTarget target, ReportType report, PageBase pageBase) {
ImportReportPopupPanel importReportPopupPanel = new ImportReportPopupPanel(pageBase.getMainPopupBodyId(), report) {
private static final long serialVersionUID = 1L;
protected void importConfirmPerformed(AjaxRequestTarget target, ReportDataType reportImportData) {
PageReport.importConfirmPerformed(target, report, reportImportData, pageBase);
pageBase.hideMainPopup(target);
}
};
pageBase.showMainPopup(importReportPopupPanel, target);
}
private static void importConfirmPerformed(AjaxRequestTarget target, ReportType reportType, ReportDataType reportImportData, PageBase pageBase) {
OperationResult result = new OperationResult(OPERATION_IMPORT_REPORT);
Task task = pageBase.createSimpleTask(OPERATION_IMPORT_REPORT);
try {
pageBase.getReportManager().importReport(reportType.asPrismObject(), reportImportData.asPrismObject(), task, result);
} catch (Exception ex) {
result.recordFatalError(ex);
} finally {
result.computeStatusIfUnknown();
}
pageBase.showResult(result);
target.add(pageBase.getFeedbackPanel());
}
public static void runReportPerformed(AjaxRequestTarget target, ReportType report, PageBase pageBase) {
if (hasParameters(report)) {
runConfirmPerformed(target, report, null, pageBase);
return;
}
RunReportPopupPanel runReportPopupPanel = new RunReportPopupPanel(pageBase.getMainPopupBodyId(), report) {
private static final long serialVersionUID = 1L;
protected void runConfirmPerformed(AjaxRequestTarget target, ReportType reportType, PrismContainer<ReportParameterType> reportParam) {
PageReport.runConfirmPerformed(target, reportType, reportParam, pageBase);
pageBase.hideMainPopup(target);
}
};
pageBase.showMainPopup(runReportPopupPanel, target);
}
private static void runConfirmPerformed(AjaxRequestTarget target, ReportType reportType, PrismContainer<ReportParameterType> reportParam, PageBase pageBase) {
OperationResult result = new OperationResult(OPERATION_RUN_REPORT);
Task task = pageBase.createSimpleTask(OPERATION_RUN_REPORT);
try {
pageBase.getReportManager().runReport(reportType.asPrismObject(), reportParam, task, result);
} catch (Exception ex) {
result.recordFatalError(ex);
} finally {
result.computeStatusIfUnknown();
}
pageBase.showResult(result);
target.add(pageBase.getFeedbackPanel());
}
private ReportType getReport() {
return getObjectWrapper().getObject().asObjectable();
}
@Override
protected Boolean isOperationalButtonsVisible() {
return true;
}
private boolean isCollectionReport() {
return getObjectWrapper().findItemDefinition(ReportType.F_OBJECT_COLLECTION) != null;
}
private ReportObjectsListPanel getReportTable() {
return (ReportObjectsListPanel) get(createComponentPath(ID_TABLE_CONTAINER, ID_TABLE_BOX, ID_REPORT_TABLE));
}
private Component getTableBox() {
return get(createComponentPath(ID_TABLE_CONTAINER, ID_TABLE_BOX));
}
private Component getTableContainer() {
return get(ID_TABLE_CONTAINER);
}
}