]> source.dussan.org Git - archiva.git/commitdiff
return url for ArtifactDownloadInfos service
authorOlivier Lamy <olamy@apache.org>
Tue, 29 May 2012 16:34:39 +0000 (16:34 +0000)
committerOlivier Lamy <olamy@apache.org>
Tue, 29 May 2012 16:34:39 +0000 (16:34 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1343827 13f79535-47bb-0310-9956-ffa450edef68

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/DefaultBrowseService.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSearchService.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/utils/ArtifactDownloadInfoBuilder.java

index 3726b6af50af495a401166e9fd0482cde985f914..41f3944038aaf557ae83de1d62aabd33eb919839 100644 (file)
@@ -28,6 +28,8 @@ import org.apache.archiva.redback.rest.services.RedbackAuthenticationThreadLocal
 import org.apache.archiva.redback.rest.services.RedbackRequestInformation;
 import org.apache.archiva.redback.users.User;
 import org.apache.archiva.redback.users.UserManager;
+import org.apache.archiva.rest.api.model.Artifact;
+import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
 import org.apache.archiva.security.AccessDeniedException;
 import org.apache.archiva.security.ArchivaSecurityException;
 import org.apache.archiva.security.PrincipalNotFoundException;
@@ -41,6 +43,7 @@ import javax.inject.Inject;
 import javax.inject.Named;
 import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -167,4 +170,55 @@ public abstract class AbstractRestService
             auditListener.auditEvent( auditEvent );
         }
     }
+
+    /**
+     * TODO add a configuration mechanism to have configured the base archiva url
+     *
+     * @param artifact
+     * @return
+     */
+    protected String getArtifactUrl( Artifact artifact, String version )
+        throws ArchivaRestServiceException
+    {
+        try
+        {
+
+            if ( httpServletRequest == null )
+            {
+                return null;
+            }
+
+            StringBuilder sb = new StringBuilder( getBaseUrl( httpServletRequest ) );
+
+            sb.append( "/repository" );
+
+            sb.append( '/' ).append( artifact.getContext() );
+
+            sb.append( '/' ).append( StringUtils.replaceChars( artifact.getGroupId(), '.', '/' ) );
+            sb.append( '/' ).append( artifact.getArtifactId() );
+            sb.append( '/' ).append( artifact.getVersion() );
+            sb.append( '/' ).append( artifact.getArtifactId() );
+            sb.append( '-' ).append( artifact.getVersion() );
+            if ( StringUtils.isNotBlank( artifact.getClassifier() ) )
+            {
+                sb.append( '-' ).append( artifact.getClassifier() );
+            }
+            // maven-plugin packaging is a jar
+            if ( StringUtils.equals( "maven-plugin", artifact.getPackaging() ) )
+            {
+                sb.append( "jar" );
+            }
+            else
+            {
+                sb.append( '.' ).append( artifact.getPackaging() );
+            }
+
+            return sb.toString();
+        }
+        catch ( RepositoryAdminException e )
+        {
+            throw new ArchivaRestServiceException( e.getMessage(),
+                                                   Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
+        }
+    }
 }
index 290a9292a62e5a3fa51f9cfd41f3086d3f5c7b0a..611f25466529ac6175f98ccd9d2803fd91326c3a 100644 (file)
@@ -686,7 +686,10 @@ public class DefaultBrowseService
                     ArtifactDownloadInfoBuilder builder =
                         new ArtifactDownloadInfoBuilder().forArtifactMetadata( artifact ).withManagedRepositoryContent(
                             repositoryContentFactory.getManagedRepositoryContent( repoId ) );
-                    artifactDownloadInfos.add( builder.build() );
+                    Artifact art = builder.build();
+
+                    art.setUrl( getArtifactUrl( art, artifact.getVersion() ) );
+                    artifactDownloadInfos.add( art );
                 }
 
             }
index 47f4e8c979b1e34e87b8ad15946e294df03e1bb7..b9b1d810d2ef618351ca2fbe461aa6f1ef320623 100644 (file)
@@ -236,59 +236,7 @@ public class DefaultSearchService
         return artifacts;
     }
 
-    /**
-     * TODO add a configuration mechanism to have configured the base archiva url
-     *
-     * @param artifact
-     * @return
-     */
-    private String getArtifactUrl( Artifact artifact, String version )
-        throws ArchivaRestServiceException
-    {
-        try
-        {
-
-            if ( httpServletRequest == null )
-            {
-                return null;
-            }
-            if ( StringUtils.isEmpty( artifact.getUrl() ) )
-            {
-                return null;
-            }
-            StringBuilder sb = new StringBuilder( getBaseUrl( httpServletRequest ) );
-
-            sb.append( "/repository" );
-
-            sb.append( '/' ).append( artifact.getContext() );
 
-            sb.append( '/' ).append( StringUtils.replaceChars( artifact.getGroupId(), '.', '/' ) );
-            sb.append( '/' ).append( artifact.getArtifactId() );
-            sb.append( '/' ).append( artifact.getVersion() );
-            sb.append( '/' ).append( artifact.getArtifactId() );
-            sb.append( '-' ).append( artifact.getVersion() );
-            if ( StringUtils.isNotBlank( artifact.getClassifier() ) )
-            {
-                sb.append( '-' ).append( artifact.getClassifier() );
-            }
-            // maven-plugin packaging is a jar
-            if ( StringUtils.equals( "maven-plugin", artifact.getPackaging() ) )
-            {
-                sb.append( "jar" );
-            }
-            else
-            {
-                sb.append( '.' ).append( artifact.getPackaging() );
-            }
-
-            return sb.toString();
-        }
-        catch ( RepositoryAdminException e )
-        {
-            throw new ArchivaRestServiceException( e.getMessage(),
-                                                   Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
-        }
-    }
 
 
 }
index 5c550b6d954875111a8fdeffcf37468b03da19a3..2dd413f44faccf9d059ea036861f85928c01c6fa 100644 (file)
@@ -98,7 +98,7 @@ public class ArtifactDownloadInfoBuilder
                 }
             }
         }
-
+        artifactDownloadInfo.setContext( managedRepositoryContent.getId() );
         DecimalFormat df = new DecimalFormat( "#,###.##", new DecimalFormatSymbols( Locale.US ) );
         artifactDownloadInfo.setSize( df.format( s ) + " " + symbol );
         return artifactDownloadInfo;