1 | |
package org.apache.maven.archiva.reporting; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
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 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | 0 | public class SimpleRepositoryStatisticsReportGenerator |
43 | |
implements RepositoryStatisticsReportGenerator |
44 | |
{ |
45 | 0 | private Logger log = LoggerFactory.getLogger( SimpleRepositoryStatisticsReportGenerator.class ); |
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
private ArchivaDAO dao; |
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
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 | |
|
81 | |
|
82 | |
|
83 | |
|
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 | |
|
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 | |
|
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 | |
|
153 | |
|
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 | |
} |