summaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-web/archiva-rest
diff options
context:
space:
mode:
authorOlivier Lamy <olamy@apache.org>2014-05-20 15:04:47 +1000
committerOlivier Lamy <olamy@apache.org>2014-05-20 15:04:47 +1000
commit85047d3bb6163b3223ec9a4b90dae2a968d6bcb6 (patch)
tree0bb1aea69b92646fda9877707da91d266be28252 /archiva-modules/archiva-web/archiva-rest
parenta78b6070bc5c8e866011b6602b196a7c17f42c7d (diff)
downloadarchiva-85047d3bb6163b3223ec9a4b90dae2a968d6bcb6.tar.gz
archiva-85047d3bb6163b3223ec9a4b90dae2a968d6bcb6.zip
[MRM-1843] provide mechanism to obtain the latest version of an artifact
start download api currently redirect
Diffstat (limited to 'archiva-modules/archiva-web/archiva-rest')
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/SearchService.java15
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/AbstractRestService.java29
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSearchService.java50
3 files changed, 84 insertions, 10 deletions
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/SearchService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/SearchService.java
index de884541c..319abdfeb 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/SearchService.java
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/SearchService.java
@@ -21,10 +21,10 @@ package org.apache.archiva.rest.api.services;
import org.apache.archiva.maven2.model.Artifact;
+import org.apache.archiva.redback.authorization.RedbackAuthorization;
import org.apache.archiva.rest.api.model.GroupIdList;
import org.apache.archiva.rest.api.model.SearchRequest;
import org.apache.archiva.rest.api.model.StringList;
-import org.apache.archiva.redback.authorization.RedbackAuthorization;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
@@ -32,6 +32,7 @@ import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
import java.util.List;
@Path( "/searchService/" )
@@ -60,8 +61,7 @@ public interface SearchService
@POST
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
@RedbackAuthorization( noPermission = true, noRestriction = true )
-
- List<Artifact> quickSearchWithRepositories( SearchRequest searchRequest )
+ List<Artifact> quickSearchWithRepositories( SearchRequest searchRequest )
throws ArchivaRestServiceException;
/**
@@ -127,4 +127,13 @@ public interface SearchService
throws ArchivaRestServiceException;
*/
+ @GET
+ @Path( "/artifact" )
+ @Produces( "text/html" )
+ @RedbackAuthorization( noPermission = true, noRestriction = true )
+ Response redirectToArtifactFile( @QueryParam( "r" ) String repositoryId, @QueryParam( "g" ) String groupId,
+ @QueryParam( "a" ) String artifactId, @QueryParam( "v" ) String version,
+ @QueryParam( "p" ) String packaging, @QueryParam( "c" ) String classifier )
+ throws ArchivaRestServiceException;
+
}
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 6fb7d0bd0..3443625e5 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
@@ -57,6 +57,7 @@ import org.springframework.context.ApplicationContext;
import javax.inject.Inject;
import javax.inject.Named;
import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import java.util.ArrayList;
@@ -87,7 +88,7 @@ public abstract class AbstractRestService
* FIXME: this could be multiple implementations and needs to be configured.
*/
@Inject
- @Named( value = "repositorySessionFactory" )
+ @Named(value = "repositorySessionFactory")
protected RepositorySessionFactory repositorySessionFactory;
@Inject
@@ -100,17 +101,20 @@ public abstract class AbstractRestService
protected RepositoryContentFactory repositoryContentFactory;
@Inject
- @Named( value = "archivaTaskScheduler#repository" )
+ @Named(value = "archivaTaskScheduler#repository")
protected DefaultRepositoryArchivaTaskScheduler repositoryTaskScheduler;
@Inject
- @Named( value = "userConfiguration#default" )
+ @Named(value = "userConfiguration#default")
protected UserConfiguration config;
@Context
protected HttpServletRequest httpServletRequest;
+ @Context
+ protected HttpServletResponse httpServletResponse;
+
protected AuditInformation getAuditInformation()
{
RedbackRequestInformation redbackRequestInformation = RedbackAuthenticationThreadLocal.get();
@@ -213,6 +217,13 @@ public abstract class AbstractRestService
protected String getArtifactUrl( Artifact artifact )
throws ArchivaRestServiceException
{
+ return getArtifactUrl( artifact, null );
+ }
+
+
+ protected String getArtifactUrl( Artifact artifact, String repositoryId )
+ throws ArchivaRestServiceException
+ {
try
{
@@ -225,10 +236,16 @@ public abstract class AbstractRestService
sb.append( "/repository" );
- // FIXME when artifact come from a remote repository when have here the remote repo id
+ // when artifact come from a remote repository when have here the remote repo id
// we must replace it with a valid managed one available for the user.
-
- sb.append( '/' ).append( artifact.getContext() );
+ if ( StringUtils.isEmpty( repositoryId ) )
+ {
+ sb.append( '/' ).append( artifact.getContext() );
+ }
+ else
+ {
+ sb.append( '/' ).append( repositoryId );
+ }
sb.append( '/' ).append( StringUtils.replaceChars( artifact.getGroupId(), '.', '/' ) );
sb.append( '/' ).append( artifact.getArtifactId() );
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 d944893aa..9dae9491d 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
@@ -37,14 +37,17 @@ import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import javax.inject.Inject;
+import javax.ws.rs.core.Response;
+import java.net.URI;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.List;
/**
* @author Olivier Lamy
*/
-@Service( "searchService#rest" )
+@Service("searchService#rest")
public class DefaultSearchService
extends AbstractRestService
implements SearchService
@@ -205,6 +208,51 @@ public class DefaultSearchService
return new StringList( getObservableRepos() );
}
+ @Override
+ public Response redirectToArtifactFile( String repositoryId, String groupId, String artifactId, String version,
+ String packaging, String classifier )
+ throws ArchivaRestServiceException
+ {
+ try
+ {
+
+ SearchFields searchField = new SearchFields();
+ searchField.setGroupId( groupId );
+ searchField.setArtifactId( artifactId );
+ searchField.setPackaging( StringUtils.isBlank( packaging ) ? "jar" : packaging );
+ searchField.setVersion( version );
+ searchField.setClassifier( classifier );
+ searchField.setRepositories( Arrays.asList( repositoryId ) );
+ searchField.setExactSearch( true );
+ SearchResults searchResults = repositorySearch.search( getPrincipal(), searchField, null );
+ List<Artifact> artifacts = getArtifacts( searchResults );
+
+ // TODO improve that with querying lucene with null value for classifier
+ // so simple loop and retain only artifact with null classifier
+ if ( classifier == null )
+ {
+ List<Artifact> filteredArtifacts = new ArrayList<>( artifacts.size() );
+ for ( Artifact artifact : artifacts )
+ {
+ if ( artifact.getClassifier() == null )
+ {
+ filteredArtifacts.add( artifact );
+ }
+ }
+
+ artifacts = filteredArtifacts;
+ }
+
+ String artifactUrl = getArtifactUrl( artifacts.get( 0 ), repositoryId );
+
+ return Response.temporaryRedirect( new URI( artifactUrl ) ).build();
+ }
+ catch ( Exception e )
+ {
+ throw new ArchivaRestServiceException( e.getMessage(), e );
+ }
+ }
+
//-------------------------------------
// internal
//-------------------------------------