diff options
author | Olivier Lamy <olamy@apache.org> | 2012-02-28 00:03:04 +0000 |
---|---|---|
committer | Olivier Lamy <olamy@apache.org> | 2012-02-28 00:03:04 +0000 |
commit | 202a699884cfc462739af0ae733191f3d4cff30d (patch) | |
tree | 0326aa91240ffd5b6fe6f0f3e2df7833c3aa8ff3 /archiva-modules/archiva-web | |
parent | 11b145105365f54557b61d613c73efea0df6f40e (diff) | |
download | archiva-202a699884cfc462739af0ae733191f3d4cff30d.tar.gz archiva-202a699884cfc462739af0ae733191f3d4cff30d.zip |
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
Diffstat (limited to 'archiva-modules/archiva-web')
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<Artifact> 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 ) /** - * <b>search will be apply on all repositories the current user has karma</b> + * <b>if not repositories in SearchRequest: search will be apply on all repositories the current user has karma</b> */ - List<Artifact> getArtifactVersions( @QueryParam( "groupId" ) String groupId, - @QueryParam( "artifactId" ) String artifactId, - @QueryParam( "packaging" ) String packaging ) + List<Artifact> quickSearchWithRepositories( SearchRequest searchRequest ) throws ArchivaRestServiceException; @Path( "searchArtifacts" ) @@ -79,6 +77,19 @@ public interface SearchService List<Artifact> searchArtifacts( SearchRequest searchRequest ) throws ArchivaRestServiceException; + @Path( "getArtifactVersions" ) + @GET + @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } ) + @RedbackAuthorization( noPermission = true, noRestriction = true ) + /** + * <b>search will be apply on all repositories the current user has karma</b> + */ + List<Artifact> 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<Artifact> quickSearchWithRepositories( SearchRequest searchRequest ) + throws ArchivaRestServiceException + { + String queryString = searchRequest.getQueryTerms(); + if ( StringUtils.isBlank( queryString ) ) + { + return Collections.emptyList(); + } + List<String> 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.<String>emptyList() ); + return getArtifacts( searchResults ); + + } + catch ( RepositorySearchException e ) + { + log.error( e.getMessage(), e ); + throw new ArchivaRestServiceException( e.getMessage() ); + } + } + public List<Artifact> getArtifactVersions( String groupId, String artifactId, String packaging ) throws ArchivaRestServiceException { |