]> source.dussan.org Git - archiva.git/commitdiff
add a method to remove namespace(groupId) in MetadataRepository
authorOlivier Lamy <olamy@apache.org>
Thu, 6 Sep 2012 12:37:14 +0000 (12:37 +0000)
committerOlivier Lamy <olamy@apache.org>
Thu, 6 Sep 2012 12:37:14 +0000 (12:37 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1381575 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoriesServiceTest.java
archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java
archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java

index 4bfe578c42a9c3c025ce8dffbefc3a5a49ba4358..7e5405f31a011298e61ed65faab044f5b9b42048 100644 (file)
@@ -31,6 +31,7 @@ import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
 import org.apache.archiva.common.utils.VersionComparator;
 import org.apache.archiva.common.utils.VersionUtil;
 import org.apache.archiva.maven2.metadata.MavenMetadataReader;
+import org.apache.archiva.maven2.model.Artifact;
 import org.apache.archiva.metadata.model.ArtifactMetadata;
 import org.apache.archiva.metadata.repository.MetadataRepository;
 import org.apache.archiva.metadata.repository.MetadataRepositoryException;
@@ -61,7 +62,6 @@ import org.apache.archiva.repository.metadata.RepositoryMetadataWriter;
 import org.apache.archiva.repository.scanner.RepositoryScanStatistics;
 import org.apache.archiva.repository.scanner.RepositoryScanner;
 import org.apache.archiva.repository.scanner.RepositoryScannerException;
-import org.apache.archiva.maven2.model.Artifact;
 import org.apache.archiva.rest.api.model.ArtifactTransferRequest;
 import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
 import org.apache.archiva.rest.api.services.RepositoriesService;
@@ -105,7 +105,7 @@ import java.util.TimeZone;
  * @author Olivier Lamy
  * @since 1.4-M1
  */
-@Service( "repositoriesService#rest" )
+@Service ( "repositoriesService#rest" )
 public class DefaultRepositoriesService
     extends AbstractRestService
     implements RepositoriesService
@@ -113,11 +113,11 @@ public class DefaultRepositoriesService
     private Logger log = LoggerFactory.getLogger( getClass() );
 
     @Inject
-    @Named( value = "archivaTaskScheduler#repository" )
+    @Named ( value = "archivaTaskScheduler#repository" )
     private RepositoryArchivaTaskScheduler repositoryTaskScheduler;
 
     @Inject
-    @Named( value = "taskExecutor#indexing" )
+    @Named ( value = "taskExecutor#indexing" )
     private ArchivaIndexingTaskExecutor archivaIndexingTaskExecutor;
 
     @Inject
@@ -136,14 +136,14 @@ public class DefaultRepositoriesService
     private RepositoryContentFactory repositoryFactory;
 
     @Inject
-    @Named( value = "archivaTaskScheduler#repository" )
+    @Named ( value = "archivaTaskScheduler#repository" )
     private ArchivaTaskScheduler scheduler;
 
     @Inject
     private DownloadRemoteIndexScheduler downloadRemoteIndexScheduler;
 
     @Inject
-    @Named( value = "repositorySessionFactory" )
+    @Named ( value = "repositorySessionFactory" )
     protected RepositorySessionFactory repositorySessionFactory;
 
     @Inject
@@ -861,18 +861,35 @@ public class DefaultRepositoriesService
             throw new ArchivaRestServiceException( "artifact.groupId cannot be null", 400, null );
         }
 
+        RepositorySession repositorySession = repositorySessionFactory.createSession();
+
         try
         {
             ManagedRepositoryContent repository = repositoryFactory.getManagedRepositoryContent( repositoryId );
 
             repository.deleteGroupId( groupId );
 
+            MetadataRepository metadataRepository = repositorySession.getRepository();
+
+            metadataRepository.removeNamespace( repositoryId, groupId );
+
+            metadataRepository.save();
+        }
+        catch ( MetadataRepositoryException e )
+        {
+            log.error( e.getMessage(), e );
+            throw new ArchivaRestServiceException( "Repository exception: " + e.getMessage(), 500, e );
         }
         catch ( RepositoryException e )
         {
             log.error( e.getMessage(), e );
             throw new ArchivaRestServiceException( "Repository exception: " + e.getMessage(), 500, e );
         }
+        finally
+        {
+
+            repositorySession.close();
+        }
         return true;
     }
 
index b784b29f4c52968cb7226c5bbb99f782a6511ad9..3a7416c97d05884f1e1bac863f47ab695ad8fc2c 100644 (file)
@@ -287,7 +287,7 @@ public class RepositoriesServiceTest
             assertTrue( "directory not exists", directory.exists() );
 
             RepositoriesService repositoriesService = getRepositoriesService( authorizationHeader );
-            repositoriesService.deleteGroupId( "org.apache.karaf.features", SOURCE_REPO_ID );
+            repositoriesService.deleteGroupId( "org.apache.karaf", SOURCE_REPO_ID );
 
             assertFalse( "directory not exists", directory.exists() );
 
@@ -297,7 +297,13 @@ public class RepositoriesServiceTest
 
             Assertions.assertThat( browseResult.getBrowseResultEntries() ).isNotNull().isEmpty();
 
-            log.info( "browseResult: {}", browseResult );
+            browseResult = browseService.browseGroupId( "org.apache.karaf", SOURCE_REPO_ID );
+
+            assertNotNull( browseResult );
+
+            Assertions.assertThat( browseResult.getBrowseResultEntries() ).isNotNull().isEmpty();
+
+            log.info( "browseResult empty: {}", browseResult );
         }
         finally
         {
index 9b33754962a4e4ad10ea94bded10583036e18939..0aed7f6413141c29d48f8a46d51e03a301787790 100644 (file)
@@ -81,6 +81,7 @@ public interface MetadataRepository
 
     /**
      * used for deleting timestamped version of SNAPSHOT artifacts
+     *
      * @param artifactMetadata the artifactMetadata with the timestamped version (2.0-20120618.214135-2)
      * @param baseVersion      the base version of the snapshot (2.0-SNAPSHOT)
      * @throws MetadataRepositoryException
@@ -110,6 +111,16 @@ public interface MetadataRepository
     void removeRepository( String repositoryId )
         throws MetadataRepositoryException;
 
+    /**
+     *
+     * @param repositoryId
+     * @param project
+     * @since 1.4-M3
+     * @throws MetadataRepositoryException
+     */
+    void removeNamespace( String repositoryId, String project )
+        throws MetadataRepositoryException;
+
     List<ArtifactMetadata> getArtifacts( String repositoryId )
         throws MetadataRepositoryException;
 
index 5322e2d918295351036c5b9b8fc79bc527c4a148..6dd78efe50c6ef8eb0dd53cecdf671ac50b29771 100644 (file)
@@ -476,6 +476,28 @@ public class JcrMetadataRepository
         }
     }
 
+    public void removeNamespace( String repositoryId, String projectId )
+        throws MetadataRepositoryException
+    {
+        try
+        {
+            Node root = getJcrSession().getRootNode();
+            String path = getNamespacePath( repositoryId, projectId );
+            if ( root.hasNode( path ) )
+            {
+                Node node = root.getNode( path );
+                if ( node.isNodeType( NAMESPACE_NODE_TYPE ) )
+                {
+                    node.remove();
+                }
+            }
+        }
+        catch ( RepositoryException e )
+        {
+            throw new MetadataRepositoryException( e.getMessage(), e );
+        }
+    }
+
     public void removeMetadataFacets( String repositoryId, String facetId )
         throws MetadataRepositoryException
     {