From: Olivier Lamy Date: Thu, 5 Apr 2012 13:03:26 +0000 (+0000) Subject: avoid duplicate code X-Git-Tag: archiva-1.4-M3~841 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f6ec74e8912daeedad77e92fe79dd611f7cded4d;p=archiva.git avoid duplicate code git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1309828 13f79535-47bb-0310-9956-ffa450edef68 --- 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 );