]> source.dussan.org Git - archiva.git/commitdiff
[MRM-823]
authorMaria Odea B. Ching <oching@apache.org>
Mon, 2 Jun 2008 06:51:21 +0000 (06:51 +0000)
committerMaria Odea B. Ching <oching@apache.org>
Mon, 2 Jun 2008 06:51:21 +0000 (06:51 +0000)
-remove repo in group when repo is removed

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@662342 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryAction.java
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.java

index 8a6ab5688cb3130008ab72499f5b84f775a112b4..4380313209a00b680974f4a15347ae87aeb45c9b 100644 (file)
@@ -41,6 +41,7 @@ import org.codehaus.plexus.redback.role.RoleManagerException;
 
 import java.io.IOException;
 import java.util.List;
+import java.util.Map;
 
 /**
  * DeleteManagedRepositoryAction
@@ -140,14 +141,9 @@ public class DeleteManagedRepositoryAction
         throws RoleManagerException, ArchivaDatabaseException
     {
         removeRepositoryRoles( cleanupRepository );
-
-        // TODO: [MRM-382] Remove index from artifacts of deleted managed repositories.
-
-        // [MRM-265] After removing a managed repository - Browse/Search still see it
         cleanupDatabase( cleanupRepository.getId() );
         cleanupScanStats( cleanupRepository.getId() );
-
-        // [MRM-520] Proxy Connectors are not deleted with the deletion of a Repository.
+        
         List<ProxyConnectorConfiguration> proxyConnectors = getProxyConnectors();
         for ( ProxyConnectorConfiguration proxyConnector : proxyConnectors )
         {
@@ -156,6 +152,19 @@ public class DeleteManagedRepositoryAction
                 archivaConfiguration.getConfiguration().removeProxyConnector( proxyConnector );
             }
         }
+
+        Map<String, List<String>> repoToGroupMap = archivaConfiguration.getConfiguration().getRepositoryToGroupMap();
+        if( repoToGroupMap != null )
+        {
+            if( repoToGroupMap.containsKey( cleanupRepository.getId() ) )
+            {
+                List<String> repoGroups = repoToGroupMap.get( cleanupRepository.getId() );
+                for( String repoGroup : repoGroups )
+                {
+                    archivaConfiguration.getConfiguration().findRepositoryGroupById( repoGroup ).removeRepository( cleanupRepository.getId() );
+                }
+            }            
+        }
     }
 
     private void cleanupDatabase( String repoId )
index f9e205f4c7c45426312e2e96dafcc7ad3eb39cb0..41536c1c726cb62dd18f1c2ff37095e657914a67 100644 (file)
@@ -26,6 +26,7 @@ import org.apache.maven.archiva.configuration.IndeterminateConfigurationExceptio
 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
 import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
 import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
+import org.apache.maven.archiva.configuration.RepositoryGroupConfiguration;
 import org.apache.maven.archiva.model.ArchivaProjectModel;
 import org.apache.maven.archiva.security.ArchivaRoleConstants;
 import org.codehaus.plexus.redback.role.RoleManager;
@@ -37,7 +38,9 @@ import org.codehaus.plexus.spring.PlexusInSpringTestCase;
 import org.easymock.MockControl;
 
 import java.io.File;
+import java.util.ArrayList;
 import java.util.Collections;
+import java.util.List;
 
 /**
  * DeleteManagedRepositoryActionTest 
@@ -128,7 +131,7 @@ public class DeleteManagedRepositoryActionTest
     {          
         prepareRoleManagerMock();
         
-        Configuration configuration = prepDeletionTest( createRepository(), 3 );                
+        Configuration configuration = prepDeletionTest( createRepository(), 4 );                
         
         String status = action.deleteEntry();        
                 
@@ -144,7 +147,7 @@ public class DeleteManagedRepositoryActionTest
     {
         prepareRoleManagerMock();
         
-        Configuration configuration = prepDeletionTest( createRepository(), 3 );              
+        Configuration configuration = prepDeletionTest( createRepository(), 4 );              
         
         String status = action.deleteContents();
                
@@ -158,7 +161,7 @@ public class DeleteManagedRepositoryActionTest
     public void testDeleteRepositoryAndAssociatedProxyConnectors()
         throws Exception
     {
-        Configuration configuration = prepDeletionTest( createRepository(), 4 );
+        Configuration configuration = prepDeletionTest( createRepository(), 5 );
         configuration.addRemoteRepository( createRemoteRepository( "codehaus", "http://repository.codehaus.org" ) );
         configuration.addRemoteRepository( createRemoteRepository( "java.net", "http://dev.java.net/maven2" ) );
         configuration.addProxyConnector( createProxyConnector( REPO_ID, "codehaus" ) );
@@ -190,6 +193,27 @@ public class DeleteManagedRepositoryActionTest
 
         assertTrue( location.exists() );
     }
+    
+    public void testDeleteRepositoryAndReposUnderRepoGroup()
+        throws Exception
+    {
+        Configuration configuration = prepDeletionTest( createRepository(), 5 );
+        List<String> repoIds = new ArrayList<String>();
+        repoIds.add( REPO_ID );
+        configuration.addRepositoryGroup( createRepoGroup( repoIds, "repo.group" ) );
+
+        prepareRoleManagerMock();
+
+        assertEquals( 1, configuration.getRepositoryGroups().size() );
+        
+        String status = action.deleteContents();
+        assertEquals( Action.SUCCESS, status );
+
+        assertTrue( configuration.getManagedRepositories().isEmpty() );
+        assertEquals( 0, ( ( RepositoryGroupConfiguration ) configuration.getRepositoryGroups().get( 0 ) ).getRepositories().size() );
+
+        assertFalse( location.exists() );
+    }
 
     private Configuration prepDeletionTest( ManagedRepositoryConfiguration originalRepository, int expectCountGetConfig )
         throws RegistryException, IndeterminateConfigurationException
@@ -276,6 +300,15 @@ public class DeleteManagedRepositoryActionTest
         return connector;
     }
 
+    private RepositoryGroupConfiguration createRepoGroup( List<String> repoIds, String repoGroupId )
+    {
+        RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration();
+        repoGroup.setId( repoGroupId );
+        repoGroup.setRepositories( repoIds );
+        
+        return repoGroup;
+    }
+    
     private void prepareRoleManagerMock()
         throws RoleManagerException
     {