diff --git a/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/ArchivaAuditLogsConstraint.java b/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/ArchivaAuditLogsConstraint.java index 2cf8e3ac3..a9c798f1f 100644 --- a/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/ArchivaAuditLogsConstraint.java +++ b/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/ArchivaAuditLogsConstraint.java @@ -30,23 +30,13 @@ public class ArchivaAuditLogsConstraint extends RangeConstraint { private String whereClause; - - /** - * Complete custom query! - * - * @param desiredArtifact - * @param desiredRepositoryId - * @param desiredEvent - * @param startDate - * @param endDate - */ + private void createWhereClause( String desiredArtifact, String desiredRepositoryId, String desiredEvent, Date startDate, Date endDate ) { - whereClause = "eventDate >= desiredStartDate && eventDate <= desiredEndDate"; - + whereClause = "eventDate >= desiredStartDate && eventDate <= desiredEndDate"; declImports = new String[] { "import java.util.Date" }; - + List declParamsList = new ArrayList(); declParamsList.add( "Date desiredStartDate" ); declParamsList.add( "Date desiredEndDate" ); diff --git a/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/MostRecentArchivaAuditLogsConstraint.java b/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/MostRecentArchivaAuditLogsConstraint.java index af3c791a3..8e2d00531 100644 --- a/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/MostRecentArchivaAuditLogsConstraint.java +++ b/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/MostRecentArchivaAuditLogsConstraint.java @@ -20,6 +20,7 @@ package org.apache.maven.archiva.database.constraints; */ import org.apache.maven.archiva.model.ArchivaAuditLogs; +import org.apache.maven.archiva.repository.audit.AuditEvent; public class MostRecentArchivaAuditLogsConstraint extends AbstractSimpleConstraint @@ -28,7 +29,12 @@ public class MostRecentArchivaAuditLogsConstraint public MostRecentArchivaAuditLogsConstraint() { - sql = "SELECT FROM " + ArchivaAuditLogs.class.getName() + " ORDER BY eventDate DESCENDING RANGE 0,1"; + sql = + "SELECT FROM " + ArchivaAuditLogs.class.getName() + + " WHERE event == uploadArtifact PARAMETERS String uploadArtifact" + + " ORDER BY eventDate DESCENDING RANGE 0,10"; + + super.params = new Object[] { AuditEvent.UPLOAD_FILE }; } public Class getResultClass() 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 392622302..ea9d9c411 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 @@ -28,9 +28,10 @@ import java.util.List; import javax.servlet.http.HttpServletRequest; import org.apache.maven.archiva.database.ArchivaAuditLogsDao; +import org.apache.maven.archiva.database.ArchivaDAO; import org.apache.maven.archiva.database.ArchivaDatabaseException; -import org.apache.maven.archiva.database.Constraint; import org.apache.maven.archiva.database.ObjectNotFoundException; +import org.apache.maven.archiva.database.SimpleConstraint; import org.apache.maven.archiva.database.constraints.ArchivaAuditLogsConstraint; import org.apache.maven.archiva.database.constraints.MostRecentArchivaAuditLogsConstraint; import org.apache.maven.archiva.model.ArchivaAuditLogs; @@ -66,6 +67,11 @@ public class ViewAuditLogReportAction */ private ArchivaAuditLogsDao auditLogsDao; + /** + * @plexus.requirement role-hint="jdo" + */ + private ArchivaDAO dao; + private String repository; private List repositories; @@ -80,11 +86,13 @@ public class ViewAuditLogReportAction private int rowCount = 30; - private int page; + private int page = 1; private List auditLogs; private static final String ALL_REPOSITORIES = "all"; + + protected int[] range = new int[2]; public SecureActionBundle getSecureActionBundle() throws SecureActionException @@ -97,6 +105,7 @@ public class ViewAuditLogReportAction this.request = request; } + @SuppressWarnings( "unchecked" ) public void prepare() throws Exception { @@ -106,34 +115,22 @@ public class ViewAuditLogReportAction auditLogs = null; - Constraint constraint = new MostRecentArchivaAuditLogsConstraint(); - - try - { - this.auditLogs = auditLogsDao.queryAuditLogs( constraint ); - } - catch( ObjectNotFoundException e ) - { - log.warn( "No audit logs found." ); - } - catch ( ArchivaDatabaseException e ) - { - log.warn( "Error occurred while querying audit logs." ); - } + SimpleConstraint constraint = new MostRecentArchivaAuditLogsConstraint(); + auditLogs = (List) dao.query( constraint ); } public String execute() throws Exception { auditLogs = null; - String artifact = null; + String artifact = ""; - if( groupId != null || !"".equals( groupId ) ) + if( groupId != null || !"".equals( groupId.trim() ) ) { artifact = groupId; } - if( artifactId != null || !"".equals( artifactId ) ) + if( artifactId != null || !"".equals( artifactId.trim() ) ) { artifact = artifact + ":" + artifactId; } @@ -153,13 +150,13 @@ public class ViewAuditLogReportAction endDate = Calendar.getInstance().getTime(); } - int[] range = {1, 30 }; + 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 ); - constraint = new ArchivaAuditLogsConstraint( artifact, repository, AuditEvent.UPLOAD_FILE, startDate, endDate ); + constraint = new ArchivaAuditLogsConstraint( range, artifact, repository, AuditEvent.UPLOAD_FILE, startDate, endDate ); } else { 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 6a84d1ebd..af853370b 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 @@ -80,30 +80,34 @@ - - + + + - + - - - - - - - + + + + + + + + + + - - - - + + + + +
EventRepositoryArtifactEvent DateUsername
EventRepositoryArtifactEvent DateUsername
${auditLog.event} ${auditLog.repositoryId}${auditLog.artifact}${auditLog.eventDate}${auditLog.username}
${auditLog.artifact}${auditLog.eventDate}${auditLog.username}
-
- +