[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

git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@888325 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Porter 2009-12-08 11:14:14 +00:00
parent 06f9863c47
commit b0304e08c3
21 changed files with 544 additions and 1702 deletions

View File

@ -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>

View File

@ -50,6 +50,5 @@ public interface ArchivaDAO
ArtifactDAO getArtifactDAO();
RepositoryProblemDAO getRepositoryProblemDAO();
RepositoryContentStatisticsDAO getRepositoryContentStatisticsDAO();
}

View File

@ -1,40 +0,0 @@
package org.apache.maven.archiva.database;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import java.util.List;
import org.apache.maven.archiva.model.RepositoryContentStatistics;
/**
* RepositoryContentStatisticsDAO
*
* @version
*/
public interface RepositoryContentStatisticsDAO
{
public List<RepositoryContentStatistics> queryRepositoryContentStatistics( Constraint constraint )
throws ObjectNotFoundException, ArchivaDatabaseException;
public RepositoryContentStatistics saveRepositoryContentStatistics( RepositoryContentStatistics stats );
public void deleteRepositoryContentStatistics( RepositoryContentStatistics stats )
throws ArchivaDatabaseException;
}

View File

@ -1,62 +0,0 @@
package org.apache.maven.archiva.database.constraints;
import java.util.Date;
import org.apache.maven.archiva.database.Constraint;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* RepositoryContentStatisticsByRepositoryConstraint
*
* @version
*/
public class RepositoryContentStatisticsByRepositoryConstraint
extends AbstractDeclarativeConstraint
{
private String whereClause;
public RepositoryContentStatisticsByRepositoryConstraint( String repoId )
{
whereClause = "repositoryId == repoId";
declParams = new String[] { "String repoId" };
params = new Object[] { repoId };
}
public RepositoryContentStatisticsByRepositoryConstraint( String repoId, Date startDate, Date endDate )
{
declImports = new String[] { "import java.util.Date" };
whereClause = "repositoryId == repoId && whenGathered >= startDate && whenGathered <= endDate";
declParams = new String[] { "String repoId", "Date startDate", "Date endDate" };
params = new Object[] { repoId, startDate, endDate };
sortDirection = Constraint.DESCENDING;
}
public String getSortColumn()
{
return "whenGathered";
}
public String getWhereCondition()
{
return whereClause;
}
}

View File

@ -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 @@ public class JdoArchivaDAO
* @plexus.requirement role-hint="jdo"
*/
private RepositoryProblemDAO repositoryProblemDAO;
/**
* @plexus.requirement role-hint="jdo"
*/
private RepositoryContentStatisticsDAO repositoryContentStatisticsDAO;
public JdoArchivaDAO()
{
@ -82,9 +76,5 @@ public RepositoryProblemDAO getRepositoryProblemDAO()
{
return repositoryProblemDAO;
}
public RepositoryContentStatisticsDAO getRepositoryContentStatisticsDAO()
{
return repositoryContentStatisticsDAO;
}
}

View File

@ -1,65 +0,0 @@
package org.apache.maven.archiva.database.jdo;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import java.util.List;
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.model.RepositoryContentStatistics;
/**
* JdoRepositoryContentStatisticsDAO
*
* @version
*
* @plexus.component role-hint="jdo"
*/
public class JdoRepositoryContentStatisticsDAO
implements RepositoryContentStatisticsDAO
{
/**
* @plexus.requirement role-hint="archiva"
*/
private JdoAccess jdo;
public void deleteRepositoryContentStatistics( RepositoryContentStatistics stats )
throws ArchivaDatabaseException
{
jdo.removeObject( stats );
}
@SuppressWarnings("unchecked")
public List<RepositoryContentStatistics> queryRepositoryContentStatistics( Constraint constraint )
throws ObjectNotFoundException, ArchivaDatabaseException
{
return (List<RepositoryContentStatistics>) jdo.queryObjects( RepositoryContentStatistics.class, constraint );
}
public RepositoryContentStatistics saveRepositoryContentStatistics( RepositoryContentStatistics stats )
{
RepositoryContentStatistics savedStats = (RepositoryContentStatistics) jdo.saveObject( stats );
return savedStats;
}
}

View File

