]> source.dussan.org Git - archiva.git/commitdiff
[MRM-84]
authorMaria Odea B. Ching <oching@apache.org>
Thu, 2 Oct 2008 08:35:42 +0000 (08:35 +0000)
committerMaria Odea B. Ching <oching@apache.org>
Thu, 2 Oct 2008 08:35:42 +0000 (08:35 +0000)
-added row count config in statistics report
-added pagination in report

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@701033 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/reports/GenerateReportAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/reports/pickReport.jsp
archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/reports/statisticsReport.jsp

index f254422dff010fad48eab8882d76f65dd3f8e30c..0fcb6234247c87347dd9d75f11003a9a7330fdd8 100644 (file)
@@ -22,6 +22,8 @@ package org.apache.maven.archiva.web.action.reports;
 import com.opensymphony.webwork.interceptor.ServletRequestAware;
 import com.opensymphony.xwork.Preparable;
 
+import org.apache.commons.lang.time.DateFormatUtils;
+import org.apache.commons.lang.time.DateUtils;
 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
 import org.apache.maven.archiva.database.ArchivaDAO;
 import org.apache.maven.archiva.database.ArchivaDatabaseException;
@@ -51,6 +53,8 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import javax.servlet.http.HttpServletRequest;
+
+import java.text.ParseException;
 import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Collection;
@@ -123,9 +127,9 @@ public class GenerateReportAction
     
     private List<String> availableRepositories;  
     
-    private Date startDate;
+    private String startDate;
     
-    private Date endDate;
+    private String endDate;
     
     private int reposSize;
     
@@ -133,6 +137,11 @@ public class GenerateReportAction
     
     private List<RepositoryStatistics> repositoryStatistics = new ArrayList<RepositoryStatistics>();
     
+    private DataLimits limits = new DataLimits();
+    
+    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" };
+    
     public void prepare()
     {
         repositoryIds = new ArrayList<String>();
@@ -177,9 +186,48 @@ public class GenerateReportAction
      */
     public String generateStatistics()
     {   
-        DataLimits limits = new DataLimits();        
-        setDefaults();
+        if( rowCount < 10 )
+        {
+            addFieldError( "rowCount", "Row count must be larger than 10." );
+            return INPUT;
+        }
         reposSize = selectedRepositories.size();
+        Date startDateInDateFormat = null;
+        Date endDateInDateFormat = null;
+        
+        if( startDate == null || "".equals( startDate ) )
+        {
+            startDateInDateFormat = getDefaultStartDate();
+        }
+        else
+        {
+            try
+            {
+                startDateInDateFormat = DateUtils.parseDate( startDate, datePatterns );
+            }
+            catch ( ParseException e )
+            {
+                addFieldError( "startDate", "Invalid date format.");
+                return INPUT;
+            }
+        }
+        
+        if( endDate == null || "".equals( endDate ) )
+        {
+            endDateInDateFormat = getDefaultEndDate();
+        }
+        else
+        {
+            try
+            {
+                endDateInDateFormat = DateUtils.parseDate( endDate, datePatterns );                
+            }
+            catch ( ParseException e )
+            {
+                addFieldError( "endDate", "Invalid date format.");
+                return INPUT;
+            }
+        }
         
         try
         {
@@ -197,7 +245,7 @@ public class GenerateReportAction
                     try
                     {
                         List contentStats = repoContentStatsDao.queryRepositoryContentStatistics( 
-                           new RepositoryContentStatisticsByRepositoryConstraint( repo, startDate, endDate ) );
+                           new RepositoryContentStatisticsByRepositoryConstraint( repo, startDateInDateFormat, endDateInDateFormat ) );
                         
                         if( contentStats == null || contentStats.isEmpty() )
                         {
@@ -206,7 +254,7 @@ public class GenerateReportAction
                             
                             continue;
                         }                        
-                        repositoryStatistics.addAll( generator.generateReport( contentStats, repo, startDate, endDate, limits ) );
+                        repositoryStatistics.addAll( generator.generateReport( contentStats, repo, startDateInDateFormat, endDateInDateFormat, limits ) );
                     }
                     catch ( ObjectNotFoundException oe )
                     {
@@ -229,7 +277,7 @@ public class GenerateReportAction
                 try
                 {
                     List<RepositoryContentStatistics> contentStats = repoContentStatsDao.queryRepositoryContentStatistics( 
-                           new RepositoryContentStatisticsByRepositoryConstraint( selectedRepo, startDate, endDate ) );
+                           new RepositoryContentStatisticsByRepositoryConstraint( selectedRepo, startDateInDateFormat, endDateInDateFormat ) );
                     
                     if( contentStats == null || contentStats.isEmpty() )
                     {   
@@ -242,7 +290,7 @@ public class GenerateReportAction
                     int totalPages = ( limits.getTotalCount() / limits.getPerPageCount() ) + extraPage;                    
                     limits.setCountOfPages( totalPages );
                     
-                    repositoryStatistics = generator.generateReport( contentStats, selectedRepo, startDate, endDate, limits );
+                    repositoryStatistics = generator.generateReport( contentStats, selectedRepo, startDateInDateFormat, endDateInDateFormat, limits );
                 }
                 catch ( ObjectNotFoundException oe )
                 {
@@ -259,7 +307,23 @@ public class GenerateReportAction
             {
                 addFieldError( "availableRepositories", "Please select a repository (or repositories) from the list." );
                 return INPUT;
-            }            
+            } 
+            
+            if( repositoryStatistics.isEmpty() )
+            {
+                return BLANK;
+            }
+            
+            if( startDate.equals( getDefaultStartDate() ) )
+            {
+                startDate = null;
+            }
+            else
+            {   
+                startDate = DateFormatUtils.format( startDateInDateFormat, "MM/dd/yyyy" );                
+            }
+            
+            endDate = DateFormatUtils.format( endDateInDateFormat, "MM/dd/yyyy" );
         }
         catch ( ArchivaReportException e )
         {
@@ -269,21 +333,19 @@ public class GenerateReportAction
         
         return SUCCESS;
     }
-
-    private void setDefaults()
+    
+    private Date getDefaultStartDate()
     {
-        if( startDate == null )
-        {
-            Calendar cal = Calendar.getInstance();
-            cal.clear();
-            cal.set( 1900, 1, 1, 0, 0, 0 );
-            startDate = cal.getTime();
-        }
+        Calendar cal = Calendar.getInstance();
+        cal.clear();
+        cal.set( 1900, 1, 1, 0, 0, 0 );
         
-        if( endDate == null )
-        {
-            endDate = Calendar.getInstance().getTime();
-        }
+        return cal.getTime();
+    }
+    
+    private Date getDefaultEndDate()
+    {
+        return Calendar.getInstance().getTime();
     }
     
     public String execute()
@@ -525,22 +587,22 @@ public class GenerateReportAction
         this.availableRepositories = availableRepositories;
     }
 
-    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;
     }
