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;
}
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 ) )
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()
{
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 );
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() );
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 );
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() );
{
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 );
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";