this.task = task;
String repoId = task.getRepositoryId();
if ( StringUtils.isBlank( repoId ) )
{
throw new TaskExecutionException( "Unable to execute RepositoryTask with blank repository Id." );
}
ManagedRepository arepo = managedRepositoryAdmin.getManagedRepository( repoId );
// execute consumers on resource file if set
if ( task.getResourceFile() != null )
{
log.debug( "Executing task from queue with job name: {}", task );
consumers.executeConsumers( arepo, task.getResourceFile(), task.isUpdateRelatedArtifacts() );
}
else
{
log.info( "Executing task from queue with job name: {}", task );
// otherwise, execute consumers on whole repository
if ( arepo == null )
{
throw new TaskExecutionException(
"Unable to execute RepositoryTask with invalid repository id: " + repoId );
}
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();
// FIXME: do something
log.info( "Finished repository task: {}", task );
this.task = null;
}
}
catch ( RepositoryAdminException e )
{
log.error( e.getMessage(), e );
throw new TaskExecutionException( e.getMessage(), e );
}
}