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
This commit is contained in:
Olivier Lamy 2012-02-28 00:03:04 +00:00
parent 11b1451053
commit 202a699884
3 changed files with 67 additions and 7 deletions

View File

@ -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( '\'' );

View File

@ -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;

View File

@ -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
{