@@ -574,4 +636,14 @@ public class GenerateReportAction
     {
         this.selectedRepo = selectedRepo;
     }
+
+    public DataLimits getLimits()
+    {
+        return limits;
+    }
+
+    public void setLimits( DataLimits limits )
+    {
+        this.limits = limits;
+    }
 }
index 5bcdb798645915205e2c819c4b9cfcc28e425f05..62c12bb38421151d9659431573387099d4b27320 100644 (file)
@@ -39,6 +39,7 @@
                
        <ww:datepicker label="Start Date" name="startDate" id="startDate"/>
        <ww:datepicker label="End Date" name="endDate" id="endDate"/>
+       <ww:textfield label="Row Count" name="rowCount" />
                    
     <ww:submit value="View Statistics"/>
   </ww:form>
index 8366f3eba3169a63850055cf44f3d70696a71a6d..dd70758c2fe64e7dcf52d9489f60ea3380a7a13b 100644 (file)
 <body>
 <h1>Statistics Report</h1>
 
+<c:url var="imgNextPageUrl" value="/images/icon_next_page.gif"/>
+<c:url var="imgPrevPageUrl" value="/images/icon_prev_page.gif"/>
+<c:url var="imgPrevPageDisabledUrl" value="/images/icon_prev_page_disabled.gif"/>
+<c:url var="imgNextPageDisabledUrl" value="/images/icon_next_page_disabled.gif"/>
+
 <div id="contentArea">                 
