[MRM-1509] change xmlrpc to use new repository administration management api

use new api for ManagedRepository

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1164392 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2011-09-02 08:18:38 +00:00
parent 56587c1e6d
commit 75f7fab6d4
6 changed files with 158 additions and 194 deletions

View File

@ -105,7 +105,7 @@ public class DefaultManagedRepositoryAdmin
throws RepositoryAdminException
{
List<ManagedRepositoryConfiguration> managedRepoConfigs =
archivaConfiguration.getConfiguration().getManagedRepositories();
getArchivaConfiguration().getConfiguration().getManagedRepositories();
List<ManagedRepository> managedRepos = new ArrayList<ManagedRepository>( managedRepoConfigs.size() );
@ -158,7 +158,7 @@ public class DefaultManagedRepositoryAdmin
throws RepositoryAdminException
{
Configuration config = archivaConfiguration.getConfiguration();
Configuration config = getArchivaConfiguration().getConfiguration();
if ( config.getManagedRepositoriesAsMap().containsKey( repoId ) )
{
@ -186,7 +186,7 @@ public class DefaultManagedRepositoryAdmin
throw new RepositoryAdminException( "Cron expression cannot be empty." );
}
if (StringUtils.isBlank( repoId ))
if ( StringUtils.isBlank( repoId ) )
{
throw new RepositoryAdminException( "Repository ID cannot be empty." );
}
@ -279,7 +279,7 @@ public class DefaultManagedRepositoryAdmin
boolean deleteContent )
throws RepositoryAdminException
{
Configuration config = archivaConfiguration.getConfiguration();
Configuration config = getArchivaConfiguration().getConfiguration();
ManagedRepositoryConfiguration repository = config.findManagedRepositoryById( repositoryId );
@ -294,7 +294,7 @@ public class DefaultManagedRepositoryAdmin
// stage repo exists ?
ManagedRepositoryConfiguration stagingRepository =
archivaConfiguration.getConfiguration().findManagedRepositoryById( repositoryId + STAGE_REPO_ID_END );
getArchivaConfiguration().getConfiguration().findManagedRepositoryById( repositoryId + STAGE_REPO_ID_END );
if ( stagingRepository != null )
{
// do not trigger event when deleting the staged one
@ -320,13 +320,13 @@ public class DefaultManagedRepositoryAdmin
{
if ( !stagedOne )
{
RepositorySession repositorySession = repositorySessionFactory.createSession();
RepositorySession repositorySession = getRepositorySessionFactory().createSession();
try
{
MetadataRepository metadataRepository = repositorySession.getRepository();
metadataRepository.removeRepository( repository.getId() );
log.debug( "call repositoryStatisticsManager.deleteStatistics" );
repositoryStatisticsManager.deleteStatistics( metadataRepository, repository.getId() );
getRepositoryStatisticsManager().deleteStatistics( metadataRepository, repository.getId() );
repositorySession.save();
}
catch ( MetadataRepositoryException e )
@ -357,7 +357,7 @@ public class DefaultManagedRepositoryAdmin
{
if ( StringUtils.equals( proxyConnector.getSourceRepoId(), repository.getId() ) )
{
archivaConfiguration.getConfiguration().removeProxyConnector( proxyConnector );
config.removeProxyConnector( proxyConnector );
}
}
@ -369,7 +369,7 @@ public class DefaultManagedRepositoryAdmin
List<String> repoGroups = repoToGroupMap.get( repository.getId() );
for ( String repoGroup : repoGroups )
{
archivaConfiguration.getConfiguration().findRepositoryGroupById( repoGroup ).removeRepository(
config.findRepositoryGroupById( repoGroup ).removeRepository(
repository.getId() );
}
}
@ -384,6 +384,9 @@ public class DefaultManagedRepositoryAdmin
throw new RepositoryAdminException(
"fail to remove repository roles for repository " + repository.getId() + " : " + e.getMessage(), e );
}
saveConfiguration( config );
return Boolean.TRUE;
}
@ -393,7 +396,7 @@ public class DefaultManagedRepositoryAdmin
throws RepositoryAdminException
{
// Ensure that the fields are valid.
Configuration configuration = archivaConfiguration.getConfiguration();
Configuration configuration = getArchivaConfiguration().getConfiguration();
log.debug( "updateManagedConfiguration repo {} needStage {} resetStats {} ",
Arrays.asList( managedRepository, needStageRepo, resetStats ).toArray() );
@ -426,19 +429,19 @@ public class DefaultManagedRepositoryAdmin
managedRepository.getCronExpression(), auditInformation );
// Save the repository configuration.
RepositorySession repositorySession = repositorySessionFactory.createSession();
RepositorySession repositorySession = getRepositorySessionFactory().createSession();
try
{
triggerAuditEvent( managedRepositoryConfiguration.getId(), null, AuditEvent.MODIFY_MANAGED_REPO,
auditInformation );
saveConfiguration( this.archivaConfiguration.getConfiguration() );
saveConfiguration( this.getArchivaConfiguration().getConfiguration() );
if ( resetStats )
{
log.debug( "call repositoryStatisticsManager.deleteStatistics" );
repositoryStatisticsManager.deleteStatistics( repositorySession.getRepository(),
managedRepositoryConfiguration.getId() );
getRepositoryStatisticsManager().deleteStatistics( repositorySession.getRepository(),
managedRepositoryConfiguration.getId() );
repositorySession.save();
}
@ -467,7 +470,7 @@ public class DefaultManagedRepositoryAdmin
new AuditEvent( repositoryId, user == null ? "null" : (String) user.getPrincipal(), resource, action );
event.setRemoteIP( auditInformation == null ? "null" : auditInformation.getRemoteAddr() );
for ( AuditListener listener : auditListeners )
for ( AuditListener listener : getAuditListeners() )
{
listener.auditEvent( event );
}
@ -477,9 +480,9 @@ public class DefaultManagedRepositoryAdmin
public String removeExpressions( String directory )
{
String value = StringUtils.replace( directory, "${appserver.base}",
registry.getString( "appserver.base", "${appserver.base}" ) );
getRegistry().getString( "appserver.base", "${appserver.base}" ) );
value = StringUtils.replace( value, "${appserver.home}",
registry.getString( "appserver.home", "${appserver.home}" ) );
getRegistry().getString( "appserver.home", "${appserver.home}" ) );
return value;
}
@ -488,7 +491,7 @@ public class DefaultManagedRepositoryAdmin
{
try
{
archivaConfiguration.save( config );
getArchivaConfiguration().save( config );
}
catch ( RegistryException e )
{
@ -542,7 +545,7 @@ public class DefaultManagedRepositoryAdmin
public Boolean scanRepository( String repositoryId, boolean fullScan )
{
if ( repositoryTaskScheduler.isProcessingRepositoryTask( repositoryId ) )
if ( getRepositoryTaskScheduler().isProcessingRepositoryTask( repositoryId ) )
{
log.info( "scanning of repository with id {} already scheduled", repositoryId );
}
@ -551,7 +554,7 @@ public class DefaultManagedRepositoryAdmin
task.setScanAll( fullScan );
try
{
repositoryTaskScheduler.queueTask( task );
getRepositoryTaskScheduler().queueTask( task );
}
catch ( TaskQueueException e )
{
@ -569,14 +572,14 @@ public class DefaultManagedRepositoryAdmin
// TODO: double check these are configured on start up
// TODO: belongs in the business logic
if ( !roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId ) )
if ( !getRoleManager().templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId ) )
{
roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId );
getRoleManager().createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId );
}
if ( !roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId ) )
if ( !getRoleManager().templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId ) )
{
roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId );
getRoleManager().createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId );
}
}
@ -585,14 +588,14 @@ public class DefaultManagedRepositoryAdmin
{
String repoId = existingRepository.getId();
if ( roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId ) )
if ( getRoleManager().templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId ) )
{
roleManager.removeTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId );
getRoleManager().removeTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId );
}
if ( roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId ) )
if ( getRoleManager().templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId ) )
{
roleManager.removeTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId );
getRoleManager().removeTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId );
}
log.debug( "removed user roles associated with repository {}", repoId );

