-
Notifications
You must be signed in to change notification settings - Fork 188
/
PageAbout.java
655 lines (544 loc) · 28.8 KB
/
PageAbout.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
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
/*
* Copyright (c) 2010-2018 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.configuration;
import com.evolveum.midpoint.gui.api.model.LoadableModel;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.gui.api.util.WebModelServiceUtils;
import com.evolveum.midpoint.init.InitialDataImport;
import com.evolveum.midpoint.model.api.ModelPublicConstants;
import com.evolveum.midpoint.model.common.SystemObjectCache;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.prism.query.*;
import com.evolveum.midpoint.schema.LabeledString;
import com.evolveum.midpoint.schema.ProvisioningDiag;
import com.evolveum.midpoint.schema.RepositoryDiag;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.security.api.AuthorizationConstants;
import com.evolveum.midpoint.security.api.MidPointPrincipal;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.task.api.TaskManager;
import com.evolveum.midpoint.util.Producer;
import com.evolveum.midpoint.util.exception.CommunicationException;
import com.evolveum.midpoint.util.exception.ConfigurationException;
import com.evolveum.midpoint.util.exception.ExpressionEvaluationException;
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.exception.SecurityViolationException;
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.component.AjaxButton;
import com.evolveum.midpoint.web.component.dialog.ConfirmationPanel;
import com.evolveum.midpoint.web.component.dialog.Popupable;
import com.evolveum.midpoint.web.page.login.PageLogin;
import com.evolveum.midpoint.web.security.util.SecurityUtils;
import com.evolveum.midpoint.xml.ns._public.common.common_3.NodeType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType;
import com.evolveum.midpoint.repo.cache.RepositoryCache;
import org.apache.catalina.util.ServerInfo;
import org.apache.commons.lang.StringUtils;
import org.apache.wicket.RestartResponseException;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;
import org.springframework.beans.factory.annotation.Autowired;
import java.io.Serializable;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.TimeUnit;
import javax.xml.namespace.QName;
/**
* @author lazyman
*/
@PageDescriptor(url = "/admin/config/about", action = {
@AuthorizationAction(actionUri = PageAdminConfiguration.AUTH_CONFIGURATION_ALL,
label = PageAdminConfiguration.AUTH_CONFIGURATION_ALL_LABEL, description = PageAdminConfiguration.AUTH_CONFIGURATION_ALL_DESCRIPTION),
@AuthorizationAction(actionUri = AuthorizationConstants.AUTZ_UI_CONFIGURATION_ABOUT_URL,
label = "PageAbout.auth.configAbout.label", description = "PageAbout.auth.configAbout.description")})
public class PageAbout extends PageAdminConfiguration {
private static final long serialVersionUID = 1L;
private static final Trace LOGGER = TraceManager.getTrace(PageAbout.class);
private static final String DOT_CLASS = PageAbout.class.getName() + ".";
private static final String OPERATION_TEST_REPOSITORY = DOT_CLASS + "testRepository";
private static final String OPERATION_TEST_REPOSITORY_CHECK_ORG_CLOSURE = DOT_CLASS + "testRepositoryCheckOrgClosure";
private static final String OPERATION_GET_REPO_DIAG = DOT_CLASS + "getRepoDiag";
private static final String OPERATION_SUBMIT_REINDEX = DOT_CLASS + "submitReindex";
private static final String OPERATION_CHECK_WORKFLOW_PROCESSES = DOT_CLASS + "checkWorkflowProcesses";
private static final String OPERATION_GET_PROVISIONING_DIAG = DOT_CLASS + "getProvisioningDiag";
private static final String OPERATION_DELETE_ALL_OBJECTS = DOT_CLASS + "deleteAllObjects";
private static final String OPERATION_DELETE_TASK = DOT_CLASS + "deleteTask";
private static final String OPERATION_LOAD_NODE = DOT_CLASS + "loadNode";
private static final String POST_INIT = DOT_CLASS + "postInit";
private static final String ID_BUILD_TIMESTAMP = "buildTimestamp";
private static final String ID_BUILD = "build";
private static final String ID_BRANCH = "branch";
private static final String ID_PROPERTY = "property";
private static final String ID_VALUE = "value";
private static final String ID_LIST_SYSTEM_ITEMS = "listSystemItems";
private static final String ID_TEST_REPOSITORY = "testRepository";
private static final String ID_TEST_REPOSITORY_CHECK_ORG_CLOSURE = "testRepositoryCheckOrgClosure";
private static final String ID_REINDEX_REPOSITORY_OBJECTS = "reindexRepositoryObjects";
private static final String ID_TEST_PROVISIONING = "testProvisioning";
private static final String ID_CHECK_WORKFLOW_PROCESSES = "checkWorkflowProcesses";
private static final String ID_IMPLEMENTATION_SHORT_NAME = "implementationShortName";
private static final String ID_IMPLEMENTATION_DESCRIPTION = "implementationDescription";
private static final String ID_IS_EMBEDDED = "isEmbedded";
private static final String ID_DRIVER_SHORT_NAME = "driverShortName";
private static final String ID_DRIVER_VERSION = "driverVersion";
private static final String ID_REPOSITORY_URL = "repositoryUrl";
private static final String ID_ADDITIONAL_DETAILS = "additionalDetails";
private static final String ID_DETAIL_NAME = "detailName";
private static final String ID_DETAIL_VALUE = "detailValue";
private static final String ID_PROVISIONING_ADDITIONAL_DETAILS = "provisioningAdditionalDetails";
private static final String ID_PROVISIONING_DETAIL_NAME = "provisioningDetailName";
private static final String ID_PROVISIONING_DETAIL_VALUE = "provisioningDetailValue";
private static final String ID_JVM_PROPERTIES = "jvmProperties";
private static final String ID_COPY_ENVIRONMENT_INFO = "copyEnvironmentInfo";
private static final String ID_CLEAR_CSS_JS_CACHE = "clearCssJsCache";
private static final String ID_FACTORY_DEFAULT = "factoryDefault";
private static final String ID_NODE_NAME = "nodeName";
private static final String ID_NODE_ID = "nodeId";
private static final String ID_NODE_URL = "nodeUrl";
private static final String[] PROPERTIES = new String[]{"file.separator", "java.class.path",
"java.home", "java.vendor", "java.vendor.url", "java.version", "line.separator", "os.arch",
"os.name", "os.version", "path.separator", "user.dir", "user.home", "user.name"};
private IModel<RepositoryDiag> repoDiagModel;
private IModel<ProvisioningDiag> provisioningDiagModel;
@Autowired RepositoryCache repositoryCache;
@Autowired protected SystemObjectCache systemObjectCache;
public PageAbout() {
repoDiagModel = new LoadableModel<RepositoryDiag>(false) {
private static final long serialVersionUID = 1L;
@Override
protected RepositoryDiag load() {
return loadRepoDiagModel();
}
};
provisioningDiagModel = new LoadableModel<ProvisioningDiag>(false) {
private static final long serialVersionUID = 1L;
@Override
protected ProvisioningDiag load() {
return loadProvisioningDiagModel();
}
};
initLayout();
}
private void initLayout() {
Label branch = new Label(ID_BRANCH, createStringResource("midpoint.system.branch"));
branch.setRenderBodyOnly(true);
add(branch);
Label revision = new Label(ID_BUILD, createStringResource("midpoint.system.build"));
revision.setRenderBodyOnly(true);
add(revision);
Label build = new Label(ID_BUILD_TIMESTAMP, createStringResource("midpoint.system.buildTimestamp"));
build.setRenderBodyOnly(true);
add(build);
ListView<SystemItem> listSystemItems = new ListView<SystemItem>(ID_LIST_SYSTEM_ITEMS, getItems()) {
private static final long serialVersionUID = 1L;
@Override
protected void populateItem(ListItem<SystemItem> item) {
SystemItem systemItem = item.getModelObject();
Label property = new Label(ID_PROPERTY, systemItem.getProperty());
property.setRenderBodyOnly(true);
item.add(property);
Label value = new Label(ID_VALUE, systemItem.getValue());
value.setRenderBodyOnly(true);
item.add(value);
}
};
add(listSystemItems);
addLabel(ID_IMPLEMENTATION_SHORT_NAME, "implementationShortName");
addLabel(ID_IMPLEMENTATION_DESCRIPTION, "implementationDescription");
addLabel(ID_IS_EMBEDDED, "isEmbedded");
addLabel(ID_DRIVER_SHORT_NAME, "driverShortName");
addLabel(ID_DRIVER_VERSION, "driverVersion");
addLabel(ID_REPOSITORY_URL, "repositoryUrl");
ListView<LabeledString> additionalDetails = new ListView<LabeledString>(ID_ADDITIONAL_DETAILS,
new PropertyModel<>(repoDiagModel, "additionalDetails")) {
private static final long serialVersionUID = 1L;
@Override
protected void populateItem(ListItem<LabeledString> item) {
LabeledString labeledString = item.getModelObject();
Label property = new Label(ID_DETAIL_NAME, labeledString.getLabel());
property.setRenderBodyOnly(true);
item.add(property);
Label value = new Label(ID_DETAIL_VALUE, labeledString.getData());
value.setRenderBodyOnly(true);
item.add(value);
}
};
add(additionalDetails);
ListView<LabeledString> provisioningAdditionalDetails = new ListView<LabeledString>(ID_PROVISIONING_ADDITIONAL_DETAILS,
new PropertyModel<>(provisioningDiagModel, "additionalDetails")) {
private static final long serialVersionUID = 1L;
@Override
protected void populateItem(ListItem<LabeledString> item) {
LabeledString labeledString = item.getModelObject();
Label property = new Label(ID_PROVISIONING_DETAIL_NAME, labeledString.getLabel());
property.setRenderBodyOnly(true);
item.add(property);
Label value = new Label(ID_PROVISIONING_DETAIL_VALUE, labeledString.getData());
value.setRenderBodyOnly(true);
item.add(value);
}
};
add(provisioningAdditionalDetails);
String nodeId = getTaskManager().getNodeId();
OperationResult result = new OperationResult(OPERATION_LOAD_NODE);
List<PrismObject<NodeType>> nodes = WebModelServiceUtils.searchObjects(NodeType.class,
getPrismContext().queryFor(NodeType.class)
.item(NodeType.F_NODE_IDENTIFIER).eq(nodeId)
.build(),
result, PageAbout.this);
if (nodes.isEmpty()) {
throw new IllegalArgumentException("Couldn't find NodeType with identifier '" + nodeId + "'");
}
if (nodes.size() > 1) {
throw new IllegalArgumentException("Found more as one NodeType with identifier '" + nodeId + "'");
}
PrismObject<NodeType> node = nodes.get(0);
if (node == null) {
throw new IllegalArgumentException("Found NodeType with identifier '" + nodeId + "' is null");
}
NodeType nodeType = node.asObjectable();
Label nodeName = new Label(ID_NODE_NAME, nodeType.getName() != null ? nodeType.getName() : "");
nodeName.setRenderBodyOnly(true);
add(nodeName);
Label nodeIdValue = new Label(ID_NODE_ID, nodeType.getNodeIdentifier());
nodeIdValue.setRenderBodyOnly(true);
add(nodeIdValue);
Label nodeUrl = new Label(ID_NODE_URL, nodeType.getUrl() != null ? nodeType.getUrl() : "");
nodeUrl.setRenderBodyOnly(true);
add(nodeUrl);
Label jvmProperties = new Label(ID_JVM_PROPERTIES, new LoadableModel<String>(false) {
private static final long serialVersionUID = 1L;
@Override
protected String load() {
try {
RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean();
List<String> arguments = runtimeMxBean.getInputArguments();
return StringUtils.join(arguments, "<br/>");
} catch (Exception ex) {
return PageAbout.this.getString("PageAbout.message.couldntObtainJvmParams");
}
}
});
jvmProperties.setEscapeModelStrings(false);
add(jvmProperties);
initButtons();
}
private void addLabel(String id, String propertyName) {
Label label = new Label(id, new PropertyModel<String>(repoDiagModel, propertyName));
label.setRenderBodyOnly(true);
add(label);
}
private void initButtons() {
AjaxButton testRepository = new AjaxButton(ID_TEST_REPOSITORY,
createStringResource("PageAbout.button.testRepository")) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
testRepositoryPerformed(target);
}
};
add(testRepository);
AjaxButton testRepositoryCheckOrgClosure = new AjaxButton(ID_TEST_REPOSITORY_CHECK_ORG_CLOSURE,
createStringResource("PageAbout.button.testRepositoryCheckOrgClosure")) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
testRepositoryCheckOrgClosurePerformed(target);
}
};
add(testRepositoryCheckOrgClosure);
AjaxButton reindexRepositoryObjects = new AjaxButton(ID_REINDEX_REPOSITORY_OBJECTS,
createStringResource("PageAbout.button.reindexRepositoryObjects")) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
reindexRepositoryObjectsPerformed(target);
}
};
add(reindexRepositoryObjects);
AjaxButton testProvisioning = new AjaxButton(ID_TEST_PROVISIONING,
createStringResource("PageAbout.button.testProvisioning")) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
testProvisioningPerformed(target);
}
};
add(testProvisioning);
AjaxButton checkWorkflowProcesses = new AjaxButton(ID_CHECK_WORKFLOW_PROCESSES,
createStringResource("PageAbout.button.checkWorkflowProcesses")) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
// checkWorkflowProcessesPerformed(target);
}
};
checkWorkflowProcesses.setVisible(false);
add(checkWorkflowProcesses);
AjaxButton clearCssJsCache = new AjaxButton(ID_CLEAR_CSS_JS_CACHE,
createStringResource("PageAbout.button.clearCssJsCache")) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
clearLessJsCache(target);
}
};
add(clearCssJsCache);
AjaxButton copyEnvironmentInfo = new AjaxButton(ID_COPY_ENVIRONMENT_INFO,
createStringResource("PageAbout.button.copyEnvironmentInfo")) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
copyEnvironmentInfoPerformed(target);
success(createStringResource("PageAbout.button.copyEnvironmentMessage").getString());
target.add(getFeedbackPanel());
}
};
copyEnvironmentInfo.setOutputMarkupId(true);
add(copyEnvironmentInfo);
AjaxButton factoryDefault = new AjaxButton(ID_FACTORY_DEFAULT,
createStringResource("PageAbout.button.factoryDefault")) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
showMainPopup(getDeleteAllObjectsConfirmationPanel(), target);
}
};
add(factoryDefault);
}
private void copyEnvironmentInfoPerformed(AjaxRequestTarget target){
StringBuilder sb = new StringBuilder("var $tempInput = document.createElement('INPUT');\n");
sb.append("document.body.appendChild($tempInput);\n");
sb.append("$tempInput.setAttribute('value', '" + getEnvironmentInfo() + "');\n");
sb.append("$tempInput.select();\n");
sb.append("document.execCommand('copy');\n");
sb.append("document.body.removeChild($tempInput);");
target.appendJavaScript(sb.toString());
}
private String getEnvironmentInfo(){
String nodesCount = createStringResource("PageAbout.environmentInfo.nodesCount",
WebModelServiceUtils.countObjects(NodeType.class, null, PageAbout.this)).getString();
Runtime runtime = Runtime.getRuntime();
String processorsCount = createStringResource("PageAbout.environmentInfo.processorsCount", runtime.availableProcessors()).getString();
String totalMemory = createStringResource("PageAbout.environmentInfo.totalMemory", runtime.totalMemory()).getString();
String javaVersion = createStringResource("PageAbout.environmentInfo.javaVersion", System.getProperty("java.version")).getString();
String tomcatVersion = createStringResource("PageAbout.environmentInfo.tomcatVersion", ServerInfo.getServerInfo()).getString();
String mpVersion = createStringResource("PageAbout.environmentInfo.mpVersion",
createStringResource("midpoint.system.version").getString()).getString();
String dbInfo = createStringResource("PageAbout.environmentInfo.databaseInfo",
repoDiagModel.getObject().getDriverShortName() + " " + repoDiagModel.getObject().getDriverVersion()).getString();
String osInfo = createStringResource("PageAbout.environmentInfo.osInfo",
System.getProperty("os.name") + System.getProperty("os.version")).getString();
return nodesCount + processorsCount + totalMemory + javaVersion + tomcatVersion + mpVersion + dbInfo + osInfo;
}
private RepositoryDiag loadRepoDiagModel() {
OperationResult result = new OperationResult(OPERATION_GET_REPO_DIAG);
RepositoryDiag diag = null;
try {
Task task = createSimpleTask(OPERATION_GET_REPO_DIAG);
diag = getModelDiagnosticService().getRepositoryDiag(task, result);
result.recordSuccessIfUnknown();
} catch (Exception ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't get repo diagnostics", ex);
result.recordFatalError(getString("PageAbout.message.loadRepoDiagModel.fatalError"), ex);
}
result.recomputeStatus();
if (!WebComponentUtil.isSuccessOrHandledError(result)) {
showResult(result);
}
return diag;
}
private ProvisioningDiag loadProvisioningDiagModel() {
OperationResult result = new OperationResult(OPERATION_GET_PROVISIONING_DIAG);
ProvisioningDiag diag = null;
try {
Task task = createSimpleTask(OPERATION_GET_PROVISIONING_DIAG);
diag = getModelDiagnosticService().getProvisioningDiag(task, result);
result.recordSuccessIfUnknown();
} catch (Exception ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't get provisioning diagnostics", ex);
result.recordFatalError(getString("PageAbout.message.loadProvisioningDiagModel.fatalError"), ex);
}
result.recomputeStatus();
if (!WebComponentUtil.isSuccessOrHandledError(result)) {
showResult(result);
}
return diag;
}
private IModel<List<SystemItem>> getItems() {
return new LoadableModel<List<SystemItem>>(false) {
private static final long serialVersionUID = 1L;
@Override
protected List<SystemItem> load() {
List<SystemItem> items = new ArrayList<>();
for (String property : PROPERTIES) {
items.add(new SystemItem(property, System.getProperty(property)));
}
return items;
}
};
}
private void testRepositoryPerformed(AjaxRequestTarget target) {
Task task = createSimpleTask(OPERATION_TEST_REPOSITORY);
OperationResult result = getModelDiagnosticService().repositorySelfTest(task);
showResult(result);
target.add(getFeedbackPanel());
}
private void testRepositoryCheckOrgClosurePerformed(AjaxRequestTarget target) {
OperationResult result = new OperationResult(OPERATION_TEST_REPOSITORY_CHECK_ORG_CLOSURE);
try {
Task task = createSimpleTask(OPERATION_TEST_REPOSITORY_CHECK_ORG_CLOSURE);
getModelDiagnosticService().repositoryTestOrgClosureConsistency(task, true, result);
} catch (SchemaException | SecurityViolationException | ExpressionEvaluationException | ObjectNotFoundException | ConfigurationException | CommunicationException e) {
result.recordFatalError(e);
} finally {
result.computeStatusIfUnknown();
}
showResult(result);
target.add(getFeedbackPanel());
}
private void reindexRepositoryObjectsPerformed(AjaxRequestTarget target) {
OperationResult result = new OperationResult(OPERATION_SUBMIT_REINDEX);
try {
TaskManager taskManager = getTaskManager();
Task task = taskManager.createTaskInstance();
MidPointPrincipal user = SecurityUtils.getPrincipalUser();
if (user == null) {
throw new RestartResponseException(PageLogin.class);
} else {
task.setOwner(user.getFocus().asPrismObject());
}
authorize(AuthorizationConstants.AUTZ_ALL_URL, null, null, null, null, null, result);
task.setChannel(SchemaConstants.CHANNEL_GUI_USER_URI);
task.setHandlerUri(ModelPublicConstants.REINDEX_TASK_HANDLER_URI);
task.setName("Reindex repository objects");
taskManager.switchToBackground(task, result);
result.setBackgroundTaskOid(task.getOid());
} catch (SecurityViolationException | SchemaException|RuntimeException | ExpressionEvaluationException | ObjectNotFoundException | CommunicationException | ConfigurationException e) {
result.recordFatalError(e);
} finally {
result.computeStatusIfUnknown();
}
showResult(result);
target.add(getFeedbackPanel());
}
private void testProvisioningPerformed(AjaxRequestTarget target) {
Task task = createSimpleTask(OPERATION_TEST_REPOSITORY);
OperationResult result = getModelDiagnosticService().provisioningSelfTest(task);
showResult(result);
target.add(getFeedbackPanel());
}
private Popupable getDeleteAllObjectsConfirmationPanel() {
return new ConfirmationPanel(getMainPopupBodyId(), createStringResource("PageAbout.message.deleteAllObjects")) {
private static final long serialVersionUID = 1L;
@Override
public void yesPerformed(AjaxRequestTarget target) {
resetStateToInitialConfig(target);
}
};
}
private void resetStateToInitialConfig(AjaxRequestTarget target) {
OperationResult result = new OperationResult(OPERATION_DELETE_ALL_OBJECTS);
String taskOid = null;
String taskName = "Delete all objects";
QueryFactory factory = getPrismContext().queryFactory();
TypeFilter nodeFilter = factory.createType(NodeType.COMPLEX_TYPE, factory.createAll());
final ObjectFilter taskFilter = getPrismContext().queryFor(TaskType.class)
.item(TaskType.F_NAME).eq(taskName).buildFilter();
NotFilter notNodeFilter = factory.createNot(nodeFilter);
NotFilter notTaskFilter = factory.createNot(taskFilter);
try {
QName type = ObjectType.COMPLEX_TYPE;
taskOid = deleteObjectsAsync(type, factory.createQuery(
factory.createAnd(notTaskFilter, notNodeFilter)), true,
taskName, result);
} catch (Exception ex) {
result.recomputeStatus();
result.recordFatalError(getString("PageAbout.message.resetStateToInitialConfig.allObject.fatalError"), ex);
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't delete all objects", ex);
}
final String taskOidToRemoving = taskOid;
try {
while(!getTaskManager().getTaskPlain(taskOid, result).isClosed()) {TimeUnit.SECONDS.sleep(5);}
runPrivileged(new Producer<Object>() {
private static final long serialVersionUID = 1L;
@Override
public Object run() {
Task task = createAnonymousTask(OPERATION_DELETE_TASK);
OperationResult result = new OperationResult(OPERATION_DELETE_TASK);
ObjectDelta<TaskType> delta = getPrismContext().deltaFactory().object()
.createDeleteDelta(TaskType.class, taskOidToRemoving);
Collection<ObjectDelta<? extends ObjectType>> deltaCollection = new ArrayList<ObjectDelta<? extends ObjectType>>() {{add(delta);}};
try {
getModelService().executeChanges(deltaCollection, null, task, result);
} catch (Exception ex) {
result.recomputeStatus();
result.recordFatalError(getString("PageAbout.message.resetStateToInitialConfig.task.fatalError"), ex);
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't delete task", ex);
}
result.computeStatus();
return null;
}
});
InitialDataImport initialDataImport = new InitialDataImport();
initialDataImport.setModel(getModelService());
initialDataImport.setTaskManager(getTaskManager());
initialDataImport.setPrismContext(getPrismContext());
initialDataImport.setConfiguration(getMidpointConfiguration());
initialDataImport.init();
// TODO consider if we need to go clusterwide here
getCacheDispatcher().dispatchInvalidation(null, null, true, null);
getModelService().shutdown();
getModelService().postInit(result);
} catch (Exception ex) {
result.recomputeStatus();
result.recordFatalError(getString("PageAbout.message.resetStateToInitialConfig.import.fatalError"), ex);
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't import initial objects", ex);
}
showResult(result);
target.add(getFeedbackPanel());
}
/**
* It's here only because of some IDEs - it's not properly filtering resources during maven build.
* "describe" variable is not replaced.
*
* @return "unknown" instead of "git describe" for current build.
*/
@Deprecated
public String getDescribe() {
return getString("PageAbout.unknownBuildNumber");
}
private static class SystemItem implements Serializable {
private String property;
private String value;
private SystemItem(String property, String value) {
this.property = property;
this.value = value;
}
public String getProperty() {
return property;
}
public String getValue() {
return value;
}
}
}