+
+  <%-- TODO: fix problem in date format! --%>
+
+  <%-- Pagination - start --%>  
+  <p>
+    
+    <%-- Set Prev & Next icons --%>
+  <c:set var="prevPageUrl">
+    <ww:url action="generateStatisticsReport" namespace="/report">
+      <ww:param name="selectedRepositories" value="%{'${selectedRepositories}'}"/>
+      <ww:param name="rowCount" value="%{'${rowCount}'}"/>
+      <ww:param name="startDate" value="%{'${startDate}'}"/>                      
+      <ww:param name="endDate" value="%{'${endDate}'}"/>
+      <ww:param name="page" value="%{'${page - 1}'}"/>
+    </ww:url>
+  </c:set>
+  <c:set var="nextPageUrl">
+    <ww:url action="generateStatisticsReport" namespace="/report">
+      <ww:param name="selectedRepositories" value="%{'${selectedRepositories}'}"/>
+      <ww:param name="rowCount" value="%{'${rowCount}'}"/>
+      <ww:param name="startDate" value="%{'${startDate}'}"/>                      
+      <ww:param name="endDate" value="%{'${endDate}'}"/>                
+      <ww:param name="page" value="%{'${page + 1}'}"/>
+    </ww:url>
+  </c:set>
+    
+  <c:choose>
+    <c:when test="${page == 1}">                               
+      <img src="${imgPrevPageDisabledUrl}"/>
+    </c:when>
+    <c:otherwise>
+      <a href="${prevPageUrl}">
+        <img src="${imgPrevPageUrl}"/>
+      </a>
+    </c:otherwise>
+  </c:choose>
+    
+  <%-- Google-style pagination --%>
+  <c:choose>
+    <c:when test="${limits.countOfPages > 11}">
+      <c:choose>
+        <c:when test="${(page - 5) < 0}">
+          <c:set var="beginVal">0</c:set>
+          <c:set var="endVal">10</c:set> 
+        </c:when>                              
+        <c:when test="${(page + 5) > (limits.countOfPages - 1)}">
+          <c:set var="beginVal">${(limits.countOfPages -1) - 10}</c:set>
+          <c:set var="endVal">${limits.countOfPages - 1}</c:set>
+        </c:when>
+        <c:otherwise>
+          <c:set var="beginVal">${page - 5}</c:set>
+          <c:set var="endVal">${page + 5}</c:set>
+        </c:otherwise>
+      </c:choose>  
+    </c:when>
+    <c:otherwise>
+      <c:set var="beginVal">0</c:set>
+      <c:set var="endVal">${limits.countOfPages - 1}</c:set> 
+    </c:otherwise>
+  </c:choose>
+    
+  <c:forEach var="i" begin="${beginVal}" end="${endVal}">      
+    <c:choose>                                             
+      <c:when test="${i != (page - 1)}">
+        <c:set var="specificPageUrl">
+          <ww:url action="generateStatisticsReport" namespace="/report">
+            <ww:param name="selectedRepositories" value="%{'${selectedRepositories}'}"/>
+            <ww:param name="rowCount" value="%{'${rowCount}'}"/>
+            <ww:param name="startDate" value="%{'${startDate}'}"/>                      
+            <ww:param name="endDate" value="%{'${endDate}'}"/>
+            <ww:param name="page" value="%{'${page + 1}'}"/>
+          </ww:url>
+        </c:set>
+        <a href="${specificPageUrl}">${i + 1}</a>
+      </c:when>
+      <c:otherwise>            
+        <b>${i + 1}</b>   
+      </c:otherwise>                                                       
+    </c:choose>      
+  </c:forEach>
+     
+  <c:choose>
+    <c:when test="${page == limits.countOfPages}">
+      <img src="${imgNextPageDisabledUrl}"/>
+    </c:when>
+    <c:otherwise>
+      <a href="${nextPageUrl}">
+        <img src="${imgNextPageUrl}"/>
+      </a>
+    </c:otherwise>   
+  </c:choose> 
+  </p>   
+  <%-- Pagination - end --%>
+  
   <c:choose>
-       <c:when test="${reposSize > 1}">
+    <c:when test="${reposSize > 1}">
        
-           <h1>Latest Statistics Comparison Report</h1>            
-               <table class="infoTable" border="1">
-               <tr>
-                 <th>Repository</th>
-                 <th>Total File Count</th>
-                 <th>Total Size</th>
-                 <th>Artifact Count</th>
-                 <th>Group Count</th>
-                 <th>Project Count</th>
-                 <th>Plugins</th>
-                 <th>Archetypes</th>
-                 <th>Jars</th>
-                 <th>Wars</th>
-                 <th>Deployments</th>
-                 <th>Downloads</th>
-               </tr>                   
+      <h1>Latest Statistics Comparison Report</h1>         
+      <table class="infoTable" border="1">
+        <tr>
+          <th>Repository</th>
+          <th>Total File Count</th>
+          <th>Total Size</th>
+          <th>Artifact Count</th>
+          <th>Group Count</th>
+          <th>Project Count</th>
+          <th>Plugins</th>
+          <th>Archetypes</th>
+          <th>Jars</th>
+          <th>Wars</th>
+          <th>Deployments</th>
+          <th>Downloads</th>
+        </tr>                  
                
