[MRM-1452] add ability to delete contents of a repository via xml-rpc

submitted by Maria Catherine Tan


git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1064444 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Maria Odea B. Ching 2011-01-28 03:19:09 +00:00
parent 55d4b5c3af
commit fc3b5a9fa1
4 changed files with 96 additions and 1 deletions

View File

@ -113,6 +113,16 @@ public interface AdministrationService
public Boolean deleteManagedRepository( String repoId ) public Boolean deleteManagedRepository( String repoId )
throws Exception; throws Exception;
/**
* Deletes a managed repository content with the given repository id
*
* @param repoId
* @return
* @throws Exception
*/
public Boolean deleteManagedRepositoryContent( String repoId )
throws Exception;
/** /**
* Get a managed repository with the given repository id. * Get a managed repository with the given repository id.
* @param repoId * @param repoId

View File

@ -43,7 +43,8 @@ public class ServiceMethodsPermissionsMapping
"AdministrationService.deleteArtifact", "AdministrationService.deleteArtifact",
"AdministrationService.addManagedRepository", "AdministrationService.addManagedRepository",
"AdministrationService.deleteManagedRepository", "AdministrationService.getManagedRepository", "AdministrationService.deleteManagedRepository", "AdministrationService.getManagedRepository",
"AdministrationService.merge"); "AdministrationService.merge",
"AdministrationService.deleteManagedRepositoryContent");
public static final List<String> SERVICE_METHODS_FOR_OPERATION_RUN_INDEXER = public static final List<String> SERVICE_METHODS_FOR_OPERATION_RUN_INDEXER =
Arrays.asList( "AdministrationService.executeRepositoryScanner" ); Arrays.asList( "AdministrationService.executeRepositoryScanner" );

View File

@ -468,6 +468,44 @@ public class AdministrationServiceImpl
return Boolean.TRUE; return Boolean.TRUE;
} }
public Boolean deleteManagedRepositoryContent( String repoId )
throws Exception
{
Configuration config = archivaConfiguration.getConfiguration();
ManagedRepositoryConfiguration repository = config.findManagedRepositoryById( repoId );
if ( repository == null )
{
throw new Exception( "Repository Id : " + repoId + " not found." );
}
RepositorySession repositorySession = repositorySessionFactory.createSession();
try
{
MetadataRepository metadataRepository = repositorySession.getRepository();
metadataRepository.removeRepository( repository.getId() );
repositorySession.save();
}
finally
{
repositorySession.close();
}
File repoDir = new File( repository.getLocation() );
File[] children = repoDir.listFiles();
if ( children != null )
{
for ( File child : children )
{
FileUtils.deleteDirectory( child );
}
}
return Boolean.TRUE;
}
public ManagedRepository getManagedRepository( String repoId ) public ManagedRepository getManagedRepository( String repoId )
throws Exception throws Exception
{ {

View File

@ -665,6 +665,52 @@ public class AdministrationServiceImplTest
assertRemoteRepo( repos.get( 1 ), remoteRepos.get( 1 ) ); assertRemoteRepo( repos.get( 1 ), remoteRepos.get( 1 ) );
} }
public void testDeleteInvalidRepositoryContent()
{
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
configControl.expectAndReturn( config.findManagedRepositoryById( "invalid" ), null );
archivaConfigControl.replay();
configControl.replay();
try
{
service.deleteManagedRepositoryContent( "invalid" );
}
catch ( Exception e )
{
assertEquals( "Repository Id : invalid not found.", e.getMessage() );
}
archivaConfigControl.verify();
configControl.verify();
}
public void testDeleteRepositoryContent()
throws Exception
{
ManagedRepositoryConfiguration managedRepo = createManagedRepo( "default", "default-repo" );
assertTrue( new File( managedRepo.getLocation(), "org" ).exists() );
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ), managedRepo );
metadataRepository.removeRepository( "internal" );
archivaConfigControl.replay();
configControl.replay();
metadataRepositoryControl.replay();
boolean success = service.deleteManagedRepositoryContent( "internal" );
assertTrue( success );
archivaConfigControl.verify();
configControl.verify();
metadataRepositoryControl.verify();
assertFalse( new File( managedRepo.getLocation(), "org" ).exists() );
assertTrue( new File( managedRepo.getLocation() ).exists() );
}
/* Merge method */ /* Merge method */
public void testMergeRepositoryWithInvalidRepository() public void testMergeRepositoryWithInvalidRepository()