long sinceWhen,
List<RepositoryContentStatistics> results,
RepositoryScanStatistics stats )
{
// I hate jpox and modello <-- and so do I
RepositoryContentStatistics dbstats = new RepositoryContentStatistics();
dbstats.setDuration( stats.getDuration() );
dbstats.setNewFileCount( stats.getNewFileCount() );
dbstats.setRepositoryId( stats.getRepositoryId() );
dbstats.setTotalFileCount( stats.getTotalFileCount() );
dbstats.setWhenGathered( stats.getWhenGathered() );
// total artifact count
try
{
List<ArchivaArtifact> artifacts = dao.getArtifactDAO().queryArtifacts(
new ArtifactsByRepositoryConstraint( arepo.getId(), stats.getWhenGathered(), "groupId", true ) );
dbstats.setTotalArtifactCount( artifacts.size() );
}
catch ( ObjectNotFoundException oe )
{
log.error( "Object not found in the database : " + oe.getMessage() );
}
catch ( ArchivaDatabaseException ae )
{
log.error( "Error occurred while querying artifacts for artifact count : " + ae.getMessage() );
}
// total repo size
long size = FileUtils.sizeOfDirectory( new File( arepo.getLocation() ) );
dbstats.setTotalSize( size );
// total unique groups
List<String> repos = new ArrayList<String>();
repos.add( arepo.getId() );
List<String> groupIds = (List<String>) dao.query( new UniqueGroupIdConstraint( repos ) );
dbstats.setTotalGroupCount( groupIds.size() );
List<Object[]> artifactIds = (List<Object[]>) dao.query( new UniqueArtifactIdConstraint( arepo.getId(), true ) );
dbstats.setTotalProjectCount( artifactIds.size() );
return dbstats;
}