]> source.dussan.org Git - archiva.git/commitdiff
more cleanup and fix a TODO :-)
authorOlivier Lamy <olamy@apache.org>
Tue, 20 May 2014 07:15:45 +0000 (17:15 +1000)
committerOlivier Lamy <olamy@apache.org>
Tue, 20 May 2014 07:15:45 +0000 (17:15 +1000)
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/AbstractRestService.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSearchService.java

index 3b43fbc096554b19bf4e0a21b70477698ae27db5..b366e441acabdb4771beac800fbc0767392435d6 100644 (file)
@@ -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<String> 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<String, List<ProxyConnector>> 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;
index c8c46210f136cd755b2ab775b2b908cee3fe97aa..f030a3b86ae6b5f7b4a99166b3851d4f9c213722 100644 (file)
@@ -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<String, List<ProxyConnector>> 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 )
         {