}
long sinceWhen = RepositoryScanner.FRESH_SCAN;
long previousFileCount = 0;
RepositorySession repositorySession = repositorySessionFactory.createSession();
MetadataRepository metadataRepository = repositorySession.getRepository();
try
{
if ( !task.isScanAll() )
{
RepositoryStatistics previousStats =
repositoryStatisticsManager.getLastStatistics( metadataRepository, repoId );
if ( previousStats != null )
{
sinceWhen = previousStats.getScanStartTime().getTime();
previousFileCount = previousStats.getTotalFileCount();
}
}
RepositoryScanStatistics stats;
try
{
stats = repoScanner.scan( arepo, sinceWhen );
}
catch ( RepositoryScannerException e )
{
throw new TaskExecutionException( "Repository error when executing repository job.", e );
}
log.info( "Finished first scan: {}", stats.toDump( arepo ) );
// further statistics will be populated by the following method
Date endTime = new Date( stats.getWhenGathered().getTime() + stats.getDuration() );
log.info( "Gathering repository statistics" );
repositoryStatisticsManager.addStatisticsAfterScan( metadataRepository, repoId,
stats.getWhenGathered(), endTime,
stats.getTotalFileCount(),
stats.getTotalFileCount() - previousFileCount );
repositorySession.save();
}
catch ( MetadataRepositoryException e )
{
throw new TaskExecutionException( "Unable to store updated statistics: " + e.getMessage(), e );
}
finally
{
repositorySession.close();
}
// log.info( "Scanning for removed repository content" );
// metadataRepository.findAllProjects();