diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java index aa5e4f7dc..8b0b11983 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java @@ -74,23 +74,7 @@ public class DefaultBrowseService public BrowseResult getRootGroups( String repositoryId ) throws ArchivaRestServiceException { - List selectedRepos = getObservableRepos(); - if ( CollectionUtils.isEmpty( selectedRepos ) ) - { - // FIXME 403 ??? - return new BrowseResult(); - } - - if ( StringUtils.isNotEmpty( repositoryId ) ) - { - // check user has karma on the repository - if ( !selectedRepos.contains( repositoryId ) ) - { - throw new ArchivaRestServiceException( "browse.root.groups.repositoy.denied", - Response.Status.FORBIDDEN.getStatusCode() ); - } - selectedRepos = Collections.singletonList( repositoryId ); - } + List selectedRepos = getSelectedRepos( repositoryId ); Set namespaces = new LinkedHashSet(); @@ -137,24 +121,7 @@ public class DefaultBrowseService public BrowseResult browseGroupId( String groupId, String repositoryId ) throws ArchivaRestServiceException { - - List selectedRepos = getObservableRepos(); - if ( CollectionUtils.isEmpty( selectedRepos ) ) - { - // FIXME 403 ??? - return new BrowseResult(); - } - - if ( StringUtils.isNotEmpty( repositoryId ) ) - { - // check user has karma on the repository - if ( !selectedRepos.contains( repositoryId ) ) - { - throw new ArchivaRestServiceException( "browse.root.groups.repositoy.denied", - Response.Status.FORBIDDEN.getStatusCode() ); - } - selectedRepos = Collections.singletonList( repositoryId ); - } + List selectedRepos = getSelectedRepos( repositoryId ); Set projects = new LinkedHashSet(); @@ -210,23 +177,7 @@ public class DefaultBrowseService public VersionsList getVersionsList( String groupId, String artifactId, String repositoryId ) throws ArchivaRestServiceException { - List selectedRepos = getObservableRepos(); - if ( CollectionUtils.isEmpty( selectedRepos ) ) - { - // FIXME 403 ??? - return new VersionsList(); - } - - if ( StringUtils.isNotEmpty( repositoryId ) ) - { - // check user has karma on the repository - if ( !selectedRepos.contains( repositoryId ) ) - { - throw new ArchivaRestServiceException( "browse.root.groups.repositoy.denied", - Response.Status.FORBIDDEN.getStatusCode() ); - } - selectedRepos = Collections.singletonList( repositoryId ); - } + List selectedRepos = getSelectedRepos( repositoryId ); try { @@ -273,24 +224,7 @@ public class DefaultBrowseService String repositoryId ) throws ArchivaRestServiceException { - List selectedRepos = getObservableRepos(); - - if ( CollectionUtils.isEmpty( selectedRepos ) ) - { - // FIXME 403 ??? - return null; - } - - if ( StringUtils.isNotEmpty( repositoryId ) ) - { - // check user has karma on the repository - if ( !selectedRepos.contains( repositoryId ) ) - { - throw new ArchivaRestServiceException( "browse.root.groups.repositoy.denied", - Response.Status.FORBIDDEN.getStatusCode() ); - } - selectedRepos = Collections.singletonList( repositoryId ); - } + List selectedRepos = getSelectedRepos( repositoryId ); RepositorySession repositorySession = null; try @@ -335,24 +269,7 @@ public class DefaultBrowseService throws ArchivaRestServiceException { - List selectedRepos = getObservableRepos(); - - if ( CollectionUtils.isEmpty( selectedRepos ) ) - { - // FIXME 403 ??? - return null; - } - - if ( StringUtils.isNotEmpty( repositoryId ) ) - { - // check user has karma on the repository - if ( !selectedRepos.contains( repositoryId ) ) - { - throw new ArchivaRestServiceException( "browse.root.groups.repositoy.denied", - Response.Status.FORBIDDEN.getStatusCode() ); - } - selectedRepos = Collections.singletonList( repositoryId ); - } + List selectedRepos = getSelectedRepos( repositoryId ); RepositorySession repositorySession = null; try @@ -480,24 +397,7 @@ public class DefaultBrowseService public List getTreeEntries( String groupId, String artifactId, String version, String repositoryId ) throws ArchivaRestServiceException { - List selectedRepos = getObservableRepos(); - - if ( CollectionUtils.isEmpty( selectedRepos ) ) - { - // FIXME 403 ??? - return null; - } - - if ( StringUtils.isNotEmpty( repositoryId ) ) - { - // check user has karma on the repository - if ( !selectedRepos.contains( repositoryId ) ) - { - throw new ArchivaRestServiceException( "browse.root.groups.repositoy.denied", - Response.Status.FORBIDDEN.getStatusCode() ); - } - selectedRepos = Collections.singletonList( repositoryId ); - } + List selectedRepos = getSelectedRepos( repositoryId ); List treeEntries = new ArrayList(); TreeDependencyNodeVisitor treeDependencyNodeVisitor = new TreeDependencyNodeVisitor( treeEntries ); @@ -704,6 +604,31 @@ public class DefaultBrowseService // internals //--------------------------- + private List getSelectedRepos( String repositoryId ) + throws ArchivaRestServiceException + { + + List selectedRepos = getObservableRepos(); + + if ( CollectionUtils.isEmpty( selectedRepos ) ) + { + // FIXME 403 ??? + return null; + } + + if ( StringUtils.isNotEmpty( repositoryId ) ) + { + // check user has karma on the repository + if ( !selectedRepos.contains( repositoryId ) ) + { + throw new ArchivaRestServiceException( "browse.root.groups.repositoy.denied", + Response.Status.FORBIDDEN.getStatusCode() ); + } + selectedRepos = Collections.singletonList( repositoryId ); + } + return selectedRepos; + } + private List getSortedList( Set set ) { List list = new ArrayList( set );