archiva-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From och...@apache.org
Subject svn commit: r890361 - in /archiva/branches/MRM-1296/archiva-modules: archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/ archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/ archiva-web/archiva-webapp/src/main...
Date Mon, 14 Dec 2009 15:08:04 GMT
Author: oching
Date: Mon Dec 14 15:08:03 2009
New Revision: 890361

URL: http://svn.apache.org/viewvc?rev=890361&view=rev
Log:
[MRM-1296] Audit Log Report
o added constraint for custom query
o support custom query in view audit log action

Added:
    archiva/branches/MRM-1296/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/ArchivaAuditLogsConstraint.java
Modified:
    archiva/branches/MRM-1296/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoAccess.java
    archiva/branches/MRM-1296/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArchivaAuditLogsDao.java
    archiva/branches/MRM-1296/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/reports/ViewAuditLogReportAction.java
    archiva/branches/MRM-1296/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/reports/auditLogReport.jsp

Added: archiva/branches/MRM-1296/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/ArchivaAuditLogsConstraint.java
URL: http://svn.apache.org/viewvc/archiva/branches/MRM-1296/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/ArchivaAuditLogsConstraint.java?rev=890361&view=auto
==============================================================================
--- archiva/branches/MRM-1296/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/ArchivaAuditLogsConstraint.java
(added)
+++ archiva/branches/MRM-1296/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/ArchivaAuditLogsConstraint.java
Mon Dec 14 15:08:03 2009
@@ -0,0 +1,116 @@
+package org.apache.maven.archiva.database.constraints;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * ArchivaAuditLogsConstraint
+ */
+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";
+
+        declImports = new String[] { "import java.util.Date" };
+
+        List<String> declParamsList = new ArrayList<String>();
+        declParamsList.add( "Date desiredStartDate" );
+        declParamsList.add( "Date desiredEndDate" );
+
+        List<Object> paramsList = new ArrayList<Object>();
+        paramsList.add( startDate );
+        paramsList.add( endDate );
+
+        if ( desiredArtifact != null && !"".equals( desiredArtifact ) )
+        {
+            whereClause = whereClause + " && artifact.like(desiredArtifact)";
+            declParamsList.add( "String desiredArtifact" );
+            paramsList.add( desiredArtifact + "%" );
+        }
+
+        if ( desiredRepositoryId != null && !"".equals( desiredRepositoryId ) )
+        {
+            whereClause = whereClause + " && repositoryId == desiredRepositoryId";
+            declParamsList.add( "String desiredRepositoryId" );
+            paramsList.add( desiredRepositoryId );
+        }
+
+        if ( desiredEvent != null && !"".equals( desiredEvent ) )
+        {
+            whereClause = whereClause + " && event ==  desiredEvent";
+            declParamsList.add( "String desiredEvent" );
+            paramsList.add( desiredEvent );
+        }
+
+        int size = declParamsList.size();
+        int i = 0;
+        declParams = new String[size];       
+        
+        while( i < size )
+        {
+            declParams[i] = declParamsList.get( i );
+            i++;
+        }        
+        
+        params = paramsList.toArray();
+    }
+
+    public ArchivaAuditLogsConstraint( int[] range, String desiredArtifact, String desiredRepositoryId,
+                                       String desiredEvent, Date startDate, Date endDate
)
+    {
+        super( range );
+        createWhereClause( desiredArtifact, desiredRepositoryId, desiredEvent, startDate,
endDate );
+    }
+    
+    public ArchivaAuditLogsConstraint( String desiredArtifact, String desiredRepositoryId,
+                                       String desiredEvent, Date startDate, Date endDate
)
+    {
+        super();
+        createWhereClause( desiredArtifact, desiredRepositoryId, desiredEvent, startDate,
endDate );
+    }
+
+
+    public String getSortColumn()
+    {
+        return "eventDate";
+    }
+
+    public String getWhereCondition()
+    {
+        return whereClause;
+    }
+}

