]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1283] moved browseGroup() functionality over to metadata repository
authorBrett Porter <brett@apache.org>
Fri, 27 Nov 2009 14:12:01 +0000 (14:12 +0000)
committerBrett Porter <brett@apache.org>
Fri, 27 Nov 2009 14:12:01 +0000 (14:12 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@884882 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/BrowseAction.java
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/metadata/repository/memory/TestMetadataResolver.java
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/BrowseActionTest.java

index 3630a75bb2061e2ad6b970dfb20773d3a37b71c0..0b32610bbd083ac2c5614bc1617c81db7fc26c4f 100644 (file)
@@ -97,11 +97,9 @@ public class BrowseAction
                 namespaces.add( collapseNamespaces( repoId, n ) );
             }
         }
-        ArrayList<String> list = new ArrayList<String>( namespaces );
-        Collections.sort( list );
 
         this.results = new BrowsingResults();
-        results.setGroupIds( list );
+        results.setGroupIds( getSortedList( namespaces ) );
         results.setSelectedRepositoryIds( selectedRepos );
         return SUCCESS;
     }
@@ -142,10 +140,37 @@ public class BrowseAction
             return GlobalResults.ACCESS_TO_NO_REPOS;
         }
 
-        this.results = repoBrowsing.selectGroupId( getPrincipal(), selectedRepos, groupId );
+        Set<String> namespaces = new LinkedHashSet<String>();
+        Set<String> projects = new LinkedHashSet<String>();
+        for ( String repoId : selectedRepos )
+        {
+            Collection<String> childNamespaces = metadataResolver.getNamespaces( repoId, groupId );
+            // TODO: this logic should be optional, particularly remembering we want to keep this code simple
+            //       it is located here to avoid the content repository implementation needing to do too much for what
+            //       is essentially presentation code
+            for ( String n : childNamespaces )
+            {
+                // TODO: check performance of this
+                namespaces.add( collapseNamespaces( repoId, groupId + "." + n ) );
+            }
+
+            projects.addAll( metadataResolver.getProjects( repoId, groupId ) );
+        }
+
+        this.results = new BrowsingResults( groupId );
+        results.setGroupIds( getSortedList( namespaces ) );
+        results.setArtifacts( getSortedList( projects ) );
+        results.setSelectedRepositoryIds( selectedRepos );
         return SUCCESS;
     }
 
