1 package org.apache.archiva.admin.repository.managed;
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
21 import org.apache.archiva.admin.model.AuditInformation;
22 import org.apache.archiva.admin.model.RepositoryAdminException;
23 import org.apache.archiva.admin.model.beans.ManagedRepository;
24 import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
25 import org.apache.archiva.admin.repository.AbstractRepositoryAdmin;
26 import org.apache.archiva.audit.AuditEvent;
27 import org.apache.archiva.common.plexusbridge.MavenIndexerUtils;
28 import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
29 import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException;
30 import org.apache.archiva.configuration.Configuration;
31 import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
32 import org.apache.archiva.configuration.ProxyConnectorConfiguration;
33 import org.apache.archiva.configuration.RepositoryGroupConfiguration;
34 import org.apache.archiva.metadata.repository.MetadataRepository;
35 import org.apache.archiva.metadata.repository.MetadataRepositoryException;
36 import org.apache.archiva.metadata.repository.RepositorySession;
37 import org.apache.archiva.metadata.repository.RepositorySessionFactory;
38 import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager;
39 import org.apache.archiva.redback.components.taskqueue.TaskQueueException;
40 import org.apache.archiva.redback.role.RoleManager;
41 import org.apache.archiva.redback.role.RoleManagerException;
42 import org.apache.archiva.scheduler.repository.model.RepositoryArchivaTaskScheduler;
43 import org.apache.archiva.scheduler.repository.model.RepositoryTask;
44 import org.apache.archiva.security.common.ArchivaRoleConstants;
45 import org.apache.commons.io.FileUtils;
46 import org.apache.commons.lang.StringUtils;
47 import org.apache.maven.index.NexusIndexer;
48 import org.apache.maven.index.context.IndexCreator;
49 import org.apache.maven.index.context.IndexingContext;
50 import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException;
51 import org.slf4j.Logger;
52 import org.slf4j.LoggerFactory;
53 import org.springframework.stereotype.Service;
55 import javax.annotation.PostConstruct;
56 import javax.annotation.PreDestroy;
57 import javax.inject.Inject;
58 import javax.inject.Named;
60 import java.io.IOException;
61 import java.net.MalformedURLException;
62 import java.util.ArrayList;
63 import java.util.Collections;
64 import java.util.HashMap;
65 import java.util.List;
69 * FIXME review the staging mechanism to have a per user session one
71 * @author Olivier Lamy
73 @Service( "managedRepositoryAdmin#default" )
74 public class DefaultManagedRepositoryAdmin
75 extends AbstractRepositoryAdmin
76 implements ManagedRepositoryAdmin
79 private Logger log = LoggerFactory.getLogger( getClass() );
81 public static final String STAGE_REPO_ID_END = "-stage";
84 @Named( value = "archivaTaskScheduler#repository" )
85 private RepositoryArchivaTaskScheduler repositoryTaskScheduler;
88 * FIXME: this could be multiple implementations and needs to be configured.
91 private RepositorySessionFactory repositorySessionFactory;
94 private RepositoryStatisticsManager repositoryStatisticsManager;
97 private PlexusSisuBridge plexusSisuBridge;
100 private MavenIndexerUtils mavenIndexerUtils;
103 protected RoleManager roleManager;
106 List<? extends IndexCreator> indexCreators;
108 NexusIndexer indexer;
111 public void initialize()
112 throws RepositoryAdminException, RoleManagerException
116 indexCreators = mavenIndexerUtils.getAllIndexCreators();
117 indexer = plexusSisuBridge.lookup( NexusIndexer.class );
119 catch ( PlexusSisuBridgeException e )
121 throw new RepositoryAdminException( e.getMessage(), e );
123 // initialize index context on start and check roles here
124 for ( ManagedRepository managedRepository : getManagedRepositories() )
126 createIndexContext( managedRepository );
127 addRepositoryRoles( managedRepository.getId() );
133 public void shutdown()
134 throws RepositoryAdminException
138 // close index on shutdown
139 for ( ManagedRepository managedRepository : getManagedRepositories() )
141 IndexingContext context = indexer.getIndexingContexts().get( managedRepository.getId() );
142 if ( context != null )
144 indexer.removeIndexingContext( context, false );
148 catch ( IOException e )
150 throw new RepositoryAdminException( e.getMessage(), e );
154 public List<ManagedRepository> getManagedRepositories()
155 throws RepositoryAdminException
157 List<ManagedRepositoryConfiguration> managedRepoConfigs =
158 getArchivaConfiguration().getConfiguration().getManagedRepositories();
160 if ( managedRepoConfigs == null )
162 return Collections.emptyList();
165 List<ManagedRepository> managedRepos = new ArrayList<ManagedRepository>( managedRepoConfigs.size() );
167 for ( ManagedRepositoryConfiguration repoConfig : managedRepoConfigs )
169 ManagedRepository repo =
170 new ManagedRepository( repoConfig.getId(), repoConfig.getName(), repoConfig.getLocation(),
171 repoConfig.getLayout(), repoConfig.isSnapshots(), repoConfig.isReleases(),
172 repoConfig.isBlockRedeployments(), repoConfig.getRefreshCronExpression(),
173 repoConfig.getIndexDir(), repoConfig.isScanned(), repoConfig.getDaysOlder(),
174 repoConfig.getRetentionCount(), repoConfig.isDeleteReleasedSnapshots(),
175 repoConfig.isStageRepoNeeded() );
176 repo.setDescription( repoConfig.getDescription() );
177 repo.setSkipPackedIndexCreation( repoConfig.isSkipPackedIndexCreation() );
178 managedRepos.add( repo );
184 public Map<String, ManagedRepository> getManagedRepositoriesAsMap()
185 throws RepositoryAdminException
187 List<ManagedRepository> managedRepositories = getManagedRepositories();
188 Map<String, ManagedRepository> repositoriesMap =
189 new HashMap<String, ManagedRepository>( managedRepositories.size() );
190 for ( ManagedRepository managedRepository : managedRepositories )
192 repositoriesMap.put( managedRepository.getId(), managedRepository );
194 return repositoriesMap;
197 public ManagedRepository getManagedRepository( String repositoryId )
198 throws RepositoryAdminException
200 List<ManagedRepository> repos = getManagedRepositories();
201 for ( ManagedRepository repo : repos )
203 if ( StringUtils.equals( repo.getId(), repositoryId ) )
211 public Boolean addManagedRepository( ManagedRepository managedRepository, boolean needStageRepo,
212 AuditInformation auditInformation )
213 throws RepositoryAdminException
216 getRepositoryCommonValidator().basicValidation( managedRepository, false );
217 getRepositoryCommonValidator().validateManagedRepository( managedRepository );
218 triggerAuditEvent( managedRepository.getId(), null, AuditEvent.ADD_MANAGED_REPO, auditInformation );
220 addManagedRepository( managedRepository.getId(), managedRepository.getLayout(), managedRepository.getName(),
221 managedRepository.getLocation(), managedRepository.isBlockRedeployments(),
222 managedRepository.isReleases(), managedRepository.isSnapshots(), needStageRepo,
223 managedRepository.getCronExpression(), managedRepository.getIndexDirectory(),
224 managedRepository.getDaysOlder(), managedRepository.getRetentionCount(),
225 managedRepository.isDeleteReleasedSnapshots(), managedRepository.getDescription(),
226 managedRepository.isSkipPackedIndexCreation(), managedRepository.isScanned(),
227 auditInformation, getArchivaConfiguration().getConfiguration() ) != null;
229 createIndexContext( managedRepository );
234 private ManagedRepositoryConfiguration addManagedRepository( String repoId, String layout, String name,
235 String location, boolean blockRedeployments,
236 boolean releasesIncluded, boolean snapshotsIncluded,
237 boolean stageRepoNeeded, String cronExpression,
238 String indexDir, int daysOlder, int retentionCount,
239 boolean deteleReleasedSnapshots, String description,
240 boolean skipPackedIndexCreation, boolean scanned,
241 AuditInformation auditInformation,
242 Configuration config )
243 throws RepositoryAdminException
246 ManagedRepositoryConfiguration repository = new ManagedRepositoryConfiguration();
248 repository.setId( repoId );
249 repository.setBlockRedeployments( blockRedeployments );
250 repository.setReleases( releasesIncluded );
251 repository.setSnapshots( snapshotsIncluded );
252 repository.setScanned( scanned );
253 repository.setName( name );
254 repository.setLocation( getRepositoryCommonValidator().removeExpressions( location ) );
255 repository.setLayout( layout );
256 repository.setRefreshCronExpression( cronExpression );
257 repository.setIndexDir( indexDir );
258 repository.setDaysOlder( daysOlder );
259 repository.setRetentionCount( retentionCount );
260 repository.setDeleteReleasedSnapshots( deteleReleasedSnapshots );
261 repository.setIndexDir( indexDir );
262 repository.setDescription( description );
263 repository.setSkipPackedIndexCreation( skipPackedIndexCreation );
264 repository.setStageRepoNeeded( stageRepoNeeded );
268 addRepository( repository, config );
269 addRepositoryRoles( repository.getId() );
271 if ( stageRepoNeeded )
273 ManagedRepositoryConfiguration stagingRepository = getStageRepoConfig( repository );
274 addRepository( stagingRepository, config );
275 addRepositoryRoles( stagingRepository.getId() );
276 triggerAuditEvent( stagingRepository.getId(), null, AuditEvent.ADD_MANAGED_REPO, auditInformation );
279 catch ( RoleManagerException e )
281 throw new RepositoryAdminException( "failed to add repository roles " + e.getMessage(), e );
283 catch ( IOException e )
285 throw new RepositoryAdminException( "failed to add repository " + e.getMessage(), e );
288 saveConfiguration( config );
290 //MRM-1342 Repository statistics report doesn't appear to be working correctly
291 //scan repository when adding of repository is successful
296 scanRepository( repoId, true );
299 // TODO need a better to define scanning or not for staged repo
300 if ( stageRepoNeeded && scanned )
302 ManagedRepositoryConfiguration stagingRepository = getStageRepoConfig( repository );
303 scanRepository( stagingRepository.getId(), true );
306 catch ( Exception e )
308 log.warn( new StringBuilder( "Unable to scan repository [" ).append( repoId ).append( "]: " ).append(
309 e.getMessage() ).toString(), e );
315 public Boolean deleteManagedRepository( String repositoryId, AuditInformation auditInformation,
316 boolean deleteContent )
317 throws RepositoryAdminException
319 Configuration config = getArchivaConfiguration().getConfiguration();
321 ManagedRepositoryConfiguration repository = config.findManagedRepositoryById( repositoryId );
323 if ( repository == null )
325 throw new RepositoryAdminException( "A repository with that id does not exist" );
328 triggerAuditEvent( repositoryId, null, AuditEvent.DELETE_MANAGED_REPO, auditInformation );
330 deleteManagedRepository( repository, deleteContent, config, false );
332 // stage repo exists ?
333 ManagedRepositoryConfiguration stagingRepository =
334 getArchivaConfiguration().getConfiguration().findManagedRepositoryById( repositoryId + STAGE_REPO_ID_END );
335 if ( stagingRepository != null )
337 // do not trigger event when deleting the staged one
338 deleteManagedRepository( stagingRepository, deleteContent, config, true );
343 saveConfiguration( config );
345 catch ( Exception e )
347 throw new RepositoryAdminException( "Error saving configuration for delete action" + e.getMessage(), e );
353 private Boolean deleteManagedRepository( ManagedRepositoryConfiguration repository, boolean deleteContent,
354 Configuration config, boolean stagedOne )
355 throws RepositoryAdminException
360 NexusIndexer nexusIndexer = plexusSisuBridge.lookup( NexusIndexer.class );
362 IndexingContext context = nexusIndexer.getIndexingContexts().get( repository.getId() );
363 if ( context != null )
365 // delete content only if directory exists
366 nexusIndexer.removeIndexingContext( context,
367 deleteContent && context.getIndexDirectoryFile().exists() );
370 catch ( PlexusSisuBridgeException e )
372 throw new RepositoryAdminException( e.getMessage(), e );
374 catch ( IOException e )
376 throw new RepositoryAdminException( e.getMessage(), e );
380 RepositorySession repositorySession = getRepositorySessionFactory().createSession();
383 MetadataRepository metadataRepository = repositorySession.getRepository();
384 metadataRepository.removeRepository( repository.getId() );
385 log.debug( "call repositoryStatisticsManager.deleteStatistics" );
386 getRepositoryStatisticsManager().deleteStatistics( metadataRepository, repository.getId() );
387 repositorySession.save();
389 catch ( MetadataRepositoryException e )
391 //throw new RepositoryAdminException( e.getMessage(), e );
392 log.warn( "skip error during removing repository from MetadatRepository:{}", e.getMessage(), e );
396 repositorySession.close();
399 config.removeManagedRepository( repository );
403 // TODO could be async ? as directory can be huge
404 File dir = new File( repository.getLocation() );
405 if ( !FileUtils.deleteQuietly( dir ) )
407 throw new RepositoryAdminException( "Cannot delete repository " + dir );
411 // olamy: copy list for reading as a unit test in webapp fail with ConcurrentModificationException
412 List<ProxyConnectorConfiguration> proxyConnectors =
413 new ArrayList<ProxyConnectorConfiguration>( config.getProxyConnectors() );
414 for ( ProxyConnectorConfiguration proxyConnector : proxyConnectors )
416 if ( StringUtils.equals( proxyConnector.getSourceRepoId(), repository.getId() ) )
418 config.removeProxyConnector( proxyConnector );
422 Map<String, List<String>> repoToGroupMap = config.getRepositoryToGroupMap();
423 if ( repoToGroupMap != null )
425 if ( repoToGroupMap.containsKey( repository.getId() ) )
427 List<String> repoGroups = repoToGroupMap.get( repository.getId() );
428 for ( String repoGroup : repoGroups )
430 // copy to prevent UnsupportedOperationException
431 RepositoryGroupConfiguration repositoryGroupConfiguration =
432 config.findRepositoryGroupById( repoGroup );
433 List<String> repos = new ArrayList<String>( repositoryGroupConfiguration.getRepositories() );
434 config.removeRepositoryGroup( repositoryGroupConfiguration );
435 repos.remove( repository.getId() );
436 repositoryGroupConfiguration.setRepositories( repos );
437 config.addRepositoryGroup( repositoryGroupConfiguration );
444 removeRepositoryRoles( repository );
446 catch ( RoleManagerException e )
448 throw new RepositoryAdminException(
449 "fail to remove repository roles for repository " + repository.getId() + " : " + e.getMessage(), e );
452 saveConfiguration( config );
458 public Boolean updateManagedRepository( ManagedRepository managedRepository, boolean needStageRepo,
459 AuditInformation auditInformation, boolean resetStats )
460 throws RepositoryAdminException
463 log.debug( "updateManagedConfiguration repo {} needStage {} resetStats {} ", managedRepository, needStageRepo,
466 // Ensure that the fields are valid.
468 getRepositoryCommonValidator().basicValidation( managedRepository, true );
470 getRepositoryCommonValidator().validateManagedRepository( managedRepository );
472 Configuration configuration = getArchivaConfiguration().getConfiguration();
474 ManagedRepositoryConfiguration toremove = configuration.findManagedRepositoryById( managedRepository.getId() );
476 boolean updateIndexContext = false;
478 if ( toremove != null )
480 configuration.removeManagedRepository( toremove );
482 updateIndexContext = !StringUtils.equals( toremove.getIndexDir(), managedRepository.getIndexDirectory() );
485 ManagedRepositoryConfiguration stagingRepository = getStageRepoConfig( toremove );
487 // TODO remove content from old if path has changed !!!!!
489 if ( stagingRepository != null )
491 configuration.removeManagedRepository( stagingRepository );
494 ManagedRepositoryConfiguration managedRepositoryConfiguration =
495 addManagedRepository( managedRepository.getId(), managedRepository.getLayout(), managedRepository.getName(),
496 managedRepository.getLocation(), managedRepository.isBlockRedeployments(),
497 managedRepository.isReleases(), managedRepository.isSnapshots(), needStageRepo,
498 managedRepository.getCronExpression(), managedRepository.getIndexDirectory(),
499 managedRepository.getDaysOlder(), managedRepository.getRetentionCount(),
500 managedRepository.isDeleteReleasedSnapshots(), managedRepository.getDescription(),
501 managedRepository.isSkipPackedIndexCreation(), managedRepository.isScanned(),
502 auditInformation, getArchivaConfiguration().getConfiguration() );
504 // Save the repository configuration.
505 RepositorySession repositorySession = getRepositorySessionFactory().createSession();
509 triggerAuditEvent( managedRepositoryConfiguration.getId(), null, AuditEvent.MODIFY_MANAGED_REPO,
512 saveConfiguration( this.getArchivaConfiguration().getConfiguration() );
515 log.debug( "call repositoryStatisticsManager.deleteStatistics" );
516 getRepositoryStatisticsManager().deleteStatistics( repositorySession.getRepository(),
517 managedRepositoryConfiguration.getId() );
518 repositorySession.save();
522 catch ( MetadataRepositoryException e )
524 throw new RepositoryAdminException( e.getMessage(), e );
528 repositorySession.close();
531 if ( updateIndexContext )
535 IndexingContext indexingContext = indexer.getIndexingContexts().get( managedRepository.getId() );
536 if ( indexingContext != null )
538 indexer.removeIndexingContext( indexingContext, true );
541 // delete directory too as only content is deleted
542 File indexDirectory = indexingContext.getIndexDirectoryFile();
543 FileUtils.deleteDirectory( indexDirectory );
545 createIndexContext( managedRepository );
547 catch ( IOException e )
549 throw new RepositoryAdminException( e.getMessage(), e );
556 //--------------------------
558 //--------------------------
561 protected void addRepository( ManagedRepositoryConfiguration repository, Configuration configuration )
562 throws RepositoryAdminException, IOException
564 // Normalize the path
565 File file = new File( repository.getLocation() );
566 if ( !file.isAbsolute() )
568 // add appserver.base/repositories
569 file = new File( getRegistry().getString( "appserver.base" ) + File.separatorChar + "repositories",
570 repository.getLocation() );
572 repository.setLocation( file.getCanonicalPath() );
573 if ( !file.exists() )
577 if ( !file.exists() || !file.isDirectory() )
579 throw new RepositoryAdminException(
580 "Unable to add repository - no write access, can not create the root directory: " + file );
583 configuration.addManagedRepository( repository );
587 public IndexingContext createIndexContext( ManagedRepository repository )
588 throws RepositoryAdminException
591 IndexingContext context = indexer.getIndexingContexts().get( repository.getId() );
593 if ( context != null )
595 log.debug( "skip creating repository indexingContent with id {} as already exists", repository.getId() );
599 // take care first about repository location as can be relative
600 File repositoryDirectory = new File( repository.getLocation() );
602 if ( !repositoryDirectory.isAbsolute() )
604 repositoryDirectory =
605 new File( getRegistry().getString( "appserver.base" ) + File.separatorChar + "repositories",
606 repository.getLocation() );
609 if ( !repositoryDirectory.exists() )
611 repositoryDirectory.mkdirs();
617 String indexDir = repository.getIndexDirectory();
618 //File managedRepository = new File( repository.getLocation() );
620 File indexDirectory = null;
621 if ( StringUtils.isNotBlank( indexDir ) )
623 indexDirectory = new File( repository.getIndexDirectory() );
624 // not absolute so create it in repository directory
625 if ( !indexDirectory.isAbsolute() )
627 indexDirectory = new File( repositoryDirectory, repository.getIndexDirectory() );
629 repository.setIndexDirectory( indexDirectory.getAbsolutePath() );
633 indexDirectory = new File( repositoryDirectory, ".indexer" );
634 if ( !repositoryDirectory.isAbsolute() )
636 indexDirectory = new File( repositoryDirectory, ".indexer" );
638 repository.setIndexDirectory( indexDirectory.getAbsolutePath() );
641 if ( !indexDirectory.exists() )
643 indexDirectory.mkdirs();
646 context = indexer.getIndexingContexts().get( repository.getId() );
648 if ( context == null )
650 context = indexer.addIndexingContext( repository.getId(), repository.getId(), repositoryDirectory,
652 repositoryDirectory.toURI().toURL().toExternalForm(),
653 indexDirectory.toURI().toURL().toString(), indexCreators );
655 context.setSearchable( repository.isScanned() );
659 catch ( MalformedURLException e )
661 throw new RepositoryAdminException( e.getMessage(), e );
663 catch ( IOException e )
665 throw new RepositoryAdminException( e.getMessage(), e );
667 catch ( UnsupportedExistingLuceneIndexException e )
669 throw new RepositoryAdminException( e.getMessage(), e );
673 private ManagedRepositoryConfiguration getStageRepoConfig( ManagedRepositoryConfiguration repository )
675 ManagedRepositoryConfiguration stagingRepository = new ManagedRepositoryConfiguration();
676 stagingRepository.setId( repository.getId() + STAGE_REPO_ID_END );
677 stagingRepository.setLayout( repository.getLayout() );
678 stagingRepository.setName( repository.getName() + STAGE_REPO_ID_END );
679 stagingRepository.setBlockRedeployments( repository.isBlockRedeployments() );
680 stagingRepository.setDaysOlder( repository.getDaysOlder() );
681 stagingRepository.setDeleteReleasedSnapshots( repository.isDeleteReleasedSnapshots() );
683 String path = repository.getLocation();
684 int lastIndex = path.replace( '\\', '/' ).lastIndexOf( '/' );
685 stagingRepository.setLocation( path.substring( 0, lastIndex ) + "/" + stagingRepository.getId() );
687 if ( StringUtils.isNotBlank( repository.getIndexDir() ) )
689 File indexDir = new File( repository.getIndexDir() );
690 // in case of absolute dir do not use the same
691 if ( indexDir.isAbsolute() )
693 stagingRepository.setIndexDir( stagingRepository.getLocation() + "/.index" );
697 stagingRepository.setIndexDir( repository.getIndexDir() );
700 stagingRepository.setRefreshCronExpression( repository.getRefreshCronExpression() );
701 stagingRepository.setReleases( repository.isReleases() );
702 stagingRepository.setRetentionCount( repository.getRetentionCount() );
703 stagingRepository.setScanned( repository.isScanned() );
704 stagingRepository.setSnapshots( repository.isSnapshots() );
705 stagingRepository.setSkipPackedIndexCreation( repository.isSkipPackedIndexCreation() );
706 // do not duplicate description
707 //stagingRepository.getDescription("")
708 return stagingRepository;
711 public Boolean scanRepository( String repositoryId, boolean fullScan )
713 if ( getRepositoryTaskScheduler().isProcessingRepositoryTask( repositoryId ) )
715 log.info( "scanning of repository with id {} already scheduled", repositoryId );
717 RepositoryTask task = new RepositoryTask();
718 task.setRepositoryId( repositoryId );
719 task.setScanAll( fullScan );
722 getRepositoryTaskScheduler().queueTask( task );
724 catch ( TaskQueueException e )
726 log.error( "failed to schedule scanning of repo with id {}", repositoryId, e );
733 private void addRepositoryRoles( ManagedRepository newRepository )
734 throws RoleManagerException
736 String repoId = newRepository.getId();
738 // TODO: double check these are configured on start up
739 // TODO: belongs in the business logic
741 if ( !getRoleManager().templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId ) )
743 getRoleManager().createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId );
746 if ( !getRoleManager().templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId ) )
748 getRoleManager().createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId );
753 private void addRepositoryRoles( String repoId )
754 throws RoleManagerException
756 // TODO: double check these are configured on start up
757 // TODO: belongs in the business logic
759 if ( !getRoleManager().templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId ) )
761 getRoleManager().createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId );
764 if ( !getRoleManager().templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId ) )
766 getRoleManager().createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId );
770 protected void removeRepositoryRoles( ManagedRepositoryConfiguration existingRepository )
771 throws RoleManagerException
773 String repoId = existingRepository.getId();
775 if ( getRoleManager().templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId ) )
777 getRoleManager().removeTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId );
780 if ( getRoleManager().templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId ) )
782 getRoleManager().removeTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId );
785 log.debug( "removed user roles associated with repository {}", repoId );
788 //--------------------------
790 //--------------------------
793 public RoleManager getRoleManager()
798 public void setRoleManager( RoleManager roleManager )
800 this.roleManager = roleManager;
803 public RepositoryStatisticsManager getRepositoryStatisticsManager()
805 return repositoryStatisticsManager;
808 public void setRepositoryStatisticsManager( RepositoryStatisticsManager repositoryStatisticsManager )
810 this.repositoryStatisticsManager = repositoryStatisticsManager;
813 public RepositorySessionFactory getRepositorySessionFactory()
815 return repositorySessionFactory;
818 public void setRepositorySessionFactory( RepositorySessionFactory repositorySessionFactory )
820 this.repositorySessionFactory = repositorySessionFactory;
824 public RepositoryArchivaTaskScheduler getRepositoryTaskScheduler()
826 return repositoryTaskScheduler;
829 public void setRepositoryTaskScheduler( RepositoryArchivaTaskScheduler repositoryTaskScheduler )
831 this.repositoryTaskScheduler = repositoryTaskScheduler;
834 public PlexusSisuBridge getPlexusSisuBridge()
836 return plexusSisuBridge;
839 public void setPlexusSisuBridge( PlexusSisuBridge plexusSisuBridge )
841 this.plexusSisuBridge = plexusSisuBridge;
844 public MavenIndexerUtils getMavenIndexerUtils()
846 return mavenIndexerUtils;
849 public void setMavenIndexerUtils( MavenIndexerUtils mavenIndexerUtils )
851 this.mavenIndexerUtils = mavenIndexerUtils;
854 public NexusIndexer getIndexer()
859 public void setIndexer( NexusIndexer indexer )
861 this.indexer = indexer;
864 public List<? extends IndexCreator> getIndexCreators()
866 return indexCreators;
869 public void setIndexCreators( List<? extends IndexCreator> indexCreators )
871 this.indexCreators = indexCreators;