mirror of https://github.com/apache/archiva.git
[MRM-1283] moved browseGroup() functionality over to metadata repository
git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@884882 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c5cb5db5c8
commit
043a336aa5
|
@ -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 ) )
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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";
|
||||
|
|
Loading…
Reference in New Issue