+    private ArrayList<String> getSortedList( Set<String> set )
+    {
+        ArrayList<String> list = new ArrayList<String>( set );
+        Collections.sort( list );
+        return list;
+    }
+
     public String browseArtifact()
     {
         if ( StringUtils.isEmpty( groupId ) )
index b0473b20119439c6b6b96f1370309adc7b214b61..658e464578f93af365f1e0c6a95f9147404c01b8 100644 (file)
@@ -107,7 +107,8 @@ public class TestMetadataResolver
 
     public Collection<String> getProjects( String repoId, String namespace )
     {
-        return projectsInNamespace.get( namespace );
+        Collection<String> list = projectsInNamespace.get( namespace );
+        return list != null ? list : Collections.<String>emptyList();
     }
 
     public void setProjectVersion( String repoId, String namespace, String projectId,
index dd95b40ccae912cc92790ca890354ddef3e4dad8..34b4da6de58d80db92bde35645e91a0cb3849b38 100644 (file)
@@ -55,7 +55,7 @@ public class BrowseActionTest
 
     private static final List<String> GROUPS =
         Arrays.asList( "org.apache.archiva", "commons-lang", "org.apache.maven", "com.sun", "com.oracle",
-                       "repeat.repeat", "org.apache", "single.group" );
+                       "repeat.repeat" );
 
     public void testInstantiation()
     {
@@ -65,8 +65,6 @@ public class BrowseActionTest
     public void testBrowse()
     {
         metadataResolver.setNamespaces( GROUPS );
-        // add an artifact in the tree to make sure "single" is not collapsed
-        metadataResolver.setProjectVersion( TEST_REPO, "single", "single", new ProjectVersionMetadata() );
 
         String result = action.browse();
         assertSuccessResult( result );
@@ -74,8 +72,7 @@ public class BrowseActionTest
         BrowsingResults results = action.getResults();
         assertNotNull( results );
         assertEquals( Arrays.asList( TEST_REPO ), results.getSelectedRepositoryIds() );
-        assertEquals( Arrays.asList( "com", "commons-lang", "org.apache", "repeat.repeat", "single" ),
-                      results.getGroupIds() );
+        assertEquals( Arrays.asList( "com", "commons-lang", "org.apache", "repeat.repeat" ), results.getGroupIds() );
         assertNull( results.getArtifacts() );
         assertNull( results.getSelectedArtifactId() );
         assertNull( results.getSelectedGroupId() );
@@ -141,10 +138,9 @@ public class BrowseActionTest
     public void testBrowseGroupNoArtifacts()
     {
         String selectedGroupId = "org";
-        List<String> groups = Arrays.asList( "apache.archiva", "apache.maven" );
+        List<String> groups = Arrays.asList( "org.apache.archiva", "org.apache.maven" );
 
-        archivaDao.setGroups( groups );
-        archivaDao.setArtifacts( Collections.<String>emptyList() );
+        metadataResolver.setNamespaces( groups );
         action.setGroupId( selectedGroupId );
         String result = action.browseGroup();
         assertSuccessResult( result );
@@ -152,7 +148,7 @@ public class BrowseActionTest
         BrowsingResults results = action.getResults();
         assertNotNull( results );
         assertEquals( Arrays.asList( TEST_REPO ), results.getSelectedRepositoryIds() );
-        assertEquals( groups, results.getGroupIds() );
+        assertEquals( Collections.singletonList( "org.apache" ), results.getGroupIds() );
         assertEquals( Collections.<String>emptyList(), results.getArtifacts() );
         assertNull( results.getSelectedArtifactId() );
         assertEquals( selectedGroupId, results.getSelectedGroupId() );
@@ -168,10 +164,10 @@ public class BrowseActionTest
     {
         String artifacts = "apache";
         String selectedGroupId = "org.apache";
-        List<String> groups = Arrays.asList( "archiva", "maven" );
+        List<String> groups = Arrays.asList( "org.apache.archiva", "org.apache.maven" );
 
-        archivaDao.setGroups( groups );
-        archivaDao.setArtifacts( Collections.singletonList( artifacts ) );
+        metadataResolver.setNamespaces( groups );
+        metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, artifacts, new ProjectVersionMetadata() );
         action.setGroupId( selectedGroupId );
         String result = action.browseGroup();
         assertSuccessResult( result );
@@ -191,6 +187,61 @@ public class BrowseActionTest
         assertNull( action.getSharedModel() );
     }
 
+    public void testBrowseWithCollapsedGroupsAndArtifacts()
+    {
+        List<String> groups = Arrays.asList( "org.apache.archiva", "org.apache" );
+
+        metadataResolver.setNamespaces( groups );
+        // add an artifact in the tree to make sure "single" is not collapsed
+        metadataResolver.setProjectVersion( TEST_REPO, "org.apache", "apache", new ProjectVersionMetadata() );
+
+        String result = action.browse();
+        assertSuccessResult( result );
+
+        BrowsingResults results = action.getResults();
+        assertNotNull( results );
+        assertEquals( Arrays.asList( TEST_REPO ), results.getSelectedRepositoryIds() );
+        assertEquals( Collections.singletonList( "org.apache" ), results.getGroupIds() );
+        assertNull( results.getArtifacts() );
+        assertNull( results.getSelectedArtifactId() );
+        assertNull( results.getSelectedGroupId() );
+        assertNull( results.getVersions() );
+
+        assertNull( action.getGroupId() );
+        assertNull( action.getArtifactId() );
+        assertNull( action.getRepositoryId() );
+        assertNull( action.getSharedModel() );
+    }
+
+    public void testBrowseGroupWithCollapsedGroupsAndArtifacts()
+    {
+        String artifacts = "apache";
+        String selectedGroupId = "org.apache";
+        List<String> groups = Arrays.asList( "org.apache.archiva", "org.apache" );
+
+        metadataResolver.setNamespaces( groups );
+        // add an artifact in the tree to make sure "single" is not collapsed
+        metadataResolver.setProjectVersion( TEST_REPO, "org.apache", "apache", new ProjectVersionMetadata() );
+
+        action.setGroupId( selectedGroupId );
+        String result = action.browseGroup();
+        assertSuccessResult( result );
+
+        BrowsingResults results = action.getResults();
+        assertNotNull( results );
+        assertEquals( Arrays.asList( TEST_REPO ), results.getSelectedRepositoryIds() );
+        assertEquals( Collections.singletonList( "org.apache.archiva" ), results.getGroupIds() );
+        assertEquals( Collections.singletonList( artifacts ), results.getArtifacts() );
+        assertNull( results.getSelectedArtifactId() );
+        assertEquals( selectedGroupId, results.getSelectedGroupId() );
+        assertNull( results.getVersions() );
+
+        assertEquals( selectedGroupId, action.getGroupId() );
+        assertNull( action.getArtifactId() );
+        assertNull( action.getRepositoryId() );
+        assertNull( action.getSharedModel() );
+    }
+
     public void testBrowseArtifactNoGroupId()
     {
         String selectedArtifactId = "apache";