@ -1,102 +0,0 @@
package org.apache.maven.archiva.database.constraints;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import java.util.List;
import org.apache.maven.archiva.database.AbstractArchivaDatabaseTestCase;
import org.apache.maven.archiva.database.Constraint;
import org.apache.maven.archiva.model.RepositoryContentStatistics;
/**
* RepositoryContentStatisticsByRepositoryConstraintTest
*
* @version
*/
public class RepositoryContentStatisticsByRepositoryConstraintTest
extends AbstractArchivaDatabaseTestCase
{
private RepositoryContentStatistics createStats( String repoId, String timestamp, long duration, long totalfiles,
long newfiles )
throws Exception
{
RepositoryContentStatistics stats = new RepositoryContentStatistics();
stats.setRepositoryId( repoId );
stats.setDuration( duration );
stats.setNewFileCount( newfiles );
stats.setTotalFileCount( totalfiles );
stats.setWhenGathered( toDate( timestamp ) );
return stats;
}
@Override
protected void setUp()
throws Exception
{
super.setUp();
dao.getRepositoryContentStatisticsDAO().saveRepositoryContentStatistics(
createStats( "internal", "2007/10/21 8:00:00", 20000, 12000, 400 ) );
dao.getRepositoryContentStatisticsDAO().saveRepositoryContentStatistics(
createStats( "internal", "2007/10/20 8:00:00", 20000, 11800, 0 ) );
dao.getRepositoryContentStatisticsDAO().saveRepositoryContentStatistics(
createStats( "internal", "2007/10/19 8:00:00", 20000, 11800, 100 ) );
dao.getRepositoryContentStatisticsDAO().saveRepositoryContentStatistics(
createStats( "internal", "2007/10/18 8:00:00", 20000, 11700, 320 ) );
}
public void testStats()
throws Exception
{
Constraint constraint = new RepositoryContentStatisticsByRepositoryConstraint( "internal" );
List<RepositoryContentStatistics> results = dao.getRepositoryContentStatisticsDAO().queryRepositoryContentStatistics( constraint );
assertNotNull( "Stats: results (not null)", results );
assertEquals( "Stats: results.size", 4, results.size() );
assertEquals( "internal", ( (RepositoryContentStatistics) results.get( 0 ) ).getRepositoryId() );
assertEquals( "internal", ( (RepositoryContentStatistics) results.get( 1 ) ).getRepositoryId() );
assertEquals( "internal", ( (RepositoryContentStatistics) results.get( 2 ) ).getRepositoryId() );
assertEquals( "internal", ( (RepositoryContentStatistics) results.get( 3 ) ).getRepositoryId() );
}
public void testStatsWithDateRange()
throws Exception
{
Constraint constraint =
new RepositoryContentStatisticsByRepositoryConstraint( "internal", toDate( "2007/10/18 8:00:00" ),
toDate( "2007/10/20 8:00:00" ) );
List<RepositoryContentStatistics> results = dao.getRepositoryContentStatisticsDAO().queryRepositoryContentStatistics( constraint );
assertNotNull( "Stats: results (not null)", results );
assertEquals( "Stats: results.size", 3, results.size() );
assertEquals( "internal", ( (RepositoryContentStatistics) results.get( 0 ) ).getRepositoryId() );
assertEquals( toDate( "2007/10/20 8:00:00" ),
( (RepositoryContentStatistics) results.get( 0 ) ).getWhenGathered() );
assertEquals( "internal", ( (RepositoryContentStatistics) results.get( 1 ) ).getRepositoryId() );
assertEquals( toDate( "2007/10/19 8:00:00" ),
( (RepositoryContentStatistics) results.get( 1 ) ).getWhenGathered() );
assertEquals( "internal", ( (RepositoryContentStatistics) results.get( 2 ) ).getRepositoryId() );
assertEquals( toDate( "2007/10/18 8:00:00" ),
( (RepositoryContentStatistics) results.get( 2 ) ).getWhenGathered() );
}
}

View File

@ -1,83 +0,0 @@
package org.apache.maven.archiva.database.jdo;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import java.util.List;
import javax.jdo.JDOHelper;
import org.apache.maven.archiva.database.AbstractArchivaDatabaseTestCase;
import org.apache.maven.archiva.database.RepositoryContentStatisticsDAO;
import org.apache.maven.archiva.database.constraints.RepositoryContentStatisticsByRepositoryConstraint;
import org.apache.maven.archiva.model.RepositoryContentStatistics;
/**
* JdoRepositoryContentStatisticsDAOTest
*
* @version
*/
public class JdoRepositoryContentStatisticsDAOTest
extends AbstractArchivaDatabaseTestCase
{
public void testCRUD()
throws Exception
{
RepositoryContentStatisticsDAO repoContentStatisticsDAO = dao.getRepositoryContentStatisticsDAO();
// create
RepositoryContentStatistics savedStats =
repoContentStatisticsDAO.saveRepositoryContentStatistics( createStats( "internal", "2007/10/21 8:00:00",
20000, 12000, 400 ) );
assertNotNull( savedStats );
String savedKeyId = JDOHelper.getObjectId( savedStats ).toString();
assertEquals( "1[OID]org.apache.maven.archiva.model.RepositoryContentStatistics", savedKeyId );
// query
List<RepositoryContentStatistics> results =
repoContentStatisticsDAO.queryRepositoryContentStatistics( new RepositoryContentStatisticsByRepositoryConstraint(
"internal" ) );
assertNotNull( results );
assertEquals( 1, results.size() );
RepositoryContentStatistics stats = (RepositoryContentStatistics) results.get( 0 );
assertEquals( "internal", stats.getRepositoryId() );
// delete
repoContentStatisticsDAO.deleteRepositoryContentStatistics( stats );
assertEquals( 0, repoContentStatisticsDAO.queryRepositoryContentStatistics(
new RepositoryContentStatisticsByRepositoryConstraint( "internal" ) ).size() );
}
private RepositoryContentStatistics createStats( String repoId, String timestamp, long duration, long totalfiles,
long newfiles )
throws Exception
{
RepositoryContentStatistics stats = new RepositoryContentStatistics();
stats.setRepositoryId( repoId );
stats.setDuration( duration );
stats.setNewFileCount( newfiles );
stats.setTotalFileCount( totalfiles );
stats.setWhenGathered( toDate( timestamp ) );
return stats;
}
}

View File

