]> source.dussan.org Git - archiva.git/commitdiff
[MRM-265]
authorMaria Odea B. Ching <oching@apache.org>
Sun, 21 Oct 2007 17:30:07 +0000 (17:30 +0000)
committerMaria Odea B. Ching <oching@apache.org>
Sun, 21 Oct 2007 17:30:07 +0000 (17:30 +0000)
- 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

15 files changed:
archiva-base/archiva-consumers/archiva-database-consumers/src/main/java/org/apache/maven/archiva/consumers/database/ProjectModelToDatabaseConsumer.java
archiva-database/src/main/java/org/apache/maven/archiva/database/ArchivaDAO.java
archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/RepositoryContentStatisticsByRepositoryConstraint.java [new file with mode: 0644]
archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAO.java
archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoRepositoryContentStatisticsDAO.java [new file with mode: 0644]
archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/RepositoryContentStatisticsByRepositoryConstraintTest.java [new file with mode: 0644]
archiva-database/src/test/java/org/apache/maven/archiva/database/jdo/JdoRepositoryContentStatisticsDAOTest.java [new file with mode: 0644]
archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/executors/ArchivaRepositoryScanningTaskExecutor.java
archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryAction.java
archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ArchivaDAOStub.java
archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ArtifactDAOStub.java [new file with mode: 0644]
archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.java
archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryArchivaDAOStub.java [new file with mode: 0644]
archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ProjectModelDAOStub.java [new file with mode: 0644]
archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.xml [new file with mode: 0644]

index a31698d0f5dffad5b97e407b6dcc5e8e22d4c63e..c323920b2ae70636216a3aabe2dd5e4c361bbb41 100644 (file)
@@ -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
index 18b1821d3b23bd6d80c2d51c4bed760d905dc639..d38aea1a3160194879cbad32dfc915c57ede9c31 100644 (file)
@@ -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 (file)
index 0000000..dc39909
--- /dev/null
@@ -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 <a href="mailto:oching@apache.org">Maria Odea Ching</a>
+ * @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;
+    }
+}
index 639106184b98ef9d4b74fcc133ae0677310f9332..680c395d8441c7c74143f84ff7cf09f01af550ae 100644 (file)
@@ -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 (file)
index 0000000..00475ed
--- /dev/null
@@ -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 <a href="mailto:oching@apache.org">Maria Odea Ching</a>
+ * @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 (file)
index 0000000..3e036b5
--- /dev/null
@@ -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 <a href="mailto:oching@apache.org">Maria Odea Ching</a>
+ * @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 (file)
index 0000000..3989d72
--- /dev/null
@@ -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 <a href="mailto:oching@apache.org">Maria Odea Ching</a>
+ * @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;
+    }
+}
index 6ce703f9cf7d864bd13854135b5e0796f34ec7c4..62e0244883b135e4042cd09ff81ed3037909a3bf 100644 (file)
@@ -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 );
-        }
+        }        
     }
 }
index c61eeb4ac98c65d0114b30964735c9c031d98975..8a6ab5688cb3130008ab72499f5b84f775a112b4 100644 (file)
@@ -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 <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
  * @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<ProxyConnectorConfiguration> 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<ArchivaArtifact> 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<RepositoryContentStatistics> 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;
+    }
 }
index 2c464c4f7ca1bb10b2cd67df821e13d7320c622c..7141af57cf7f5e1e90e2df99f43331687925cd1d 100644 (file)
@@ -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<RepositoryContentStatistics> stats = new ArrayList<RepositoryContentStatistics>();
         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 (file)
index 0000000..61e2f8b
--- /dev/null
@@ -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 <a href="mailto:oching@apache.org">Maria Odea Ching</a>
+ * @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<ArchivaArtifact> queryArtifacts( Constraint constraint )
+        throws ObjectNotFoundException, ArchivaDatabaseException
+    {
+
+        List<ArchivaArtifact> artifacts = new ArrayList<ArchivaArtifact>();
+
+        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;
+    }
+        
+}
index a9b2e44243b1157e4a7fb761be097677071fa1c9..95f25df2b9e26ec736b2b18ec671b20113bd8ca9 100644 (file)
@@ -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 (file)
index 0000000..d48ccc4
--- /dev/null
@@ -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 <a href="mailto:oching@apache.org">Maria Odea Ching</a>
+ * @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 (file)
index 0000000..7414ebd
--- /dev/null
@@ -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 <a href="mailto:oching@apache.org">Maria Odea Ching</a>
+ * @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 (file)
index 0000000..c6e3578
--- /dev/null
@@ -0,0 +1,78 @@
+<!--
+  ~ 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.
+  -->
+
+<plexus>
+  <components>  
+       <component>
+      <role>org.codehaus.plexus.logging.LoggerManager</role>
+      <implementation>org.codehaus.plexus.logging.slf4j.Slf4jLoggerManager</implementation>
+      <lifecycle-handler>basic</lifecycle-handler>
+    </component>
+    <component>
+      <role>com.opensymphony.xwork.Action</role>
+      <role-hint>deleteManagedRepositoryAction</role-hint>
+      <implementation>org.apache.maven.archiva.web.action.admin.repositories.DeleteManagedRepositoryAction</implementation>
+      <instantiation-strategy>per-lookup</instantiation-strategy>
+      <requirements>
+        <requirement>
+          <role>org.apache.maven.archiva.database.ArchivaDAO</role>
+          <role-hint>jdo</role-hint>
+          <field-name>archivaDAO</field-name>
+        </requirement>
+      </requirements>
+    </component>
+       <component>
+      <role>org.apache.maven.archiva.database.ArchivaDAO</role>
+      <role-hint>jdo</role-hint>
+      <implementation>org.apache.maven.archiva.web.action.admin.repositories.DeleteManagedRepositoryArchivaDAOStub</implementation>
+      <requirements>
+       <requirement>
+               <role>org.apache.maven.archiva.database.ArtifactDAO</role>
+               <role-hint>jdo</role-hint>
+               <field-name>artifactDAO</field-name>
+       </requirement>
+       <requirement>
+               <role>org.apache.maven.archiva.database.ProjectModelDAO</role>
+               <role-hint>jdo</role-hint>
+               <field-name>projectModelDAO</field-name>
+       </requirement>
+       <requirement>
+               <role>org.apache.maven.archiva.database.RepositoryContentStatisticsDAO</role>
+               <role-hint>jdo</role-hint>
+               <field-name>repoContentStatisticsDAO</field-name>
+       </requirement>           
+      </requirements>            
+    </component>
+    <component>
+      <role>org.apache.maven.archiva.database.ArtifactDAO</role>
+      <role-hint>jdo</role-hint>
+      <implementation>org.apache.maven.archiva.web.action.admin.repositories.ArtifactDAOStub</implementation>
+    </component>        
+    <component>
+      <role>org.apache.maven.archiva.database.ProjectModelDAO</role>
+      <role-hint>jdo</role-hint>
+      <implementation>org.apache.maven.archiva.web.action.admin.repositories.ProjectModelDAOStub</implementation>
+    </component>   
+    <component>
+      <role>org.apache.maven.archiva.database.RepositoryContentStatisticsDAO</role>
+      <role-hint>jdo</role-hint>
+      <implementation>org.apache.maven.archiva.web.action.admin.repositories.RepositoryContentStatisticsDAOStub</implementation>
+    </component>        
+  </components>
+</plexus>