-               <c:forEach var="stats" items="${repositoryStatistics}">
-                       <tr>
-                               <td>${stats.repositoryId}</td>
-                               <td align="right">${stats.fileCount}</td>
-                               <td align="right">${stats.totalSize}</td>
-                               <td align="right">${stats.artifactCount}</td>
-                               <td align="right">${stats.groupCount}</td>
-                               <td align="right">${stats.projectCount}</td>
-                               <td align="right">${stats.pluginCount}</td>
-                               <td align="right">${stats.archetypeCount}</td>
-                               <td align="right">${stats.jarCount}</td>
-                               <td align="right">${stats.warCount}</td>
-                               <td align="right">${stats.deploymentCount}</td>
-                               <td align="right">${stats.downloadCount}</td>
-                       </tr>                           
-               </c:forEach>
-         </table>
-               
-       </c:when>
-       <c:otherwise>
+        <c:forEach var="stats" items="${repositoryStatistics}">
+        <tr>
+          <td>${stats.repositoryId}</td>
+          <td align="right">${stats.fileCount}</td>
+          <td align="right">${stats.totalSize}</td>
+          <td align="right">${stats.artifactCount}</td>
+          <td align="right">${stats.groupCount}</td>
+          <td align="right">${stats.projectCount}</td>
+          <td align="right">${stats.pluginCount}</td>
+          <td align="right">${stats.archetypeCount}</td>
+          <td align="right">${stats.jarCount}</td>
+          <td align="right">${stats.warCount}</td>
+          <td align="right">${stats.deploymentCount}</td>
+          <td align="right">${stats.downloadCount}</td>
+        </tr>                          
+        </c:forEach>
+      </table>                 
+    </c:when>
+    <c:otherwise>
        
-               <h1>Statistics for Repository '${selectedRepo}'</h1>
-               <table class="infoTable" border="1">
-                       <tr>
-                         <th>Date of Scan</th>
-                         <th>Total File Count</th>
-                         <th>Total Size</th>
-                         <th>Artifact Count</th>
-                         <th>Group Count</th>
-                         <th>Project Count</th>
-                         <th>Plugins</th>
-                         <th>Archetypes</th>
-                         <th>Jars</th>
-                         <th>Wars</th>
-                         <th>Deployments</th>
-                         <th>Downloads</th>
-                       </tr>                   
+      <h1>Statistics for Repository '${selectedRepo}'</h1>
+      <table class="infoTable" border="1">
+        <tr>
+          <th>Date of Scan</th>
+          <th>Total File Count</th>
+          <th>Total Size</th>
+          <th>Artifact Count</th>
+          <th>Group Count</th>
+          <th>Project Count</th>
+          <th>Plugins</th>
+          <th>Archetypes</th>
+          <th>Jars</th>
+          <th>Wars</th>
+          <th>Deployments</th>
+          <th>Downloads</th>
+        </tr>                  
                        
-                       <c:forEach var="stats" items="${repositoryStatistics}">
-                               <tr>
-                                       <td align="right">${stats.dateOfScan}</td>
-                                       <td align="right">${stats.fileCount}</td>
-                                       <td align="right">${stats.totalSize}</td>
-                                       <td align="right">${stats.artifactCount}</td>
-                                       <td align="right">${stats.groupCount}</td>
-                                       <td align="right">${stats.projectCount}</td>
-                                       <td align="right">${stats.pluginCount}</td>
-                                       <td align="right">${stats.archetypeCount}</td>
-                                       <td align="right">${stats.jarCount}</td>
-                                       <td align="right">${stats.warCount}</td>
-                                       <td align="right">${stats.deploymentCount}</td>
-                                       <td align="right">${stats.downloadCount}</td>
-                               </tr>                           
-                       </c:forEach>
-               </table>
-                               
-       </c:otherwise>
+        <c:forEach var="stats" items="${repositoryStatistics}">
+        <tr>
+          <td align="right">${stats.dateOfScan}</td>
+          <td align="right">${stats.fileCount}</td>
+          <td align="right">${stats.totalSize}</td>
+          <td align="right">${stats.artifactCount}</td>
+          <td align="right">${stats.groupCount}</td>
+          <td align="right">${stats.projectCount}</td>
+          <td align="right">${stats.pluginCount}</td>
+          <td align="right">${stats.archetypeCount}</td>
+          <td align="right">${stats.jarCount}</td>
+          <td align="right">${stats.warCount}</td>
+          <td align="right">${stats.deploymentCount}</td>
+          <td align="right">${stats.downloadCount}</td>
+        </tr>                          
+        </c:forEach>
+      </table>
+                                       
+    </c:otherwise>
   </c:choose>
  
 </div>