archiva-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1163024 - in /archiva/trunk/archiva-modules/archiva-base/archiva-repository-admin/src: main/java/org/apache/archiva/admin/repository/managed/ test/java/org/apache/archiva/admin/repository/managed/
Date Mon, 29 Aug 2011 21:41:35 GMT
Author: olamy
Date: Mon Aug 29 21:41:34 2011
New Revision: 1163024

URL: http://svn.apache.org/viewvc?rev=1163024&view=rev
Log:
[MRM-1504] repository admin module : implements delete ManagedRepository

Modified:
    archiva/trunk/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java
    archiva/trunk/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdminTest.java

Modified: archiva/trunk/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java?rev=1163024&r1=1163023&r2=1163024&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java
(original)
+++ archiva/trunk/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java
Mon Aug 29 21:41:34 2011
@@ -19,14 +19,21 @@ package org.apache.archiva.admin.reposit
  */
 
 import org.apache.archiva.admin.repository.RepositoryAdminException;
+import org.apache.archiva.metadata.repository.MetadataRepository;
+import org.apache.archiva.metadata.repository.MetadataRepositoryException;
+import org.apache.archiva.metadata.repository.RepositorySession;
+import org.apache.archiva.metadata.repository.RepositorySessionFactory;
+import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager;
 import org.apache.archiva.scheduler.repository.RepositoryArchivaTaskScheduler;
 import org.apache.archiva.scheduler.repository.RepositoryTask;
+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;
 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
+import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
 import org.codehaus.plexus.registry.Registry;
 import org.codehaus.plexus.registry.RegistryException;
 import org.codehaus.plexus.taskqueue.TaskQueueException;
@@ -41,6 +48,7 @@ import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 
 /**
  * FIXME remove all generic Exception to have usefull ones
@@ -71,6 +79,13 @@ public class DefaultManagedRepositoryAdm
     @Named( value = "archivaTaskScheduler#repository" )
     private RepositoryArchivaTaskScheduler repositoryTaskScheduler;
 
+    @Inject
+    private RepositorySessionFactory repositorySessionFactory;
+
+
+    @Inject
+    private RepositoryStatisticsManager repositoryStatisticsManager;
+
     public List<ManagedRepository> getManagedRepositories()
         throws RepositoryAdminException
     {
@@ -226,14 +241,80 @@ public class DefaultManagedRepositoryAdm
     }
 
 
-    public Boolean updateManagedRepository( ManagedRepository managedRepository, boolean
needStageRepo )
+    public Boolean deleteManagedRepository( String repositoryId )
         throws RepositoryAdminException
     {
-        return null;  //To change body of implemented methods use File | Settings | File
Templates.
+        Configuration config = archivaConfiguration.getConfiguration();
+
+        ManagedRepositoryConfiguration repository = config.findManagedRepositoryById( repositoryId
);
+
+        if ( repository == null )
+        {
+            throw new RepositoryAdminException( "A repository with that id does not exist"
);
+        }
+
+        RepositorySession repositorySession = repositorySessionFactory.createSession();
+        try
+        {
+            MetadataRepository metadataRepository = repositorySession.getRepository();
+            metadataRepository.removeRepository( repository.getId() );
+            repositoryStatisticsManager.deleteStatistics( metadataRepository, repository.getId()
);
+            repositorySession.save();
+        }
+        catch ( MetadataRepositoryException e )
+        {
+            throw new RepositoryAdminException( e.getMessage(), e );
+        }
+        finally
+        {
+            repositorySession.close();
+        }
+        config.removeManagedRepository( repository );
+
+        try
+        {
+            saveConfiguration( config );
+        }
+        catch ( Exception e )
+        {
+            throw new RepositoryAdminException( "Error saving configuration for delete action"
+ e.getMessage() );
+        }
+
+        // TODO could be async ? as directory can be huge
+        File dir = new File( repository.getLocation() );
+        if ( !FileUtils.deleteQuietly( dir ) )
+        {
+            throw new RepositoryAdminException( "Cannot delete repository " + dir );
+        }
+
+        List<ProxyConnectorConfiguration> proxyConnectors = config.getProxyConnectors();
+        for ( ProxyConnectorConfiguration proxyConnector : proxyConnectors )
+        {
+            if ( StringUtils.equals( proxyConnector.getSourceRepoId(), repository.getId()
) )
+            {
+                archivaConfiguration.getConfiguration().removeProxyConnector( proxyConnector
);
+            }
+        }
+
+        Map<String, List<String>> repoToGroupMap = archivaConfiguration.getConfiguration().getRepositoryToGroupMap();
+        if ( repoToGroupMap != null )
+        {
+            if ( repoToGroupMap.containsKey( repository.getId() ) )
+            {
+                List<String> repoGroups = repoToGroupMap.get( repository.getId() );
+                for ( String repoGroup : repoGroups )
+                {
+                    archivaConfiguration.getConfiguration().findRepositoryGroupById( repoGroup
).removeRepository(
+                        repository.getId() );
+                }
+            }
+        }
+
+        return Boolean.TRUE;
     }
 
 
-    public Boolean deleteManagedRepository( String repositoryId )
+    public Boolean updateManagedRepository( ManagedRepository managedRepository, boolean
needStageRepo )
         throws RepositoryAdminException
     {
         return null;  //To change body of implemented methods use File | Settings | File
Templates.

Modified: archiva/trunk/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdminTest.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdminTest.java?rev=1163024&r1=1163023&r2=1163024&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdminTest.java
(original)
+++ archiva/trunk/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdminTest.java
Mon Aug 29 21:41:34 2011
@@ -59,7 +59,7 @@ public class ManagedRepositoryAdminTest
     }
 
     @Test
-    public void addManagedRepo()
+    public void addDeleteManagedRepo()
         throws Exception
     {
         List<ManagedRepository> repos = managedRepositoryAdmin.getManagedRepositories();
@@ -77,6 +77,12 @@ public class ManagedRepositoryAdminTest
         assertEquals( initialSize + 1, repos.size() );
 
         assertNotNull( managedRepositoryAdmin.getManagedRepository( "test-new-one" ) );
+
+        managedRepositoryAdmin.deleteManagedRepository( "test-new-one" );
+
+        repos = managedRepositoryAdmin.getManagedRepositories();
+        assertNotNull( repos );
+        assertEquals( initialSize, repos.size() );
     }
 
 



Mime
View raw message