mirror of https://github.com/apache/archiva.git
[MRM-1296] Audit Log Reports
o fixed query for recent audit logs o added bits for pagination git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1296@890604 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
15768140dd
commit
9557917486
|
@ -30,23 +30,13 @@ public class ArchivaAuditLogsConstraint
|
||||||
extends RangeConstraint
|
extends RangeConstraint
|
||||||
{
|
{
|
||||||
private String whereClause;
|
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,
|
private void createWhereClause( String desiredArtifact, String desiredRepositoryId, String desiredEvent,
|
||||||
Date startDate, Date endDate )
|
Date startDate, Date endDate )
|
||||||
{
|
{
|
||||||
whereClause = "eventDate >= desiredStartDate && eventDate <= desiredEndDate";
|
whereClause = "eventDate >= desiredStartDate && eventDate <= desiredEndDate";
|
||||||
|
|
||||||
declImports = new String[] { "import java.util.Date" };
|
declImports = new String[] { "import java.util.Date" };
|
||||||
|
|
||||||
List<String> declParamsList = new ArrayList<String>();
|
List<String> declParamsList = new ArrayList<String>();
|
||||||
declParamsList.add( "Date desiredStartDate" );
|
declParamsList.add( "Date desiredStartDate" );
|
||||||
declParamsList.add( "Date desiredEndDate" );
|
declParamsList.add( "Date desiredEndDate" );
|
||||||
|
|
|
@ -20,6 +20,7 @@ package org.apache.maven.archiva.database.constraints;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.apache.maven.archiva.model.ArchivaAuditLogs;
|
import org.apache.maven.archiva.model.ArchivaAuditLogs;
|
||||||
|
import org.apache.maven.archiva.repository.audit.AuditEvent;
|
||||||
|
|
||||||
public class MostRecentArchivaAuditLogsConstraint
|
public class MostRecentArchivaAuditLogsConstraint
|
||||||
extends AbstractSimpleConstraint
|
extends AbstractSimpleConstraint
|
||||||
|
@ -28,7 +29,12 @@ public class MostRecentArchivaAuditLogsConstraint
|
||||||
|
|
||||||
public 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()
|
public Class<?> getResultClass()
|
||||||
|
|
|
@ -28,9 +28,10 @@ import java.util.List;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import org.apache.maven.archiva.database.ArchivaAuditLogsDao;
|
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.ArchivaDatabaseException;
|
||||||
import org.apache.maven.archiva.database.Constraint;
|
|
||||||
import org.apache.maven.archiva.database.ObjectNotFoundException;
|
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.ArchivaAuditLogsConstraint;
|
||||||
import org.apache.maven.archiva.database.constraints.MostRecentArchivaAuditLogsConstraint;
|
import org.apache.maven.archiva.database.constraints.MostRecentArchivaAuditLogsConstraint;
|
||||||
import org.apache.maven.archiva.model.ArchivaAuditLogs;
|
import org.apache.maven.archiva.model.ArchivaAuditLogs;
|
||||||
|
@ -66,6 +67,11 @@ public class ViewAuditLogReportAction
|
||||||
*/
|
*/
|
||||||
private ArchivaAuditLogsDao auditLogsDao;
|
private ArchivaAuditLogsDao auditLogsDao;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @plexus.requirement role-hint="jdo"
|
||||||
|
*/
|
||||||
|
private ArchivaDAO dao;
|
||||||
|
|
||||||
private String repository;
|
private String repository;
|
||||||
|
|
||||||
private List<String> repositories;
|
private List<String> repositories;
|
||||||
|
@ -80,11 +86,13 @@ public class ViewAuditLogReportAction
|
||||||
|
|
||||||
private int rowCount = 30;
|
private int rowCount = 30;
|
||||||
|
|
||||||
private int page;
|
private int page = 1;
|
||||||
|
|
||||||
private List<ArchivaAuditLogs> auditLogs;
|
private List<ArchivaAuditLogs> auditLogs;
|
||||||
|
|
||||||
private static final String ALL_REPOSITORIES = "all";
|
private static final String ALL_REPOSITORIES = "all";
|
||||||
|
|
||||||
|
protected int[] range = new int[2];
|
||||||
|
|
||||||
public SecureActionBundle getSecureActionBundle()
|
public SecureActionBundle getSecureActionBundle()
|
||||||
throws SecureActionException
|
throws SecureActionException
|
||||||
|
@ -97,6 +105,7 @@ public class ViewAuditLogReportAction
|
||||||
this.request = request;
|
this.request = request;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings( "unchecked" )
|
||||||
public void prepare()
|
public void prepare()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
@ -106,34 +115,22 @@ public class ViewAuditLogReportAction
|
||||||
|
|
||||||
auditLogs = null;
|
auditLogs = null;
|
||||||
|
|
||||||
Constraint constraint = new MostRecentArchivaAuditLogsConstraint();
|
SimpleConstraint constraint = new MostRecentArchivaAuditLogsConstraint();
|
||||||
|
auditLogs = (List<ArchivaAuditLogs>) dao.query( constraint );
|
||||||
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." );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String execute()
|
public String execute()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
auditLogs = null;
|
auditLogs = null;
|
||||||
String artifact = null;
|
String artifact = "";
|
||||||
|
|
||||||
if( groupId != null || !"".equals( groupId ) )
|
if( groupId != null || !"".equals( groupId.trim() ) )
|
||||||
{
|
{
|
||||||
artifact = groupId;
|
artifact = groupId;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( artifactId != null || !"".equals( artifactId ) )
|
if( artifactId != null || !"".equals( artifactId.trim() ) )
|
||||||
{
|
{
|
||||||
artifact = artifact + ":" + artifactId;
|
artifact = artifact + ":" + artifactId;
|
||||||
}
|
}
|
||||||
|
@ -153,13 +150,13 @@ public class ViewAuditLogReportAction
|
||||||
endDate = Calendar.getInstance().getTime();
|
endDate = Calendar.getInstance().getTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
int[] range = {1, 30 };
|
range[0] = ( page - 1 ) * rowCount;
|
||||||
|
range[1] = ( page * rowCount ) + 1;
|
||||||
|
|
||||||
ArchivaAuditLogsConstraint constraint = null;
|
ArchivaAuditLogsConstraint constraint = null;
|
||||||
if( !repository.equals( ALL_REPOSITORIES ) )
|
if( !repository.equals( ALL_REPOSITORIES ) )
|
||||||
{
|
{
|
||||||
//constraint = new ArchivaAuditLogsConstraint( range, artifact, repository, AuditEvent.UPLOAD_FILE, startDate, endDate );
|
constraint = new ArchivaAuditLogsConstraint( range, artifact, repository, AuditEvent.UPLOAD_FILE, startDate, endDate );
|
||||||
constraint = new ArchivaAuditLogsConstraint( artifact, repository, AuditEvent.UPLOAD_FILE, startDate, endDate );
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -80,30 +80,34 @@
|
||||||
<s:textfield label="Row Count" name="rowCount" />
|
<s:textfield label="Row Count" name="rowCount" />
|
||||||
|
|
||||||
<s:submit value="View Audit Log"/>
|
<s:submit value="View Audit Log"/>
|
||||||
</div>
|
</div>
|
||||||
</s:form>
|
|
||||||
|
</s:form>
|
||||||
|
|
||||||
<c:if test="${not empty (auditLogs)}">
|
<c:if test="${not empty (auditLogs)}">
|
||||||
<table border="1">
|
<table border="1">
|
||||||
<tr>
|
<thead>
|
||||||
<th align="center">Event</th>
|
<tr>
|
||||||
<th align="center">Repository</th>
|
<th align="center">Event</th>
|
||||||
<th align="center">Artifact</th>
|
<th align="center">Repository</th>
|
||||||
<th align="center">Event Date</th>
|
<th align="center">Artifact</th>
|
||||||
<th align="center">Username</th>
|
<th align="center">Event Date</th>
|
||||||
</tr>
|
<th align="center">Username</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
<c:forEach items="${auditLogs}" var="auditLog" varStatus="i">
|
<c:forEach items="${auditLogs}" var="auditLog" varStatus="i">
|
||||||
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<td>${auditLog.event}</td>
|
<td>${auditLog.event}</td>
|
||||||
<td>${auditLog.repositoryId}</td>
|
<td>${auditLog.repositoryId}</td>
|
||||||
<td>${auditLog.artifact}</td>
|
<td>${auditLog.artifact}</td>
|
||||||
<td>${auditLog.eventDate}</td>
|
<td>${auditLog.eventDate}</td>
|
||||||
<td>${auditLog.username}</td>
|
<td>${auditLog.username}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
</tbody>
|
||||||
</c:forEach>
|
</c:forEach>
|
||||||
</table>
|
</table>
|
||||||
</c:if>
|
</c:if>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
Loading…
Reference in New Issue