@ -1,233 +0,0 @@
package org.apache.maven.archiva.reporting;
import java.util.Date;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* RepositoryStatistics
*
*/
public class RepositoryStatistics
{
private String repositoryId;
private long fileCount = 0;
private long totalSize = 0;
private long projectCount = 0;
private long groupCount = 0;
private long artifactCount = 0;
private long pluginCount = 0;
private long archetypeCount = 0;
private long jarCount = 0;
private long warCount = 0;
private long earCount = 0;
private long dllCount = 0;
private long exeCount = 0;
private long pomCount = 0;
private long deploymentCount = 0;
private long downloadCount = 0;
private Date dateOfScan;
public String getRepositoryId()
{
return repositoryId;
}
public void setRepositoryId( String repositoryId )
{
this.repositoryId = repositoryId;
}
public long getFileCount()
{
return fileCount;
}
public void setFileCount( long fileCount )
{
this.fileCount = fileCount;
}
public long getTotalSize()
{
return totalSize;
}
public void setTotalSize( long totalSize )
{
this.totalSize = totalSize;
}
public long getProjectCount()
{
return projectCount;
}
public void setProjectCount( long projectCount )
{
this.projectCount = projectCount;
}
public long getGroupCount()
{
return groupCount;
}
public void setGroupCount( long groupCount )
{
this.groupCount = groupCount;
}
public long getArtifactCount()
{
return artifactCount;
}
public void setArtifactCount( long artifactCount )
{
this.artifactCount = artifactCount;
}
public long getPluginCount()
{
return pluginCount;
}
public void setPluginCount( long pluginCount )
{
this.pluginCount = pluginCount;
}
public long getArchetypeCount()
{
return archetypeCount;
}
public void setArchetypeCount( long archetypeCount )
{
this.archetypeCount = archetypeCount;
}
public long getJarCount()
{
return jarCount;
}
public void setJarCount( long jarCount )
{
this.jarCount = jarCount;
}
public long getWarCount()
{
return warCount;
}
public void setWarCount( long warCount )
{
this.warCount = warCount;
}
public long getEarCount()
{
return earCount;
}
public void setEarCount( long earCount )
{
this.earCount = earCount;
}
public long getDllCount()
{
return dllCount;
}
public void setDllCount( long dllCount )
{
this.dllCount = dllCount;
}
public long getExeCount()
{
return exeCount;
}
public void setExeCount( long exeCount )
{
this.exeCount = exeCount;
}
public long getPomCount()
{
return pomCount;
}
public void setPomCount( long pomCount )
{
this.pomCount = pomCount;
}
public long getDeploymentCount()
{
return deploymentCount;
}
public void setDeploymentCount( long deploymentCount )
{
this.deploymentCount = deploymentCount;
}
public long getDownloadCount()
{
return downloadCount;
}
public void setDownloadCount( long downloadCount )
{
this.downloadCount = downloadCount;
}
public Date getDateOfScan()
{
return dateOfScan;
}
public void setDateOfScan( Date dateOfScan )
{
this.dateOfScan = dateOfScan;
}
}

View File

@ -1,71 +0,0 @@
package org.apache.maven.archiva.reporting;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import java.util.Date;
import java.util.List;
import org.apache.maven.archiva.model.RepositoryContentStatistics;
/**
* RepositoryStatisticsReportGenerator
*
* @version $Id: RepositoryStatisticsReportGenerator.java
*/
public interface RepositoryStatisticsReportGenerator
{
public static final String JAR_TYPE = "jar";
public static final String WAR_TYPE = "war";
public static final String POM_TYPE = "pom";
public static final String MAVEN_PLUGIN = "maven-plugin";
public static final String ARCHETYPE = "archetype";
/**
* Generate report with limits. Used for pagination.
*
* @param repoContentStats
* @param repository
* @param startDate
* @param endDate
* @param limits
* @return
* @throws ArchivaReportException
*/
public List<RepositoryStatistics> generateReport( List<RepositoryContentStatistics> repoContentStats, String repository, Date startDate, Date endDate, DataLimits limits )
throws ArchivaReportException;
/**
* Generate report without limits. Used for exporting the report.
*
* @param repoContentStats
* @param repository
* @param startDate
* @param endDate
* @param firstStatsOnly TODO
* @return
* @throws ArchivaReportException
*/
public List<RepositoryStatistics> generateReport( List<RepositoryContentStatistics> repoContentStats, String repository, Date startDate, Date endDate, boolean firstStatsOnly )
throws ArchivaReportException;
}

View File