Modified: archiva/branches/MRM-1296/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoAccess.java
URL: http://svn.apache.org/viewvc/archiva/branches/MRM-1296/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoAccess.java?rev=890361&r1=890360&r2=890361&view=diff
==============================================================================
--- archiva/branches/MRM-1296/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoAccess.java
(original)
+++ archiva/branches/MRM-1296/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoAccess.java
Mon Dec 14 15:08:03 2009
@@ -395,7 +395,7 @@
             case 3:
                 return (List<?>) query.execute( parameters[0], parameters[1], parameters[2]
);
             default:
-                throw new JDOException( "Unable to use more than 3 parameters." );
+                return (List<?>) query.executeWithArray( parameters );            
   
         }
     }
 

Modified: archiva/branches/MRM-1296/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArchivaAuditLogsDao.java
URL: http://svn.apache.org/viewvc/archiva/branches/MRM-1296/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArchivaAuditLogsDao.java?rev=890361&r1=890360&r2=890361&view=diff
==============================================================================
--- archiva/branches/MRM-1296/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArchivaAuditLogsDao.java
(original)
+++ archiva/branches/MRM-1296/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArchivaAuditLogsDao.java
Mon Dec 14 15:08:03 2009
@@ -48,6 +48,7 @@
         jdo.removeObject( logs );
     }
 
