Coverage Report - org.apache.maven.archiva.reporting.SimpleRepositoryStatisticsReportGenerator
 
Classes in this File Line Coverage Branch Coverage Complexity
SimpleRepositoryStatisticsReportGenerator
0%
0/45
0%
0/8
0
 
 1  
 package org.apache.maven.archiva.reporting;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *  http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import java.util.ArrayList;
 23  
 import java.util.Date;
 24  
 import java.util.List;
 25  
 
 26  
 import org.apache.maven.archiva.database.ArchivaDAO;
 27  
 import org.apache.maven.archiva.database.ArchivaDatabaseException;
 28  
 import org.apache.maven.archiva.database.ArtifactDAO;
 29  
 import org.apache.maven.archiva.database.constraints.ArtifactsByRepositoryConstraint;
 30  
 import org.apache.maven.archiva.model.ArchivaArtifact;
 31  
 import org.apache.maven.archiva.model.RepositoryContentStatistics;
 32  
 import org.slf4j.Logger;
 33  
 import org.slf4j.LoggerFactory;
 34  
 
 35  
 /**
 36  
  * SimpleRepositoryStatisticsReportGenerator
 37  
  * 
 38  
  * @version $Id: SimpleRepositoryStatisticsReportGenerator.java
 39  
  * 
 40  
  * @plexus.component role="org.apache.maven.archiva.reporting.RepositoryStatisticsReportGenerator" role-hint="simple"
 41  
  */
 42  0
 public class SimpleRepositoryStatisticsReportGenerator
 43  
     implements RepositoryStatisticsReportGenerator
 44  
 {   
 45  0
     private Logger log = LoggerFactory.getLogger( SimpleRepositoryStatisticsReportGenerator.class );
 46  
     
 47  
     /**
 48  
      * @plexus.requirement role-hint="jdo"
 49  
      */
 50  
     private ArchivaDAO dao;
 51  
     
 52  
     /**
 53  
      * {@inheritDoc}
 54  
      * 
 55  
      * @see org.apache.maven.archiva.reporting.RepositoryStatisticsReportGenerator#generateReport(java.util.List
 56  
      *      repoContentStats, java.util.String repository, java.util.Date startDate, java.util.Date endDate,
 57  
      *      org.apache.maven.archiva.reporting.DataLimits limits )
 58  
      */
 59  
     public List<RepositoryStatistics> generateReport( List<RepositoryContentStatistics> repoContentStats,
 60  
                                                       String repository, Date startDate, Date endDate, DataLimits limits )
 61  
         throws ArchivaReportException
 62  
     {   
 63  0
         if( limits.getCurrentPage() > limits.getCountOfPages() )
 64  
         {
 65  0
             throw new ArchivaReportException( "The requested page exceeds the total number of pages." );
 66  
         }
 67  
          
 68  0
         int start = ( limits.getPerPageCount() * limits.getCurrentPage() ) - limits.getPerPageCount();
 69  0
         int end = ( start + limits.getPerPageCount() ) - 1;
 70  
         
 71  0
         if( end > repoContentStats.size() )
 72  
         {
 73  0
             end = repoContentStats.size() - 1;
 74  
         }
 75  
         
 76  0
         return constructRepositoryStatistics( repoContentStats, repository, endDate, start, end );
 77  
     }
 78  
     
 79  
     /**
 80  
      * {@inheritDoc}
 81  
      * 
 82  
      * @see org.apache.maven.archiva.reporting.RepositoryStatisticsReportGenerator#generateReport(java.util.List
 83  
      *      repoContentStats, java.util.String repository, java.util.Date startDate, java.util.Date endDate, boolean firstStatsOnly)
 84  
      */
 85  
     public List<RepositoryStatistics> generateReport( List<RepositoryContentStatistics> repoContentStats,
 86  
                                                       String repository, Date startDate, Date endDate,
 87  
                                                       boolean firstStatsOnly )
 88  
         throws ArchivaReportException
 89  
     {
 90  0
         if( firstStatsOnly )
 91  
         {
 92  0
             return constructRepositoryStatistics( repoContentStats, repository, endDate, 0, 0 );
 93  
         }
 94  
         else
 95  
         {
 96  0
             return constructRepositoryStatistics( repoContentStats, repository, endDate, 0, repoContentStats.size() - 1 );
 97  
         }
 98  
     }
 99  
     
 100  
     private List<RepositoryStatistics> constructRepositoryStatistics(
 101  
                                                                       List<RepositoryContentStatistics> repoContentStats,
 102  
                                                                       String repository, Date endDate,
 103  
                                                                       int start, int end )
 104  
     {
 105  0
         ArtifactDAO artifactDao = dao.getArtifactDAO();    
 106  
         
 107  0
         List<RepositoryStatistics> repoStatisticsList = new ArrayList<RepositoryStatistics>();
 108  0
         for( int i = start; i <= end; i++ )
 109  
         {   
 110  0
             RepositoryContentStatistics repoContentStat = (RepositoryContentStatistics) repoContentStats.get( i );
 111  0
             RepositoryStatistics repoStatistics = new RepositoryStatistics();
 112  0
             repoStatistics.setRepositoryId( repository );
 113  
             
 114  
             // get only the latest                
 115  0
             repoStatistics.setArtifactCount( repoContentStat.getTotalArtifactCount() );
 116  0
             repoStatistics.setGroupCount( repoContentStat.getTotalGroupCount() );
 117  0
             repoStatistics.setProjectCount( repoContentStat.getTotalProjectCount() );
 118  0
             repoStatistics.setTotalSize( repoContentStat.getTotalSize() );
 119  0
             repoStatistics.setFileCount( repoContentStat.getTotalFileCount() );
 120  0
             repoStatistics.setDateOfScan( repoContentStat.getWhenGathered() );
 121  
                 
 122  
             try
 123  
             {
 124  
                 //TODO use the repo content stats whenGathered date instead of endDate for single repo reports
 125  0
                 List<ArchivaArtifact> types = artifactDao.queryArtifacts( 
 126  
                          new ArtifactsByRepositoryConstraint( repository, JAR_TYPE, endDate, "whenGathered" ) );
 127  0
                 repoStatistics.setJarCount( types.size() );
 128  
                 
 129  0
                 types = artifactDao.queryArtifacts( 
 130  
                         new ArtifactsByRepositoryConstraint( repository, WAR_TYPE, endDate, "whenGathered" ) );
 131  0
                 repoStatistics.setWarCount( types.size() );
 132  
                 
 133  0
                 types = artifactDao.queryArtifacts( 
 134  
                         new ArtifactsByRepositoryConstraint( repository, MAVEN_PLUGIN, endDate, "whenGathered" ) );
 135  0
                 repoStatistics.setPluginCount( types.size() );
 136  
 
 137  0
                 types = artifactDao.queryArtifacts(
 138  
                          new ArtifactsByRepositoryConstraint( repository, EAR_TYPE, endDate, "whenGathered" ) );
 139  0
                 repoStatistics.setEarCount( types.size() );
 140  
 
 141  0
                 types = artifactDao.queryArtifacts( 
 142  
                          new ArtifactsByRepositoryConstraint( repository, DLL_TYPE, endDate, "whenGathered" ) );
 143  0
                 repoStatistics.setDllCount( types.size() );
 144  
 
 145  0
                 types = artifactDao.queryArtifacts(
 146  
                          new ArtifactsByRepositoryConstraint( repository, EXE_TYPE, endDate, "whenGathered" ) );
 147  0
                 repoStatistics.setExeCount( types.size() );
 148  
 
 149  0
                 types = artifactDao.queryArtifacts(
 150  
                          new ArtifactsByRepositoryConstraint( repository, ZIP_TYPE, endDate, "whenGathered" ) );
 151  0
                 repoStatistics.setZipCount( types.size() );
 152  
                 // TODO: must need to be able to track archetypes. possible way of identifying an 
 153  
                 //      archetype is by checking if archetype.xml exists in src/main/resources/META-INF/
 154  
                 
 155  
             }
 156  0
             catch( ArchivaDatabaseException e )
 157  
             {
 158  0
                 log.error( "Error occurred while querying artifacts from the database.", e.getMessage() );                 
 159  0
             }            
 160  
                             
 161  0
             repoStatisticsList.add( repoStatistics );  
 162  
         }
 163  
         
 164  0
         return repoStatisticsList;
 165  
     }
 166  
         
 167  
     public void setDao( ArchivaDAO dao )
 168  
     {
 169  0
         this.dao = dao;
 170  0
     }
 171  
 }