archiva-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r888325 - in /archiva/branches/MRM-1025/archiva-modules: archiva-base/archiva-model/src/main/mdo/ archiva-database/src/main/java/org/apache/maven/archiva/database/ archiva-database/src/main/java/org/apache/maven/archiva/database/constraints...
Date Tue, 08 Dec 2009 11:14:15 GMT
Author: brett
Date: Tue Dec  8 11:14:14 2009
New Revision: 888325

URL: http://svn.apache.org/viewvc?rev=888325&view=rev
Log:
[MRM-1293] remove RepositoryContentStatistics in favour of new repository-statistics module and adjust reporting action. Note that data population is still required to complete this issue

Removed:
    archiva/branches/MRM-1025/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/RepositoryContentStatisticsDAO.java
    archiva/branches/MRM-1025/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/RepositoryContentStatisticsByRepositoryConstraint.java
    archiva/branches/MRM-1025/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoRepositoryContentStatisticsDAO.java
    archiva/branches/MRM-1025/archiva-modules/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/RepositoryContentStatisticsByRepositoryConstraintTest.java
    archiva/branches/MRM-1025/archiva-modules/archiva-database/src/test/java/org/apache/maven/archiva/database/jdo/JdoRepositoryContentStatisticsDAOTest.java
    archiva/branches/MRM-1025/archiva-modules/archiva-reporting/archiva-report-manager/src/main/java/org/apache/maven/archiva/reporting/RepositoryStatistics.java
    archiva/branches/MRM-1025/archiva-modules/archiva-reporting/archiva-report-manager/src/main/java/org/apache/maven/archiva/reporting/RepositoryStatisticsReportGenerator.java
    archiva/branches/MRM-1025/archiva-modules/archiva-reporting/archiva-report-manager/src/main/java/org/apache/maven/archiva/reporting/SimpleRepositoryStatisticsReportGenerator.java
    archiva/branches/MRM-1025/archiva-modules/archiva-reporting/archiva-report-manager/src/test/java/org/apache/maven/archiva/reporting/SimpleRepositoryStatisticsReportGeneratorTest.java
Modified:
    archiva/branches/MRM-1025/archiva-modules/archiva-base/archiva-model/src/main/mdo/archiva-base.xml
    archiva/branches/MRM-1025/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/ArchivaDAO.java
    archiva/branches/MRM-1025/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAO.java
    archiva/branches/MRM-1025/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/test/java/org/apache/archiva/scheduler/repository/TestRepositoryStatisticsManager.java
    archiva/branches/MRM-1025/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/reports/GenerateReportAction.java
    archiva/branches/MRM-1025/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/reports/basicReport.jsp
    archiva/branches/MRM-1025/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/reports/statisticsReport.jsp
    archiva/branches/MRM-1025/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ArchivaDAOStub.java
    archiva/branches/MRM-1025/archiva-modules/plugins/repository-statistics/pom.xml
    archiva/branches/MRM-1025/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java
    archiva/branches/MRM-1025/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManager.java
    archiva/branches/MRM-1025/archiva-modules/plugins/repository-statistics/src/test/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManagerTest.java

Modified: archiva/branches/MRM-1025/archiva-modules/archiva-base/archiva-model/src/main/mdo/archiva-base.xml
URL: http://svn.apache.org/viewvc/archiva/branches/MRM-1025/archiva-modules/archiva-base/archiva-model/src/main/mdo/archiva-base.xml?rev=888325&r1=888324&r2=888325&view=diff
==============================================================================
--- archiva/branches/MRM-1025/archiva-modules/archiva-base/archiva-model/src/main/mdo/archiva-base.xml (original)
+++ archiva/branches/MRM-1025/archiva-modules/archiva-base/archiva-model/src/main/mdo/archiva-base.xml Tue Dec  8 11:14:14 2009
@@ -52,14 +52,6 @@
             <multiplicity>*</multiplicity>
           </association>
         </field>
-        <field>
-          <name>repositoryContentStatistics</name>
-          <version>1.0.0+</version>
-          <association>
-            <type>RepositoryContentStatistics</type>
-            <multiplicity>*</multiplicity>
-          </association>
-        </field>
       </fields>
       <codeSegments>
         <codeSegment>
@@ -948,115 +940,5 @@
         </codeSegment>
       </codeSegments>
     </class>
