You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by ol...@apache.org on 2012/06/06 01:17:24 UTC

svn commit: r1346651 - in /archiva/trunk/archiva-modules: archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/ archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/ archiva-web/archiva-...

Author: olamy
Date: Tue Jun  5 23:17:23 2012
New Revision: 1346651

URL: http://svn.apache.org/viewvc?rev=1346651&view=rev
Log:
implement service to delete groupId

Modified:
    archiva/trunk/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/ManagedRepositoryContent.java
    archiva/trunk/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/ManagedDefaultRepositoryContent.java
    archiva/trunk/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/ManagedLegacyRepositoryContent.java
    archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RepositoriesService.java
    archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java
    archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoriesServiceTest.java

Modified: archiva/trunk/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/ManagedRepositoryContent.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/ManagedRepositoryContent.java?rev=1346651&r1=1346650&r2=1346651&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/ManagedRepositoryContent.java (original)
+++ archiva/trunk/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/ManagedRepositoryContent.java Tue Jun  5 23:17:23 2012
@@ -49,6 +49,7 @@ public interface ManagedRepositoryConten
 
     /**
      * delete a specified artifact from the repository
+     *
      * @param artifactReference
      * @throws ContentNotFoundException
      */
@@ -56,6 +57,14 @@ public interface ManagedRepositoryConten
         throws ContentNotFoundException;
 
     /**
+     * @since 1.4-M3
+     * @param groupId
+     * @throws ContentNotFoundException
+     */
+    void deleteGroupId( String groupId )
+        throws ContentNotFoundException;
+
+    /**
      * <p>
      * Convenience method to get the repository id.
      * </p>

Modified: archiva/trunk/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/ManagedDefaultRepositoryContent.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/ManagedDefaultRepositoryContent.java?rev=1346651&r1=1346650&r2=1346651&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/ManagedDefaultRepositoryContent.java (original)
+++ archiva/trunk/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/ManagedDefaultRepositoryContent.java Tue Jun  5 23:17:23 2012
@@ -31,6 +31,7 @@ import org.apache.archiva.repository.Con
 import org.apache.archiva.repository.ManagedRepositoryContent;
 import org.apache.archiva.repository.layout.LayoutException;
 import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang.StringUtils;
 import org.springframework.context.annotation.Scope;
 import org.springframework.stereotype.Service;
 
@@ -102,6 +103,27 @@ public class ManagedDefaultRepositoryCon
         }
     }
 
+    public void deleteGroupId( String groupId )
+        throws ContentNotFoundException
+    {
+
+        String path = StringUtils.replaceChars( groupId, '.', '/' );
+
+        File directory = new File( getRepoRoot(), path );
+
+        if ( directory.exists() )
+        {
+            try
+            {
+                FileUtils.deleteDirectory( directory );
+            }
+            catch ( IOException e )
+            {
+                log.warn( "skip error deleting directory {}:", directory.getPath(), e );
+            }
+        }
+    }
+
     public String getId()
     {
         return repository.getId();

Modified: archiva/trunk/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/ManagedLegacyRepositoryContent.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/ManagedLegacyRepositoryContent.java?rev=1346651&r1=1346650&r2=1346651&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/ManagedLegacyRepositoryContent.java (original)
+++ archiva/trunk/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/ManagedLegacyRepositoryContent.java Tue Jun  5 23:17:23 2012
@@ -20,8 +20,6 @@ package org.apache.archiva.repository.co
  */
 
 import org.apache.archiva.admin.model.beans.ManagedRepository;
-import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.lang.StringUtils;
 import org.apache.archiva.common.utils.PathUtil;
 import org.apache.archiva.configuration.FileTypes;
 import org.apache.archiva.model.ArchivaArtifact;
@@ -31,6 +29,8 @@ import org.apache.archiva.model.Versione
 import org.apache.archiva.repository.ContentNotFoundException;
 import org.apache.archiva.repository.ManagedRepositoryContent;
 import org.apache.archiva.repository.layout.LayoutException;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang.StringUtils;
 import org.springframework.context.annotation.Scope;
 import org.springframework.stereotype.Service;
 
