From 202a699884cfc462739af0ae733191f3d4cff30d Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Tue, 28 Feb 2012 00:03:04 +0000 Subject: [PATCH] add rest method to search with query on a set of repositories git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1294404 13f79535-47bb-0310-9956-ffa450edef68 --- .../archiva/rest/api/model/SearchRequest.java | 20 ++++++++++++- .../rest/api/services/SearchService.java | 26 +++++++++++++---- .../rest/services/DefaultSearchService.java | 28 +++++++++++++++++++ 3 files changed, 67 insertions(+), 7 deletions(-) diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/SearchRequest.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/SearchRequest.java index 93744e05d..6d82b5b44 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/SearchRequest.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/SearchRequest.java @@ -25,6 +25,13 @@ import java.util.List; @XmlRootElement( name = "searchRequest" ) public class SearchRequest { + + /** + * @since 1.4-M3 + * to be able to search with a query on selected repositories + */ + private String queryTerms; + /** * groupId */ @@ -229,12 +236,23 @@ public class SearchRequest this.includePomArtifacts = includePomArtifacts; } + public String getQueryTerms() + { + return queryTerms; + } + + public void setQueryTerms( String queryTerms ) + { + this.queryTerms = queryTerms; + } + @Override public String toString() { final StringBuilder sb = new StringBuilder(); sb.append( "SearchRequest" ); - sb.append( "{groupId='" ).append( groupId ).append( '\'' ); + sb.append( "{queryTerms='" ).append( queryTerms ).append( '\'' ); + sb.append( ", groupId='" ).append( groupId ).append( '\'' ); sb.append( ", artifactId='" ).append( artifactId ).append( '\'' ); sb.append( ", version='" ).append( version ).append( '\'' ); sb.append( ", packaging='" ).append( packaging ).append( '\'' ); 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 f55a223ac..bc71f2495 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 @@ -56,16 +56,14 @@ public interface SearchService List quickSearch( @QueryParam( "queryString" ) String queryString ) throws ArchivaRestServiceException; - @Path( "getArtifactVersions" ) - @GET + @Path( "quickSearch" ) + @POST @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } ) @RedbackAuthorization( noPermission = true, noRestriction = true ) /** - * search will be apply on all repositories the current user has karma + * if not repositories in SearchRequest: search will be apply on all repositories the current user has karma */ - List getArtifactVersions( @QueryParam( "groupId" ) String groupId, - @QueryParam( "artifactId" ) String artifactId, - @QueryParam( "packaging" ) String packaging ) + List quickSearchWithRepositories( SearchRequest searchRequest ) throws ArchivaRestServiceException; @Path( "searchArtifacts" ) @@ -79,6 +77,19 @@ public interface SearchService List searchArtifacts( SearchRequest searchRequest ) throws ArchivaRestServiceException; + @Path( "getArtifactVersions" ) + @GET + @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } ) + @RedbackAuthorization( noPermission = true, noRestriction = true ) + /** + * search will be apply on all repositories the current user has karma + */ + List getArtifactVersions( @QueryParam( "groupId" ) String groupId, + @QueryParam( "artifactId" ) String artifactId, + @QueryParam( "packaging" ) String packaging ) + throws ArchivaRestServiceException; + + @Path( "getAllGroupIds" ) @GET @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } ) @@ -93,6 +104,9 @@ public interface SearchService @GET @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } ) @RedbackAuthorization( noPermission = true, noRestriction = true ) + /** + * @since 1.4-M3 + */ StringList getObservablesRepoIds() throws ArchivaRestServiceException; 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 41d5d2181..6cfb749e7 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 @@ -78,6 +78,34 @@ public class DefaultSearchService } } + public List quickSearchWithRepositories( SearchRequest searchRequest ) + throws ArchivaRestServiceException + { + String queryString = searchRequest.getQueryTerms(); + if ( StringUtils.isBlank( queryString ) ) + { + return Collections.emptyList(); + } + List repositories = searchRequest.getRepositories(); + if ( repositories == null || repositories.isEmpty() ) + { + repositories = getObservableRepos(); + } + SearchResultLimits limits = new SearchResultLimits( 0 ); + try + { + SearchResults searchResults = repositorySearch.search( getPrincipal(), repositories, queryString, limits, + Collections.emptyList() ); + return getArtifacts( searchResults ); + + } + catch ( RepositorySearchException e ) + { + log.error( e.getMessage(), e ); + throw new ArchivaRestServiceException( e.getMessage() ); + } + } + public List getArtifactVersions( String groupId, String artifactId, String packaging ) throws ArchivaRestServiceException {