-
-    <!-- _______________________________________________________________
-          ____  _        _   _     _   _
-         / ___|| |_ __ _| |_(_)___| |_(_) ___ ___
-         \___ \| __/ _` | __| / __| __| |/ __/ __|
-          ___) | || (_| | |_| \__ \ |_| | (__\__ \
-         |____/ \__\__,_|\__|_|___/\__|_|\___|___/
-      -->
-
-    <class stash.storable="true"
-           jpox.table="REPOSITORY_STATS">
-      <name>RepositoryContentStatistics</name>
-      <version>1.0.0+</version>
-      <fields>
-        <field stash.maxSize="50">
-          <name>repositoryId</name>
-          <version>1.0.0+</version>
-          <identifier>false</identifier>
-          <required>true</required>
-          <type>String</type>
-          <description>
-            The repository id the statistics belong to.
-          </description>
-        </field>
-        <field>
-          <name>whenGathered</name>
-          <version>1.0.0+</version>
-          <identifier>false</identifier>
-          <required>true</required>
-          <type>Date</type>
-          <description>
-            The timestamp on when this set of statistics was gathered.
-          </description>
-        </field>
-        <field>
-          <name>duration</name>
-          <version>1.0.0+</version>
-          <identifier>false</identifier>
-          <required>true</required>
-          <type>long</type>
-          <description>
-            The duration (in milliseconds) for the gathering of the statistics.
-          </description>
-        </field>
-        <field>
-          <name>totalFileCount</name>
-          <version>1.0.0+</version>
-          <identifier>false</identifier>
-          <required>true</required>
-          <type>long</type>
-          <description>
-            The total number of files in the repository.
-          </description>
-        </field>
-        <field>
-          <name>newFileCount</name>
-          <version>1.0.0+</version>
-          <identifier>false</identifier>
-          <required>true</required>
-          <type>long</type>
-          <description>
-            The number of new files discovered.
-          </description>
-        </field>
-        <field jpox.null-value="default">
-          <name>totalProjectCount</name>
-          <version>1.2.0+</version>
-          <identifier>false</identifier>
-          <type>long</type>
-          <description>
-            The total number of unique projects in the repository.
-          </description>
-        </field>
-        <field jpox.null-value="default">
-          <name>totalGroupCount</name>
-          <version>1.2.0+</version>
-          <identifier>false</identifier>
-          <type>long</type>
-          <description>
-            The total number of unique groups in the repository.
-          </description>
-        </field>
-        <field jpox.null-value="default">
-          <name>totalArtifactCount</name>
-          <version>1.2.0+</version>
-          <identifier>false</identifier>
-          <type>long</type>
-          <description>
-            The total number of artifacts in the repository. 
-          </description>
-        </field>
-        <field jpox.null-value="default">
-          <name>totalSize</name>
-          <version>1.2.0+</version>
-          <identifier>false</identifier>
-          <type>long</type>
-          <description>
-            The total size in bytes of the repository.
-          </description>
-        </field>
-      </fields>
-      <codeSegments>
-        <codeSegment>
-          <version>1.0.0+</version>
-          <code><![CDATA[
-    private static final long serialVersionUID = -7113629916828442780L;
-          ]]></code>
-        </codeSegment>
-      </codeSegments>
-    </class>
   </classes>
 </model>

Modified: archiva/branches/MRM-1025/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/ArchivaDAO.java
URL: http://svn.apache.org/viewvc/archiva/branches/MRM-1025/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/ArchivaDAO.java?rev=888325&r1=888324&r2=888325&view=diff
==============================================================================
--- archiva/branches/MRM-1025/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/ArchivaDAO.java (original)
+++ archiva/branches/MRM-1025/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/ArchivaDAO.java Tue Dec  8 11:14:14 2009
@@ -50,6 +50,5 @@
     ArtifactDAO getArtifactDAO();
 
     RepositoryProblemDAO getRepositoryProblemDAO();
-    
-    RepositoryContentStatisticsDAO getRepositoryContentStatisticsDAO();
+
 }

Modified: archiva/branches/MRM-1025/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAO.java
URL: http://svn.apache.org/viewvc/archiva/branches/MRM-1025/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAO.java?rev=888325&r1=888324&r2=888325&view=diff
==============================================================================
--- archiva/branches/MRM-1025/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAO.java (original)
+++ archiva/branches/MRM-1025/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAO.java Tue Dec  8 11:14:14 2009
@@ -24,7 +24,6 @@
 
 import org.apache.maven.archiva.database.ArchivaDAO;
 import org.apache.maven.archiva.database.ArtifactDAO;
-import org.apache.maven.archiva.database.RepositoryContentStatisticsDAO;
 import org.apache.maven.archiva.database.RepositoryProblemDAO;
 import org.apache.maven.archiva.database.SimpleConstraint;
 
@@ -52,11 +51,6 @@
      * @plexus.requirement role-hint="jdo"
      */
     private RepositoryProblemDAO repositoryProblemDAO;
-    
-    /**
-     * @plexus.requirement role-hint="jdo"
-     */
-    private RepositoryContentStatisticsDAO repositoryContentStatisticsDAO;
 
     public JdoArchivaDAO()
     {
@@ -82,9 +76,5 @@
     {
         return repositoryProblemDAO;
     }
-    
-    public RepositoryContentStatisticsDAO getRepositoryContentStatisticsDAO()
-    {
-        return repositoryContentStatisticsDAO;
-    }
+
 }

Modified: archiva/branches/MRM-1025/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/test/java/org/apache/archiva/scheduler/repository/TestRepositoryStatisticsManager.java
URL: http://svn.apache.org/viewvc/archiva/branches/MRM-1025/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/test/java/org/apache/archiva/scheduler/repository/TestRepositoryStatisticsManager.java?rev=888325&r1=888324&r2=888325&view=diff
==============================================================================
--- archiva/branches/MRM-1025/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/test/java/org/apache/archiva/scheduler/repository/TestRepositoryStatisticsManager.java (original)
+++ archiva/branches/MRM-1025/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/test/java/org/apache/archiva/scheduler/repository/TestRepositoryStatisticsManager.java Tue Dec  8 11:14:14 2009
@@ -20,6 +20,7 @@
  */
 
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -51,6 +52,11 @@
         repoStats.remove( repositoryId );
     }
 
+    public List<RepositoryStatistics> getStatisticsInRange( String repositoryId, Date startDate, Date endDate )
+    {
+        throw new UnsupportedOperationException();
+    }
+
     private List<RepositoryStatistics> getStatsList( String repositoryId )
     {
         List<RepositoryStatistics> stats = repoStats.get( repositoryId );

Modified: archiva/branches/MRM-1025/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/reports/GenerateReportAction.java
URL: http://svn.apache.org/viewvc/archiva/branches/MRM-1025/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/reports/GenerateReportAction.java?rev=888325&r1=888324&r2=888325&view=diff
==============================================================================
--- archiva/branches/MRM-1025/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/reports/GenerateReportAction.java (original)
+++ archiva/branches/MRM-1025/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/reports/GenerateReportAction.java Tue Dec  8 11:14:14 2009
@@ -34,28 +34,22 @@
 import javax.servlet.http.HttpServletRequest;
 
 import com.opensymphony.xwork2.Preparable;
+import org.apache.archiva.metadata.repository.stats.RepositoryStatistics;
+import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang.StringUtils;
 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;
 import org.apache.maven.archiva.database.Constraint;
-import org.apache.maven.archiva.database.ObjectNotFoundException;
-import org.apache.maven.archiva.database.RepositoryContentStatisticsDAO;
 import org.apache.maven.archiva.database.constraints.RangeConstraint;
-import org.apache.maven.archiva.database.constraints.RepositoryContentStatisticsByRepositoryConstraint;
 import org.apache.maven.archiva.database.constraints.RepositoryProblemByGroupIdConstraint;
 import org.apache.maven.archiva.database.constraints.RepositoryProblemByRepositoryIdConstraint;
 import org.apache.maven.archiva.database.constraints.RepositoryProblemConstraint;
 import org.apache.maven.archiva.database.constraints.UniqueFieldConstraint;
-import org.apache.maven.archiva.model.RepositoryContentStatistics;
 import org.apache.maven.archiva.model.RepositoryProblem;
 import org.apache.maven.archiva.model.RepositoryProblemReport;
 import org.apache.maven.archiva.reporting.ArchivaReportException;
-import org.apache.maven.archiva.reporting.DataLimits;
-import org.apache.maven.archiva.reporting.RepositoryStatistics;
-import org.apache.maven.archiva.reporting.RepositoryStatisticsReportGenerator;
 import org.apache.maven.archiva.security.ArchivaRoleConstants;
 import org.apache.maven.archiva.web.action.PlexusActionSupport;
 import org.apache.struts2.interceptor.ServletRequestAware;
@@ -73,77 +67,64 @@
     extends PlexusActionSupport
     implements SecureAction, ServletRequestAware, Preparable
 {
+    public static final String ALL_REPOSITORIES = "All Repositories";
+
+    public static final String BLANK = "blank";
+
+    private static final 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 static final String SEND_FILE = "send-file";
+
     private Logger log = LoggerFactory.getLogger( GenerateReportAction.class );
 
     /**
      * @plexus.requirement role-hint="jdo"
      */
-    protected ArchivaDAO dao;
+    private ArchivaDAO dao;
 
     /**
      * @plexus.requirement
      */
     private ArchivaConfiguration archivaConfiguration;
 
-    protected HttpServletRequest request;
-
-    protected List<RepositoryProblemReport> reports = new ArrayList<RepositoryProblemReport>();
+    /**
+     * @plexus.requirement
+     */
+    private RepositoryStatisticsManager repositoryStatisticsManager;
 
-    protected String groupId;
+    private HttpServletRequest request;
 
-    protected String repositoryId;
+    private String groupId;
 
-    protected String prev;
+    private String repositoryId;
 
-    protected String next;
+    private int page = 1;
 
-    protected int page = 1;
+    private int rowCount = 100;
 
-    protected int rowCount = 100;
+    private List<String> selectedRepositories = new ArrayList<String>();
 
-    protected boolean isLastPage;
+    private String startDate;
 
-    public static final String BLANK = "blank";
+    private String endDate;
 
-    private static Boolean jasperPresent;
+    private int numPages;
 
     private Collection<String> repositoryIds;
 
-    public static final String ALL_REPOSITORIES = "All Repositories";
-
-    protected Map<String, List<RepositoryProblemReport>> repositoriesMap =
+    private Map<String, List<RepositoryProblemReport>> repositoriesMap =
         new TreeMap<String, List<RepositoryProblemReport>>();
 
-    // for statistics report
-    /**
-     * @plexus.requirement role-hint="simple"
-     */
-    private RepositoryStatisticsReportGenerator generator;
-
-    private List<String> selectedRepositories = new ArrayList<String>();
-
     private List<String> availableRepositories;
 
-    private String startDate;
-
-    private String endDate;
-
-    private int reposSize;
-
-    private String selectedRepo;
-
     private List<RepositoryStatistics> repositoryStatistics = new ArrayList<RepositoryStatistics>();
 
-    private DataLimits limits = new DataLimits();
-
-    private static final 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 static final String SEND_FILE = "send-file";
-
     private InputStream inputStream;
 
+    private boolean lastPage;
+
     @SuppressWarnings("unchecked")
     public void prepare()
     {
@@ -165,11 +146,6 @@
         }
     }
 
-    public Collection<String> getRepositoryIds()
-    {
-        return repositoryIds;
-    }
-
     /**
      * Generate the statistics report.
      *
@@ -185,29 +161,24 @@
      * - required params: repositories, endDate
      * - total pages = repositories / rows per page
      *
-     * @return
+     * @return action result
      */
     public String generateStatistics()
     {
         if ( rowCount < 10 )
         {
+            // TODO: move to validation framework
             addFieldError( "rowCount", "Row count must be larger than 10." );
             return INPUT;
         }
-        reposSize = selectedRepositories.size();
-
         try
         {
-            RepositoryContentStatisticsDAO repoContentStatsDao = dao.getRepositoryContentStatisticsDAO();
-            Date startDateInDF = null;
-            Date endDateInDF = null;
+            Date startDateInDF;
+            Date endDateInDF;
 
             if ( selectedRepositories.size() > 1 )
             {
-                limits.setTotalCount( selectedRepositories.size() );
-                limits.setCurrentPage( 1 );
-                limits.setPerPageCount( 1 );
-                limits.setCountOfPages( 1 );
+                numPages = 1;
 
                 try
                 {
@@ -227,14 +198,23 @@
                 }
 
                 // multiple repos
-                generateReportForMultipleRepos( repoContentStatsDao, startDateInDF, endDateInDF, true );
+                for ( String repo : selectedRepositories )
+                {
+                    List<RepositoryStatistics> stats =
+                        repositoryStatisticsManager.getStatisticsInRange( repo, startDateInDF, endDateInDF );
+                    if ( stats.isEmpty() )
+                    {
+                        log.info( "No statistics available for repository '" + repo + "'." );
+                        // TODO set repo's stats to 0
+                        continue;
+                    }
+
+                    repositoryStatistics.add( stats.get( 0 ) );
+                }
             }
             else if ( selectedRepositories.size() == 1 )
             {
-                limits.setCurrentPage( getPage() );
-                limits.setPerPageCount( getRowCount() );
-
-                selectedRepo = selectedRepositories.get( 0 );
+                repositoryId = selectedRepositories.get( 0 );
                 try
                 {
                     startDateInDF = getStartDateInDateFormat();
@@ -246,35 +226,36 @@
                         return INPUT;
                     }
 
-                    List<RepositoryContentStatistics> contentStats =
-                        repoContentStatsDao.queryRepositoryContentStatistics(
-                            new RepositoryContentStatisticsByRepositoryConstraint( selectedRepo, startDateInDF,
-                                                                                   endDateInDF ) );
+                    List<RepositoryStatistics> stats =
+                        repositoryStatisticsManager.getStatisticsInRange( repositoryId, startDateInDF, endDateInDF );
 
-                    if ( contentStats == null || contentStats.isEmpty() )
+                    if ( stats.isEmpty() )
                     {
                         addActionError(
                             "No statistics available for repository. Repository might not have been scanned." );
                         return ERROR;
                     }
 
-                    limits.setTotalCount( contentStats.size() );
-                    int extraPage = ( limits.getTotalCount() % limits.getPerPageCount() ) != 0 ? 1 : 0;
-                    int totalPages = ( limits.getTotalCount() / limits.getPerPageCount() ) + extraPage;
-                    limits.setCountOfPages( totalPages );
+                    int rowCount = getRowCount();
+                    int extraPage = ( stats.size() % rowCount ) != 0 ? 1 : 0;
+                    int totalPages = ( stats.size() / rowCount ) + extraPage;
+                    numPages = totalPages;
 
-                    repositoryStatistics =
-                        generator.generateReport( contentStats, selectedRepo, startDateInDF, endDateInDF, limits );
-                }
-                catch ( ObjectNotFoundException oe )
-                {
-                    addActionError( oe.getMessage() );
-                    return ERROR;
-                }
-                catch ( ArchivaDatabaseException de )
-                {
-                    addActionError( de.getMessage() );
-                    return ERROR;
+                    int currentPage = getPage();
+                    if ( currentPage > totalPages )
+                    {
+                        throw new ArchivaReportException( "The requested page exceeds the total number of pages." );
+                    }
+
+                    int start = rowCount * ( currentPage - 1 );
+                    int end = ( start + rowCount ) - 1;
+
+                    if ( end > stats.size() )
+                    {
+                        end = stats.size() - 1;
+                    }
+
+                    repositoryStatistics = stats.subList( start, end + 1 );
                 }
                 catch ( ParseException pe )
                 {
@@ -305,105 +286,136 @@
     /**
      * Export report to CSV.
      *
-     * @return
+     * @return action result
      */
     public String downloadStatisticsReport()
     {
-        try
+        Date startDateInDF;
+        Date endDateInDF;
+
+        selectedRepositories = parseSelectedRepositories();
+        List<RepositoryStatistics> repositoryStatistics = new ArrayList<RepositoryStatistics>();
+
+        StringBuffer input = null;
+        if ( selectedRepositories.size() > 1 )
         {
-            Date startDateInDF = null;
-            Date endDateInDF = null;
+            try
+            {
+                startDateInDF = getStartDateInDateFormat();
+                endDateInDF = getEndDateInDateFormat();
+            }
+            catch ( ParseException e )
+            {
+                addActionError( "Error parsing date(s)." );
+                return ERROR;
+            }
 
-            selectedRepositories = parseSelectedRepositories();
-            repositoryStatistics = new ArrayList<RepositoryStatistics>();
+            if ( startDateInDF.after( endDateInDF ) )
+            {
+                addFieldError( "startDate", "Start Date must be earlier than the End Date" );
+                return INPUT;
+            }
 
-            RepositoryContentStatisticsDAO repoContentStatsDao = dao.getRepositoryContentStatisticsDAO();
-            if ( selectedRepositories.size() > 1 )
+            // multiple repos
+            for ( String repo : selectedRepositories )
             {
-                try
+                List<RepositoryStatistics> stats =
+                    repositoryStatisticsManager.getStatisticsInRange( repo, startDateInDF, endDateInDF );
+                if ( stats.isEmpty() )
                 {
-                    startDateInDF = getStartDateInDateFormat();
-                    endDateInDF = getEndDateInDateFormat();
-                }
-                catch ( ParseException e )
-                {
-                    addActionError( "Error parsing date(s)." );
-                    return ERROR;
+                    log.info( "No statistics available for repository '" + repo + "'." );
+                    // TODO set repo's stats to 0
+                    continue;
                 }
 
+                // only the first one
+                RepositoryStatistics repositoryStats = stats.get( 0 );
+                repositoryStatistics.add( repositoryStats );
+
+                input = new StringBuffer(
+                    "Repository,Total File Count,Total Size,Artifact Count,Group Count,Project Count," +
+                        "Plugins,Archetypes,Jars,Wars,Deployments,Downloads\n" );
+
+                input.append( repo ).append( "," );
+                input.append( repositoryStats.getTotalFileCount() ).append( "," );
+                input.append( repositoryStats.getTotalArtifactFileSize() ).append( "," );
+                input.append( repositoryStats.getTotalArtifactCount() ).append( "," );
+                input.append( repositoryStats.getTotalGroupCount() ).append( "," );
+                input.append( repositoryStats.getTotalProjectCount() ).append( "," );
+                // TODO
+//                input.append( repositoryStats.getPluginCount() ).append( "," );
+//                input.append( repositoryStats.getArchetypeCount() ).append( "," );
+//                input.append( repositoryStats.getJarCount() ).append( "," );
+//                input.append( repositoryStats.getWarCount() ).append( "," );
+//                input.append( repositoryStats.getDeploymentCount() ).append( "," );
+//                input.append( repositoryStats.getDownloadCount() ).append( "\n" );
+                input.append( "\n" );
+            }
+        }
+        else if ( selectedRepositories.size() == 1 )
+        {
+            repositoryId = selectedRepositories.get( 0 );
+            try
+            {
+                startDateInDF = getStartDateInDateFormat();
+                endDateInDF = getEndDateInDateFormat();
+
                 if ( startDateInDF.after( endDateInDF ) )
                 {
                     addFieldError( "startDate", "Start Date must be earlier than the End Date" );
                     return INPUT;
                 }
 
-                // multiple repos
-                generateReportForMultipleRepos( repoContentStatsDao, startDateInDF, endDateInDF, false );
-            }
-            else if ( selectedRepositories.size() == 1 )
-            {
-                selectedRepo = selectedRepositories.get( 0 );
-                try
-                {
-                    startDateInDF = getStartDateInDateFormat();
-                    endDateInDF = getEndDateInDateFormat();
-
-                    if ( startDateInDF.after( endDateInDF ) )
-                    {
-                        addFieldError( "startDate", "Start Date must be earlier than the End Date" );
-                        return INPUT;
-                    }
-
-                    List<RepositoryContentStatistics> contentStats =
-                        repoContentStatsDao.queryRepositoryContentStatistics(
-                            new RepositoryContentStatisticsByRepositoryConstraint( selectedRepo, startDateInDF,
-                                                                                   endDateInDF ) );
-
-                    if ( contentStats == null || contentStats.isEmpty() )
-                    {
-                        addActionError(
-                            "No statistics available for repository. Repository might not have been scanned." );
-                        return ERROR;
-                    }
-
-                    repositoryStatistics =
-                        generator.generateReport( contentStats, selectedRepo, startDateInDF, endDateInDF, false );
-                }
-                catch ( ObjectNotFoundException oe )
+                List<RepositoryStatistics> stats =
+                    repositoryStatisticsManager.getStatisticsInRange( repositoryId, startDateInDF, endDateInDF );
+                if ( stats.isEmpty() )
                 {
-                    addActionError( oe.getMessage() );
+                    addActionError( "No statistics available for repository. Repository might not have been scanned." );
                     return ERROR;
                 }
-                catch ( ArchivaDatabaseException de )
-                {
-                    addActionError( de.getMessage() );
-                    return ERROR;
-                }
-                catch ( ParseException pe )
-                {
-                    addActionError( pe.getMessage() );
-                    return ERROR;
+
+                input = new StringBuffer(
+                    "Date of Scan,Total File Count,Total Size,Artifact Count,Group Count,Project Count," +
+                        "Plugins,Archetypes,Jars,Wars,Deployments,Downloads\n" );
+
+                for ( RepositoryStatistics repositoryStats : stats )
+                {
+                    input.append( repositoryStats.getScanStartTime() ).append( "," );
+                    input.append( repositoryStats.getTotalFileCount() ).append( "," );
+                    input.append( repositoryStats.getTotalArtifactFileSize() ).append( "," );
+                    input.append( repositoryStats.getTotalArtifactCount() ).append( "," );
+                    input.append( repositoryStats.getTotalGroupCount() ).append( "," );
+                    input.append( repositoryStats.getTotalProjectCount() ).append( "," );
+                    // TODO
+//                input.append( repositoryStats.getPluginCount() ).append( "," );
+//                input.append( repositoryStats.getArchetypeCount() ).append( "," );
+//                input.append( repositoryStats.getJarCount() ).append( "," );
+//                input.append( repositoryStats.getWarCount() ).append( "," );
+//                input.append( repositoryStats.getDeploymentCount() ).append( "," );
+//                input.append( repositoryStats.getDownloadCount() );
+                    input.append( "\n" );
                 }
-            }
-            else
-            {
-                addFieldError( "availableRepositories", "Please select a repository (or repositories) from the list." );
-                return INPUT;
-            }
 
-            if ( repositoryStatistics.isEmpty() )
+                repositoryStatistics = stats;
+            }
+            catch ( ParseException pe )
             {
-                return BLANK;
+                addActionError( pe.getMessage() );
+                return ERROR;
             }
         }
-        catch ( ArchivaReportException e )
+        else
         {
-            addActionError( "Error encountered while generating report :: " + e.getMessage() );
-            return ERROR;
+            addFieldError( "availableRepositories", "Please select a repository (or repositories) from the list." );
+            return INPUT;
+        }
+
+        if ( repositoryStatistics.isEmpty() )
+        {
+            return BLANK;
         }
 
-        // write output stream depending on single or comparison report              
-        StringBuffer input = getInput();
+        // write output stream depending on single or comparison report
         StringReader reader = new StringReader( input.toString() );
 
         try
@@ -429,9 +441,9 @@
             String[] tokens = StringUtils.split( repo, ',' );
             if ( tokens.length > 1 )
             {
-                for ( int i = 0; i < tokens.length; i++ )
+                for ( String token : tokens )
                 {
-                    pasedSelectedRepos.add( StringUtils.remove( StringUtils.remove( tokens[i], '[' ), ']' ).trim() );
+                    pasedSelectedRepos.add( StringUtils.remove( StringUtils.remove( token, '[' ), ']' ).trim() );
                 }
             }
             else
@@ -442,48 +454,6 @@
         return pasedSelectedRepos;
     }
 
-    private void generateReportForMultipleRepos( RepositoryContentStatisticsDAO repoContentStatsDao, Date startDateInDF,
-                                                 Date endDateInDF, boolean useLimits )
-        throws ArchivaReportException
-    {
-        for ( String repo : selectedRepositories )
-        {
-            try
-            {
-                List<RepositoryContentStatistics> contentStats = repoContentStatsDao.queryRepositoryContentStatistics(
-                    new RepositoryContentStatisticsByRepositoryConstraint( repo, startDateInDF, endDateInDF ) );
-
-                if ( contentStats == null || contentStats.isEmpty() )
-                {
-                    log.info( "No statistics available for repository '" + repo + "'." );
-                    // TODO set repo's stats to 0
-                    continue;
-                }
-
-                if ( useLimits )
-                {
-                    repositoryStatistics.addAll(
-                        generator.generateReport( contentStats, repo, startDateInDF, endDateInDF, limits ) );
-                }
-                else
-                {
-                    repositoryStatistics.addAll(
-                        generator.generateReport( contentStats, repo, startDateInDF, endDateInDF, true ) );
-                }
-            }
-            catch ( ObjectNotFoundException oe )
-            {
-                log.error( "No statistics available for repository '" + repo + "'." );
-                // TODO set repo's stats to 0
-            }
-            catch ( ArchivaDatabaseException ae )
-            {
-                log.error( "Error encountered while querying statistics of repository '" + repo + "'." );
-                // TODO set repo's stats to 0
-            }
-        }
-    }
-
     private Date getStartDateInDateFormat()
         throws ParseException
     {
@@ -510,61 +480,15 @@
         else
         {
             endDateInDF = DateUtils.parseDate( endDate, datePatterns );
-        }
-
-        return endDateInDF;
-    }
 
-    private StringBuffer getInput()
-    {
-        StringBuffer input = null;
-
-        if ( selectedRepositories.size() == 1 )
-        {
-            input = new StringBuffer(
-                "Date of Scan,Total File Count,Total Size,Artifact Count,Group Count,Project Count," +
-                    "Plugins,Archetypes,Jars,Wars,Deployments,Downloads\n" );
-
-            for ( RepositoryStatistics stats : repositoryStatistics )
-            {
-                input.append( stats.getDateOfScan() ).append( "," );
-                input.append( stats.getFileCount() ).append( "," );
-                input.append( stats.getTotalSize() ).append( "," );
-                input.append( stats.getArtifactCount() ).append( "," );
-                input.append( stats.getGroupCount() ).append( "," );
-                input.append( stats.getProjectCount() ).append( "," );
-                input.append( stats.getPluginCount() ).append( "," );
-                input.append( stats.getArchetypeCount() ).append( "," );
-                input.append( stats.getJarCount() ).append( "," );
-                input.append( stats.getWarCount() ).append( "," );
-                input.append( stats.getDeploymentCount() ).append( "," );
-                input.append( stats.getDownloadCount() ).append( "\n" );
-            }
-        }
-        else if ( selectedRepositories.size() > 1 )
-        {
-            input = new StringBuffer(
-                "Repository,Total File Count,Total Size,Artifact Count,Group Count,Project Count," +
-                    "Plugins,Archetypes,Jars,Wars,Deployments,Downloads\n" );
-
-            for ( RepositoryStatistics stats : repositoryStatistics )
-            {
-                input.append( stats.getRepositoryId() ).append( "," );
-                input.append( stats.getFileCount() ).append( "," );
-                input.append( stats.getTotalSize() ).append( "," );
-                input.append( stats.getArtifactCount() ).append( "," );
-                input.append( stats.getGroupCount() ).append( "," );
-                input.append( stats.getProjectCount() ).append( "," );
-                input.append( stats.getPluginCount() ).append( "," );
-                input.append( stats.getArchetypeCount() ).append( "," );
-                input.append( stats.getJarCount() ).append( "," );
-                input.append( stats.getWarCount() ).append( "," );
-                input.append( stats.getDeploymentCount() ).append( "," );
-                input.append( stats.getDownloadCount() ).append( "\n" );
-            }
+            // add a day, since we don't inclue time and want the date to be inclusive
+            Calendar cal = Calendar.getInstance();
+            cal.setTime( endDateInDF );
+            cal.add( Calendar.DAY_OF_MONTH, 1 );
+            endDateInDF = cal.getTime();
         }
 
-        return input;
+        return endDateInDF;
     }
 
     private Date getDefaultStartDate()
@@ -601,72 +525,44 @@
 
         String contextPath =
             request.getRequestURL().substring( 0, request.getRequestURL().indexOf( request.getRequestURI() ) );
-        RepositoryProblem problemArtifact;
-        RepositoryProblemReport problemArtifactReport;
-        for ( int i = 0; i < problemArtifacts.size(); i++ )
+        for ( RepositoryProblem problem : problemArtifacts )
         {
-            problemArtifact = (RepositoryProblem) problemArtifacts.get( i );
-            problemArtifactReport = new RepositoryProblemReport( problemArtifact );
+            RepositoryProblemReport problemArtifactReport = new RepositoryProblemReport( problem );
 
-            problemArtifactReport.setGroupURL( contextPath + "/browse/" + problemArtifact.getGroupId() );
+            problemArtifactReport.setGroupURL( contextPath + "/browse/" + problem.getGroupId() );
             problemArtifactReport.setArtifactURL(
-                contextPath + "/browse/" + problemArtifact.getGroupId() + "/" + problemArtifact.getArtifactId() );
+                contextPath + "/browse/" + problem.getGroupId() + "/" + problem.getArtifactId() );
 
-            addToList( problemArtifactReport );
+            List<RepositoryProblemReport> problemsList;
+            if ( repositoriesMap.containsKey( problemArtifactReport.getRepositoryId() ) )
+            {
+                problemsList = repositoriesMap.get( problemArtifactReport.getRepositoryId() );
+            }
+            else
+            {
+                problemsList = new ArrayList<RepositoryProblemReport>();
+                repositoriesMap.put( problemArtifactReport.getRepositoryId(), problemsList );
+            }
 
-            // retained the reports list because this is the datasource for the jasper report            
-            reports.add( problemArtifactReport );
+            problemsList.add( problemArtifactReport );
         }
 
-        if ( reports.size() <= rowCount )
+        // TODO: handling should be improved
+        if ( problemArtifacts.size() <= rowCount )
         {
-            isLastPage = true;
+            lastPage = true;
         }
-        else
-        {
-            reports.remove( rowCount );
-        }
-
-        prev = request.getRequestURL() + "?page=" + ( page - 1 ) + "&rowCount=" + rowCount + "&groupId=" + groupId +
-            "&repositoryId=" + repositoryId;
-        next = request.getRequestURL() + "?page=" + ( page + 1 ) + "&rowCount=" + rowCount + "&groupId=" + groupId +
-            "&repositoryId=" + repositoryId;
 
-        if ( reports.size() == 0 && page == 1 )
+        if ( problemArtifacts.isEmpty() && page == 1 )
         {
             return BLANK;
         }
-        else if ( isJasperPresent() )
-        {
-            return "jasper";
-        }
         else
         {
             return SUCCESS;
         }
     }
 
-    private static boolean isJasperPresent()
-    {
-        if ( jasperPresent == null )
-        {
-            try
-            {
-                Class.forName( "net.sf.jasperreports.engine.JRExporterParameter" );
-                jasperPresent = Boolean.TRUE;
-            }
-            catch ( NoClassDefFoundError e )
-            {
-                jasperPresent = Boolean.FALSE;
-            }
-            catch ( ClassNotFoundException e )
-            {
-                jasperPresent = Boolean.FALSE;
-            }
-        }
-        return jasperPresent.booleanValue();
-    }
-
     private Constraint configureConstraint()
     {
         Constraint constraint;
@@ -725,14 +621,14 @@
         problemsList.add( repoProblemReport );
     }
 
-    public void setServletRequest( HttpServletRequest request )
+    public Collection<String> getRepositoryIds()
     {
-        this.request = request;
+        return repositoryIds;
     }
 
-    public List<RepositoryProblemReport> getReports()
+    public void setServletRequest( HttpServletRequest request )
     {
-        return reports;
+        this.request = request;
     }
 
     public String getGroupId()
@@ -755,16 +651,6 @@
         this.repositoryId = repositoryId;
     }
 
-    public String getPrev()
-    {
-        return prev;
-    }
-
-    public String getNext()
-    {
-        return next;
-    }
-
     public int getPage()
     {
         return page;
@@ -785,11 +671,6 @@
         this.rowCount = rowCount;
     }
 
-    public boolean getIsLastPage()
-    {
-        return isLastPage;
-    }
-
     public void setRepositoriesMap( Map<String, List<RepositoryProblemReport>> repositoriesMap )
     {
         this.repositoriesMap = repositoriesMap;
@@ -850,38 +731,23 @@
         this.repositoryStatistics = repositoryStatistics;
     }
 
-    public int getReposSize()
-    {
-        return reposSize;
-    }
-
-    public void setReposSize( int reposSize )
-    {
-        this.reposSize = reposSize;
-    }
-
-    public String getSelectedRepo()
+    public boolean isLastPage()
     {
-        return selectedRepo;
+        return lastPage;
     }
 
-    public void setSelectedRepo( String selectedRepo )
+    public void setLastPage( boolean lastPage )
     {
-        this.selectedRepo = selectedRepo;
+        this.lastPage = lastPage;
     }
 
-    public DataLimits getLimits()
-    {
-        return limits;
-    }
-
-    public void setLimits( DataLimits limits )
+    public InputStream getInputStream()
     {
-        this.limits = limits;
+        return inputStream;
     }
 
-    public InputStream getInputStream()
+    public int getNumPages()
     {
-        return inputStream;
+        return numPages;
     }
 }

Modified: archiva/branches/MRM-1025/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/reports/basicReport.jsp
URL: http://svn.apache.org/viewvc/archiva/branches/MRM-1025/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/reports/basicReport.jsp?rev=888325&r1=888324&r2=888325&view=diff
==============================================================================
--- archiva/branches/MRM-1025/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/reports/basicReport.jsp (original)
+++ archiva/branches/MRM-1025/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/reports/basicReport.jsp Tue Dec  8 11:14:14 2009
@@ -32,8 +32,6 @@
 
 <div id="contentArea">
 
-  <s:set name="reports" value="reports"/>  
-    
   <c:forEach var="repository" items="${repositoriesMap}">
 	<strong>Repository: ${repository.key}</strong>
 	<c:forEach var="report" items='${repository.value}'>
@@ -54,11 +52,27 @@
 	</c:forEach>
   </c:forEach>
 
+  <c:set var="prevPageUrl">
+    <s:url action="generateReport" namespace="/">
+      <s:param name="groupId" value="${groupId}"/>
+      <s:param name="repositoryId" value="${repositoryId}"/>
+      <s:param name="rowCount" value="${rowCount}"/>
+      <s:param name="page" value="${page - 1}"/>
+    </s:url>
+  </c:set>
+  <c:set var="nextPageUrl">
+    <s:url action="generateReport" namespace="/">
+      <s:param name="groupId" value="${groupId}"/>
+      <s:param name="repositoryId" value="${repositoryId}"/>
+      <s:param name="rowCount" value="${rowCount}"/>
+      <s:param name="page" value="${page + 1}"/>
+    </s:url>
+  </c:set>
   <s:set name="page" value="page"/>
-  <c:if test="${page > 1}"><a href="<s:property value='prev' />">&lt;&lt;</a></c:if>
+  <c:if test="${page > 1}"><a href="${prevPageUrl}">&lt;&lt;</a></c:if>
   Page: ${page}
-  <s:set name="isLastPage" value="isLastPage"/>
-  <c:if test="${!isLastPage}"><a href="<s:property value='next' />">&gt;&gt;</a></c:if>
+  <s:set name="lastPage" value="lastPage"/>
+  <c:if test="${!lastPage}"><a href="${nextPageUrl}">&gt;&gt;</a></c:if>
 
 </div>
 </body>

Modified: archiva/branches/MRM-1025/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/reports/statisticsReport.jsp
URL: http://svn.apache.org/viewvc/archiva/branches/MRM-1025/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/reports/statisticsReport.jsp?rev=888325&r1=888324&r2=888325&view=diff
==============================================================================
--- archiva/branches/MRM-1025/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/reports/statisticsReport.jsp (original)
+++ archiva/branches/MRM-1025/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/reports/statisticsReport.jsp Tue Dec  8 11:14:14 2009
@@ -75,15 +75,15 @@
     
   <%-- Google-style pagination --%>
   <c:choose>
-    <c:when test="${limits.countOfPages > 11}">
+    <c:when test="${numPages > 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 test="${(page + 5) > (numPages - 1)}">
+          <c:set var="beginVal">${(numPages - 1) - 10}</c:set>
+          <c:set var="endVal">${numPages - 1}</c:set>
         </c:when>
         <c:otherwise>
           <c:set var="beginVal">${page - 5}</c:set>
@@ -93,7 +93,7 @@
     </c:when>
     <c:otherwise>
       <c:set var="beginVal">0</c:set>
-      <c:set var="endVal">${limits.countOfPages - 1}</c:set> 
+      <c:set var="endVal">${numPages - 1}</c:set>
     </c:otherwise>
   </c:choose>
     
@@ -118,7 +118,7 @@
   </c:forEach>
      
   <c:choose>
-    <c:when test="${page == limits.countOfPages}">
+    <c:when test="${page == numPages}">
       <img src="${imgNextPageDisabledUrl}"/>
     </c:when>
     <c:otherwise>
@@ -139,7 +139,7 @@
   <s:a href="%{downloadStatsReportUrl}">Export to CSV</s:a>
             
   <c:choose>
-    <c:when test="${reposSize > 1}">
+    <c:when test="${repositoryId == null}">
   	
       <h1>Latest Statistics Comparison Report</h1>  	    
       <table class="infoTable" border="1">
@@ -150,35 +150,39 @@
           <th>Artifact Count</th>
           <th>Group Count</th>
           <th>Project Count</th>
+          <%-- TODO
           <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}">
+        <c:forEach var="stats" items="${repositoryStatistics}" varStatus="i">
         <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>${selectedRepositories[i.count-1]}</td>
+          <td align="right">${stats.totalFileCount}</td>
+          <td align="right">${stats.totalArtifactFileSize}</td>
+          <td align="right">${stats.totalArtifactCount}</td>
+          <td align="right">${stats.totalGroupCount}</td>
+          <td align="right">${stats.totalProjectCount}</td>
+          <%-- TODO
           <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>
+      <h1>Statistics for Repository '${repositoryId}'</h1>
       <table class="infoTable" border="1">
         <tr>
           <th>Date of Scan</th>
@@ -187,29 +191,33 @@
           <th>Artifact Count</th>
           <th>Group Count</th>
           <th>Project Count</th>
+          <%-- TODO
           <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.scanStartTime}</td>
+          <td align="right">${stats.totalFileCount}</td>
+          <td align="right">${stats.totalArtifactFileSize}</td>
+          <td align="right">${stats.totalArtifactCount}</td>
+          <td align="right">${stats.totalGroupCount}</td>
+          <td align="right">${stats.totalProjectCount}</td>
+          <%-- TODO
           <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>				
+          --%>
+        </tr>
         </c:forEach>
       </table>
         		  		

Modified: archiva/branches/MRM-1025/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ArchivaDAOStub.java
URL: http://svn.apache.org/viewvc/archiva/branches/MRM-1025/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ArchivaDAOStub.java?rev=888325&r1=888324&r2=888325&view=diff
==============================================================================
--- archiva/branches/MRM-1025/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ArchivaDAOStub.java (original)
+++ archiva/branches/MRM-1025/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ArchivaDAOStub.java Tue Dec  8 11:14:14 2009
@@ -6,7 +6,6 @@
 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
 import org.apache.maven.archiva.database.ArchivaDAO;
 import org.apache.maven.archiva.database.ArtifactDAO;
-import org.apache.maven.archiva.database.RepositoryContentStatisticsDAO;
 import org.apache.maven.archiva.database.RepositoryProblemDAO;
 import org.apache.maven.archiva.database.SimpleConstraint;
 import org.apache.maven.archiva.database.constraints.UniqueArtifactIdConstraint;
@@ -82,11 +81,6 @@
         throw new UnsupportedOperationException( "method not implemented for stub" );
     }
 
-    public RepositoryContentStatisticsDAO getRepositoryContentStatisticsDAO()
-    {
-        throw new UnsupportedOperationException( "method not implemented for stub" );
-    }
-
     public void setArtifactDao( ArtifactDAO artifactDao )
     {
         this.artifactDao = artifactDao;

Modified: archiva/branches/MRM-1025/archiva-modules/plugins/repository-statistics/pom.xml
URL: http://svn.apache.org/viewvc/archiva/branches/MRM-1025/archiva-modules/plugins/repository-statistics/pom.xml?rev=888325&r1=888324&r2=888325&view=diff
==============================================================================
--- archiva/branches/MRM-1025/archiva-modules/plugins/repository-statistics/pom.xml (original)
+++ archiva/branches/MRM-1025/archiva-modules/plugins/repository-statistics/pom.xml Tue Dec  8 11:14:14 2009
@@ -39,6 +39,10 @@
     </dependency>
     <dependency>
       <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
       <artifactId>slf4j-simple</artifactId>
       <scope>test</scope>
     </dependency>

Modified: archiva/branches/MRM-1025/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java
URL: http://svn.apache.org/viewvc/archiva/branches/MRM-1025/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java?rev=888325&r1=888324&r2=888325&view=diff
==============================================================================
--- archiva/branches/MRM-1025/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java (original)
+++ archiva/branches/MRM-1025/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java Tue Dec  8 11:14:14 2009
@@ -20,11 +20,16 @@
  */
 
 import java.text.DateFormat;
+import java.text.ParseException;
 import java.text.SimpleDateFormat;
+import java.util.ArrayList;
 import java.util.Collections;
+import java.util.Date;
 import java.util.List;
 
 import org.apache.archiva.metadata.repository.MetadataRepository;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * @plexus.component role="org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager" role-hint="default"
@@ -32,6 +37,8 @@
 public class DefaultRepositoryStatisticsManager
     implements RepositoryStatisticsManager
 {
+    private static final Logger log = LoggerFactory.getLogger( DefaultRepositoryStatisticsManager.class );
+
     /**
      * @plexus.requirement
      */
@@ -58,7 +65,13 @@
 
     public void addStatisticsAfterScan( String repositoryId, RepositoryStatistics repositoryStatistics )
     {
-        // TODO
+        // In the future, instead of being tied to a scan we might want to record information in the fly based on
+        // events that are occurring. Even without these totals we could query much of the information on demand based
+        // on information from the metadata content repository. In the mean time, we lock information in at scan time.
+        // Note that if new types are later discoverable due to a code change or new plugin, historical stats will not
+        // be updated and the repository will need to be rescanned.
+
+        // TODO, populate these and also a count per artifact type
         // populate total artifact count from content repository
 //        repositoryStatistics.setTotalArtifactCount(  );
         // populate total size from content repository
@@ -78,6 +91,34 @@
         metadataRepository.removeMetadataFacets( repositoryId, RepositoryStatistics.FACET_ID );
     }
 
+    public List<RepositoryStatistics> getStatisticsInRange( String repositoryId, Date startTime, Date endTime )
+    {
+        List<RepositoryStatistics> results = new ArrayList<RepositoryStatistics>();
+        List<String> list = metadataRepository.getMetadataFacets( repositoryId, RepositoryStatistics.FACET_ID );
+        Collections.sort( list, Collections.reverseOrder() );
+        for ( String name : list )
+        {
+            try
+            {
+                Date date = SCAN_TIMESTAMP.parse( name );
+                if ( !date.before( startTime ) && !date.after( endTime ) )
+                {
+                    RepositoryStatistics stats =
+                        (RepositoryStatistics) metadataRepository.getMetadataFacet( repositoryId,
+                                                                                    RepositoryStatistics.FACET_ID,
+                                                                                    name );
+                    results.add( stats );
+                }
+            }
+            catch ( ParseException e )
+            {
+                log.error( "Invalid scan result found in the metadata repository: " + e.getMessage() );
+                // continue and ignore this one
+            }
+        }
+        return results;
+    }
+
     public void setMetadataRepository( MetadataRepository metadataRepository )
     {
         this.metadataRepository = metadataRepository;

Modified: archiva/branches/MRM-1025/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManager.java
URL: http://svn.apache.org/viewvc/archiva/branches/MRM-1025/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManager.java?rev=888325&r1=888324&r2=888325&view=diff
==============================================================================
--- archiva/branches/MRM-1025/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManager.java (original)
+++ archiva/branches/MRM-1025/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManager.java Tue Dec  8 11:14:14 2009
@@ -19,6 +19,9 @@
  * under the License.
  */
 
+import java.util.Date;
+import java.util.List;
+
 public interface RepositoryStatisticsManager
 {
     RepositoryStatistics getLastStatistics( String repositoryId );
@@ -26,4 +29,6 @@
     void addStatisticsAfterScan( String repositoryId, RepositoryStatistics repositoryStatistics );
 
     void deleteStatistics( String repositoryId );
+
+    List<RepositoryStatistics> getStatisticsInRange( String repositoryId, Date startTime, Date endTime );
 }

Modified: archiva/branches/MRM-1025/archiva-modules/plugins/repository-statistics/src/test/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManagerTest.java
URL: http://svn.apache.org/viewvc/archiva/branches/MRM-1025/archiva-modules/plugins/repository-statistics/src/test/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManagerTest.java?rev=888325&r1=888324&r2=888325&view=diff
==============================================================================
--- archiva/branches/MRM-1025/archiva-modules/plugins/repository-statistics/src/test/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManagerTest.java (original)
+++ archiva/branches/MRM-1025/archiva-modules/plugins/repository-statistics/src/test/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManagerTest.java Tue Dec  8 11:14:14 2009
@@ -20,9 +20,13 @@
  */
 
 import java.text.ParseException;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.Date;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
 
 import junit.framework.TestCase;
 import org.apache.archiva.metadata.repository.MetadataRepository;
@@ -43,6 +47,8 @@
 
     private static final String SECOND_TEST_SCAN = "20091202.012345.678";
 
+    private Map<String, RepositoryStatistics> statsCreated = new LinkedHashMap<String, RepositoryStatistics>();
+
     @Override
     protected void setUp()
         throws Exception
@@ -202,6 +208,199 @@
         metadataRepositoryControl.verify();
     }
 
+    public void testGetStatsRangeInside()
+    {
+        Date current = new Date();
+
+        addStats( new Date( current.getTime() - 12345 ), new Date( current.getTime() - 6000 ) );
+        addStats( new Date( current.getTime() - 3000 ), new Date( current.getTime() - 2000 ) );
+        addStats( new Date( current.getTime() - 1000 ), current );
+
+        ArrayList<String> keys = new ArrayList<String>( statsCreated.keySet() );
+        metadataRepositoryControl.expectAndReturn(
+            metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), keys );
+
+        // only match the middle one
+        String key = keys.get( 1 );
+        metadataRepositoryControl.expectAndReturn(
+            metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ),
+            statsCreated.get( key ) );
+
+        metadataRepositoryControl.replay();
+
+        for ( RepositoryStatistics stats : statsCreated.values() )
+        {
+            repositoryStatisticsManager.addStatisticsAfterScan( TEST_REPO_ID, stats );           
+        }
+
+        List<RepositoryStatistics> list =
+            repositoryStatisticsManager.getStatisticsInRange( TEST_REPO_ID, new Date( current.getTime() - 4000 ),
+                                                              new Date( current.getTime() - 2000 ) );
+
+        assertEquals( 1, list.size() );
+        assertEquals( new Date( current.getTime() - 3000 ), list.get( 0 ).getScanStartTime() );
+
+        metadataRepositoryControl.verify();
+    }
+
+    public void testGetStatsRangeUpperOutside()
+    {
+        Date current = new Date();
+
+        addStats( new Date( current.getTime() - 12345 ), new Date( current.getTime() - 6000 ) );
+        addStats( new Date( current.getTime() - 3000 ), new Date( current.getTime() - 2000 ) );
+        addStats( new Date( current.getTime() - 1000 ), current );
+
+        ArrayList<String> keys = new ArrayList<String>( statsCreated.keySet() );
+        metadataRepositoryControl.expectAndReturn(
+            metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), keys );
+
+        String key = keys.get( 1 );
+        metadataRepositoryControl.expectAndReturn(
+            metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ),
+            statsCreated.get( key ) );
+        key = keys.get( 2 );
+        metadataRepositoryControl.expectAndReturn(
+            metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ),
+            statsCreated.get( key ) );
+
+        metadataRepositoryControl.replay();
+
+        for ( RepositoryStatistics stats : statsCreated.values() )
+        {
+            repositoryStatisticsManager.addStatisticsAfterScan( TEST_REPO_ID, stats );
+        }
+
+        List<RepositoryStatistics> list =
+            repositoryStatisticsManager.getStatisticsInRange( TEST_REPO_ID, new Date( current.getTime() - 4000 ),
+                                                              current );
+
+        assertEquals( 2, list.size() );
+        assertEquals( new Date( current.getTime() - 3000 ), list.get( 1 ).getScanStartTime() );
+        assertEquals( new Date( current.getTime() - 1000 ), list.get( 0 ).getScanStartTime() );
+
+        metadataRepositoryControl.verify();
+    }
+
+    public void testGetStatsRangeLowerOutside()
+    {
+        Date current = new Date();
+
+        addStats( new Date( current.getTime() - 12345 ), new Date( current.getTime() - 6000 ) );
+        addStats( new Date( current.getTime() - 3000 ), new Date( current.getTime() - 2000 ) );
+        addStats( new Date( current.getTime() - 1000 ), current );
+
+        ArrayList<String> keys = new ArrayList<String>( statsCreated.keySet() );
+        metadataRepositoryControl.expectAndReturn(
+            metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), keys );
+
+        String key = keys.get( 0 );
+        metadataRepositoryControl.expectAndReturn(
+            metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ),
+            statsCreated.get( key ) );
+        key = keys.get( 1 );
+        metadataRepositoryControl.expectAndReturn(
+            metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ),
+            statsCreated.get( key ) );
+
+        metadataRepositoryControl.replay();
+
+        for ( RepositoryStatistics stats : statsCreated.values() )
+        {
+            repositoryStatisticsManager.addStatisticsAfterScan( TEST_REPO_ID, stats );
+        }
+
+        List<RepositoryStatistics> list =
+            repositoryStatisticsManager.getStatisticsInRange( TEST_REPO_ID, new Date( current.getTime() - 20000 ),
+                                                              new Date( current.getTime() - 2000 ) );
+
+        assertEquals( 2, list.size() );
+        assertEquals( new Date( current.getTime() - 12345 ), list.get( 1 ).getScanStartTime() );
+        assertEquals( new Date( current.getTime() - 3000 ), list.get( 0 ).getScanStartTime() );
+
+        metadataRepositoryControl.verify();
+    }
+
+    public void testGetStatsRangeLowerAndUpperOutside()
+    {
+        Date current = new Date();
+
+        addStats( new Date( current.getTime() - 12345 ), new Date( current.getTime() - 6000 ) );
+        addStats( new Date( current.getTime() - 3000 ), new Date( current.getTime() - 2000 ) );
+        addStats( new Date( current.getTime() - 1000 ), current );
+
+        ArrayList<String> keys = new ArrayList<String>( statsCreated.keySet() );
+        metadataRepositoryControl.expectAndReturn(
+            metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), keys );
+
+        String key = keys.get( 0 );
+        metadataRepositoryControl.expectAndReturn(
+            metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ),
+            statsCreated.get( key ) );
+        key = keys.get( 1 );
+        metadataRepositoryControl.expectAndReturn(
+            metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ),
+            statsCreated.get( key ) );
+        key = keys.get( 2 );
+        metadataRepositoryControl.expectAndReturn(
+            metadataRepository.getMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, key ),
+            statsCreated.get( key ) );
+
+        metadataRepositoryControl.replay();
+
+        for ( RepositoryStatistics stats : statsCreated.values() )
+        {
+            repositoryStatisticsManager.addStatisticsAfterScan( TEST_REPO_ID, stats );
+        }
+
+        List<RepositoryStatistics> list =
+            repositoryStatisticsManager.getStatisticsInRange( TEST_REPO_ID, new Date( current.getTime() - 20000 ),
+                                                              current );
+
+        assertEquals( 3, list.size() );
+        assertEquals( new Date( current.getTime() - 12345 ), list.get( 2 ).getScanStartTime() );
+        assertEquals( new Date( current.getTime() - 3000 ), list.get( 1 ).getScanStartTime() );
+        assertEquals( new Date( current.getTime() - 1000 ), list.get( 0 ).getScanStartTime() );
+
+        metadataRepositoryControl.verify();
+    }
+
+    public void testGetStatsRangeNotInside()
+    {
+        Date current = new Date();
+
+        addStats( new Date( current.getTime() - 12345 ), new Date( current.getTime() - 6000 ) );
+        addStats( new Date( current.getTime() - 3000 ), new Date( current.getTime() - 2000 ) );
+        addStats( new Date( current.getTime() - 1000 ), current );
+
+        ArrayList<String> keys = new ArrayList<String>( statsCreated.keySet() );
+        metadataRepositoryControl.expectAndReturn(
+            metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryStatistics.FACET_ID ), keys );
+
+        metadataRepositoryControl.replay();
+
+        for ( RepositoryStatistics stats : statsCreated.values() )
+        {
+            repositoryStatisticsManager.addStatisticsAfterScan( TEST_REPO_ID, stats );
+        }
+
+        List<RepositoryStatistics> list =
+            repositoryStatisticsManager.getStatisticsInRange( TEST_REPO_ID, new Date( current.getTime() - 20000 ),
+                                                              new Date( current.getTime() - 16000 ) );
+
+        assertEquals( 0, list.size() );
+
+        metadataRepositoryControl.verify();
+    }
+
+    private void addStats( Date startTime, Date endTime )
+    {
+        RepositoryStatistics stats = createTestStats( startTime, endTime );
+        String startTimeAsString = DefaultRepositoryStatisticsManager.SCAN_TIMESTAMP.format( startTime );
+        metadataRepository.addMetadataFacet( TEST_REPO_ID, RepositoryStatistics.FACET_ID, startTimeAsString, stats );
+        statsCreated.put( startTimeAsString, stats );
+    }
+
     private RepositoryStatistics createTestStats( Date startTime, Date endTime )
     {
         RepositoryStatistics stats = new RepositoryStatistics();



Mime
View raw message