@ -1,156 +0,0 @@
package org.apache.maven.archiva.reporting;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.apache.maven.archiva.database.ArchivaDAO;
import org.apache.maven.archiva.database.ArchivaDatabaseException;
import org.apache.maven.archiva.database.ArtifactDAO;
import org.apache.maven.archiva.database.constraints.ArtifactsByRepositoryConstraint;
import org.apache.maven.archiva.model.ArchivaArtifact;
import org.apache.maven.archiva.model.RepositoryContentStatistics;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* SimpleRepositoryStatisticsReportGenerator
*
* @version $Id: SimpleRepositoryStatisticsReportGenerator.java
*
* @plexus.component role="org.apache.maven.archiva.reporting.RepositoryStatisticsReportGenerator" role-hint="simple"
*/
public class SimpleRepositoryStatisticsReportGenerator
implements RepositoryStatisticsReportGenerator
{
private Logger log = LoggerFactory.getLogger( SimpleRepositoryStatisticsReportGenerator.class );
/**
* @plexus.requirement role-hint="jdo"
*/
private ArchivaDAO dao;
/**
* {@inheritDoc}
*
* @see org.apache.maven.archiva.reporting.RepositoryStatisticsReportGenerator#generateReport(java.util.List
* repoContentStats, java.util.String repository, java.util.Date startDate, java.util.Date endDate,
* org.apache.maven.archiva.reporting.DataLimits limits )
*/
public List<RepositoryStatistics> generateReport( List<RepositoryContentStatistics> repoContentStats,
String repository, Date startDate, Date endDate, DataLimits limits )
throws ArchivaReportException
{
if( limits.getCurrentPage() > limits.getCountOfPages() )
{
throw new ArchivaReportException( "The requested page exceeds the total number of pages." );
}
int start = ( limits.getPerPageCount() * limits.getCurrentPage() ) - limits.getPerPageCount();
int end = ( start + limits.getPerPageCount() ) - 1;
if( end > repoContentStats.size() )
{
end = repoContentStats.size() - 1;
}
return constructRepositoryStatistics( repoContentStats, repository, endDate, start, end );
}
/**
* {@inheritDoc}
*
* @see org.apache.maven.archiva.reporting.RepositoryStatisticsReportGenerator#generateReport(java.util.List
* repoContentStats, java.util.String repository, java.util.Date startDate, java.util.Date endDate, boolean firstStatsOnly)
*/
public List<RepositoryStatistics> generateReport( List<RepositoryContentStatistics> repoContentStats,
String repository, Date startDate, Date endDate,
boolean firstStatsOnly )
throws ArchivaReportException
{
if( firstStatsOnly )
{
return constructRepositoryStatistics( repoContentStats, repository, endDate, 0, 0 );
}
else
{
return constructRepositoryStatistics( repoContentStats, repository, endDate, 0, repoContentStats.size() - 1 );
}
}
private List<RepositoryStatistics> constructRepositoryStatistics(
List<RepositoryContentStatistics> repoContentStats,
String repository, Date endDate,
int start, int end )
{
ArtifactDAO artifactDao = dao.getArtifactDAO();
List<RepositoryStatistics> repoStatisticsList = new ArrayList<RepositoryStatistics>();
for( int i = start; i <= end; i++ )
{
RepositoryContentStatistics repoContentStat = (RepositoryContentStatistics) repoContentStats.get( i );
RepositoryStatistics repoStatistics = new RepositoryStatistics();
repoStatistics.setRepositoryId( repository );
// get only the latest
repoStatistics.setArtifactCount( repoContentStat.getTotalArtifactCount() );
repoStatistics.setGroupCount( repoContentStat.getTotalGroupCount() );
repoStatistics.setProjectCount( repoContentStat.getTotalProjectCount() );
repoStatistics.setTotalSize( repoContentStat.getTotalSize() );
repoStatistics.setFileCount( repoContentStat.getTotalFileCount() );
repoStatistics.setDateOfScan( repoContentStat.getWhenGathered() );
try
{
//TODO use the repo content stats whenGathered date instead of endDate for single repo reports
List<ArchivaArtifact> types = artifactDao.queryArtifacts(
new ArtifactsByRepositoryConstraint( repository, JAR_TYPE, endDate, "whenGathered" ) );
repoStatistics.setJarCount( types.size() );
types = artifactDao.queryArtifacts(
new ArtifactsByRepositoryConstraint( repository, WAR_TYPE, endDate, "whenGathered" ) );
repoStatistics.setWarCount( types.size() );
types = artifactDao.queryArtifacts(
new ArtifactsByRepositoryConstraint( repository, MAVEN_PLUGIN, endDate, "whenGathered" ) );
repoStatistics.setPluginCount( types.size() );
// TODO: must need to be able to track archetypes. possible way of identifying an
// archetype is by checking if archetype.xml exists in src/main/resources/META-INF/
}
catch( ArchivaDatabaseException e )
{
log.error( "Error occurred while querying artifacts from the database.", e.getMessage() );
}
repoStatisticsList.add( repoStatistics );
}
return repoStatisticsList;
}
public void setDao( ArchivaDAO dao )
{
this.dao = dao;
}
}

View File

