From 511858d4ab738b77aaefec9b752f513e3148c1ad Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Tue, 20 May 2014 17:15:45 +1000 Subject: [PATCH] more cleanup and fix a TODO :-) --- .../rest/services/AbstractRestService.java | 27 ++++++++++++-- .../rest/services/DefaultSearchService.java | 35 +------------------ 2 files changed, 25 insertions(+), 37 deletions(-) diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/AbstractRestService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/AbstractRestService.java index 3b43fbc09..b366e441a 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/AbstractRestService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/AbstractRestService.java @@ -22,6 +22,7 @@ package org.apache.archiva.rest.services; import org.apache.archiva.admin.model.AuditInformation; import org.apache.archiva.admin.model.RepositoryAdminException; import org.apache.archiva.admin.model.admin.ArchivaAdministration; +import org.apache.archiva.admin.model.beans.ProxyConnector; import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin; import org.apache.archiva.admin.model.proxyconnector.ProxyConnectorAdmin; import org.apache.archiva.audit.AuditEvent; @@ -244,7 +245,27 @@ public abstract class AbstractRestService // we must replace it with a valid managed one available for the user. if ( StringUtils.isEmpty( repositoryId ) ) { - sb.append( '/' ).append( artifact.getContext() ); + List userRepos = userRepositories.getObservableRepositoryIds( getPrincipal() ); + // is it a good one? if yes nothing to + // if not search the repo who is proxy for this remote + if ( !userRepos.contains( artifact.getContext() ) ) + { + for ( Map.Entry> entry : proxyConnectorAdmin.getProxyConnectorAsMap().entrySet() ) + { + for ( ProxyConnector proxyConnector : entry.getValue() ) + { + if ( StringUtils.equals( "remote-" + proxyConnector.getTargetRepoId(), + artifact.getContext() ) // + && userRepos.contains( entry.getKey() ) ) + { + sb.append( '/' ).append( entry.getKey() ); + } + } + } + + } + + } else { @@ -279,7 +300,7 @@ public abstract class AbstractRestService return sb.toString(); } - catch ( RepositoryAdminException e ) + catch ( Exception e ) { throw new ArchivaRestServiceException( e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e ); @@ -301,7 +322,7 @@ public abstract class AbstractRestService new ArtifactBuilder().forArtifactMetadata( artifact ).withManagedRepositoryContent( repositoryContentFactory.getManagedRepositoryContent( repositoryId ) ); Artifact art = builder.build(); - art.setUrl( getArtifactUrl( art ) ); + art.setUrl( getArtifactUrl( art, repositoryId ) ); artifacts.add( art ); } return artifacts; diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSearchService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSearchService.java index c8c46210f..f030a3b86 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSearchService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSearchService.java @@ -19,7 +19,6 @@ package org.apache.archiva.rest.services; * under the License. */ -import org.apache.archiva.admin.model.beans.ProxyConnector; import org.apache.archiva.indexer.search.RepositorySearch; import org.apache.archiva.indexer.search.RepositorySearchException; import org.apache.archiva.indexer.search.SearchFields; @@ -44,7 +43,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; -import java.util.Map; /** * @author Olivier Lamy @@ -369,40 +367,9 @@ public class DefaultSearchService } ).build(); } - String artifactUrl = null; - Artifact artifact = artifacts.get( 0 ); - // we need to configure correctly the repositoryId - if ( StringUtils.isEmpty( repositoryId ) ) - { - // is it a good one? if yes nothing to - // if not search the repo who is proxy for this remote - if ( !userRepos.contains( artifact.getContext() ) ) - { - for ( Map.Entry> entry : proxyConnectorAdmin.getProxyConnectorAsMap().entrySet() ) - { - for ( ProxyConnector proxyConnector : entry.getValue() ) - { - if ( StringUtils.equals( "remote-" + proxyConnector.getTargetRepoId(), - artifact.getContext() ) // - && userRepos.contains( entry.getKey() ) ) - { - return Response.temporaryRedirect( - new URI( getArtifactUrl( artifact, entry.getKey() ) ) ).build(); - } - } - } - - } - - } - else - { - artifactUrl = getArtifactUrl( artifact, repositoryId ); - } - - return Response.temporaryRedirect( new URI( artifactUrl ) ).build(); + return Response.temporaryRedirect( new URI( artifact.getUrl() ) ).build(); } catch ( Exception e ) {