From 2a3f4b76be792f9780656c18f3dcce3377f69ce4 Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Tue, 8 Dec 2009 04:02:18 +0000 Subject: [PATCH] [MRM-1293] remove use of repository content statistics from the managed repository deletion git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@888245 13f79535-47bb-0310-9956-ffa450edef68 --- .../DeleteManagedRepositoryAction.java | 41 ++++------ .../AddManagedRepositoryActionTest.java | 10 +-- .../DeleteManagedRepositoryActionTest.java | 42 +++++++++- .../EditManagedRepositoryActionTest.java | 2 +- .../AbstractManagedRepositoriesActionTest.xml | 82 ------------------- .../DeleteManagedRepositoryActionTest.xml | 68 --------------- 6 files changed, 61 insertions(+), 184 deletions(-) delete mode 100644 archiva-modules/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/admin/repositories/AbstractManagedRepositoriesActionTest.xml delete mode 100644 archiva-modules/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.xml diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryAction.java index 508ea8da2..73738a6b5 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryAction.java @@ -24,18 +24,17 @@ import java.util.List; import java.util.Map; import com.opensymphony.xwork2.Preparable; +import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager; import org.apache.commons.lang.StringUtils; import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration; -import org.apache.maven.archiva.database.ArchivaDAO; import org.apache.maven.archiva.database.ArchivaDatabaseException; +import org.apache.maven.archiva.database.ArtifactDAO; import org.apache.maven.archiva.database.Constraint; import org.apache.maven.archiva.database.ObjectNotFoundException; import org.apache.maven.archiva.database.constraints.ArtifactsByRepositoryConstraint; -import org.apache.maven.archiva.database.constraints.RepositoryContentStatisticsByRepositoryConstraint; import org.apache.maven.archiva.model.ArchivaArtifact; -import org.apache.maven.archiva.model.RepositoryContentStatistics; import org.apache.maven.archiva.repository.audit.AuditEvent; import org.codehaus.plexus.redback.role.RoleManagerException; @@ -56,7 +55,12 @@ public class DeleteManagedRepositoryAction /** * @plexus.requirement role-hint="jdo" */ - private ArchivaDAO archivaDAO; + private ArtifactDAO artifactDao; + + /** + * @plexus.requirement + */ + private RepositoryStatisticsManager repositoryStatisticsManager; public void prepare() { @@ -96,7 +100,7 @@ public class DeleteManagedRepositoryAction return ERROR; } - String result = SUCCESS; + String result; try { @@ -138,7 +142,7 @@ public class DeleteManagedRepositoryAction { removeRepositoryRoles( cleanupRepository ); cleanupDatabase( cleanupRepository.getId() ); - cleanupScanStats( cleanupRepository.getId() ); + repositoryStatisticsManager.deleteStatistics( cleanupRepository.getId() ); // TODO: delete all content for a repository from the content API? List proxyConnectors = getProxyConnectors(); @@ -169,14 +173,14 @@ public class DeleteManagedRepositoryAction { Constraint constraint = new ArtifactsByRepositoryConstraint( repoId ); - List artifacts = archivaDAO.getArtifactDAO().queryArtifacts( constraint ); + List artifacts = artifactDao.queryArtifacts( constraint ); for ( ArchivaArtifact artifact : artifacts ) { log.info( "Removing artifact " + artifact + " from the database." ); try { - archivaDAO.getArtifactDAO().deleteArtifact( artifact ); + artifactDao.deleteArtifact( artifact ); } catch ( ObjectNotFoundException oe ) @@ -192,19 +196,6 @@ public class DeleteManagedRepositoryAction } } - private void cleanupScanStats( String repoId ) - throws ArchivaDatabaseException - { - List results = - archivaDAO.getRepositoryContentStatisticsDAO().queryRepositoryContentStatistics( - new RepositoryContentStatisticsByRepositoryConstraint( repoId ) ); - - for ( RepositoryContentStatistics stats : results ) - { - archivaDAO.getRepositoryContentStatisticsDAO().deleteRepositoryContentStatistics( stats ); - } - } - public ManagedRepositoryConfiguration getRepository() { return repository; @@ -225,13 +216,13 @@ public class DeleteManagedRepositoryAction this.repoid = repoid; } - public void setArchivaDAO( ArchivaDAO archivaDAO ) + public void setRepositoryStatisticsManager( RepositoryStatisticsManager repositoryStatisticsManager ) { - this.archivaDAO = archivaDAO; + this.repositoryStatisticsManager = repositoryStatisticsManager; } - public ArchivaDAO getArchivaDAO() + public void setArtifactDao( ArtifactDAO artifactDao ) { - return archivaDAO; + this.artifactDao = artifactDao; } } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryActionTest.java index 5ef78ba39..e72b4eee7 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryActionTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryActionTest.java @@ -19,6 +19,9 @@ package org.apache.maven.archiva.web.action.admin.repositories; * under the License. */ +import java.io.File; +import java.util.Collections; + import com.opensymphony.xwork2.Action; import org.apache.commons.io.FileUtils; import org.apache.maven.archiva.configuration.ArchivaConfiguration; @@ -26,14 +29,11 @@ import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.security.ArchivaRoleConstants; import org.codehaus.plexus.redback.role.RoleManager; +import org.codehaus.plexus.spring.PlexusInSpringTestCase; import org.codehaus.redback.integration.interceptor.SecureActionBundle; import org.codehaus.redback.integration.interceptor.SecureActionException; -import org.codehaus.plexus.spring.PlexusInSpringTestCase; import org.easymock.MockControl; -import java.io.File; -import java.util.Collections; - /** * AddManagedRepositoryActionTest * @@ -68,7 +68,7 @@ public class AddManagedRepositoryActionTest { super.setUp(); - action = (AddManagedRepositoryAction) lookup( Action.class.getName(), "addManagedRepositoryAction" ); + action = new AddManagedRepositoryAction(); archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class ); archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock(); diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.java index 2f33c5058..de38053c4 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.java @@ -25,6 +25,7 @@ import java.util.Collections; import java.util.List; import com.opensymphony.xwork2.Action; +import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.IndeterminateConfigurationException; @@ -63,6 +64,10 @@ public class DeleteManagedRepositoryActionTest private File location; + private MockControl repositoryStatisticsManagerControl; + + private RepositoryStatisticsManager repositoryStatisticsManager; + @Override protected String getPlexusConfigLocation() { @@ -74,7 +79,7 @@ public class DeleteManagedRepositoryActionTest { super.setUp(); - action = (DeleteManagedRepositoryAction) lookup( Action.class.getName(), "deleteManagedRepositoryAction" ); + action = new DeleteManagedRepositoryAction(); archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class ); archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock(); @@ -83,7 +88,13 @@ public class DeleteManagedRepositoryActionTest roleManagerControl = MockControl.createControl( RoleManager.class ); roleManager = (RoleManager) roleManagerControl.getMock(); action.setRoleManager( roleManager ); - location = getTestFile( "target/test/location" ); + location = getTestFile( "target/test/location" ); + + repositoryStatisticsManagerControl = MockControl.createControl( RepositoryStatisticsManager.class ); + repositoryStatisticsManager = (RepositoryStatisticsManager) repositoryStatisticsManagerControl.getMock(); + action.setRepositoryStatisticsManager( repositoryStatisticsManager ); + + action.setArtifactDao( new ArtifactDAOStub() ); } public void testSecureActionBundle() @@ -126,7 +137,11 @@ public class DeleteManagedRepositoryActionTest public void testDeleteRepositoryKeepContent() throws Exception - { + { + // even when we keep the content, we don't keep the metadata at this point + repositoryStatisticsManager.deleteStatistics( REPO_ID ); + repositoryStatisticsManagerControl.replay(); + prepareRoleManagerMock(); Configuration configuration = prepDeletionTest( createRepository(), 4 ); @@ -138,11 +153,16 @@ public class DeleteManagedRepositoryActionTest assertTrue( configuration.getManagedRepositories().isEmpty() ); assertTrue( location.exists() ); + + repositoryStatisticsManagerControl.verify(); } public void testDeleteRepositoryDeleteContent() throws Exception { + repositoryStatisticsManager.deleteStatistics( REPO_ID ); + repositoryStatisticsManagerControl.replay(); + prepareRoleManagerMock(); Configuration configuration = prepDeletionTest( createRepository(), 4 ); @@ -154,11 +174,16 @@ public class DeleteManagedRepositoryActionTest assertTrue( configuration.getManagedRepositories().isEmpty() ); assertFalse( location.exists() ); + + repositoryStatisticsManagerControl.verify(); } public void testDeleteRepositoryAndAssociatedProxyConnectors() throws Exception { + repositoryStatisticsManager.deleteStatistics( REPO_ID ); + repositoryStatisticsManagerControl.replay(); + Configuration configuration = prepDeletionTest( createRepository(), 5 ); configuration.addRemoteRepository( createRemoteRepository( "codehaus", "http://repository.codehaus.org" ) ); configuration.addRemoteRepository( createRemoteRepository( "java.net", "http://dev.java.net/maven2" ) ); @@ -175,11 +200,15 @@ public class DeleteManagedRepositoryActionTest assertEquals( 0, configuration.getProxyConnectors().size() ); assertFalse( location.exists() ); + + repositoryStatisticsManagerControl.verify(); } public void testDeleteRepositoryCancelled() throws Exception { + repositoryStatisticsManagerControl.replay(); + ManagedRepositoryConfiguration originalRepository = createRepository(); Configuration configuration = prepDeletionTest( originalRepository, 3 ); String status = action.execute(); @@ -190,11 +219,16 @@ public class DeleteManagedRepositoryActionTest assertEquals( Collections.singletonList( originalRepository ), configuration.getManagedRepositories() ); assertTrue( location.exists() ); + + repositoryStatisticsManagerControl.verify(); } public void testDeleteRepositoryAndReposUnderRepoGroup() throws Exception { + repositoryStatisticsManager.deleteStatistics( REPO_ID ); + repositoryStatisticsManagerControl.replay(); + Configuration configuration = prepDeletionTest( createRepository(), 5 ); List repoIds = new ArrayList(); repoIds.add( REPO_ID ); @@ -211,6 +245,8 @@ public class DeleteManagedRepositoryActionTest assertEquals( 0, ( ( RepositoryGroupConfiguration ) configuration.getRepositoryGroups().get( 0 ) ).getRepositories().size() ); assertFalse( location.exists() ); + + repositoryStatisticsManagerControl.verify(); } private Configuration prepDeletionTest( ManagedRepositoryConfiguration originalRepository, int expectCountGetConfig ) diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryActionTest.java index ec70cd62b..cdad5af84 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryActionTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryActionTest.java @@ -68,7 +68,7 @@ public class EditManagedRepositoryActionTest { super.setUp(); - action = (EditManagedRepositoryAction) lookup( Action.class.getName(), "editManagedRepositoryAction" ); + action = new EditManagedRepositoryAction(); archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class ); archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock(); diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/admin/repositories/AbstractManagedRepositoriesActionTest.xml b/archiva-modules/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/admin/repositories/AbstractManagedRepositoriesActionTest.xml deleted file mode 100644 index 030af3bff..000000000 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/admin/repositories/AbstractManagedRepositoriesActionTest.xml +++ /dev/null @@ -1,82 +0,0 @@ - - - - - - com.opensymphony.xwork2.Action - addManagedRepositoryAction - org.apache.maven.archiva.web.action.admin.repositories.AddManagedRepositoryAction - per-lookup - - - - - com.opensymphony.xwork2.Action - deleteManagedRepositoryAction - org.apache.maven.archiva.web.action.admin.repositories.DeleteManagedRepositoryAction - per-lookup - - - org.apache.maven.archiva.database.ArchivaDAO - jdo - archivaDAO - - - - - - com.opensymphony.xwork2.Action - editManagedRepositoryAction - org.apache.maven.archiva.web.action.admin.repositories.EditManagedRepositoryAction - per-lookup - - - - - - org.apache.maven.archiva.database.ArchivaDAO - jdo - org.apache.maven.archiva.web.action.admin.repositories.AbstractManagedRepositoryArchivaDAOStub - - - org.apache.maven.archiva.database.ArtifactDAO - jdo - artifactDAO - - - org.apache.maven.archiva.database.RepositoryContentStatisticsDAO - jdo - repoContentStatisticsDAO - - - - - org.apache.maven.archiva.database.ArtifactDAO - jdo - org.apache.maven.archiva.web.action.admin.repositories.ArtifactDAOStub - - - org.apache.maven.archiva.database.RepositoryContentStatisticsDAO - jdo - org.apache.maven.archiva.web.action.admin.repositories.RepositoryContentStatisticsDAOStub - - - - diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.xml b/archiva-modules/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.xml deleted file mode 100644 index de0cd78db..000000000 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.xml +++ /dev/null @@ -1,68 +0,0 @@ - - - - - - org.codehaus.plexus.redback.role.RoleManager - default - org.apache.maven.archiva.web.action.admin.repositories.RoleManagerStub - - - com.opensymphony.xwork2.Action - deleteManagedRepositoryAction - org.apache.maven.archiva.web.action.admin.repositories.DeleteManagedRepositoryAction - per-lookup - - - org.apache.maven.archiva.database.ArchivaDAO - jdo - archivaDAO - - - - - org.apache.maven.archiva.database.ArchivaDAO - jdo - org.apache.maven.archiva.web.action.admin.repositories.DeleteManagedRepositoryArchivaDAOStub - - - org.apache.maven.archiva.database.ArtifactDAO - jdo - artifactDAO - - - org.apache.maven.archiva.database.RepositoryContentStatisticsDAO - jdo - repoContentStatisticsDAO - - - - - org.apache.maven.archiva.database.ArtifactDAO - jdo - org.apache.maven.archiva.web.action.admin.repositories.ArtifactDAOStub - - - org.apache.maven.archiva.database.RepositoryContentStatisticsDAO - jdo - org.apache.maven.archiva.web.action.admin.repositories.RepositoryContentStatisticsDAOStub - - - -- 2.39.5