@ -1,354 +0,0 @@
package org.apache.maven.archiva.reporting;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import org.apache.maven.archiva.database.ArchivaDAO;
import org.apache.maven.archiva.database.ArtifactDAO;
import org.apache.maven.archiva.database.constraints.ArtifactsByRepositoryConstraint;
import org.apache.maven.archiva.model.ArchivaArtifact;
import org.apache.maven.archiva.model.RepositoryContentStatistics;
import org.codehaus.plexus.spring.PlexusInSpringTestCase;
import org.easymock.MockControl;
import org.easymock.internal.AlwaysMatcher;
/**
* SimpleRepositoryStatisticsReportGeneratorTest
*
* @version $Id: SimpleRepositoryStatisticsReportGenerator.java
*
* @plexus.component role="org.apache.maven.archiva.reporting.RepositoryStatisticsReportGenerator" role-hint="simple"
*/
public class SimpleRepositoryStatisticsReportGeneratorTest
extends PlexusInSpringTestCase
{
private MockControl daoControl;
private ArchivaDAO dao;
private MockControl artifactDaoControl;
private ArtifactDAO artifactDao;
private SimpleRepositoryStatisticsReportGenerator generator;
private static final String REPO = "test-repo";
@Override
public void setUp()
throws Exception
{
super.setUp();
daoControl = MockControl.createControl( ArchivaDAO.class );
dao = ( ArchivaDAO ) daoControl.getMock();
generator = new SimpleRepositoryStatisticsReportGenerator();
generator.setDao( dao );
artifactDaoControl = MockControl.createControl( ArtifactDAO.class );
artifactDaoControl.setDefaultMatcher( new AlwaysMatcher() );
artifactDao = ( ArtifactDAO ) artifactDaoControl.getMock();
}
private Date toDate( int year, int month, int date, int hour, int min, int sec )
{
Calendar cal = Calendar.getInstance();
cal.clear();
cal.set( year, month, date, hour, min, sec );
return cal.getTime();
}
private List<ArchivaArtifact> createArtifacts( String type )
{
List<ArchivaArtifact> artifacts = new ArrayList<ArchivaArtifact>();
artifacts.add( createArtifact( REPO, "org.apache.archiva", "repository-statistics-" + type, "1.0", type ) );
artifacts.add( createArtifact( REPO, "org.apache.archiva", "repository-statistics-" + type, "1.1", type ) );
artifacts.add( createArtifact( REPO, "org.apache.archiva", "repository-statistics-" + type, "1.2", type ) );
artifacts.add( createArtifact( REPO, "org.apache.archiva", "repository-statistics-" + type, "2.0", type ) );
artifacts.add( createArtifact( REPO, "org.apache.archiva", "repository-statistics-" + type, "3.0", type ) );
return artifacts;
}
private ArchivaArtifact createArtifact( String repoId, String groupId, String artifactId, String version, String type )
{
ArchivaArtifact artifact = new ArchivaArtifact( groupId, artifactId, version, null, type, repoId );
artifact.getModel().setLastModified( new Date() );
return artifact;
}
private RepositoryContentStatistics createRepositoryContentStatistics( Date startDate, String repositoryId )
{
RepositoryContentStatistics repoContentStats = new RepositoryContentStatistics();
repoContentStats.setRepositoryId( repositoryId );
repoContentStats.setDuration( 10000 );
repoContentStats.setNewFileCount( 100 );
repoContentStats.setTotalArtifactCount( 200 );
repoContentStats.setTotalFileCount( 250 );
repoContentStats.setTotalGroupCount( 100 );
repoContentStats.setTotalProjectCount( 180 );
repoContentStats.setTotalSize( 200000 );
repoContentStats.setWhenGathered( startDate );
return repoContentStats;
}
private List<RepositoryContentStatistics> createStatisticsHistoryForSingleRepositoryTest( String repoId )
{
List<RepositoryContentStatistics> repoContentStatsList = new ArrayList<RepositoryContentStatistics>();
repoContentStatsList.add( createRepositoryContentStatistics( toDate( 2008, 11, 1, 0, 0, 0 ), repoId ) );
repoContentStatsList.add( createRepositoryContentStatistics( toDate( 2008, 10, 16, 0, 0, 0 ), repoId ) );
repoContentStatsList.add( createRepositoryContentStatistics( toDate( 2008, 10, 1, 0, 0, 0 ), repoId ) );
repoContentStatsList.add( createRepositoryContentStatistics( toDate( 2008, 9, 16, 0, 0, 0 ), repoId ) );
repoContentStatsList.add( createRepositoryContentStatistics( toDate( 2008, 9, 1, 0, 0, 0 ), repoId ) );
repoContentStatsList.add( createRepositoryContentStatistics( toDate( 2008, 8, 16, 0, 0, 0 ), repoId ) );
repoContentStatsList.add( createRepositoryContentStatistics( toDate( 2008, 8, 1, 0, 0, 0 ), repoId ) );
repoContentStatsList.add( createRepositoryContentStatistics( toDate( 2008, 7, 16, 0, 0, 0 ), repoId ) );
repoContentStatsList.add( createRepositoryContentStatistics( toDate( 2008, 7, 1, 0, 0, 0 ), repoId ) );
repoContentStatsList.add( createRepositoryContentStatistics( toDate( 2008, 6, 16, 0, 0, 0 ), repoId ) );
repoContentStatsList.add( createRepositoryContentStatistics( toDate( 2008, 6, 1, 0, 0, 0 ), repoId ) );
repoContentStatsList.add( createRepositoryContentStatistics( toDate( 2008, 5, 16, 0, 0, 0 ), repoId ) );
repoContentStatsList.add( createRepositoryContentStatistics( toDate( 2008, 5, 1, 0, 0, 0 ), repoId ) );
repoContentStatsList.add( createRepositoryContentStatistics( toDate( 2008, 4, 16, 0, 0, 0 ), repoId ) );
repoContentStatsList.add( createRepositoryContentStatistics( toDate( 2008, 4, 1, 0, 0, 0 ), repoId ) );
repoContentStatsList.add( createRepositoryContentStatistics( toDate( 2008, 3, 16, 0, 0, 0 ), repoId ) );
repoContentStatsList.add( createRepositoryContentStatistics( toDate( 2008, 3, 1, 0, 0, 0 ), repoId ) );
repoContentStatsList.add( createRepositoryContentStatistics( toDate( 2008, 2, 16, 0, 0, 0 ), repoId ) );
repoContentStatsList.add( createRepositoryContentStatistics( toDate( 2008, 2, 1, 0, 0, 0 ), repoId ) );
repoContentStatsList.add( createRepositoryContentStatistics( toDate( 2008, 1, 16, 0, 0, 0 ), repoId ) );
repoContentStatsList.add( createRepositoryContentStatistics( toDate( 2008, 1, 1, 0, 0, 0 ), repoId ) );
return repoContentStatsList;
}
public void testSimpleReportWithPagination()
throws Exception
{
Date startDate = toDate( 2008, 1, 1, 0, 0, 0 );
Date endDate = toDate( 2008, 11, 30, 0, 0, 0 );
DataLimits limits = new DataLimits();
limits.setPerPageCount( 5 );
limits.setCurrentPage( 1 );
limits.setCountOfPages( 5 );
limits.setTotalCount( 21 );
List<ArchivaArtifact> jarArtifacts = createArtifacts( RepositoryStatisticsReportGenerator.JAR_TYPE );
List<ArchivaArtifact> warArtifacts = createArtifacts( RepositoryStatisticsReportGenerator.WAR_TYPE );
List<ArchivaArtifact> mavenPlugins = createArtifacts( RepositoryStatisticsReportGenerator.MAVEN_PLUGIN );
List<RepositoryContentStatistics> repoContentStats = createStatisticsHistoryForSingleRepositoryTest( REPO );
// get first page
daoControl.expectAndReturn( dao.getArtifactDAO(), artifactDao );
artifactDaoControl.expectAndReturn( artifactDao.queryArtifacts(
new ArtifactsByRepositoryConstraint( REPO, RepositoryStatisticsReportGenerator.JAR_TYPE, endDate, "whenGathered") ), jarArtifacts, 5 );
artifactDaoControl.expectAndReturn( artifactDao.queryArtifacts(
new ArtifactsByRepositoryConstraint( REPO, RepositoryStatisticsReportGenerator.WAR_TYPE, endDate, "whenGathered") ), warArtifacts, 5 );
artifactDaoControl.expectAndReturn( artifactDao.queryArtifacts(
new ArtifactsByRepositoryConstraint( REPO, RepositoryStatisticsReportGenerator.MAVEN_PLUGIN, endDate, "whenGathered") ), mavenPlugins, 5 );
daoControl.replay();
artifactDaoControl.replay();
List<RepositoryStatistics> data = generator.generateReport( repoContentStats, REPO, startDate, endDate, limits );
daoControl.verify();
artifactDaoControl.verify();
assertEquals( 5, data.size() );
RepositoryStatistics stats = (RepositoryStatistics) data.get( 0 );
assertEquals( REPO, stats.getRepositoryId() );
assertEquals( 200, stats.getArtifactCount() );
assertEquals( 5, stats.getJarCount() );
assertEquals( 5, stats.getWarCount() );
assertEquals( 5, stats.getPluginCount() );
assertEquals( toDate( 2008, 11, 1, 0, 0, 0 ).getTime(), stats.getDateOfScan().getTime() );
assertEquals( toDate( 2008, 9, 1, 0, 0, 0 ).getTime(), ( (RepositoryStatistics) data.get( 4 ) ).getDateOfScan().getTime() );
// get last page
limits.setCurrentPage( 5 );
daoControl.reset();
artifactDaoControl.reset();
artifactDaoControl.setDefaultMatcher( new AlwaysMatcher() );
daoControl.expectAndReturn( dao.getArtifactDAO(), artifactDao );
artifactDaoControl.expectAndReturn( artifactDao.queryArtifacts(
new ArtifactsByRepositoryConstraint( REPO, RepositoryStatisticsReportGenerator.JAR_TYPE, endDate, "whenGathered") ), jarArtifacts );
artifactDaoControl.expectAndReturn( artifactDao.queryArtifacts(
new ArtifactsByRepositoryConstraint( REPO, RepositoryStatisticsReportGenerator.WAR_TYPE, endDate, "whenGathered") ), warArtifacts );
artifactDaoControl.expectAndReturn( artifactDao.queryArtifacts(
new ArtifactsByRepositoryConstraint( REPO, RepositoryStatisticsReportGenerator.MAVEN_PLUGIN, endDate, "whenGathered") ), mavenPlugins );
daoControl.replay();
artifactDaoControl.replay();
data = generator.generateReport( repoContentStats, REPO, startDate, endDate, limits );
daoControl.verify();
artifactDaoControl.verify();
assertEquals( 1, data.size() );
stats = (RepositoryStatistics) data.get( 0 );
assertEquals( REPO, stats.getRepositoryId() );
assertEquals( 200, stats.getArtifactCount() );
assertEquals( 5, stats.getJarCount() );
assertEquals( 5, stats.getWarCount() );
assertEquals( 5, stats.getPluginCount() );
assertEquals( toDate( 2008, 1, 1, 0, 0, 0 ).getTime(), stats.getDateOfScan().getTime() );
}
public void testSimpleReportWithoutPagination()
throws Exception
{
Date startDate = toDate( 2008, 1, 1, 0, 0, 0 );
Date endDate = toDate( 2008, 11, 30, 0, 0, 0 );
List<ArchivaArtifact> jarArtifacts = createArtifacts( RepositoryStatisticsReportGenerator.JAR_TYPE );
List<ArchivaArtifact> warArtifacts = createArtifacts( RepositoryStatisticsReportGenerator.WAR_TYPE );
List<ArchivaArtifact> mavenPlugins = createArtifacts( RepositoryStatisticsReportGenerator.MAVEN_PLUGIN );
List<RepositoryContentStatistics> repoContentStats = createStatisticsHistoryForSingleRepositoryTest( REPO );
// get first page
daoControl.expectAndReturn( dao.getArtifactDAO(), artifactDao );
artifactDaoControl.expectAndReturn( artifactDao.queryArtifacts(
new ArtifactsByRepositoryConstraint( REPO, RepositoryStatisticsReportGenerator.JAR_TYPE, endDate, "whenGathered") ), jarArtifacts, 21 );
artifactDaoControl.expectAndReturn( artifactDao.queryArtifacts(
new ArtifactsByRepositoryConstraint( REPO, RepositoryStatisticsReportGenerator.WAR_TYPE, endDate, "whenGathered") ), warArtifacts, 21 );
artifactDaoControl.expectAndReturn( artifactDao.queryArtifacts(
new ArtifactsByRepositoryConstraint( REPO, RepositoryStatisticsReportGenerator.MAVEN_PLUGIN, endDate, "whenGathered") ), mavenPlugins, 21 );
daoControl.replay();
artifactDaoControl.replay();
List<RepositoryStatistics> data = generator.generateReport( repoContentStats, REPO, startDate, endDate, false );
daoControl.verify();
artifactDaoControl.verify();
assertEquals( 21, data.size() );
RepositoryStatistics stats = (RepositoryStatistics) data.get( 0 );
assertEquals( REPO, stats.getRepositoryId() );
assertEquals( 200, stats.getArtifactCount() );
assertEquals( 5, stats.getJarCount() );
assertEquals( 5, stats.getWarCount() );
assertEquals( 5, stats.getPluginCount() );
assertEquals( toDate( 2008, 11, 1, 0, 0, 0 ).getTime(), stats.getDateOfScan().getTime() );
assertEquals( toDate( 2008, 1, 1, 0, 0, 0 ).getTime(), ( (RepositoryStatistics) data.get( 20 ) ).getDateOfScan().getTime() );
}
public void testSimpleReportNoArtifactCountStatisticsAvailable()
throws Exception
{
Date startDate = toDate( 2008, 1, 1, 0, 0, 0 );
Date endDate = toDate( 2008, 11, 30, 0, 0, 0 );
DataLimits limits = new DataLimits();
limits.setPerPageCount( 5 );
limits.setCurrentPage( 1 );
limits.setCountOfPages( 5 );
limits.setTotalCount( 21 );
List<ArchivaArtifact> jarArtifacts = new ArrayList<ArchivaArtifact>();
List<ArchivaArtifact> warArtifacts = new ArrayList<ArchivaArtifact>();
List<ArchivaArtifact> mavenPlugins = new ArrayList<ArchivaArtifact>();
List<RepositoryContentStatistics> repoContentStats = createStatisticsHistoryForSingleRepositoryTest( REPO );
daoControl.expectAndReturn( dao.getArtifactDAO(), artifactDao );
artifactDaoControl.expectAndReturn( artifactDao.queryArtifacts(
new ArtifactsByRepositoryConstraint( REPO, RepositoryStatisticsReportGenerator.JAR_TYPE, endDate, "whenGathered") ), jarArtifacts, 5 );
artifactDaoControl.expectAndReturn( artifactDao.queryArtifacts(
new ArtifactsByRepositoryConstraint( REPO, RepositoryStatisticsReportGenerator.WAR_TYPE, endDate, "whenGathered") ), warArtifacts, 5 );
artifactDaoControl.expectAndReturn( artifactDao.queryArtifacts(
new ArtifactsByRepositoryConstraint( REPO, RepositoryStatisticsReportGenerator.MAVEN_PLUGIN, endDate, "whenGathered") ), mavenPlugins, 5 );
daoControl.replay();
artifactDaoControl.replay();
List<RepositoryStatistics> data = generator.generateReport( repoContentStats, REPO, startDate, endDate, limits );
daoControl.verify();
artifactDaoControl.verify();
assertEquals( 5, data.size() );
RepositoryStatistics stats = (RepositoryStatistics) data.get( 0 );
assertEquals( REPO, stats.getRepositoryId() );
assertEquals( 200, stats.getArtifactCount() );
assertEquals( 0, stats.getJarCount() );
assertEquals( 0, stats.getWarCount() );
assertEquals( 0, stats.getPluginCount() );
assertEquals( toDate( 2008, 11, 1, 0, 0, 0 ).getTime(), stats.getDateOfScan().getTime() );
assertEquals( toDate( 2008, 9, 1, 0, 0, 0 ).getTime(), ( (RepositoryStatistics) data.get( 4 ) ).getDateOfScan().getTime() );
// no results found when ArtifactDAO was queried
}
public void testSimpleReportWithPaginationInvalidRequestedPage()
throws Exception
{
Date startDate = toDate( 2008, 1, 1, 0, 0, 0 );
Date endDate = toDate( 2008, 11, 30, 0, 0, 0 );
DataLimits limits = new DataLimits();
limits.setPerPageCount( 5 );
limits.setCurrentPage( 10 );
limits.setCountOfPages( 5 );
limits.setTotalCount( 21 );
List<RepositoryContentStatistics> repoContentStats = createStatisticsHistoryForSingleRepositoryTest( REPO );
try
{
generator.generateReport( repoContentStats, REPO, startDate, endDate, limits );
fail( "An ArchivaReportException should have been thrown." );
}
catch ( ArchivaReportException a )
{
}
// requested page exceeds total number of pages
}
}