View File

@ -35,6 +35,10 @@
<groupId>org.apache.archiva</groupId>
<artifactId>stage-repository-merge</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-repository-admin</artifactId>
</dependency>
<dependency>
<groupId>com.atlassian.xmlrpc</groupId>
<artifactId>atlassian-xmlrpc-binder-annotations</artifactId>

View File

@ -19,75 +19,78 @@ package org.apache.archiva.web.xmlrpc.api;
* under the License.
*/
import java.util.List;
import com.atlassian.xmlrpc.ServiceObject;
import org.apache.archiva.admin.repository.RepositoryAdminException;
import org.apache.archiva.web.xmlrpc.api.beans.ManagedRepository;
import org.apache.archiva.web.xmlrpc.api.beans.RemoteRepository;
import java.util.List;
@ServiceObject( "AdministrationService" )
public interface AdministrationService
{
/**
* Executes repository scanner on the given repository.
*
*
* @param repoId id of the repository to be scanned
* @return
* @throws Exception
*/
public Boolean executeRepositoryScanner( String repoId )
Boolean executeRepositoryScanner( String repoId )
throws Exception;
/**
* Gets all available repository consumers.
*
*
* @return
*/
public List<String> getAllRepositoryConsumers();
List<String> getAllRepositoryConsumers();
// TODO should we already implement config of consumers per repository?
/**
* Configures (enable or disable) repository consumer.
*
*
* @param repoId
* @param consumerId
* @param enable
* @return
* @throws Exception
*/
public Boolean configureRepositoryConsumer( String repoId, String consumerId, boolean enable )
Boolean configureRepositoryConsumer( String repoId, String consumerId, boolean enable )
throws Exception;
/**
* Gets all managed repositories.
*
*
* @return
*/
public List<ManagedRepository> getAllManagedRepositories();
List<ManagedRepository> getAllManagedRepositories()
throws RepositoryAdminException;
/**
* Gets all remote repositories.
*
*
* @return
*/
public List<RemoteRepository> getAllRemoteRepositories();
List<RemoteRepository> getAllRemoteRepositories();
/**
* Deletes given artifact from the specified repository.
*
* @param repoId id of the repository where the artifact to be deleted resides
* @param groupId groupId of the artifact to be deleted
*
* @param repoId id of the repository where the artifact to be deleted resides
* @param groupId groupId of the artifact to be deleted
* @param artifactId artifactId of the artifact to be deleted
* @param version version of the artifact to be deleted
* @param version version of the artifact to be deleted
* @return
* @throws Exception
*/
public Boolean deleteArtifact( String repoId, String groupId, String artifactId, String version )
Boolean deleteArtifact( String repoId, String groupId, String artifactId, String version )
throws Exception;
/**
* Create a new managed repository with the given parameters.
*
*
* @param repoId
* @param layout
* @param name
@ -99,37 +102,39 @@ public interface AdministrationService
* @return
* @throws Exception
*/
public Boolean addManagedRepository( String repoId, String layout, String name, String location,
boolean blockRedeployments, boolean releasesIncluded,
boolean snapshotsIncluded, boolean stageRepoNeeded, String cronExpression )
Boolean addManagedRepository( String repoId, String layout, String name, String location,
boolean blockRedeployments, boolean releasesIncluded, boolean snapshotsIncluded,
boolean stageRepoNeeded, String cronExpression )
throws Exception;
/**
* Deletes a managed repository with the given repository id.
*
*
* @param repoId
* @return
*/
public Boolean deleteManagedRepository( String repoId )
Boolean deleteManagedRepository( String repoId )
throws Exception;
/**
* Deletes a managed repository content with the given repository id
*
*
* @param repoId
* @return
* @throws Exception
*/
public Boolean deleteManagedRepositoryContent( String repoId )
Boolean deleteManagedRepositoryContent( String repoId )
throws Exception;
/**
* Get a managed repository with the given repository id.
*
* @param repoId
* @return
* @throws Exception
*/
public ManagedRepository getManagedRepository(String repoId) throws Exception;
ManagedRepository getManagedRepository( String repoId )
throws Exception;
// TODO
// consider the following as additional services:
// - getAllConfiguredRepositoryConsumers( String repoId ) - list all enabled consumers for the repo
@ -137,11 +142,13 @@ public interface AdministrationService
/**
* Merge staging repository with the managed repository and skips if there are conflicts
*
* @param repoId
* @param skipConflicts
* @return
* @throws Exception
*/
public boolean merge( String repoId, boolean skipConflicts ) throws Exception;
boolean merge( String repoId, boolean skipConflicts )
throws Exception;
}

