summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaria Odea B. Ching <oching@apache.org>2011-01-28 03:19:09 +0000
committerMaria Odea B. Ching <oching@apache.org>2011-01-28 03:19:09 +0000
commitfc3b5a9fa12a5110366c9a457d498754d8c0fbc4 (patch)
tree349b7649049c5dc4e1868c43cc2568670af3f813
parent55d4b5c3af3f8cebd79abfc1bbe711e8c120e134 (diff)
downloadarchiva-fc3b5a9fa12a5110366c9a457d498754d8c0fbc4.tar.gz
archiva-fc3b5a9fa12a5110366c9a457d498754d8c0fbc4.zip
[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
-rw-r--r--archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/src/main/java/org/apache/archiva/web/xmlrpc/api/AdministrationService.java10
-rw-r--r--archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-security/src/main/java/org/apache/archiva/web/xmlrpc/security/ServiceMethodsPermissionsMapping.java3
-rw-r--r--archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java38
-rw-r--r--archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java46
4 files changed, 96 insertions, 1 deletions
diff --git a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/src/main/java/org/apache/archiva/web/xmlrpc/api/AdministrationService.java b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/src/main/java/org/apache/archiva/web/xmlrpc/api/AdministrationService.java
index 214c9bad2..78e90b24c 100644
--- a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/src/main/java/org/apache/archiva/web/xmlrpc/api/AdministrationService.java
+++ b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/src/main/java/org/apache/archiva/web/xmlrpc/api/AdministrationService.java
@@ -114,6 +114,16 @@ public interface AdministrationService
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
* @return
diff --git a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-security/src/main/java/org/apache/archiva/web/xmlrpc/security/ServiceMethodsPermissionsMapping.java b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-security/src/main/java/org/apache/archiva/web/xmlrpc/security/ServiceMethodsPermissionsMapping.java
index 457ab8b7b..5183d3271 100644
--- a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-security/src/main/java/org/apache/archiva/web/xmlrpc/security/ServiceMethodsPermissionsMapping.java
+++ b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-security/src/main/java/org/apache/archiva/web/xmlrpc/security/ServiceMethodsPermissionsMapping.java
@@ -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" );
diff --git a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java
index 0dc4cc127..2d894dde9 100644
--- a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java
+++ b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java
@@ -468,6 +468,44 @@ public class AdministrationServiceImpl
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
{
diff --git a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java
index 53620eb7b..d4eb637ef 100644
--- a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java
+++ b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java
@@ -665,6 +665,52 @@ public class AdministrationServiceImplTest
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()