From 7250b799d092891556f8e1fb42f4d8223ce25d3b Mon Sep 17 00:00:00 2001 From: "Maria Odea B. Ching" Date: Tue, 15 Dec 2009 17:50:10 +0000 Subject: [PATCH] [MRM-1296] Audit Log Report o fixed pagination o prettify report UI git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1296@890916 13f79535-47bb-0310-9956-ffa450edef68 --- .../reports/ViewAuditLogReportAction.java | 131 ++++++++++---- .../WEB-INF/jsp/reports/auditLogReport.jsp | 163 ++++++++++-------- .../src/main/webapp/css/site.css | 44 ++++- 3 files changed, 240 insertions(+), 98 deletions(-) diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/reports/ViewAuditLogReportAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/reports/ViewAuditLogReportAction.java index 24a8ed197..3b4c11546 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/reports/ViewAuditLogReportAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/reports/ViewAuditLogReportAction.java @@ -24,10 +24,11 @@ import java.util.Calendar; import java.util.Collections; import java.util.Date; import java.util.List; -import java.util.regex.Pattern; import javax.servlet.http.HttpServletRequest; +import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang.time.DateUtils; import org.apache.maven.archiva.database.ArchivaAuditLogsDao; import org.apache.maven.archiva.database.ArchivaDAO; import org.apache.maven.archiva.database.ArchivaDatabaseException; @@ -82,10 +83,10 @@ public class ViewAuditLogReportAction private String artifactId; - private Date startDate; - - private Date endDate; + private String startDate; + private String endDate; + private int rowCount = 30; private int page = 1; @@ -101,6 +102,18 @@ public class ViewAuditLogReportAction private static final String ALL_REPOSITORIES = "all"; protected int[] range = new int[2]; + + private String initial = "true"; + + private String headerName; + + private static final String HEADER_LATEST_EVENTS = "Latest Events"; + + private static final String HEADER_RESULTS = "Results"; + + private String[] datePatterns = new String[] { "MM/dd/yy", "MM/dd/yyyy", "MMMMM/dd/yyyy", "MMMMM/dd/yy", + "dd MMMMM yyyy", "dd/MM/yy", "dd/MM/yyyy", "yyyy/MM/dd", "yyyy-MM-dd", "yyyy-dd-MM", "MM-dd-yyyy", + "MM-dd-yy" }; public SecureActionBundle getSecureActionBundle() throws SecureActionException @@ -125,6 +138,15 @@ public class ViewAuditLogReportAction groupId = ""; artifactId = ""; repository = ""; + + if( Boolean.parseBoolean( initial ) ) + { + headerName = HEADER_LATEST_EVENTS; + } + else + { + headerName = HEADER_RESULTS; + } SimpleConstraint constraint = new MostRecentArchivaAuditLogsConstraint(); auditLogs = (List) dao.query( constraint ); @@ -144,44 +166,72 @@ public class ViewAuditLogReportAction { artifact = ( artifactId != null && !"".equals( artifactId.trim() ) ) ? ( "%:" + artifactId + ":%" ) : ""; } - - if ( startDate == null ) - { + + Date startDateInDF = null; + Date endDateInDF = null; + if ( startDate == null || "".equals( startDate ) ) + { Calendar cal = Calendar.getInstance(); cal.set( Calendar.HOUR, 0 ); cal.set( Calendar.MINUTE, 0 ); cal.set( Calendar.SECOND, 0 ); - startDate = cal.getTime(); + startDateInDF = cal.getTime(); + } + else + { + startDateInDF = DateUtils.parseDate( startDate, datePatterns ); } - if ( startDate.equals( endDate ) || endDate == null ) + if ( endDate == null || "".equals( endDate ) ) { - endDate = Calendar.getInstance().getTime(); + endDateInDF = Calendar.getInstance().getTime(); + } + else + { + endDateInDF = DateUtils.parseDate( endDate, datePatterns ); + if( endDate.equals( startDate ) ) + { + Calendar cal = Calendar.getInstance(); + cal.setTime( endDateInDF ); + cal.set( Calendar.HOUR, 23 ); + cal.set( Calendar.MINUTE, 59 ); + cal.set( Calendar.SECOND, 59 ); + + endDateInDF = cal.getTime(); + } } range[0] = ( page - 1 ) * rowCount; range[1] = ( page * rowCount ) + 1; - + ArchivaAuditLogsConstraint constraint = null; if ( !repository.equals( ALL_REPOSITORIES ) ) { constraint = - new ArchivaAuditLogsConstraint( range, artifact, repository, AuditEvent.UPLOAD_FILE, startDate, endDate ); + new ArchivaAuditLogsConstraint( range, artifact, repository, AuditEvent.UPLOAD_FILE, startDateInDF, endDateInDF ); } else { constraint = - new ArchivaAuditLogsConstraint( range, artifact, null, AuditEvent.UPLOAD_FILE, startDate, endDate ); + new ArchivaAuditLogsConstraint( range, artifact, null, AuditEvent.UPLOAD_FILE, startDateInDF, endDateInDF ); } try { - auditLogs = auditLogsDao.queryAuditLogs( constraint ); + auditLogs = auditLogsDao.queryAuditLogs( constraint ); if( auditLogs.isEmpty() ) { addActionError( "No audit logs found." ); + initial = "true"; + } + else + { + initial = "false"; } + + headerName = HEADER_RESULTS; + paginate(); } catch ( ObjectNotFoundException e ) { @@ -193,31 +243,34 @@ public class ViewAuditLogReportAction addActionError( "Error occurred while querying audit logs." ); return ERROR; } - - // pagination - paginate(); - - startDate = null; - endDate = null; return SUCCESS; } - + private void paginate() { if ( auditLogs.size() <= rowCount ) { isLastPage = true; } + else + { + isLastPage = false; + auditLogs.remove( rowCount ); + } prev = request.getRequestURL() + "?page=" + ( page - 1 ) + "&rowCount=" + rowCount + "&groupId=" + groupId + - "&artifactId=" + artifactId + "&repositoryId=" + repository + "&startDate=" + startDate + "&endDate=" + + "&artifactId=" + artifactId + "&repository=" + repository + "&startDate=" + startDate + "&endDate=" + endDate; + next = request.getRequestURL() + "?page=" + ( page + 1 ) + "&rowCount=" + rowCount + "&groupId=" + groupId + - "&artifactId=" + artifactId + "&repositoryId=" + repository + "&startDate=" + startDate + "&endDate=" + + "&artifactId=" + artifactId + "&repository=" + repository + "&startDate=" + startDate + "&endDate=" + endDate; + + prev = StringUtils.replace( prev, " ", "%20" ); + next = StringUtils.replace( next, " ", "%20" ); } private List getObservableRepositories() @@ -301,22 +354,22 @@ public class ViewAuditLogReportAction this.rowCount = rowCount; } - public Date getStartDate() + public String getStartDate() { return startDate; } - public void setStartDate( Date startDate ) + public void setStartDate( String startDate ) { this.startDate = startDate; } - public Date getEndDate() + public String getEndDate() { return endDate; } - public void setEndDate( Date endDate ) + public void setEndDate( String endDate ) { this.endDate = endDate; } @@ -331,12 +384,12 @@ public class ViewAuditLogReportAction this.page = page; } - public boolean isLastPage() + public boolean getIsLastPage() { return isLastPage; } - public void setLastPage( boolean isLastPage ) + public void setIsLastPage( boolean isLastPage ) { this.isLastPage = isLastPage; } @@ -360,4 +413,24 @@ public class ViewAuditLogReportAction { this.next = next; } + + public String getInitial() + { + return initial; + } + + public void setInitial( String initial ) + { + this.initial = initial; + } + + public String getHeaderName() + { + return headerName; + } + + public void setHeaderName( String headerName ) + { + this.headerName = headerName; + } } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/reports/auditLogReport.jsp b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/reports/auditLogReport.jsp index ece7ca95c..664f8e7fa 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/reports/auditLogReport.jsp +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/reports/auditLogReport.jsp @@ -46,79 +46,106 @@ -

- -

- + +
- - - - - - - - <%-- - - --%> - - - <%-- - - --%> - - - - - - - << - Page: ${page} - - >> - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Repository:
Group ID:
Artifact ID:
Start Date: + <%-- + + --%> +
End Date: + <%-- + + --%> +
Row Count:
+
+ +

+ +

+ +

${headerName}

+

+ +

+ + + + + + + + + + + + + + + + + + + + +
EventRepositoryArtifactEvent DateUsername
${auditLog.event}${auditLog.repositoryId}${auditLog.artifact}${auditLog.eventDate}${auditLog.username}
+ + + << + Page: ${page} + + >> +
+
- - - - - - - - - - - - - - - - - - - - - - -
EventRepositoryArtifactEvent DateUsername
${auditLog.event}${auditLog.repositoryId}${auditLog.artifact}${auditLog.eventDate}${auditLog.username}
-
+ diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/css/site.css b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/css/site.css index a68b439a2..996614608 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/css/site.css +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/css/site.css @@ -435,4 +435,46 @@ div.versions { div.versions a.expand { font-size: 7pt; color: gray; -} \ No newline at end of file +} + +table.auditlogs { + text-align: center; + font-family: Verdana, Geneva, Arial, Helvetica, sans-serif ; + font-weight: normal; + font-size: 11px; + color: #fff; + width: 100%; + background-color: #666; + border: 0px; + border-collapse: collapse; + border-spacing: 0px; +} + +table.auditlogs th { + background-color: #666; + color: #fff; + padding: 4px; + text-align: center; + border-bottom: 2px #fff solid; + font-size: 12px; + font-weight: bold; +} + +table.auditlogs td { + background-color: #CCC; + color: #000; + padding: 4px; + text-align: center; + border: 1px #fff solid; +} + +div.auditLogReportResults { + border: 1px dashed #DFDEDE; + margin-bottom: 15px; + margin-left: 2px; + padding: 5px; +} + + + + -- 2.39.5