View File

@ -39,6 +39,10 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-repository-admin</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-xmlrpc-security</artifactId>

View File

@ -19,6 +19,9 @@ package org.apache.archiva.web.xmlrpc.services;
* under the License.
*/
import org.apache.archiva.admin.AuditInformation;
import org.apache.archiva.admin.repository.RepositoryAdminException;
import org.apache.archiva.admin.repository.managed.ManagedRepositoryAdmin;
import org.apache.archiva.audit.AuditEvent;
import org.apache.archiva.audit.AuditListener;
import org.apache.archiva.metadata.model.ArtifactMetadata;
@ -38,7 +41,6 @@ import org.apache.archiva.web.xmlrpc.api.beans.ManagedRepository;
import org.apache.archiva.web.xmlrpc.api.beans.RemoteRepository;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.validator.GenericValidator;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
@ -54,9 +56,7 @@ import org.apache.maven.archiva.repository.ManagedRepositoryContent;
import org.apache.maven.archiva.repository.RepositoryContentFactory;
import org.apache.maven.archiva.repository.RepositoryException;
import org.apache.maven.archiva.repository.RepositoryNotFoundException;
import org.codehaus.plexus.registry.Registry;
import org.codehaus.plexus.registry.RegistryException;
import org.codehaus.redback.components.scheduler.CronExpressionValidator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -98,7 +98,7 @@ public class AdministrationServiceImpl
private RepositorySessionFactory repositorySessionFactory;
private Registry registry;
private ManagedRepositoryAdmin managedRepositoryAdmin;
private static final String REPOSITORY_ID_VALID_EXPRESSION = "^[a-zA-Z0-9._-]+$";
@ -113,7 +113,7 @@ public class AdministrationServiceImpl
Collection<RepositoryListener> listeners,
RepositoryStatisticsManager repositoryStatisticsManager,
RepositoryMerger repositoryMerger, AuditListener auditListener,
Registry registry )
ManagedRepositoryAdmin managedRepositoryAdmin )
{
this.archivaConfiguration = archivaConfig;
this.repoConsumersUtil = repoConsumersUtil;
@ -124,7 +124,7 @@ public class AdministrationServiceImpl
this.repositoryStatisticsManager = repositoryStatisticsManager;
this.repositoryMerger = repositoryMerger;
this.auditListener = auditListener;
this.registry = registry;
this.managedRepositoryAdmin = managedRepositoryAdmin;
}
/**
@ -214,8 +214,8 @@ public class AdministrationServiceImpl
repoContent.deleteVersion( ref );
MetadataRepository metadataRepository = repositorySession.getRepository();
Collection<ArtifactMetadata> artifacts = metadataRepository.getArtifacts( repoId, groupId, artifactId,
version );
Collection<ArtifactMetadata> artifacts =
metadataRepository.getArtifacts( repoId, groupId, artifactId, version );
for ( ArtifactMetadata artifact : artifacts )
{
@ -307,18 +307,15 @@ public class AdministrationServiceImpl
* @see AdministrationService#getAllManagedRepositories()
*/
public List<ManagedRepository> getAllManagedRepositories()
throws RepositoryAdminException
{
List<ManagedRepository> managedRepos = new ArrayList<ManagedRepository>();
Configuration config = archivaConfiguration.getConfiguration();
List<ManagedRepositoryConfiguration> managedRepoConfigs = config.getManagedRepositories();
for ( ManagedRepositoryConfiguration repoConfig : managedRepoConfigs )
for ( org.apache.archiva.admin.repository.managed.ManagedRepository repoConfig : managedRepositoryAdmin.getManagedRepositories() )
{
// TODO fix resolution of repo url!
ManagedRepository repo = new ManagedRepository( repoConfig.getId(), repoConfig.getName(), "URL",
repoConfig.getLayout(), repoConfig.isSnapshots(),
repoConfig.isReleases() );
ManagedRepository repo =
new ManagedRepository( repoConfig.getId(), repoConfig.getName(), repoConfig.getLocation(),
repoConfig.getLayout(), repoConfig.isSnapshots(), repoConfig.isReleases() );
managedRepos.add( repo );
}
@ -368,89 +365,12 @@ public class AdministrationServiceImpl
throws Exception
{
Configuration config = archivaConfiguration.getConfiguration();
org.apache.archiva.admin.repository.managed.ManagedRepository repository =
new org.apache.archiva.admin.repository.managed.ManagedRepository( repoId, name, location, layout,
snapshotsIncluded, releasesIncluded,
blockRedeployments, cronExpression );
return managedRepositoryAdmin.addManagedRepository( repository, stageRepoNeeded, getAuditInformation() );
CronExpressionValidator validator = new CronExpressionValidator();
if ( config.getManagedRepositoriesAsMap().containsKey( repoId ) )
{
throw new Exception( "Unable to add new repository with id [" + repoId +
"], that id already exists as a managed repository." );
}
else if ( config.getRemoteRepositoriesAsMap().containsKey( repoId ) )
{
throw new Exception( "Unable to add new repository with id [" + repoId +
"], that id already exists as a remote repository." );
}
else if ( config.getRepositoryGroupsAsMap().containsKey( repoId ) )
{
throw new Exception( "Unable to add new repository with id [" + repoId +
"], that id already exists as a repository group." );
}
if ( !validator.validate( cronExpression ) )
{
throw new Exception( "Invalid cron expression." );
}
if( !GenericValidator.matchRegexp( repoId, REPOSITORY_ID_VALID_EXPRESSION ) )
{
throw new Exception( "Invalid repository ID. Identifier must only contain alphanumeric characters, underscores(_), dots(.), and dashes(-)." );
}
if( !GenericValidator.matchRegexp( name, REPOSITORY_NAME_VALID_EXPRESSION ) )
{
throw new Exception( "Invalid repository name. Repository Name must only contain alphanumeric characters, white-spaces(' '), " +
"forward-slashes(/), open-parenthesis('('), close-parenthesis(')'), underscores(_), dots(.), and dashes(-)." );
}
String repoLocation = removeExpressions( location );
if( !GenericValidator.matchRegexp( repoLocation, REPOSITORY_LOCATION_VALID_EXPRESSION ) )
{
throw new Exception( "Invalid repository location. Directory must only contain alphanumeric characters, equals(=), question-marks(?), " +
"exclamation-points(!), ampersands(&amp;), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-)." );
}
ManagedRepositoryConfiguration repository = new ManagedRepositoryConfiguration();
repository.setId( repoId );
repository.setBlockRedeployments( blockRedeployments );
repository.setReleases( releasesIncluded );
repository.setSnapshots( snapshotsIncluded );
repository.setName( name );
repository.setLocation( repoLocation );
repository.setLayout( layout );
repository.setRefreshCronExpression( cronExpression );
addRepository( repository, config );
if ( stageRepoNeeded )
{
ManagedRepositoryConfiguration stagingRepository = getStageRepoConfig( repository );
addRepository( stagingRepository, config );
}
saveConfiguration( config );
//MRM-1342 Repository statistics report doesn't appear to be working correctly
//scan repository when adding of repository is successful
try
{
executeRepositoryScanner( repoId );
if ( stageRepoNeeded )
{
ManagedRepositoryConfiguration stagingRepository = getStageRepoConfig( repository );
executeRepositoryScanner( stagingRepository.getId() );
}
}
catch ( Exception e )
{
log.warn( new StringBuilder( "Unable to scan repository [" ).append( repoId ).append( "]: " ).append(
e.getMessage() ).toString(), e );
}
return Boolean.TRUE;
}
public Boolean deleteManagedRepository( String repoId )
@ -608,16 +528,16 @@ public class AdministrationServiceImpl
log.info( "Repository to be merged contains releases only.." );
if ( skipConflicts )
{
List<ArtifactMetadata> conflicts = repositoryMerger.getConflictingArtifacts(
metadataRepository, repoId, stagingId );
List<ArtifactMetadata> conflicts =
repositoryMerger.getConflictingArtifacts( metadataRepository, repoId, stagingId );
if ( log.isDebugEnabled() )
{
log.debug( "Artifacts in conflict.." );
for ( ArtifactMetadata metadata : conflicts )
{
log.debug( metadata.getNamespace() + ":" + metadata.getProject() + ":" +
metadata.getProjectVersion() );
log.debug( metadata.getNamespace() + ":" + metadata.getProject() + ":"
+ metadata.getProjectVersion() );
}
}
@ -637,16 +557,16 @@ public class AdministrationServiceImpl
log.info( "Repository to be merged has snapshot artifacts.." );
if ( skipConflicts )
{
List<ArtifactMetadata> conflicts = repositoryMerger.getConflictingArtifacts(
metadataRepository, repoId, stagingId );
List<ArtifactMetadata> conflicts =
repositoryMerger.getConflictingArtifacts( metadataRepository, repoId, stagingId );
if ( log.isDebugEnabled() )
{
log.debug( "Artifacts in conflict.." );
for ( ArtifactMetadata metadata : conflicts )
{
log.debug( metadata.getNamespace() + ":" + metadata.getProject() + ":" +
metadata.getProjectVersion() );
log.debug( metadata.getNamespace() + ":" + metadata.getProject() + ":"
+ metadata.getProjectVersion() );
}
}
@ -654,19 +574,19 @@ public class AdministrationServiceImpl
log.debug( "Source artifacts size :: " + sourceArtifacts.size() );
Filter<ArtifactMetadata> artifactsWithOutConflicts = new IncludesFilter<ArtifactMetadata>(
sourceArtifacts );
Filter<ArtifactMetadata> artifactsWithOutConflicts =
new IncludesFilter<ArtifactMetadata>( sourceArtifacts );
repositoryMerger.merge( metadataRepository, stagingId, repoId, artifactsWithOutConflicts );
log.info( "Staging repository '" + stagingId + "' merged successfully with managed repo '" +
repoId + "'." );
log.info( "Staging repository '" + stagingId + "' merged successfully with managed repo '"
+ repoId + "'." );
}
else
{
repositoryMerger.merge( metadataRepository, stagingId, repoId );
log.info( "Staging repository '" + stagingId + "' merged successfully with managed repo '" +
repoId + "'." );
log.info( "Staging repository '" + stagingId + "' merged successfully with managed repo '"
+ repoId + "'." );
}
}
}
@ -705,25 +625,6 @@ public class AdministrationServiceImpl
return true;
}
protected void addRepository( ManagedRepositoryConfiguration repository, Configuration configuration )
throws IOException
{
// Normalize the path
File file = new File( repository.getLocation() );
repository.setLocation( file.getCanonicalPath() );
if ( !file.exists() )
{
file.mkdirs();
}
if ( !file.exists() || !file.isDirectory() )
{
throw new IOException(
"Unable to add repository - no write access, can not create the root directory: " + file );
}
configuration.addManagedRepository( repository );
}
// todo: setting userid of audit event
private AuditEvent createAuditEvent( ManagedRepositoryConfiguration repoConfig )
{
@ -779,12 +680,9 @@ public class AdministrationServiceImpl
return stagingRepository;
}
private String removeExpressions( String directory )
// FIXME find a way to get user id and adress
private AuditInformation getAuditInformation()
{
String value = StringUtils.replace( directory, "${appserver.base}", registry.getString( "appserver.base",
"${appserver.base}" ) );
value = StringUtils.replace( value, "${appserver.home}", registry.getString( "appserver.home",
"${appserver.home}" ) );
return value;
return new AuditInformation( null, null );
}
}