+    @SuppressWarnings( "unchecked" )
     public List<ArchivaAuditLogs> queryAuditLogs( Constraint constraint )
         throws ObjectNotFoundException, ArchivaDatabaseException
     {

Modified: archiva/branches/MRM-1296/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/reports/ViewAuditLogReportAction.java
URL: http://svn.apache.org/viewvc/archiva/branches/MRM-1296/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/reports/ViewAuditLogReportAction.java?rev=890361&r1=890360&r2=890361&view=diff
==============================================================================
--- archiva/branches/MRM-1296/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/reports/ViewAuditLogReportAction.java
(original)
+++ archiva/branches/MRM-1296/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/reports/ViewAuditLogReportAction.java
Mon Dec 14 15:08:03 2009
@@ -20,7 +20,9 @@
  */
 
 import java.util.ArrayList;
+import java.util.Calendar;
 import java.util.Collections;
+import java.util.Date;
 import java.util.List;
 
 import javax.servlet.http.HttpServletRequest;
@@ -29,8 +31,10 @@
 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.constraints.ArchivaAuditLogsConstraint;
 import org.apache.maven.archiva.database.constraints.MostRecentArchivaAuditLogsConstraint;
 import org.apache.maven.archiva.model.ArchivaAuditLogs;
+import org.apache.maven.archiva.repository.audit.AuditEvent;
 import org.apache.maven.archiva.security.AccessDeniedException;
 import org.apache.maven.archiva.security.ArchivaSecurityException;
 import org.apache.maven.archiva.security.PrincipalNotFoundException;
@@ -69,11 +73,19 @@
     private String groupId;
     
     private String artifactId;
+    
+    private Date startDate;
+
+    private Date endDate;
         
     private int rowCount = 30;
     
-    private List<ArchivaAuditLogs> auditLogs = new ArrayList<ArchivaAuditLogs>();
   
+    private int page;
+
+    private List<ArchivaAuditLogs> auditLogs;    
     
+    private static final String ALL_REPOSITORIES = "all";
+        
     public SecureActionBundle getSecureActionBundle()
         throws SecureActionException
     {        
@@ -88,7 +100,11 @@
     public void prepare()
         throws Exception
     {     
-        repositories = getObservableRepositories();
+        repositories = new ArrayList<String>();
+        repositories.add( ALL_REPOSITORIES );
+        repositories.addAll( getObservableRepositories() );
+        
+        auditLogs = null;
         
         Constraint constraint = new MostRecentArchivaAuditLogsConstraint();
         
@@ -108,7 +124,65 @@
     
     public String execute()
         throws Exception
-    {   
+    {     
+        auditLogs = null;
+        String artifact = null;
+        
+        if( groupId != null || !"".equals( groupId ) )
+        {
+            artifact = groupId;
+        }
+        
+        if( artifactId != null || !"".equals( artifactId ) )
+        {
+            artifact = artifact + ":" + artifactId;
+        }
+        
+        if( startDate == null )
+        {
+            Calendar cal = Calendar.getInstance();
+            cal.set( Calendar.HOUR, 0 );
+            cal.set( Calendar.MINUTE, 0 );
+            cal.set( Calendar.SECOND, 0 );            
+            
+            startDate = cal.getTime(); 
+        }
+        
+        if( startDate.equals( endDate ) || endDate == null )
+        {
+            endDate = Calendar.getInstance().getTime();
+        }
+                
+        int[] range = {1, 30 };        
+
+        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 );
+        }
+        else
+        {
+            constraint = new ArchivaAuditLogsConstraint( range, artifact, null, AuditEvent.UPLOAD_FILE,
startDate, endDate );
+        }
+        
+        try
+        {
+            auditLogs = auditLogsDao.queryAuditLogs( constraint );
+            startDate = null;
+            endDate = null;
+        }
+        catch ( ObjectNotFoundException e )
+        {
+            addActionError( "No audit logs found." );
+            return ERROR;
+        }
+        catch( ArchivaDatabaseException e )
+        {
+            addActionError( "Error occurred while querying audit logs." );
+            return ERROR;
+        }
+        
         return SUCCESS;
     }
     
@@ -192,4 +266,34 @@
     {
         this.rowCount = rowCount;
     }
+    
+    public Date getStartDate()
+    {
+        return startDate;
+    }
+
+    public void setStartDate( Date startDate )
+    {
+        this.startDate = startDate;
+    }
+
+    public Date getEndDate()
+    {
+        return endDate;
+    }
+
+    public void setEndDate( Date endDate )
+    {
+        this.endDate = endDate;
+    }
+    
+    public int getPage()
+    {
+        return page;
+    }
+
+    public void setPage( int page )
+    {
+        this.page = page;
+    }
 }

Modified: archiva/branches/MRM-1296/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/reports/auditLogReport.jsp
URL: http://svn.apache.org/viewvc/archiva/branches/MRM-1296/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/reports/auditLogReport.jsp?rev=890361&r1=890360&r2=890361&view=diff
==============================================================================
--- archiva/branches/MRM-1296/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/reports/auditLogReport.jsp
(original)
+++ archiva/branches/MRM-1296/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/reports/auditLogReport.jsp
Mon Dec 14 15:08:03 2009
@@ -83,25 +83,26 @@
     </div>
   </s:form> 
   
-  
-  <table border="1">
-    <tr>
-      <th align="center">Event</th>
-      <th align="center">Repository</th>
-      <th align="center">Artifact</th>
-      <th align="center">Event Date</th>
-      <th align="center">Username</th>
-    </tr>
-    <c:forEach items="${auditLogs}" var="auditLog" varStatus="i">
-      <tr>
-        <td>${auditLog.event}</td>
-        <td>${auditLog.repositoryId}</td>
-          <td>${auditLog.artifact}</td>
-          <td>${auditLog.eventDate}</td>
-          <td>${auditLog.username}</td>
-        </tr>
-    </c:forEach>
-  </table>   
+  <c:if test="${not empty (auditLogs)}">
+	  <table border="1">
+	    <tr>
+	      <th align="center">Event</th>
+	      <th align="center">Repository</th>
+	      <th align="center">Artifact</th>
+	      <th align="center">Event Date</th>
+	      <th align="center">Username</th>
+	    </tr>
+	    <c:forEach items="${auditLogs}" var="auditLog" varStatus="i">
+	      <tr>
+	        <td>${auditLog.event}</td>
+	        <td>${auditLog.repositoryId}</td>
+	          <td>${auditLog.artifact}</td>
+	          <td>${auditLog.eventDate}</td>
+	          <td>${auditLog.username}</td>
+	        </tr>
+	    </c:forEach>
+	  </table>   
+  </c:if>
 
 </div>
 



Mime
View raw message