]> source.dussan.org Git - archiva.git/commitdiff
add a method to retrieve all groupIds available in indexs
authorOlivier Lamy <olamy@apache.org>
Tue, 11 Oct 2011 11:45:22 +0000 (11:45 +0000)
committerOlivier Lamy <olamy@apache.org>
Tue, 11 Oct 2011 11:45:22 +0000 (11:45 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1181728 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NexusRepositorySearch.java
archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/RepositorySearch.java
archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/NexusRepositorySearchTest.java

index a44c09989a2d0ea08db8fbd29bd6edc828df0539..4b5ad3b369ae84ab8400b17034036f29257b55ac 100644 (file)
@@ -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<String> previousSearchTerms)
         throws RepositorySearchException
     {
-        List<String> indexingContextIds = addIndexingContexts(selectedRepos);
+        List<String> 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<String> getAllGroupIds(String principal, List<String> selectedRepos)
+        throws RepositorySearchException
+    {
+        List<IndexingContext> indexContexts = getIndexingContexts( selectedRepos );
+        if (indexContexts == null || indexContexts.isEmpty())
+        {
+            return Collections.emptyList();
+        }
+
+        try
+        {
+            Set<String> allGroupIds = new HashSet<String>(  );
+            for (IndexingContext indexingContext : indexContexts)
+            {
+                allGroupIds.addAll( indexingContext.getAllGroups() );
+            }
+            return allGroupIds;
+        } catch ( IOException e )
+        {
+            throw new RepositorySearchException( e.getMessage(), e );
+        }
+    }
 
     protected List<? extends IndexCreator> getAllIndexCreators()
     {
index b0f64c129a6650f7eba0fa684c9e4f07fdc795a1..ccfc133de60a48633cb5b7dc7c82ee66ebb16f86 100644 (file)
@@ -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<String> getAllGroupIds( String principal, List<String> selectedRepos )
+        throws RepositorySearchException;
 }
index f57200ccb3491737f96ea65c008dc1ce300f3150..02c2a8a7ab5ea7b645883bb25ff0cb3f2b750830 100644 (file)
@@ -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<String> selectedRepos = Arrays.asList( TEST_REPO_1 );
+
+        archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config , 0 , 2 );
+
+        archivaConfigControl.replay();
+
+        Collection<String> groupIds = search.getAllGroupIds( "user", selectedRepos );
+
+        archivaConfigControl.verify();
+
+        log.info( "groupIds: " + groupIds );
+    }
 }