@@ -40,14 +40,13 @@ import java.util.HashSet;
 import java.util.Set;
 
 /**
- * ManagedLegacyRepositoryContent 
+ * ManagedLegacyRepositoryContent
  *
  * @version $Id$
- * 
  * @todo no need to be a component when filetypes, legacy path parser is not
  */
-@Service("managedRepositoryContent#legacy")
-@Scope("prototype")
+@Service( "managedRepositoryContent#legacy" )
+@Scope( "prototype" )
 public class ManagedLegacyRepositoryContent
     extends AbstractLegacyRepositoryContent
     implements ManagedRepositoryContent
@@ -67,14 +66,14 @@ public class ManagedLegacyRepositoryCont
 
         if ( !groupDir.exists() )
         {
-            throw new ContentNotFoundException( "Unable to get versions using a non-existant groupId directory: "
-                + groupDir.getAbsolutePath() );
+            throw new ContentNotFoundException(
+                "Unable to get versions using a non-existant groupId directory: " + groupDir.getAbsolutePath() );
         }
 
         if ( !groupDir.isDirectory() )
         {
-            throw new ContentNotFoundException( "Unable to get versions using a non-directory: "
-                + groupDir.getAbsolutePath() );
+            throw new ContentNotFoundException(
+                "Unable to get versions using a non-directory: " + groupDir.getAbsolutePath() );
         }
 
         // First gather up the versions found as artifacts in the managed repository.
@@ -159,14 +158,14 @@ public class ManagedLegacyRepositoryCont
 
         if ( !repoDir.exists() )
         {
-            throw new ContentNotFoundException( "Unable to get related artifacts using a non-existant directory: "
-                + repoDir.getAbsolutePath() );
+            throw new ContentNotFoundException(
+                "Unable to get related artifacts using a non-existant directory: " + repoDir.getAbsolutePath() );
         }
 
         if ( !repoDir.isDirectory() )
         {
-            throw new ContentNotFoundException( "Unable to get related artifacts using a non-directory: "
-                + repoDir.getAbsolutePath() );
+            throw new ContentNotFoundException(
+                "Unable to get related artifacts using a non-directory: " + repoDir.getAbsolutePath() );
         }
 
         Set<ArtifactReference> foundArtifacts = new HashSet<ArtifactReference>();
@@ -210,14 +209,14 @@ public class ManagedLegacyRepositoryCont
 
         if ( !groupDir.exists() )
         {
-            throw new ContentNotFoundException( "Unable to get versions using a non-existant groupId directory: "
-                + groupDir.getAbsolutePath() );
+            throw new ContentNotFoundException(
+                "Unable to get versions using a non-existant groupId directory: " + groupDir.getAbsolutePath() );
         }
 
         if ( !groupDir.isDirectory() )
         {
-            throw new ContentNotFoundException( "Unable to get versions using a non-directory: "
-                + groupDir.getAbsolutePath() );
+            throw new ContentNotFoundException(
+                "Unable to get versions using a non-directory: " + groupDir.getAbsolutePath() );
         }
 
         Set<String> foundVersions = new HashSet<String>();
@@ -250,14 +249,14 @@ public class ManagedLegacyRepositoryCont
 
         if ( !groupDir.exists() )
         {
-            throw new ContentNotFoundException( "Unable to get versions using a non-existant groupId directory: "
-                + groupDir.getAbsolutePath() );
+            throw new ContentNotFoundException(
+                "Unable to get versions using a non-existant groupId directory: " + groupDir.getAbsolutePath() );
         }
 
         if ( !groupDir.isDirectory() )
         {
-            throw new ContentNotFoundException( "Unable to get versions using a non-directory: "
-                + groupDir.getAbsolutePath() );
+            throw new ContentNotFoundException(
+                "Unable to get versions using a non-directory: " + groupDir.getAbsolutePath() );
         }
 
         Set<String> foundVersions = new HashSet<String>();
@@ -322,7 +321,7 @@ public class ManagedLegacyRepositoryCont
 
     /**
      * Convert a path to an artifact reference.
-     * 
+     *
      * @param path the path to convert. (relative or full location path)
      * @throws LayoutException if the path cannot be converted to an artifact reference.
      */
@@ -337,7 +336,7 @@ public class ManagedLegacyRepositoryCont
 
         return super.toArtifactReference( path );
     }
