mirror of
https://github.com/apache/archiva.git
synced 2025-02-07 02:29:23 +00:00
[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:
parent
55d4b5c3af
commit
fc3b5a9fa1
@ -113,6 +113,16 @@ public Boolean addManagedRepository( String repoId, String layout, String name,
|
||||
public 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 )
|
||||
throws Exception;
|
||||
|
||||
/**
|
||||
* Get a managed repository with the given repository id.
|
||||
* @param repoId
|
||||
|
@ -43,7 +43,8 @@ public class ServiceMethodsPermissionsMapping
|
||||
"AdministrationService.deleteArtifact",
|
||||
"AdministrationService.addManagedRepository",
|
||||
"AdministrationService.deleteManagedRepository", "AdministrationService.getManagedRepository",
|
||||
"AdministrationService.merge");
|
||||
"AdministrationService.merge",
|
||||
"AdministrationService.deleteManagedRepositoryContent");
|
||||
|
||||
public static final List<String> SERVICE_METHODS_FOR_OPERATION_RUN_INDEXER =
|
||||
Arrays.asList( "AdministrationService.executeRepositoryScanner" );
|
||||
|
@ -468,6 +468,44 @@ public Boolean deleteManagedRepository( String repoId )
|
||||
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 )
|
||||
throws Exception
|
||||
{
|
||||
|
@ -665,6 +665,52 @@ public void testGetAllRemoteRepositories()
|
||||
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 */
|
||||
|
||||
public void testMergeRepositoryWithInvalidRepository()
|
||||
|
Loading…
x
Reference in New Issue
Block a user