Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master'
- Loading branch information
Showing
39 changed files
with
822 additions
and
405 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
307 changes: 132 additions & 175 deletions
307
...in-gui/src/main/java/com/evolveum/midpoint/web/page/admin/reports/PageAuditLogViewer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,195 +1,152 @@ | ||
package com.evolveum.midpoint.web.page.admin.reports; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import javax.xml.datatype.XMLGregorianCalendar; | ||
|
||
import org.apache.wicket.ajax.AjaxRequestTarget; | ||
import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn; | ||
import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn; | ||
import org.apache.wicket.markup.html.WebMarkupContainer; | ||
import org.apache.wicket.markup.html.form.Form; | ||
import org.apache.wicket.model.IModel; | ||
import org.apache.wicket.model.Model; | ||
import org.apache.wicket.model.util.ListModel; | ||
|
||
import com.evolveum.midpoint.audit.api.AuditEventRecord; | ||
import com.evolveum.midpoint.gui.api.page.PageBase; | ||
import com.evolveum.midpoint.gui.api.util.WebComponentUtil; | ||
import com.evolveum.midpoint.security.api.AuthorizationConstants; | ||
import com.evolveum.midpoint.util.MiscUtil; | ||
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.data.BoxedTablePanel; | ||
import com.evolveum.midpoint.web.component.input.DatePanel; | ||
import com.evolveum.midpoint.web.component.util.ListDataProvider; | ||
import com.evolveum.midpoint.web.component.input.DropDownChoicePanel; | ||
import com.evolveum.midpoint.web.component.input.TextPanel; | ||
import com.evolveum.midpoint.web.component.util.SelectableBean; | ||
import com.evolveum.midpoint.web.page.admin.configuration.PageAdminConfiguration; | ||
import com.evolveum.midpoint.web.page.admin.reports.dto.AuditEventRecordProvider; | ||
import com.evolveum.midpoint.web.session.UserProfileStorage; | ||
import com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordType; | ||
import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn; | ||
import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn; | ||
import org.apache.wicket.markup.html.WebMarkupContainer; | ||
import org.apache.wicket.markup.html.form.Form; | ||
import org.apache.wicket.model.IModel; | ||
|
||
import javax.xml.datatype.XMLGregorianCalendar; | ||
import java.sql.Timestamp; | ||
import java.util.*; | ||
|
||
/** | ||
* Created by honchar. | ||
*/ | ||
@PageDescriptor(url = "/admin/auditLogViewer", action = { | ||
@AuthorizationAction(actionUri = PageAdminReports.AUTH_REPORTS_ALL, | ||
label = PageAdminConfiguration.AUTH_CONFIGURATION_ALL_LABEL, | ||
description = PageAdminConfiguration.AUTH_CONFIGURATION_ALL_DESCRIPTION), | ||
@AuthorizationAction(actionUri = AuthorizationConstants.AUTZ_UI_AUDIT_LOG_VIEWER_URL, | ||
label = "PageAuditLogViewer.auth.auditLogViewer.label", | ||
description = "PageAuditLogViewer.auth.auditLogViewer.description")}) | ||
@AuthorizationAction(actionUri = PageAdminReports.AUTH_REPORTS_ALL, | ||
label = PageAdminConfiguration.AUTH_CONFIGURATION_ALL_LABEL, | ||
description = PageAdminConfiguration.AUTH_CONFIGURATION_ALL_DESCRIPTION), | ||
@AuthorizationAction(actionUri = AuthorizationConstants.AUTZ_UI_AUDIT_LOG_VIEWER_URL, | ||
label = "PageAuditLogViewer.auth.auditLogViewer.label", | ||
description = "PageAuditLogViewer.auth.auditLogViewer.description")}) | ||
public class PageAuditLogViewer extends PageBase{ | ||
private List<AuditEventRecord> auditEventRecordList; | ||
|
||
Map<String, Object> params = new HashMap<>(); | ||
|
||
private static final String ID_PARAMETERS_PANEL = "parametersPanel"; | ||
private static final String ID_TABLE = "table"; | ||
private static final String ID_FROM = "fromField"; | ||
private static final String ID_MAIN_FORM = "mainForm"; | ||
|
||
private static final String AUDIT_RECORDS_QUERY = "from RAuditEventRecord as aer where 1=1 and "; | ||
private static final String AUDIT_RECORDS_QUERY_COUNT = "select count(*) from RAuditEventRecord as aer where 1=1 and "; | ||
|
||
public PageAuditLogViewer(){ | ||
initLayout(); | ||
} | ||
private void initLayout(){ | ||
Form mainForm = new Form(ID_MAIN_FORM); | ||
add(mainForm); | ||
|
||
initParametersPanel(mainForm); | ||
initTable(mainForm); | ||
} | ||
|
||
private void initParametersPanel(Form mainForm){ | ||
WebMarkupContainer parametersPanel = new WebMarkupContainer(ID_PARAMETERS_PANEL); | ||
parametersPanel.setOutputMarkupId(true); | ||
mainForm.add(parametersPanel); | ||
|
||
|
||
final DatePanel from = new DatePanel(ID_FROM, | ||
new IModel<XMLGregorianCalendar>() { | ||
@Override | ||
public XMLGregorianCalendar getObject() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void setObject(XMLGregorianCalendar date) { | ||
|
||
} | ||
|
||
@Override | ||
public void detach() { | ||
|
||
} | ||
}); | ||
from.setOutputMarkupId(true); | ||
parametersPanel.add(from); | ||
} | ||
|
||
private void initTable(Form mainForm){ | ||
IModel<List<AuditEventRecordType>> model = new IModel<List<AuditEventRecordType>>() { | ||
@Override | ||
public List<AuditEventRecordType> getObject() { | ||
return getAuditEventRecordList(); | ||
} | ||
|
||
@Override | ||
public void setObject(List<AuditEventRecordType> auditEventRecord) { | ||
|
||
} | ||
|
||
@Override | ||
public void detach() { | ||
|
||
} | ||
}; | ||
ListDataProvider provider = new ListDataProvider<AuditEventRecordType>(PageAuditLogViewer.this, model); | ||
BoxedTablePanel table = new BoxedTablePanel(ID_TABLE, provider, | ||
initColumns(), | ||
UserProfileStorage.TableId.PAGE_AUDIT_LOG_VIEWER, | ||
(int) getItemsPerPage(UserProfileStorage.TableId.PAGE_AUDIT_LOG_VIEWER)) { | ||
|
||
}; | ||
table.setShowPaging(true); | ||
table.setOutputMarkupId(true); | ||
mainForm.add(table); | ||
} | ||
|
||
private List<AuditEventRecordType> getAuditEventRecordList(){ | ||
String parameterQuery = generateFullQuery(AUDIT_RECORDS_QUERY); | ||
List<AuditEventRecord> auditRecords = getAuditService().listRecords(parameterQuery + " order by aer.timestamp asc", params); | ||
if (auditRecords == null){ | ||
auditRecords = new ArrayList<>(); | ||
} | ||
List<AuditEventRecordType> auditRecordList = new ArrayList<>(); | ||
for (AuditEventRecord record : auditRecords){ | ||
AuditEventRecordType newRecord = getAuditEventRecordType(record); | ||
auditRecordList.add(newRecord); | ||
} | ||
// parameterQuery = generateFullQuery(AUDIT_RECORDS_QUERY_COUNT); | ||
// long count = getAuditService().countObjects(parameterQuery, params); | ||
// if (count != 0){ | ||
// | ||
// } | ||
return auditRecordList; | ||
} | ||
|
||
private List<IColumn<SelectableBean<AuditEventRecordType>, String>> initColumns() { | ||
List<IColumn<SelectableBean<AuditEventRecordType>, String>> columns = new ArrayList<>(); | ||
|
||
IColumn column; | ||
column = new PropertyColumn( | ||
createStringResource("PageAuditLogViewer.column.time"), "timestamp"); | ||
columns.add(column); | ||
|
||
//TODO add columns | ||
|
||
return columns; | ||
} | ||
|
||
private AuditEventRecordType getAuditEventRecordType(AuditEventRecord record){ | ||
AuditEventRecordType newRecord = new AuditEventRecordType(); | ||
newRecord.setTimestamp(MiscUtil.asXMLGregorianCalendar(new Date(record.getTimestamp()))); | ||
//TODO fill in others fields | ||
return newRecord; | ||
} | ||
|
||
private String generateFullQuery(String query){ | ||
if (params.get("from") != null) { | ||
query += "(aer.timestamp >= :from) and "; | ||
} else { | ||
params.remove("from"); | ||
} | ||
if (params.get("to") != null) { | ||
query += "(aer.timestamp <= :to) and "; | ||
} else { | ||
params.remove("to"); | ||
} | ||
if (params.get("eventType") != null) { | ||
query += "(aer.eventType = :eventType) and "; | ||
} else { | ||
params.remove("eventType"); | ||
} | ||
if (params.get("eventStage") != null) { | ||
query += "(aer.eventStage = :eventStage) and "; | ||
} else { | ||
params.remove("eventStage"); | ||
} | ||
if (params.get("outcome") != null) { | ||
query += "(aer.outcome = :outcome) and "; | ||
} else { | ||
params.remove("outcome"); | ||
} | ||
if (params.get("initiatorName") != null) { | ||
query += "(aer.initiatorName = :initiatorName) and "; | ||
} else { | ||
params.remove("initiatorName"); | ||
} | ||
if (params.get("targetName") != null) { | ||
query += "(aer.targetName = :targetName) and "; | ||
} else { | ||
params.remove("targetName"); | ||
} | ||
|
||
query = query.substring(0, query.length()-5); // remove trailing and | ||
return query; | ||
} | ||
|
||
private List<AuditEventRecord> auditEventRecordList; | ||
|
||
Map<String, Object> params = new HashMap<>(); | ||
|
||
private static final String ID_PARAMETERS_PANEL = "parametersPanel"; | ||
private static final String ID_TABLE = "table"; | ||
private static final String ID_FROM = "fromField"; | ||
private static final String ID_TO = "toField"; | ||
private static final String ID_INITIATOR = "initiatorField"; | ||
private static final String ID_CHANNEL = "channelField"; | ||
private static final String ID_PROPERTY = "propertyField"; | ||
private static final String ID_MAIN_FORM = "mainForm"; | ||
private static final String ID_SEARCH_BUTTON = "searchButton"; | ||
|
||
private IModel<XMLGregorianCalendar> fromModel; | ||
private IModel<XMLGregorianCalendar> toModel; | ||
private IModel<String> initiatorModel; | ||
private IModel<String> channelModel; | ||
private IModel<String> channelListModel; | ||
private IModel<String> propertyModel; | ||
|
||
public PageAuditLogViewer(){ | ||
fromModel = new Model(); | ||
toModel = new Model(); | ||
initiatorModel = new Model(); | ||
channelModel = new Model(); | ||
channelListModel = new ListModel(new WebComponentUtil().getChannelList()); | ||
propertyModel = new Model(); | ||
initLayout(); | ||
} | ||
|
||
private void initLayout(){ | ||
Form mainForm = new Form(ID_MAIN_FORM); | ||
mainForm.setOutputMarkupId(true); | ||
add(mainForm); | ||
|
||
initParametersPanel(mainForm); | ||
initTable(mainForm); | ||
} | ||
|
||
private void initParametersPanel(Form mainForm){ | ||
WebMarkupContainer parametersPanel = new WebMarkupContainer(ID_PARAMETERS_PANEL); | ||
parametersPanel.setOutputMarkupId(true); | ||
mainForm.add(parametersPanel); | ||
|
||
final DatePanel from = new DatePanel(ID_FROM, fromModel); | ||
from.setOutputMarkupId(true); | ||
parametersPanel.add(from); | ||
|
||
final DatePanel to = new DatePanel(ID_TO, toModel); | ||
to.setOutputMarkupId(true); | ||
parametersPanel.add(to); | ||
|
||
final TextPanel initiator = new TextPanel(ID_INITIATOR, initiatorModel); | ||
initiator.setOutputMarkupId(true); | ||
parametersPanel.add(initiator); | ||
|
||
final DropDownChoicePanel channel = new DropDownChoicePanel(ID_CHANNEL, channelModel, channelListModel); | ||
channel.setOutputMarkupId(true); | ||
parametersPanel.add(channel); | ||
|
||
final TextPanel property = new TextPanel(ID_PROPERTY, propertyModel); | ||
property.setOutputMarkupId(true); | ||
parametersPanel.add(property); | ||
|
||
AjaxButton ajaxButton = new AjaxButton(ID_SEARCH_BUTTON, createStringResource("BasicSearchPanel.search")) { | ||
@Override | ||
public void onClick(AjaxRequestTarget arg0) { | ||
Form mainForm = (Form)get(ID_MAIN_FORM); | ||
initTable(mainForm); | ||
arg0.add(mainForm); | ||
// TODO Auto-generated method stub | ||
} | ||
}; | ||
ajaxButton.setOutputMarkupId(true); | ||
parametersPanel.add(ajaxButton); | ||
} | ||
|
||
private void initTable(Form mainForm){ | ||
AuditEventRecordProvider provider = new AuditEventRecordProvider(PageAuditLogViewer.this); | ||
BoxedTablePanel table = new BoxedTablePanel(ID_TABLE, provider, | ||
initColumns(), | ||
UserProfileStorage.TableId.PAGE_AUDIT_LOG_VIEWER, | ||
(int) getItemsPerPage(UserProfileStorage.TableId.PAGE_AUDIT_LOG_VIEWER)); | ||
table.setShowPaging(true); | ||
table.setOutputMarkupId(true); | ||
mainForm.add(table); | ||
} | ||
|
||
private List<IColumn<SelectableBean<AuditEventRecordType>, String>> initColumns() { | ||
List<IColumn<SelectableBean<AuditEventRecordType>, String>> columns = new ArrayList<>(); | ||
IColumn timeColumn = new PropertyColumn(createStringResource("PageAuditLogViewer.column.time"), "timestamp"); | ||
columns.add(timeColumn); | ||
IColumn initiatorColumn = new PropertyColumn(createStringResource("PageAuditLogViewer.column.initiatorRef"), "initiatorRef"); | ||
columns.add(initiatorColumn); | ||
IColumn taskIdentifierColumn = new PropertyColumn(createStringResource("PageAuditLogViewer.column.taskIdentifier"), "taskIdentifier"); | ||
columns.add(taskIdentifierColumn); | ||
IColumn channelColumn = new PropertyColumn(createStringResource("PageAuditLogViewer.column.channel"), "channel"); | ||
columns.add(channelColumn); | ||
IColumn deltaColumn = new PropertyColumn(createStringResource("PageAuditLogViewer.column.delta"), "delta"); | ||
columns.add(deltaColumn); | ||
return columns; | ||
} | ||
|
||
} |
Oops, something went wrong.