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/archiva-web | |
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/archiva-web')
2 files changed, 31 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 { |