View File

@ -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 @@ public void deleteStatistics( String repositoryId )
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 );

View File

@ -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,68 +67,9 @@ public class GenerateReportAction
extends PlexusActionSupport
implements SecureAction, ServletRequestAware, Preparable
{
private Logger log = LoggerFactory.getLogger( GenerateReportAction.class );
/**
* @plexus.requirement role-hint="jdo"
*/
protected ArchivaDAO dao;
/**
* @plexus.requirement
*/
private ArchivaConfiguration archivaConfiguration;
protected HttpServletRequest request;
protected List<RepositoryProblemReport> reports = new ArrayList<RepositoryProblemReport>();
protected String groupId;
protected String repositoryId;
protected String prev;
protected String next;
protected int page = 1;
protected int rowCount = 100;
protected boolean isLastPage;
public static final String BLANK = "blank";
private static Boolean jasperPresent;
private Collection<String> repositoryIds;
public static final String ALL_REPOSITORIES = "All Repositories";
protected 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();
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",
@ -142,8 +77,54 @@ public class GenerateReportAction
public static final String SEND_FILE = "send-file";
private Logger log = LoggerFactory.getLogger( GenerateReportAction.class );
/**
* @plexus.requirement role-hint="jdo"
*/
private ArchivaDAO dao;
/**
* @plexus.requirement
*/
private ArchivaConfiguration archivaConfiguration;
/**
* @plexus.requirement
*/
private RepositoryStatisticsManager repositoryStatisticsManager;
private HttpServletRequest request;
private String groupId;
private String repositoryId;
private int page = 1;
private int rowCount = 100;
private List<String> selectedRepositories = new ArrayList<String>();
private String startDate;
private String endDate;
private int numPages;
private Collection<String> repositoryIds;
private Map<String, List<RepositoryProblemReport>> repositoriesMap =
new TreeMap<String, List<RepositoryProblemReport>>();
private List<String> availableRepositories;
private List<RepositoryStatistics> repositoryStatistics = new ArrayList<RepositoryStatistics>();
private InputStream inputStream;
private boolean lastPage;
@SuppressWarnings("unchecked")
public void prepare()
{
@ -165,11 +146,6 @@ public void prepare()
}
}
public Collection<String> getRepositoryIds()
{
return repositoryIds;
}
/**
* Generate the statistics report.
*
@ -185,29 +161,24 @@ public Collection<String> getRepositoryIds()
* - 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 @@ public String generateStatistics()
}
// 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 @@ else if ( selectedRepositories.size() == 1 )
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 @@ else if ( selectedRepositories.size() == 1 )
/**
* 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;
selectedRepositories = parseSelectedRepositories();
repositoryStatistics = new ArrayList<RepositoryStatistics>();
RepositoryContentStatisticsDAO repoContentStatsDao = dao.getRepositoryContentStatisticsDAO();
if ( selectedRepositories.size() > 1 )
try
{
try
startDateInDF = getStartDateInDateFormat();
endDateInDF = getEndDateInDateFormat();
}
catch ( ParseException e )
{
addActionError( "Error parsing date(s)." );
return ERROR;
}
if ( startDateInDF.after( endDateInDF ) )
{
addFieldError( "startDate", "Start Date must be earlier than the End Date" );
return INPUT;
}
// multiple repos
for ( String repo : selectedRepositories )
{
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
List<RepositoryStatistics> stats =
repositoryStatisticsManager.getStatisticsInRange( repositoryId, startDateInDF, endDateInDF );
if ( stats.isEmpty() )
{
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 )
{
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;
}
}
else
{
addFieldError( "availableRepositories", "Please select a repository (or repositories) from the list." );
return INPUT;
}
if ( repositoryStatistics.isEmpty() )
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" );
}
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;
}
// write output stream depending on single or comparison report
StringBuffer input = getInput();
if ( repositoryStatistics.isEmpty() )
{
return BLANK;
}
// write output stream depending on single or comparison report
StringReader reader = new StringReader( input.toString() );
try
@ -429,9 +441,9 @@ private List<String> parseSelectedRepositories()
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 @@ private List<String> parseSelectedRepositories()
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,63 +480,17 @@ private Date getEndDateInDateFormat()
else
{
endDateInDF = DateUtils.parseDate( endDate, datePatterns );
// 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 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" );
}
}
return input;
}
private Date getDefaultStartDate()
{
Calendar cal = Calendar.getInstance();
@ -601,72 +525,44 @@ public String execute()
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;
}
else
{
reports.remove( rowCount );
lastPage = true;
}
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,16 +621,16 @@ private void addToList( RepositoryProblemReport repoProblemReport )
problemsList.add( repoProblemReport );
}
public Collection<String> getRepositoryIds()
{
return repositoryIds;
}
public void setServletRequest( HttpServletRequest request )
{
this.request = request;
}
public List<RepositoryProblemReport> getReports()
{
return reports;
}
public String getGroupId()
{
return groupId;
@ -755,16 +651,6 @@ public void setRepositoryId( String repositoryId )
this.repositoryId = repositoryId;
}
public String getPrev()
{
return prev;
}
public String getNext()
{
return next;
}
public int getPage()
{
return page;
@ -785,11 +671,6 @@ public void setRowCount( int rowCount )
this.rowCount = rowCount;
}
public boolean getIsLastPage()
{
return isLastPage;
}
public void setRepositoriesMap( Map<String, List<RepositoryProblemReport>> repositoriesMap )
{
this.repositoriesMap = repositoriesMap;
@ -850,38 +731,23 @@ public void setRepositoryStatistics( List<RepositoryStatistics> repositoryStatis
this.repositoryStatistics = repositoryStatistics;
}
public int getReposSize()
public boolean isLastPage()
{
return reposSize;
return lastPage;
}
public void setReposSize( int reposSize )
public void setLastPage( boolean lastPage )
{
this.reposSize = reposSize;
}
public String getSelectedRepo()
{
return selectedRepo;
}
public void setSelectedRepo( String selectedRepo )
{
this.selectedRepo = selectedRepo;
}
public DataLimits getLimits()
{
return limits;
}
public void setLimits( DataLimits limits )
{
this.limits = limits;
this.lastPage = lastPage;
}
public InputStream getInputStream()
{
return inputStream;
}
public int getNumPages()
{
return numPages;
}
}

View File

@ -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>

View File

@ -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>

View File

@ -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 @@ public RepositoryProblemDAO getRepositoryProblemDAO()
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;

View File

@ -37,6 +37,10 @@
<artifactId>plexus-spring</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>

View File

@ -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 RepositoryStatistics getLastStatistics( String repositoryId )
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 @@ public void deleteStatistics( String repositoryId )
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;

View File

@ -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 @@ public interface RepositoryStatisticsManager
void addStatisticsAfterScan( String repositoryId, RepositoryStatistics repositoryStatistics );
void deleteStatistics( String repositoryId );
List<RepositoryStatistics> getStatisticsInRange( String repositoryId, Date startTime, Date endTime );
}

View File

@ -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 @@ public class RepositoryStatisticsManagerTest
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 @@ public void testDeleteStatsWhenEmpty()
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();