deleteContent && context.getIndexDirectoryFile().exists() );
}
}
catch ( PlexusSisuBridgeException e )
{
throw new RepositoryAdminException( e.getMessage(), e );
}
catch ( IOException e )
{
throw new RepositoryAdminException( e.getMessage(), e );
}
if ( !stagedOne )
{
RepositorySession repositorySession = getRepositorySessionFactory().createSession();
try
{
MetadataRepository metadataRepository = repositorySession.getRepository();
metadataRepository.removeRepository( repository.getId() );
//invalidate cache
namespacesCache.remove( repository.getId() );
log.debug( "call repositoryStatisticsManager.deleteStatistics" );
getRepositoryStatisticsManager().deleteStatistics( metadataRepository, repository.getId() );
repositorySession.save();
}
catch ( MetadataRepositoryException e )
{
//throw new RepositoryAdminException( e.getMessage(), e );
log.warn( "skip error during removing repository from MetadataRepository:{}", e.getMessage(), e );
}
finally
{
repositorySession.close();
}
}
config.removeManagedRepository( repository );
if ( deleteContent )
{
// TODO could be async ? as directory can be huge
File dir = new File( repository.getLocation() );
if ( !FileUtils.deleteQuietly( dir ) )
{
throw new RepositoryAdminException( "Cannot delete repository " + dir );
}
}
// olamy: copy list for reading as a unit test in webapp fail with ConcurrentModificationException
List<ProxyConnectorConfiguration> proxyConnectors = new ArrayList<>( config.getProxyConnectors() );
for ( ProxyConnectorConfiguration proxyConnector : proxyConnectors )
{
if ( StringUtils.equals( proxyConnector.getSourceRepoId(), repository.getId() ) )
{
config.removeProxyConnector( proxyConnector );
}
}
Map<String, List<String>> repoToGroupMap = config.getRepositoryToGroupMap();
if ( repoToGroupMap != null )
{
if ( repoToGroupMap.containsKey( repository.getId() ) )
{
List<String> repoGroups = repoToGroupMap.get( repository.getId() );
for ( String repoGroup : repoGroups )
{
// copy to prevent UnsupportedOperationException
RepositoryGroupConfiguration repositoryGroupConfiguration =
config.findRepositoryGroupById( repoGroup );
List<String> repos = new ArrayList<>( repositoryGroupConfiguration.getRepositories() );
config.removeRepositoryGroup( repositoryGroupConfiguration );
repos.remove( repository.getId() );
repositoryGroupConfiguration.setRepositories( repos );
config.addRepositoryGroup( repositoryGroupConfiguration );
}
}
}
try
{
removeRepositoryRoles( repository );
}
catch ( RoleManagerException e )
{
throw new RepositoryAdminException(
"fail to remove repository roles for repository " + repository.getId() + " : " + e.getMessage(), e );
}
saveConfiguration( config );