-
Notifications
You must be signed in to change notification settings - Fork 188
/
ObjectHistoryTabPanel.java
221 lines (182 loc) · 10.8 KB
/
ObjectHistoryTabPanel.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
/*
* Copyright (c) 2016 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.component.objectdetails;
import static java.util.Arrays.asList;
import java.util.List;
import com.evolveum.midpoint.gui.api.GuiStyleConstants;
import com.evolveum.midpoint.web.component.AjaxIconButton;
import com.evolveum.midpoint.web.component.data.MultiButtonPanel;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator;
import org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractColumn;
import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
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.prism.PrismContext;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.ObjectTypeUtil;
import com.evolveum.midpoint.task.api.Task;
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.component.DateLabelComponent;
import com.evolveum.midpoint.web.component.data.column.DoubleButtonColumn;
import com.evolveum.midpoint.web.component.form.Form;
import com.evolveum.midpoint.web.component.prism.ObjectWrapper;
import com.evolveum.midpoint.web.page.admin.PageAdminObjectDetails;
import com.evolveum.midpoint.web.page.admin.reports.component.AuditLogViewerPanel;
import com.evolveum.midpoint.web.page.admin.reports.dto.AuditSearchDto;
import com.evolveum.midpoint.web.page.admin.users.PageXmlDataReview;
import com.evolveum.midpoint.web.session.AuditLogStorage;
import com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordType;
import com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventStageType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
/**
* Created by honchar.
*/
public abstract class ObjectHistoryTabPanel<F extends FocusType> extends AbstractObjectTabPanel<F> {
private static final long serialVersionUID = 1L;
private static final String ID_MAIN_PANEL = "mainPanel";
private static final Trace LOGGER = TraceManager.getTrace(ObjectHistoryTabPanel.class);
private static final String DOT_CLASS = ObjectHistoryTabPanel.class.getName() + ".";
private static final String OPERATION_RESTRUCT_OBJECT = DOT_CLASS + "restructObject";
public ObjectHistoryTabPanel(String id, Form mainForm, LoadableModel<ObjectWrapper<F>> focusWrapperModel,
PageAdminObjectDetails<F> parentPage) {
super(id, mainForm, focusWrapperModel, parentPage);
parentPage.getSessionStorage().setUserHistoryAuditLog(new AuditLogStorage());
initLayout(focusWrapperModel, parentPage);
}
private void initLayout(final LoadableModel<ObjectWrapper<F>> focusWrapperModel, final PageAdminObjectDetails<F> page) {
AuditSearchDto auditSearchDto = createAuditSearchDto(focusWrapperModel.getObject().getObject().asObjectable());
AuditLogViewerPanel panel = new AuditLogViewerPanel(ID_MAIN_PANEL, Model.of(auditSearchDto), true) {
private static final long serialVersionUID = 1L;
@Override
protected List<IColumn<AuditEventRecordType, String>> initColumns() {
List<IColumn<AuditEventRecordType, String>> columns = super.initColumns();
IColumn<AuditEventRecordType, String> column
= new AbstractColumn<AuditEventRecordType, String>(new Model<>()) {
private static final long serialVersionUID = 1L;
@Override
public void populateItem(Item<ICellPopulator<AuditEventRecordType>> cellItem, String componentId,
IModel<AuditEventRecordType> rowModel) {
cellItem.add(new MultiButtonPanel<AuditEventRecordType>(componentId, rowModel, 2) {
private static final long serialVersionUID = 1L;
@Override
protected AjaxIconButton createButton(int index, String componentId, IModel<AuditEventRecordType> model) {
AjaxIconButton btn = null;
switch (index) {
case 0:
btn = buildDefaultButton(componentId, new Model<>("fa fa-circle-o"),
createStringResource("ObjectHistoryTabPanel.viewHistoricalObjectDataTitle"),
new Model<>("btn btn-sm " + DoubleButtonColumn.BUTTON_COLOR_CLASS.INFO),
target ->
currentStateButtonClicked(target, getReconstructedObject(focusWrapperModel.getObject().getOid(),
model.getObject().getEventIdentifier(), page.getCompileTimeClass()),
WebComponentUtil.getLocalizedDate(model.getObject().getTimestamp(), DateLabelComponent.SHORT_NOTIME_STYLE)));
break;
case 1:
btn = buildDefaultButton(componentId, new Model<>(GuiStyleConstants.CLASS_FILE_TEXT),
createStringResource("ObjectHistoryTabPanel.viewHistoricalObjectXmlTitle"),
new Model<>("btn btn-sm " + DoubleButtonColumn.BUTTON_COLOR_CLASS.SUCCESS),
target ->
viewObjectXmlButtonClicked(focusWrapperModel.getObject().getOid(),
model.getObject().getEventIdentifier(),
page.getCompileTimeClass(),
WebComponentUtil.getLocalizedDate(model.getObject().getTimestamp(), DateLabelComponent.SHORT_NOTIME_STYLE)));
break;
}
return btn;
}
});
}
};
columns.add(column);
return columns;
}
@Override
protected void updateAuditSearchStorage(AuditSearchDto searchDto) {
getPageBase().getSessionStorage().getUserHistoryAuditLog().setSearchDto(searchDto);
getPageBase().getSessionStorage().getUserHistoryAuditLog().setPageNumber(0);
}
@Override
protected void resetAuditSearchStorage() {
getPageBase().getSessionStorage().getUserHistoryAuditLog().setSearchDto(createAuditSearchDto(focusWrapperModel.getObject().getObject().asObjectable()));
}
@Override
protected void updateCurrentPage(long current) {
getPageBase().getSessionStorage().getUserHistoryAuditLog().setPageNumber(current);
}
@Override
protected long getCurrentPage() {
return getPageBase().getSessionStorage().getUserHistoryAuditLog().getPageNumber();
}
};
panel.setOutputMarkupId(true);
add(panel);
}
private AuditSearchDto createAuditSearchDto(F focus) {
AuditSearchDto searchDto = new AuditSearchDto();
ObjectReferenceType ort = ObjectTypeUtil.createObjectRef(focus, getPrismContext());
searchDto.setTargetNames(asList(ort));
searchDto.setEventStage(AuditEventStageType.EXECUTION);
return searchDto;
}
protected abstract void currentStateButtonClicked(AjaxRequestTarget target, PrismObject<F> object, String date);
private PrismObject<F> getReconstructedObject(String oid, String eventIdentifier,
Class type) {
OperationResult result = new OperationResult(OPERATION_RESTRUCT_OBJECT);
try {
Task task = getPageBase().createSimpleTask(OPERATION_RESTRUCT_OBJECT);
PrismObject<F> object = WebModelServiceUtils.reconstructObject(type, oid, eventIdentifier, task, result);
return object;
} catch (Exception ex) {
result.recordFatalError("Couldn't restruct object.", ex);
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't restruct object", ex);
}
return null;
}
private void viewObjectXmlButtonClicked(String oid, String eventIdentifier, Class type, String date) {
PrismObject<F> object = getReconstructedObject(oid, eventIdentifier, type);
String name = WebComponentUtil.getName(object);
getPageBase().navigateToNext(new PageXmlDataReview(getPageBase().createStringResource("PageXmlDataReview.aceEditorPanelTitle", name, date),
new IModel<String>() {
private static final long serialVersionUID = 1L;
@Override
public String getObject() {
PrismContext context = getPageBase().getPrismContext();
String xml = "";
try {
xml = context.serializerFor(PrismContext.LANG_XML).serialize(object);
} catch (Exception ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't serialize object", ex);
}
return xml;
}
@Override
public void setObject(String s) {
}
@Override
public void detach() {
}
}));
}
}