From 21a61ab5f9c0a139bb25a64c7d8136af6a00dc96 Mon Sep 17 00:00:00 2001 From: "Maria Odea B. Ching" Date: Sun, 21 Oct 2007 17:30:07 +0000 Subject: [PATCH] [MRM-265] - added method for deleting the artifacts in the db when a repo is deleted - also deleted repo scan statistics when the repo is deleted - created DAO that does retrieving, deleting and adding of RepositoryContentStatistics to the db - added and updated tests git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@586919 13f79535-47bb-0310-9956-ffa450edef68 --- .../ProjectModelToDatabaseConsumer.java | 3 +- .../maven/archiva/database/ArchivaDAO.java | 6 +- ...ntentStatisticsByRepositoryConstraint.java | 49 ++++++++++ .../archiva/database/jdo/JdoArchivaDAO.java | 14 ++- .../JdoRepositoryContentStatisticsDAO.java | 67 +++++++++++++ ...tStatisticsByRepositoryConstraintTest.java | 79 ++++++++++++++++ ...JdoRepositoryContentStatisticsDAOTest.java | 84 +++++++++++++++++ ...ArchivaRepositoryScanningTaskExecutor.java | 5 +- .../DeleteManagedRepositoryAction.java | 94 +++++++++++++++++-- .../admin/repositories/ArchivaDAOStub.java | 14 ++- .../admin/repositories/ArtifactDAOStub.java | 90 ++++++++++++++++++ .../DeleteManagedRepositoryActionTest.java | 32 +++++-- ...DeleteManagedRepositoryArchivaDAOStub.java | 85 +++++++++++++++++ .../repositories/ProjectModelDAOStub.java | 78 +++++++++++++++ .../DeleteManagedRepositoryActionTest.xml | 78 +++++++++++++++ 15 files changed, 754 insertions(+), 24 deletions(-) create mode 100644 archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/RepositoryContentStatisticsByRepositoryConstraint.java create mode 100644 archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoRepositoryContentStatisticsDAO.java create mode 100644 archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/RepositoryContentStatisticsByRepositoryConstraintTest.java create mode 100644 archiva-database/src/test/java/org/apache/maven/archiva/database/jdo/JdoRepositoryContentStatisticsDAOTest.java create mode 100644 archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ArtifactDAOStub.java create mode 100644 archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryArchivaDAOStub.java create mode 100644 archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ProjectModelDAOStub.java create mode 100644 archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.xml diff --git a/archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/ProjectModelToDatabaseConsumer.java b/archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/ProjectModelToDatabaseConsumer.java index a31698d0f..c323920b2 100644 --- a/archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/ProjectModelToDatabaseConsumer.java +++ b/archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/ProjectModelToDatabaseConsumer.java @@ -166,8 +166,7 @@ public class ProjectModelToDatabaseConsumer if ( isValidModel( model, repo, artifact ) ) { - getLogger().info( "Adding project model to database - " + Keys.toKey( model ) ); - + getLogger().info( "Adding project model to database - " + Keys.toKey( model ) ); dao.getProjectModelDAO().saveProjectModel( model ); } else diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/ArchivaDAO.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/ArchivaDAO.java index 18b1821d3..d38aea1a3 100644 --- a/archiva-database/src/main/java/org/apache/maven/archiva/database/ArchivaDAO.java +++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/ArchivaDAO.java @@ -22,6 +22,8 @@ package org.apache.maven.archiva.database; import java.io.Serializable; import java.util.List; +import org.apache.maven.archiva.model.RepositoryContentStatistics; + /** * ArchivaDAO - The interface for all content within the database. * @@ -47,10 +49,12 @@ public interface ArchivaDAO * @return the post-serialized object. */ Object save( Serializable obj ); - + ArtifactDAO getArtifactDAO(); ProjectModelDAO getProjectModelDAO(); RepositoryProblemDAO getRepositoryProblemDAO(); + + RepositoryContentStatisticsDAO getRepositoryContentStatisticsDAO(); } diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/RepositoryContentStatisticsByRepositoryConstraint.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/RepositoryContentStatisticsByRepositoryConstraint.java new file mode 100644 index 000000000..dc3990980 --- /dev/null +++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/RepositoryContentStatisticsByRepositoryConstraint.java @@ -0,0 +1,49 @@ +package org.apache.maven.archiva.database.constraints; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * RepositoryContentStatisticsByRepositoryConstraint + * + * @author Maria Odea Ching + * @version + */ +public class RepositoryContentStatisticsByRepositoryConstraint + extends AbstractDeclarativeConstraint +{ + private String whereClause; + + public RepositoryContentStatisticsByRepositoryConstraint( String repoId ) + { + whereClause = "repositoryId == repoId"; + declParams = new String[] { "String repoId" }; + params = new Object[] { repoId }; + } + + public String getSortColumn() + { + return "whenGathered"; + } + + public String getWhereCondition() + { + return whereClause; + } +} diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAO.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAO.java index 639106184..680c395d8 100644 --- a/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAO.java +++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAO.java @@ -22,6 +22,7 @@ package org.apache.maven.archiva.database.jdo; import org.apache.maven.archiva.database.ArchivaDAO; import org.apache.maven.archiva.database.ArtifactDAO; import org.apache.maven.archiva.database.ProjectModelDAO; +import org.apache.maven.archiva.database.RepositoryContentStatisticsDAO; import org.apache.maven.archiva.database.RepositoryProblemDAO; import org.apache.maven.archiva.database.SimpleConstraint; import org.codehaus.plexus.logging.AbstractLogEnabled; @@ -60,6 +61,12 @@ public class JdoArchivaDAO * @plexus.requirement role-hint="jdo" */ private RepositoryProblemDAO repositoryProblemDAO; + + /** + * @plexus.requirement role-hint="jdo" + */ + private RepositoryContentStatisticsDAO repositoryContentStatisticsDAO; + public List query( SimpleConstraint constraint ) { @@ -70,7 +77,7 @@ public class JdoArchivaDAO { return jdo.saveObject( obj ); } - + public ArtifactDAO getArtifactDAO() { return artifactDAO; @@ -85,4 +92,9 @@ public class JdoArchivaDAO { return repositoryProblemDAO; } + + public RepositoryContentStatisticsDAO getRepositoryContentStatisticsDAO() + { + return repositoryContentStatisticsDAO; + } } diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoRepositoryContentStatisticsDAO.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoRepositoryContentStatisticsDAO.java new file mode 100644 index 000000000..00475ed9e --- /dev/null +++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoRepositoryContentStatisticsDAO.java @@ -0,0 +1,67 @@ +package org.apache.maven.archiva.database.jdo; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.util.List; + +import org.apache.maven.archiva.database.ArchivaDatabaseException; +import org.apache.maven.archiva.database.Constraint; +import org.apache.maven.archiva.database.ObjectNotFoundException; +import org.apache.maven.archiva.database.RepositoryContentStatisticsDAO; +import org.apache.maven.archiva.model.RepositoryContentStatistics; + +/** + * JdoRepositoryContentStatisticsDAO + * + * @author Maria Odea Ching + * @version + * + * @plexus.component role-hint="jdo" + */ +public class JdoRepositoryContentStatisticsDAO + implements RepositoryContentStatisticsDAO +{ + /** + * @plexus.requirement role-hint="archiva" + */ + private JdoAccess jdo; + + public void deleteRepositoryContentStatistics( RepositoryContentStatistics stats ) + throws ArchivaDatabaseException + { + jdo.removeObject( stats ); + } + + public List queryRepositoryContentStatistics( Constraint constraint ) + throws ObjectNotFoundException, ArchivaDatabaseException + { + List results = jdo.queryObjects( RepositoryContentStatistics.class, constraint ); + + return results; + } + + public RepositoryContentStatistics saveRepositoryContentStatistics( RepositoryContentStatistics stats ) + { + RepositoryContentStatistics savedStats = (RepositoryContentStatistics) jdo.saveObject( stats ); + + return savedStats; + } + +} diff --git a/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/RepositoryContentStatisticsByRepositoryConstraintTest.java b/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/RepositoryContentStatisticsByRepositoryConstraintTest.java new file mode 100644 index 000000000..3e036b554 --- /dev/null +++ b/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/RepositoryContentStatisticsByRepositoryConstraintTest.java @@ -0,0 +1,79 @@ +package org.apache.maven.archiva.database.constraints; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.util.List; + +import org.apache.maven.archiva.database.AbstractArchivaDatabaseTestCase; +import org.apache.maven.archiva.database.Constraint; +import org.apache.maven.archiva.model.RepositoryContentStatistics; + +/** + * RepositoryContentStatisticsByRepositoryConstraintTest + * + * @author Maria Odea Ching + * @version + */ +public class RepositoryContentStatisticsByRepositoryConstraintTest + extends AbstractArchivaDatabaseTestCase +{ + private RepositoryContentStatistics createStats( String repoId, String timestamp, long duration, long totalfiles, + long newfiles ) + throws Exception + { + RepositoryContentStatistics stats = new RepositoryContentStatistics(); + stats.setRepositoryId( repoId ); + stats.setDuration( duration ); + stats.setNewFileCount( newfiles ); + stats.setTotalFileCount( totalfiles ); + stats.setWhenGathered( toDate( timestamp ) ); + + return stats; + } + + protected void setUp() + throws Exception + { + super.setUp(); + + dao.getRepositoryContentStatisticsDAO().saveRepositoryContentStatistics( + createStats( "internal", "2007/10/21 8:00:00", 20000, 12000, 400 ) ); + dao.getRepositoryContentStatisticsDAO().saveRepositoryContentStatistics( + createStats( "internal", "2007/10/20 8:00:00", 20000, 11800, 0 ) ); + dao.getRepositoryContentStatisticsDAO().saveRepositoryContentStatistics( + createStats( "internal", "2007/10/19 8:00:00", 20000, 11800, 100 ) ); + dao.getRepositoryContentStatisticsDAO().saveRepositoryContentStatistics( + createStats( "internal", "2007/10/18 8:00:00", 20000, 11700, 320 ) ); + } + + public void testStats() + throws Exception + { + Constraint constraint = new RepositoryContentStatisticsByRepositoryConstraint( "internal" ); + List results = dao.getRepositoryContentStatisticsDAO().queryRepositoryContentStatistics( constraint ); + assertNotNull( "Stats: results (not null)", results ); + assertEquals( "Stats: results.size", 4, results.size() ); + + assertEquals( "internal", ( (RepositoryContentStatistics) results.get( 0 ) ).getRepositoryId() ); + assertEquals( "internal", ( (RepositoryContentStatistics) results.get( 1 ) ).getRepositoryId() ); + assertEquals( "internal", ( (RepositoryContentStatistics) results.get( 2 ) ).getRepositoryId() ); + assertEquals( "internal", ( (RepositoryContentStatistics) results.get( 3 ) ).getRepositoryId() ); + } +} diff --git a/archiva-database/src/test/java/org/apache/maven/archiva/database/jdo/JdoRepositoryContentStatisticsDAOTest.java b/archiva-database/src/test/java/org/apache/maven/archiva/database/jdo/JdoRepositoryContentStatisticsDAOTest.java new file mode 100644 index 000000000..3989d72fe --- /dev/null +++ b/archiva-database/src/test/java/org/apache/maven/archiva/database/jdo/JdoRepositoryContentStatisticsDAOTest.java @@ -0,0 +1,84 @@ +package org.apache.maven.archiva.database.jdo; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.util.List; + +import javax.jdo.JDOHelper; + +import org.apache.maven.archiva.database.AbstractArchivaDatabaseTestCase; +import org.apache.maven.archiva.database.RepositoryContentStatisticsDAO; +import org.apache.maven.archiva.database.constraints.RepositoryContentStatisticsByRepositoryConstraint; +import org.apache.maven.archiva.model.RepositoryContentStatistics; + +/** + * JdoRepositoryContentStatisticsDAOTest + * + * @author Maria Odea Ching + * @version + */ +public class JdoRepositoryContentStatisticsDAOTest + extends AbstractArchivaDatabaseTestCase +{ + public void testCRUD() + throws Exception + { + RepositoryContentStatisticsDAO repoContentStatisticsDAO = dao.getRepositoryContentStatisticsDAO(); + + // create + RepositoryContentStatistics savedStats = + repoContentStatisticsDAO.saveRepositoryContentStatistics( createStats( "internal", "2007/10/21 8:00:00", + 20000, 12000, 400 ) ); + assertNotNull( savedStats ); + + String savedKeyId = JDOHelper.getObjectId( savedStats ).toString(); + assertEquals( "1[OID]org.apache.maven.archiva.model.RepositoryContentStatistics", savedKeyId ); + + // query + List results = + repoContentStatisticsDAO.queryRepositoryContentStatistics( new RepositoryContentStatisticsByRepositoryConstraint( + "internal" ) ); + assertNotNull( results ); + assertEquals( 1, results.size() ); + + RepositoryContentStatistics stats = (RepositoryContentStatistics) results.get( 0 ); + assertEquals( "internal", stats.getRepositoryId() ); + + // delete + repoContentStatisticsDAO.deleteRepositoryContentStatistics( stats ); + + assertEquals( 0, repoContentStatisticsDAO.queryRepositoryContentStatistics( + new RepositoryContentStatisticsByRepositoryConstraint( "internal" ) ).size() ); + } + + private RepositoryContentStatistics createStats( String repoId, String timestamp, long duration, long totalfiles, + long newfiles ) + throws Exception + { + RepositoryContentStatistics stats = new RepositoryContentStatistics(); + stats.setRepositoryId( repoId ); + stats.setDuration( duration ); + stats.setNewFileCount( newfiles ); + stats.setTotalFileCount( totalfiles ); + stats.setWhenGathered( toDate( timestamp ) ); + + return stats; + } +} diff --git a/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/executors/ArchivaRepositoryScanningTaskExecutor.java b/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/executors/ArchivaRepositoryScanningTaskExecutor.java index 6ce703f9c..62e024488 100644 --- a/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/executors/ArchivaRepositoryScanningTaskExecutor.java +++ b/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/executors/ArchivaRepositoryScanningTaskExecutor.java @@ -24,6 +24,7 @@ import org.apache.commons.lang.StringUtils; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.database.ArchivaDAO; +import org.apache.maven.archiva.database.ArchivaDatabaseException; import org.apache.maven.archiva.database.constraints.MostRecentRepositoryScanStatistics; import org.apache.maven.archiva.model.RepositoryContentStatistics; import org.apache.maven.archiva.repository.RepositoryException; @@ -114,11 +115,11 @@ public class ArchivaRepositoryScanningTaskExecutor dbstats.setTotalFileCount( stats.getTotalFileCount() ); dbstats.setWhenGathered( stats.getWhenGathered() ); - dao.save( dbstats ); + dao.getRepositoryContentStatisticsDAO().saveRepositoryContentStatistics( dbstats ); } catch ( RepositoryException e ) { throw new TaskExecutionException( "Repository error when executing repository job.", e ); - } + } } } diff --git a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryAction.java b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryAction.java index c61eeb4ac..8a6ab5688 100644 --- a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryAction.java +++ b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryAction.java @@ -24,18 +24,29 @@ import com.opensymphony.xwork.Preparable; 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.database.ArchivaDAO; +import org.apache.maven.archiva.database.ArchivaDatabaseException; +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.ArchivaProjectModel; +import org.apache.maven.archiva.model.RepositoryContentStatistics; + import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration; + import org.codehaus.plexus.redback.role.RoleManagerException; import java.io.IOException; import java.util.List; /** - * DeleteManagedRepositoryAction - * + * DeleteManagedRepositoryAction + * * @author Joakim Erdfelt * @version $Id$ - * * @plexus.component role="com.opensymphony.xwork.Action" role-hint="deleteManagedRepositoryAction" */ public class DeleteManagedRepositoryAction @@ -46,6 +57,11 @@ public class DeleteManagedRepositoryAction private String repoid; + /** + * @plexus.requirement role-hint="jdo" + */ + private ArchivaDAO archivaDAO; + public void prepare() { if ( StringUtils.isNotBlank( repoid ) ) @@ -89,13 +105,12 @@ public class DeleteManagedRepositoryAction try { Configuration configuration = archivaConfiguration.getConfiguration(); + cleanupRepositoryData( existingRepository ); removeRepository( repoid, configuration ); result = saveConfiguration( configuration ); if ( result.equals( SUCCESS ) ) { - cleanupRepositoryData( existingRepository ); - if ( deleteContents ) { removeContents( existingRepository ); @@ -112,19 +127,26 @@ public class DeleteManagedRepositoryAction addActionError( "Unable to delete repository: " + e.getMessage() ); result = ERROR; } + catch ( ArchivaDatabaseException e ) + { + addActionError( "Unable to delete repositoy: " + e.getMessage() ); + result = ERROR; + } return result; } private void cleanupRepositoryData( ManagedRepositoryConfiguration cleanupRepository ) - throws RoleManagerException + throws RoleManagerException, ArchivaDatabaseException { removeRepositoryRoles( cleanupRepository ); // TODO: [MRM-382] Remove index from artifacts of deleted managed repositories. - // TODO: [MRM-265] After removing a managed repository - Browse/Search still see it - + // [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 proxyConnectors = getProxyConnectors(); for ( ProxyConnectorConfiguration proxyConnector : proxyConnectors ) @@ -136,6 +158,52 @@ public class DeleteManagedRepositoryAction } } + private void cleanupDatabase( String repoId ) + throws ArchivaDatabaseException + { + Constraint constraint = new ArtifactsByRepositoryConstraint( repoId ); + + List artifacts = archivaDAO.getArtifactDAO().queryArtifacts( constraint ); + + for ( ArchivaArtifact artifact : artifacts ) + { + getLogger().info( "Removing artifact " + artifact + " from the database." ); + try + { + archivaDAO.getArtifactDAO().deleteArtifact( artifact ); + + ArchivaProjectModel projectModel = + archivaDAO.getProjectModelDAO().getProjectModel( artifact.getGroupId(), artifact.getArtifactId(), + artifact.getVersion() ); + + archivaDAO.getProjectModelDAO().deleteProjectModel( projectModel ); + } + catch ( ObjectNotFoundException oe ) + { + getLogger().info( "Project model of artifact " + artifact + " does not exist in the database. " + + "Moving on to the next artifact." ); + } + catch ( ArchivaDatabaseException ae ) + { + getLogger().info( "Unable to delete artifact " + artifact + " from the database. " + + "Moving on to the next artifact." ); + } + } + } + + 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; @@ -155,4 +223,14 @@ public class DeleteManagedRepositoryAction { this.repoid = repoid; } + + public void setArchivaDAO( ArchivaDAO archivaDAO ) + { + this.archivaDAO = archivaDAO; + } + + public ArchivaDAO getArchivaDAO() + { + return archivaDAO; + } } diff --git a/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ArchivaDAOStub.java b/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ArchivaDAOStub.java index 2c464c4f7..7141af57c 100644 --- a/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ArchivaDAOStub.java +++ b/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ArchivaDAOStub.java @@ -4,6 +4,7 @@ import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.database.ArchivaDAO; import org.apache.maven.archiva.database.ArtifactDAO; import org.apache.maven.archiva.database.ProjectModelDAO; +import org.apache.maven.archiva.database.RepositoryContentStatisticsDAO; import org.apache.maven.archiva.database.RepositoryProblemDAO; import org.apache.maven.archiva.database.SimpleConstraint; import org.apache.maven.archiva.model.RepositoryContentStatistics; @@ -46,6 +47,7 @@ public class ArchivaDAOStub public List query( SimpleConstraint constraint ) { Assert.assertEquals( RepositoryContentStatistics.class, constraint.getResultClass() ); + List stats = new ArrayList(); for ( String repo : configuration.getConfiguration().getManagedRepositoriesAsMap().keySet() ) @@ -64,16 +66,22 @@ public class ArchivaDAOStub public ArtifactDAO getArtifactDAO() { - throw new UnsupportedOperationException( "query not implemented for stub" ); + throw new UnsupportedOperationException( "method not implemented for stub" ); } public ProjectModelDAO getProjectModelDAO() { - throw new UnsupportedOperationException( "query not implemented for stub" ); + throw new UnsupportedOperationException( "method not implemented for stub" ); } public RepositoryProblemDAO getRepositoryProblemDAO() { - throw new UnsupportedOperationException( "query not implemented for stub" ); + throw new UnsupportedOperationException( "method not implemented for stub" ); + } + + public RepositoryContentStatisticsDAO getRepositoryContentStatisticsDAO() + { + throw new UnsupportedOperationException( "method not implemented for stub" ); } + } diff --git a/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ArtifactDAOStub.java b/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ArtifactDAOStub.java new file mode 100644 index 000000000..61e2f8bd3 --- /dev/null +++ b/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ArtifactDAOStub.java @@ -0,0 +1,90 @@ +package org.apache.maven.archiva.web.action.admin.repositories; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.util.ArrayList; +import java.util.List; + +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.model.ArchivaArtifact; +import org.apache.maven.archiva.model.ArchivaArtifactModel; + +/** + * ArtifactDAOStub + * + * @author Maria Odea Ching + * @version + */ +public class ArtifactDAOStub + implements ArtifactDAO +{ + + public ArchivaArtifact createArtifact( String groupId, String artifactId, String version, String classifier, + String type ) + { + // TODO Auto-generated method stub + return null; + } + + public void deleteArtifact( ArchivaArtifact artifact ) + throws ArchivaDatabaseException + { + // TODO Auto-generated method stub + + } + + public ArchivaArtifact getArtifact( String groupId, String artifactId, String version, String classifier, + String type ) + throws ObjectNotFoundException, ArchivaDatabaseException + { + // TODO Auto-generated method stub + return null; + } + + public List queryArtifacts( Constraint constraint ) + throws ObjectNotFoundException, ArchivaDatabaseException + { + + List artifacts = new ArrayList(); + + ArchivaArtifactModel model = new ArchivaArtifactModel(); + model.setGroupId( "org.apache.maven.archiva" ); + model.setArtifactId( "test-artifact" ); + model.setVersion( "1.0" ); + model.setType( "jar" ); + model.setRepositoryId( "repo-ident" ); + + ArchivaArtifact artifact = new ArchivaArtifact( model ); + artifacts.add( artifact ); + + return artifacts; + } + + public ArchivaArtifact saveArtifact( ArchivaArtifact artifact ) + throws ArchivaDatabaseException + { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.java b/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.java index a9b2e4424..95f25df2b 100644 --- a/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.java +++ b/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.java @@ -25,8 +25,12 @@ 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.model.ArchivaProjectModel; + import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration; import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration; + import org.apache.maven.archiva.security.ArchivaRoleConstants; import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.redback.role.RoleManager; @@ -57,7 +61,7 @@ public class DeleteManagedRepositoryActionTest private MockControl archivaConfigurationControl; private ArchivaConfiguration archivaConfiguration; - + private static final String REPO_ID = "repo-ident"; private File location; @@ -68,7 +72,7 @@ public class DeleteManagedRepositoryActionTest super.setUp(); action = (DeleteManagedRepositoryAction) lookup( Action.class.getName(), "deleteManagedRepositoryAction" ); - + archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class ); archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock(); action.setArchivaConfiguration( archivaConfiguration ); @@ -76,7 +80,7 @@ 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" ); } public void testSecureActionBundle() @@ -119,11 +123,13 @@ public class DeleteManagedRepositoryActionTest public void testDeleteRepositoryKeepContent() throws Exception - { + { prepareRoleManagerMock(); - Configuration configuration = prepDeletionTest( createRepository(), 3 ); - String status = action.deleteEntry(); + Configuration configuration = prepDeletionTest( createRepository(), 3 ); + + String status = action.deleteEntry(); + assertEquals( Action.SUCCESS, status ); assertTrue( configuration.getManagedRepositories().isEmpty() ); @@ -136,8 +142,10 @@ public class DeleteManagedRepositoryActionTest { prepareRoleManagerMock(); - Configuration configuration = prepDeletionTest( createRepository(), 3 ); + Configuration configuration = prepDeletionTest( createRepository(), 3 ); + String status = action.deleteContents(); + assertEquals( Action.SUCCESS, status ); assertTrue( configuration.getManagedRepositories().isEmpty() ); @@ -277,4 +285,14 @@ public class DeleteManagedRepositoryActionTest roleManager.removeTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_MANAGER, REPO_ID ); roleManagerControl.replay(); } + + protected ArchivaProjectModel createProjectModel( String groupId, String artifactId, String version ) + { + ArchivaProjectModel projectModel = new ArchivaProjectModel(); + projectModel.setGroupId( groupId ); + projectModel.setArtifactId( artifactId ); + projectModel.setVersion( version ); + + return projectModel; + } } diff --git a/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryArchivaDAOStub.java b/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryArchivaDAOStub.java new file mode 100644 index 000000000..d48ccc455 --- /dev/null +++ b/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryArchivaDAOStub.java @@ -0,0 +1,85 @@ +package org.apache.maven.archiva.web.action.admin.repositories; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.io.Serializable; +import java.util.List; + +import org.apache.maven.archiva.database.ArchivaDAO; +import org.apache.maven.archiva.database.ArtifactDAO; +import org.apache.maven.archiva.database.ProjectModelDAO; +import org.apache.maven.archiva.database.RepositoryContentStatisticsDAO; +import org.apache.maven.archiva.database.RepositoryProblemDAO; +import org.apache.maven.archiva.database.SimpleConstraint; + +/** + * DeleteManagedRepositoryArchivaDAOStub + * + * @author Maria Odea Ching + * @version + */ +public class DeleteManagedRepositoryArchivaDAOStub + implements ArchivaDAO +{ + /** + * @plexus.requirement role-hint="jdo" + */ + private ProjectModelDAO projectModelDAO; + + /** + * @plexus.requirement role-hint="jdo" + */ + private ArtifactDAO artifactDAO; + + /** + * @plexus.requirement role-hint="jdo" + */ + private RepositoryContentStatisticsDAO repoContentStatisticsDAO; + + public List query( SimpleConstraint constraint ) + { + return null; + } + + public Object save( Serializable obj ) + { + throw new UnsupportedOperationException( "query not implemented for stub" ); + } + + public ArtifactDAO getArtifactDAO() + { + return artifactDAO; + } + + public ProjectModelDAO getProjectModelDAO() + { + return projectModelDAO; + } + + public RepositoryProblemDAO getRepositoryProblemDAO() + { + throw new UnsupportedOperationException( "query not implemented for stub" ); + } + + public RepositoryContentStatisticsDAO getRepositoryContentStatisticsDAO() + { + return repoContentStatisticsDAO; + } +} diff --git a/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ProjectModelDAOStub.java b/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ProjectModelDAOStub.java new file mode 100644 index 000000000..7414ebd8c --- /dev/null +++ b/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ProjectModelDAOStub.java @@ -0,0 +1,78 @@ +package org.apache.maven.archiva.web.action.admin.repositories; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.util.List; + +import org.apache.maven.archiva.database.ArchivaDatabaseException; +import org.apache.maven.archiva.database.Constraint; +import org.apache.maven.archiva.database.ObjectNotFoundException; +import org.apache.maven.archiva.database.ProjectModelDAO; +import org.apache.maven.archiva.model.ArchivaProjectModel; + +/** + * ProjectModelDAOStub + * + * @author Maria Odea Ching + * @version + */ +public class ProjectModelDAOStub + implements ProjectModelDAO +{ + + public ArchivaProjectModel createProjectModel( String groupId, String artifactId, String version ) + { + // TODO Auto-generated method stub + return null; + } + + public void deleteProjectModel( ArchivaProjectModel model ) + throws ArchivaDatabaseException + { + // TODO Auto-generated method stub + + } + + public ArchivaProjectModel getProjectModel( String groupId, String artifactId, String version ) + throws ObjectNotFoundException, ArchivaDatabaseException + { + ArchivaProjectModel projectModel = new ArchivaProjectModel(); + projectModel.setGroupId( groupId ); + projectModel.setArtifactId( artifactId ); + projectModel.setVersion( version ); + + return projectModel; + } + + public List queryProjectModels( Constraint constraint ) + throws ObjectNotFoundException, ArchivaDatabaseException + { + // TODO Auto-generated method stub + return null; + } + + public ArchivaProjectModel saveProjectModel( ArchivaProjectModel model ) + throws ArchivaDatabaseException + { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.xml b/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.xml new file mode 100644 index 000000000..c6e35788e --- /dev/null +++ b/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.xml @@ -0,0 +1,78 @@ + + + + + + org.codehaus.plexus.logging.LoggerManager + org.codehaus.plexus.logging.slf4j.Slf4jLoggerManager + basic + + + com.opensymphony.xwork.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.ProjectModelDAO + jdo + projectModelDAO + + + 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.ProjectModelDAO + jdo + org.apache.maven.archiva.web.action.admin.repositories.ProjectModelDAOStub + + + org.apache.maven.archiva.database.RepositoryContentStatisticsDAO + jdo + org.apache.maven.archiva.web.action.admin.repositories.RepositoryContentStatisticsDAOStub + + + -- 2.39.5