From: Olivier Lamy Date: Tue, 11 Oct 2011 11:45:22 +0000 (+0000) Subject: add a method to retrieve all groupIds available in indexs X-Git-Tag: archiva-1.4-M1~43 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3d268094df1e8046bf46ab08e11b0ba5940a8e4a;p=archiva.git add a method to retrieve all groupIds available in indexs git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1181728 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NexusRepositorySearch.java b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NexusRepositorySearch.java index a44c09989..4b5ad3b36 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NexusRepositorySearch.java +++ b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NexusRepositorySearch.java @@ -49,6 +49,7 @@ import javax.inject.Inject; import java.io.File; import java.io.IOException; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.List; @@ -95,7 +96,7 @@ public class NexusRepositorySearch List previousSearchTerms) throws RepositorySearchException { - List indexingContextIds = addIndexingContexts(selectedRepos); + List indexingContextIds = addIndexingContexts( selectedRepos ); // since upgrade to nexus 2.0.0, query has changed from g:[QUERIED TERM]* to g:*[QUERIED TERM]* // resulting to more wildcard searches so we need to increase max clause count @@ -399,6 +400,28 @@ public class NexusRepositorySearch return ids; } + public Collection getAllGroupIds(String principal, List selectedRepos) + throws RepositorySearchException + { + List indexContexts = getIndexingContexts( selectedRepos ); + if (indexContexts == null || indexContexts.isEmpty()) + { + return Collections.emptyList(); + } + + try + { + Set allGroupIds = new HashSet( ); + for (IndexingContext indexingContext : indexContexts) + { + allGroupIds.addAll( indexingContext.getAllGroups() ); + } + return allGroupIds; + } catch ( IOException e ) + { + throw new RepositorySearchException( e.getMessage(), e ); + } + } protected List getAllIndexCreators() { diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/RepositorySearch.java b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/RepositorySearch.java index b0f64c129..ccfc133de 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/RepositorySearch.java +++ b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/RepositorySearch.java @@ -19,6 +19,7 @@ package org.apache.archiva.indexer.search; * under the License. */ +import java.util.Collection; import java.util.List; @@ -48,4 +49,7 @@ public interface RepositorySearch */ SearchResults search( String principal, SearchFields searchFields, SearchResultLimits limits ) throws RepositorySearchException; + + Collection getAllGroupIds( String principal, List selectedRepos ) + throws RepositorySearchException; } diff --git a/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/NexusRepositorySearchTest.java b/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/NexusRepositorySearchTest.java index f57200ccb..02c2a8a7a 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/NexusRepositorySearchTest.java +++ b/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/NexusRepositorySearchTest.java @@ -29,6 +29,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.io.File; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.List; @@ -803,4 +804,22 @@ public class NexusRepositorySearchTest assertEquals( 1, results.getHits().size() ); assertEquals( "test-webapp", results.getHits().get( 0 ).getArtifactId() ); } + + @Test + public void getAllGroupIds() throws Exception + { + createIndexContainingMoreArtifacts( true ); + + List selectedRepos = Arrays.asList( TEST_REPO_1 ); + + archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 0 , 2 ); + + archivaConfigControl.replay(); + + Collection groupIds = search.getAllGroupIds( "user", selectedRepos ); + + archivaConfigControl.verify(); + + log.info( "groupIds: " + groupIds ); + } }