diff options
author | Olivier Lamy <olamy@apache.org> | 2012-09-06 12:37:14 +0000 |
---|---|---|
committer | Olivier Lamy <olamy@apache.org> | 2012-09-06 12:37:14 +0000 |
commit | 911dd05b235fc2b684049b5ab9dac30acf52fce6 (patch) | |
tree | 780e4fbc098e310f0735c21db29fa7288798f472 /archiva-modules | |
parent | 035423d8a7d4319170e2f6696e37421093c7b1e2 (diff) | |
download | archiva-911dd05b235fc2b684049b5ab9dac30acf52fce6.tar.gz archiva-911dd05b235fc2b684049b5ab9dac30acf52fce6.zip |
add a method to remove namespace(groupId) in MetadataRepository
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1381575 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules')
4 files changed, 64 insertions, 8 deletions
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java index 4bfe578c4..7e5405f31 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java @@ -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; } diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoriesServiceTest.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoriesServiceTest.java index b784b29f4..3a7416c97 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoriesServiceTest.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/RepositoriesServiceTest.java @@ -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 { diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java index 9b3375496..0aed7f641 100644 --- a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java +++ b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java @@ -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; diff --git a/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java b/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java index 5322e2d91..6dd78efe5 100644 --- a/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java +++ b/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java @@ -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 { |