{
List repos = archivaConfiguration.getConfiguration().getRepositories();
Iterator it = repos.iterator();
while ( it.hasNext() )
{
RepositoryConfiguration repoConfig = (RepositoryConfiguration) it.next();
try
{
try
{
ArchivaRepository repository = dao.getRepositoryDAO().getRepository( repoConfig.getId() );
// Found repository. Update it.
repository.getModel().setName( repoConfig.getName() );
repository.getModel().setUrl( repoConfig.getUrl() );
repository.getModel().setLayoutName( repoConfig.getLayout() );
repository.getModel().setCreationSource( "configuration" );
repository.getModel().setReleasePolicy( repoConfig.isReleases() );
repository.getModel().setSnapshotPolicy( repoConfig.isSnapshots() );
dao.getRepositoryDAO().saveRepository( repository );
}
catch ( ObjectNotFoundException e )
{
// Add the repository to the database.
getLogger().info( "Adding repository configuration to DB: " + repoConfig );
ArchivaRepository drepo = ArchivaConfigurationAdaptor.toArchivaRepository( repoConfig );
drepo.getModel().setCreationSource( "configuration" );
dao.getRepositoryDAO().saveRepository( drepo );
}
}
catch ( ArchivaDatabaseException e )
{
// Log error.
getLogger().error( "Unable to add configured repositories to the database: " + e.getMessage(), e );
}
// manage roles for repositories
try
{
if ( !roleManager.templatedRoleExists( "archiva-repository-observer", repoConfig.getId() ) )
{
roleManager.createTemplatedRole( "archiva-repository-observer", repoConfig.getId() );
}
if ( !roleManager.templatedRoleExists( "archiva-repository-manager", repoConfig.getId() ) )
{
roleManager.createTemplatedRole( "archiva-repository-manager", repoConfig.getId() );
}
}
catch ( RoleManagerException e )
{
// Log error.