Skip to content

Commit 527d5e3

Browse files
committed
Improve audit logs
1 parent fc14c6a commit 527d5e3

File tree

6 files changed

+170
-6
lines changed

6 files changed

+170
-6
lines changed

roda-ui/roda-wui/src/main/java/config/i18n/client/ClientMessages.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,6 +1476,8 @@ SafeHtml searchPreFilterLongRangeFilterParameterGreaterThan(String searchPreFilt
14761476

14771477
String logEntryIdentifier();
14781478

1479+
String logEntryReason();
1480+
14791481
String logEntryComponent();
14801482

14811483
String logEntryMethod();
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
/**
2+
* The contents of this file are subject to the license and copyright
3+
* detailed in the LICENSE file at the root of the source
4+
* tree and available online at
5+
*
6+
* https://github.com/keeps/roda
7+
*/
8+
package org.roda.wui.client.common.lists;
9+
10+
import java.util.Arrays;
11+
import java.util.Date;
12+
import java.util.HashMap;
13+
import java.util.List;
14+
import java.util.Map;
15+
16+
import org.roda.core.data.common.RodaConstants;
17+
import org.roda.core.data.v2.index.collapse.Collapse;
18+
import org.roda.core.data.v2.index.sort.Sorter;
19+
import org.roda.core.data.v2.log.LogEntry;
20+
import org.roda.wui.client.common.lists.utils.AsyncTableCell;
21+
import org.roda.wui.client.common.lists.utils.AsyncTableCellOptions;
22+
import org.roda.wui.client.common.utils.HtmlSnippetUtils;
23+
import org.roda.wui.common.client.tools.Humanize;
24+
import org.roda.wui.common.client.tools.StringUtils;
25+
26+
import com.google.gwt.cell.client.DateCell;
27+
import com.google.gwt.cell.client.SafeHtmlCell;
28+
import com.google.gwt.core.client.GWT;
29+
import com.google.gwt.i18n.client.DateTimeFormat;
30+
import com.google.gwt.safehtml.shared.SafeHtml;
31+
import com.google.gwt.safehtml.shared.SafeHtmlUtils;
32+
import com.google.gwt.user.cellview.client.CellTable;
33+
import com.google.gwt.user.cellview.client.Column;
34+
import com.google.gwt.user.cellview.client.ColumnSortList;
35+
import com.google.gwt.user.cellview.client.ColumnSortList.ColumnSortInfo;
36+
import com.google.gwt.user.cellview.client.TextColumn;
37+
38+
import config.i18n.client.ClientMessages;
39+
40+
public class InternalLogEntryList extends AsyncTableCell<LogEntry> {
41+
42+
private static final ClientMessages messages = GWT.create(ClientMessages.class);
43+
44+
private Column<LogEntry, Date> dateColumn;
45+
private Column<LogEntry, SafeHtml> actionComponentColumn;
46+
private TextColumn<LogEntry> actionMethodColumn;
47+
private TextColumn<LogEntry> usernameColumn;
48+
private TextColumn<LogEntry> durationColumn;
49+
private Column<LogEntry, SafeHtml> stateColumn;
50+
51+
private static final List<String> fieldsToReturn = Arrays.asList(RodaConstants.INDEX_UUID, RodaConstants.LOG_ID,
52+
RodaConstants.LOG_DATETIME, RodaConstants.LOG_ACTION_COMPONENT, RodaConstants.LOG_ACTION_METHOD,
53+
RodaConstants.LOG_USERNAME, RodaConstants.LOG_DURATION, RodaConstants.LOG_STATE,
54+
RodaConstants.LOG_REQUEST_HEADER_UUID);
55+
56+
public InternalLogEntryList() {
57+
super();
58+
}
59+
60+
@Override
61+
protected void adjustOptions(AsyncTableCellOptions<LogEntry> options) {
62+
options.withFieldsToReturn(fieldsToReturn);
63+
}
64+
65+
@Override
66+
protected void configureDisplay(CellTable<LogEntry> display) {
67+
dateColumn = new Column<LogEntry, Date>(
68+
new DateCell(DateTimeFormat.getFormat(RodaConstants.DEFAULT_DATETIME_FORMAT))) {
69+
@Override
70+
public Date getValue(LogEntry logEntry) {
71+
return logEntry != null ? logEntry.getDatetime() : null;
72+
}
73+
};
74+
75+
actionComponentColumn = new Column<LogEntry, SafeHtml>(new SafeHtmlCell()) {
76+
@Override
77+
public SafeHtml getValue(LogEntry logEntry) {
78+
return SafeHtmlUtils
79+
.fromSafeConstant(translate(RodaConstants.LOG_ACTION_COMPONENT, logEntry.getActionComponent()));
80+
}
81+
};
82+
83+
actionMethodColumn = new TextColumn<LogEntry>() {
84+
@Override
85+
public String getValue(LogEntry logEntry) {
86+
if (logEntry == null) {
87+
return null;
88+
}
89+
90+
return StringUtils.getPrettifiedActionMethod(logEntry.getActionMethod());
91+
}
92+
};
93+
94+
usernameColumn = new TextColumn<LogEntry>() {
95+
@Override
96+
public String getValue(LogEntry logEntry) {
97+
return logEntry != null ? logEntry.getUsername() : null;
98+
}
99+
};
100+
101+
durationColumn = new TextColumn<LogEntry>() {
102+
@Override
103+
public String getValue(LogEntry logEntry) {
104+
return logEntry != null ? Humanize.durationMillisToShortDHMS(logEntry.getDuration()) : null;
105+
}
106+
};
107+
108+
stateColumn = new Column<LogEntry, SafeHtml>(new SafeHtmlCell()) {
109+
@Override
110+
public SafeHtml getValue(LogEntry logEntry) {
111+
return HtmlSnippetUtils.getLogEntryStateHtml(logEntry.getState());
112+
}
113+
};
114+
115+
dateColumn.setSortable(true);
116+
actionComponentColumn.setSortable(true);
117+
actionMethodColumn.setSortable(true);
118+
usernameColumn.setSortable(true);
119+
durationColumn.setSortable(true);
120+
stateColumn.setSortable(true);
121+
122+
addColumn(dateColumn, messages.logEntryDate(), true, false, 14);
123+
addColumn(actionComponentColumn, messages.logEntryComponent(), true, false);
124+
addColumn(actionMethodColumn, messages.logEntryMethod(), true, false);
125+
addColumn(usernameColumn, messages.logEntryUser(), true, false);
126+
addColumn(durationColumn, messages.logEntryDuration(), true, true, 5);
127+
addColumn(stateColumn, messages.logEntryState(), true, false);
128+
129+
// default sorting
130+
display.getColumnSortList().push(new ColumnSortInfo(dateColumn, false));
131+
addStyleName("my-collections-table");
132+
}
133+
134+
@Override
135+
protected Sorter getSorter(ColumnSortList columnSortList) {
136+
Map<Column<LogEntry, ?>, List<String>> columnSortingKeyMap = new HashMap<>();
137+
columnSortingKeyMap.put(dateColumn, Arrays.asList(RodaConstants.LOG_DATETIME));
138+
columnSortingKeyMap.put(actionComponentColumn, Arrays.asList(RodaConstants.LOG_ACTION_COMPONENT));
139+
columnSortingKeyMap.put(actionMethodColumn, Arrays.asList(RodaConstants.LOG_ACTION_METHOD));
140+
columnSortingKeyMap.put(usernameColumn, Arrays.asList(RodaConstants.LOG_USERNAME));
141+
columnSortingKeyMap.put(durationColumn, Arrays.asList(RodaConstants.LOG_DURATION));
142+
columnSortingKeyMap.put(stateColumn, Arrays.asList(RodaConstants.LOG_STATE));
143+
return createSorter(columnSortList, columnSortingKeyMap);
144+
}
145+
146+
@Override
147+
public Collapse getCollapse() {
148+
return null;
149+
}
150+
}

roda-ui/roda-wui/src/main/java/org/roda/wui/client/common/lists/LogEntryList.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public SafeHtml getValue(LogEntry logEntry) {
150150
stateColumn.setSortable(true);
151151

152152
addColumn(dateColumn, messages.logEntryDate(), true, false, 14);
153-
addColumn(requestReasonColumn, "Reason", true, false);
153+
addColumn(requestReasonColumn, messages.logEntryReason(), true, false);
154154
addColumn(actionComponentColumn, messages.logEntryComponent(), true, false);
155155
addColumn(actionMethodColumn, messages.logEntryMethod(), true, false);
156156
addColumn(usernameColumn, messages.logEntryUser(), true, false);

roda-ui/roda-wui/src/main/java/org/roda/wui/client/management/ShowLogEntry.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import org.roda.core.data.v2.log.LogEntry;
1919
import org.roda.core.data.v2.log.LogEntryParameter;
2020
import org.roda.wui.client.common.UserLogin;
21-
import org.roda.wui.client.common.lists.LogEntryList;
21+
import org.roda.wui.client.common.lists.InternalLogEntryList;
2222
import org.roda.wui.client.common.lists.utils.AsyncTableCellOptions;
2323
import org.roda.wui.client.common.lists.utils.ListBuilder;
2424
import org.roda.wui.client.common.search.SearchWrapper;
@@ -98,7 +98,10 @@ interface MyUiBinder extends UiBinder<Widget, ShowLogEntry> {
9898
Label logIdLabel;
9999
@UiField
100100
Label logIdValue;
101-
101+
@UiField
102+
Label logReasonLabel;
103+
@UiField
104+
Label logReasonValue;
102105
@UiField
103106
Label logComponentLabel;
104107
@UiField
@@ -153,6 +156,10 @@ public ShowLogEntry(LogEntry logEntry) {
153156
logIdLabel.setVisible(StringUtils.isNotBlank(logEntry.getId()));
154157
logIdValue.setVisible(StringUtils.isNotBlank(logEntry.getId()));
155158

159+
logReasonValue.setText(logEntry.getAuditLogRequestHeaders().getReason());
160+
logReasonLabel.setVisible(StringUtils.isNotBlank(logEntry.getAuditLogRequestHeaders().getReason()));
161+
logReasonValue.setVisible(StringUtils.isNotBlank(logEntry.getAuditLogRequestHeaders().getReason()));
162+
156163
logInstanceIdValue.setText(logEntry.getInstanceId());
157164
logInstanceIdLabel.setVisible(StringUtils.isNotBlank(logEntry.getInstanceId()));
158165
logInstanceIdValue.setVisible(StringUtils.isNotBlank(logEntry.getInstanceId()));
@@ -204,8 +211,6 @@ public ShowLogEntry(LogEntry logEntry) {
204211

205212
expandedAuditLogsList.setVisible(false);
206213

207-
GWT.log(logEntry.getAuditLogRequestHeaders().toString());
208-
209214
if (logEntry.getAuditLogRequestHeaders() != null) {
210215
Label relatedAuditLogs = new Label();
211216
relatedAuditLogs.addStyleName("h5");
@@ -215,7 +220,7 @@ public ShowLogEntry(LogEntry logEntry) {
215220
Filter filter = new Filter(new SimpleFilterParameter(RodaConstants.LOG_REQUEST_HEADER_UUID,
216221
logEntry.getAuditLogRequestHeaders().getUuid()));
217222

218-
ListBuilder<LogEntry> auditLogListBuilder = new ListBuilder<>(() -> new LogEntryList(false),
223+
ListBuilder<LogEntry> auditLogListBuilder = new ListBuilder<>(() -> new InternalLogEntryList(),
219224
new AsyncTableCellOptions<>(LogEntry.class, "AuditLogs_triggeredLogs").withFilter(filter)
220225
.withSummary(messages.listOfAIPs()).bindOpener());
221226

roda-ui/roda-wui/src/main/java/org/roda/wui/client/management/ShowLogEntry.ui.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818
</g:Label>
1919
<g:Label styleName="value" ui:field="logIdValue" />
2020
</g:FlowPanel>
21+
<g:FlowPanel styleName="field">
22+
<g:Label styleName="label" ui:field="logReasonLabel">
23+
<ui:text from='{messages.logEntryReason}' />
24+
</g:Label>
25+
<g:Label styleName="value" ui:field="logReasonValue" />
26+
</g:FlowPanel>
2127
<g:FlowPanel styleName="field">
2228
<g:Label styleName="label" ui:field="logInstanceIdLabel">
2329
<ui:text from='{messages.logEntryInstanceId}' />

roda-ui/roda-wui/src/main/resources/config/i18n/client/ClientMessages.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,7 @@ learnMore:Learn More
959959
searchDuplicateWarningMessage:The {0} field is duplicated. An 'OR' operator will be used.
960960
# Activity log
961961
logEntryIdentifier:Identifier
962+
logEntryReason: Reason
962963
logEntryComponent:Component
963964
logEntryMethod:Method
964965
logEntryAddress:Address

0 commit comments

Comments
 (0)