]> source.dussan.org Git - archiva.git/commitdiff
add rest method to search with query on a set of repositories
authorOlivier Lamy <olamy@apache.org>
Tue, 28 Feb 2012 00:03:04 +0000 (00:03 +0000)
committerOlivier Lamy <olamy@apache.org>
Tue, 28 Feb 2012 00:03:04 +0000 (00:03 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1294404 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/SearchRequest.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/SearchService.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSearchService.java

index 93744e05d009d3c6ca269395bf061ad90d48ccc2..6d82b5b44ee4caef21d4de1b4a3707908f6b91b0 100644 (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( '\'' );
index f55a223acb169baae4aa785bf1c8dcffa5864d47..bc71f2495b915f6e91a361d3f5e79c160b5885ad 100644 (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;
 
index 41d5d2181f5da16a7f291a31575ee3dfd3f5cecc..6cfb749e73088e7b18a23727843f074b2933faeb 100644 (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
     {