aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-web
diff options
context:
space:
mode:
authorOlivier Lamy <olamy@apache.org>2012-05-29 16:34:39 +0000
committerOlivier Lamy <olamy@apache.org>2012-05-29 16:34:39 +0000
commit62895209c396727a0d291a246883ec6b09b74949 (patch)
tree171c056ca1317823b0b3bb32266dd93dd817e458 /archiva-modules/archiva-web
parent5cdaedb142bff355002d7442ef5bf6866819172d (diff)
downloadarchiva-62895209c396727a0d291a246883ec6b09b74949.tar.gz
archiva-62895209c396727a0d291a246883ec6b09b74949.zip
return url for ArtifactDownloadInfos service
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1343827 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/archiva-web')
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/AbstractRestService.java54
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java5
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSearchService.java52
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/utils/ArtifactDownloadInfoBuilder.java2
4 files changed, 59 insertions, 54 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 3726b6af5..41f394403 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
@@ -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 );
+ }
+ }
}
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 290a9292a..611f25466 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
@@ -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 );
}
}
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 47f4e8c97..b9b1d810d 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
@@ -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 );
- }
- }
}
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/utils/ArtifactDownloadInfoBuilder.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/utils/ArtifactDownloadInfoBuilder.java
index 5c550b6d9..2dd413f44 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/utils/ArtifactDownloadInfoBuilder.java
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/utils/ArtifactDownloadInfoBuilder.java
@@ -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;