View File

@ -20,6 +20,8 @@ package org.apache.archiva.web.xmlrpc.services;
*/
import junit.framework.TestCase;
import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin;
import org.apache.archiva.admin.repository.managed.ManagedRepositoryAdmin;
import org.apache.archiva.audit.AuditEvent;
import org.apache.archiva.audit.AuditListener;
import org.apache.archiva.metadata.model.ArtifactMetadata;
@ -53,6 +55,8 @@ import org.apache.maven.archiva.repository.content.ManagedDefaultRepositoryConte
import org.apache.maven.archiva.repository.content.ManagedLegacyRepositoryContent;
import org.apache.maven.archiva.repository.content.PathParser;
import org.apache.maven.archiva.repository.layout.LayoutException;
import org.apache.maven.archiva.security.ArchivaRoleConstants;
import org.codehaus.plexus.redback.role.RoleManager;
import org.codehaus.plexus.registry.Registry;
import org.easymock.MockControl;
import org.easymock.classextension.MockClassControl;
@ -65,6 +69,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
@ -140,12 +145,18 @@ public class AdministrationServiceImplTest
private AuditListener auditListener;
private MockControl roleManagerControl;
private RoleManager roleManager;
private MockControl registryControl;
private Registry registry;
private static final String STAGE = "-stage";
private DefaultManagedRepositoryAdmin managedRepositoryAdmin;
@Before
public void setUp()
throws Exception
@ -189,6 +200,9 @@ public class AdministrationServiceImplTest
listenerControl = MockControl.createControl( RepositoryListener.class );
listener = (RepositoryListener) listenerControl.getMock();
roleManagerControl = MockControl.createControl( RoleManager.class );
roleManager = (RoleManager) roleManagerControl.getMock();
repositoryStatisticsManagerControl = MockControl.createControl( RepositoryStatisticsManager.class );
repositoryStatisticsManager = (RepositoryStatisticsManager) repositoryStatisticsManagerControl.getMock();
@ -201,10 +215,20 @@ public class AdministrationServiceImplTest
registryControl = MockControl.createControl( Registry.class );
registry = (Registry) registryControl.getMock();
managedRepositoryAdmin = new DefaultManagedRepositoryAdmin();
managedRepositoryAdmin.setArchivaConfiguration( archivaConfig );
managedRepositoryAdmin.setRegistry( registry );
managedRepositoryAdmin.setRepositoryStatisticsManager( repositoryStatisticsManager );
managedRepositoryAdmin.setRepositoryTaskScheduler( repositoryTaskScheduler );
managedRepositoryAdmin.setRepositorySessionFactory( repositorySessionFactory );
managedRepositoryAdmin.setAuditListeners( Arrays.asList( auditListener ) );
managedRepositoryAdmin.setRoleManager( roleManager );
service = new AdministrationServiceImpl( archivaConfig, repoConsumersUtil, repositoryFactory,
repositorySessionFactory, repositoryTaskScheduler,
Collections.singletonList( listener ), repositoryStatisticsManager,
repositoryMerger, auditListener, registry );
repositoryMerger, auditListener, managedRepositoryAdmin );
}
/* Tests for repository consumers */
@ -948,6 +972,27 @@ public class AdministrationServiceImplTest
configControl.expectAndReturn( config.getManagedRepositoriesAsMap(), managedRepoMap );
configControl.expectAndReturn( config.getRemoteRepositoriesAsMap(), remoteRepoMap );
configControl.expectAndReturn( config.getRepositoryGroupsAsMap(), repoGroupMap );
roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId );
roleManagerControl.setReturnValue( false );
roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId );
roleManagerControl.setVoidCallable();
roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId );
roleManagerControl.setReturnValue( false );
roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId );
roleManagerControl.setVoidCallable();
roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId + "-stage" );
roleManagerControl.setReturnValue( false );
roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, repoId + "-stage" );
roleManagerControl.setVoidCallable();
roleManager.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId + "-stage" );
roleManagerControl.setReturnValue( false );
roleManager.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, repoId + "-stage" );
roleManagerControl.setVoidCallable();
roleManagerControl.replay();
registryControl.expectAndReturn( registry.getString( "appserver.base", "${appserver.base}" ), appserverBase );
registryControl.expectAndReturn( registry.getString( "appserver.home", "${appserver.home}" ), appserverBase );
config.addManagedRepository( managedRepo );
@ -959,6 +1004,9 @@ public class AdministrationServiceImplTest
archivaConfig.save( config );
archivaConfigControl.setVoidCallable();
//managed repo
repositoryTaskSchedulerControl.expectAndReturn( repositoryTaskScheduler.isProcessingRepositoryTask( repoId ), false );