-    
+
     public File toFile( ArchivaArtifact reference )
     {
         return new File( repository.getLocation(), toPath( reference ) );
@@ -454,7 +453,7 @@ public class ManagedLegacyRepositoryCont
             }
         }
     }
-    
+
     public void setFileTypes( FileTypes fileTypes )
     {
         this.filetypes = fileTypes;
@@ -465,4 +464,10 @@ public class ManagedLegacyRepositoryCont
     {
         // TODO implements for legacy ??
     }
+
+    public void deleteGroupId( String groupId )
+        throws ContentNotFoundException
+    {
+        // TODO implements for legacy ??
+    }
 }

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RepositoriesService.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RepositoriesService.java?rev=1346651&r1=1346650&r2=1346651&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RepositoriesService.java (original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RepositoriesService.java Tue Jun  5 23:17:23 2012
@@ -137,7 +137,7 @@ public interface RepositoriesService
      * <b>permissions are checked in impl</b>
      * @since 1.4-M3
      */
-    Boolean deleteGroupId( @QueryParam( "groupId" ) String groupId )
+    Boolean deleteGroupId( @QueryParam( "groupId" ) String groupId, @QueryParam( "repositoryId" ) String repositoryId )
         throws ArchivaRestServiceException;
 
 }

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java?rev=1346651&r1=1346650&r2=1346651&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java (original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java Tue Jun  5 23:17:23 2012
@@ -804,9 +804,36 @@ public class DefaultRepositoriesService
         return Boolean.TRUE;
     }
 
-    public Boolean deleteGroupId( String groupId )
+    public Boolean deleteGroupId( String groupId, String repositoryId )
         throws ArchivaRestServiceException
     {
+        if ( StringUtils.isEmpty( repositoryId ) )
+        {
+            throw new ArchivaRestServiceException( "repositoryId cannot be null", 400, null );
+        }
+
+        if ( !isAuthorizedToDeleteArtifacts( repositoryId ) )
+        {
+            throw new ArchivaRestServiceException( "not authorized to delete artifacts", 403, null );
+        }
+
+        if ( StringUtils.isEmpty( groupId ) )
+        {
+            throw new ArchivaRestServiceException( "artifact.groupId cannot be null", 400, null );
+        }
+
+        try
+        {
+            ManagedRepositoryContent repository = repositoryFactory.getManagedRepositoryContent( repositoryId );
+
+            repository.deleteGroupId( groupId );
+
+        }
+        catch ( RepositoryException e )
+        {
+            log.error( e.getMessage(), e );
+            throw new ArchivaRestServiceException( "Repository exception: " + e.getMessage(), 500, e );
+        }
         return true;
     }
 

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoriesServiceTest.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoriesServiceTest.java?rev=1346651&r1=1346650&r2=1346651&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoriesServiceTest.java (original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoriesServiceTest.java Tue Jun  5 23:17:23 2012
@@ -274,10 +274,28 @@ public class RepositoriesServiceTest
 
             assertNotNull( browseResult );
 
+            log.info( "browseResult: {}", browseResult );
+
             Assertions.assertThat( browseResult.getBrowseResultEntries() ).isNotNull().isNotEmpty().contains(
                 new BrowseResultEntry( "org.apache.karaf.features.org.apache.karaf.features.command", true ),
                 new BrowseResultEntry( "org.apache.karaf.features.org.apache.karaf.features.core", true ) );
 
+            File directory =
+                new File( "target/test-origin-repo/org/apache/karaf/features/org.apache.karaf.features.command" );
+
+            assertTrue( "directory not exists", directory.exists() );
+
+            RepositoriesService repositoriesService = getRepositoriesService( authorizationHeader );
+            repositoriesService.deleteGroupId( "org.apache.karaf.features", SOURCE_REPO_ID );
+
+            assertFalse( "directory not exists", directory.exists() );
+
+            browseResult = browseService.browseGroupId( "org.apache.karaf.features", SOURCE_REPO_ID );
+
+            assertNotNull( browseResult );
+
+            Assertions.assertThat( browseResult.getBrowseResultEntries() ).isNotNull().isEmpty();
+
             log.info( "browseResult: {}", browseResult );
         }
         finally