]> source.dussan.org Git - archiva.git/commitdiff
Adding additional parameter for artifact search
authorMartin Stockhammer <martin_s@apache.org>
Sat, 18 Dec 2021 21:04:32 +0000 (22:04 +0100)
committerMartin Stockhammer <martin_s@apache.org>
Sat, 18 Dec 2021 21:04:32 +0000 (22:04 +0100)
archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/MavenRepositorySearch.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
archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/remotedownload/DownloadArtifactFromQueryTest.java

index 848ca78c1ae501ec3d42e47a8c4d6d42aa70ec25..906f3579d15587cdd612841c4b09d04fd33c043c 100644 (file)
@@ -182,8 +182,8 @@ public class MavenRepositorySearch
 
         if ( StringUtils.isNotBlank( searchFields.getVersion() ) )
         {
-            q.add( indexer.constructQuery( MAVEN.VERSION, searchFields.isExactSearch() ? new SourcedSearchExpression(
-                searchFields.getVersion() ) : new SourcedSearchExpression( searchFields.getVersion() ) ), Occur.MUST );
+            q.add( indexer.constructQuery( MAVEN.VERSION, new SourcedSearchExpression(
+                searchFields.getVersion( ) ) ), Occur.MUST );
         }
 
         if ( StringUtils.isNotBlank( searchFields.getPackaging() ) )
index 1b3fa08b5b60a8bf2c1f2ab79f26fd7c70e04b9f..9fb6c126f5282cc5d0ae8b7826c848511f7c49b1 100644 (file)
@@ -27,6 +27,7 @@ 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 javax.ws.rs.DefaultValue;
 import javax.ws.rs.GET;
 import javax.ws.rs.POST;
 import javax.ws.rs.Path;
@@ -120,7 +121,21 @@ public interface SearchService
         throws ArchivaRestServiceException;
     */
 
-
+    /**
+     * Returns a redirect to a artifact file, that matches given search parameter
+     * @param repositoryId The repository id (optional)
+     * @param groupId The search pattern for the group id of the artifact (required)
+     * @param artifactId  The search pattern for the artifact id of the artifact (required)
+     * @param version The search pattern for the version of the artifact (required)
+     *                LATEST returns the latest version of the artifact.
+     * @param packaging the packaging
+     * @param classifier the artifact classifier
+     * @param literalVersion true, if the version string should be treated literally, which means
+     *                       LATEST search for versions with LATEST in the version string.
+     *                       false, is default and treats v=LATEST special
+     * @return the redirect response, if a artifact was found
+     * @throws ArchivaRestServiceException
+     */
     @GET
     @Path( "/artifact" )
     @Produces( "text/html" )
@@ -130,7 +145,9 @@ public interface SearchService
                                      @QueryParam( "a" ) String artifactId, //
                                      @QueryParam( "v" ) String version, //
                                      @QueryParam( "p" ) String packaging, //
-                                     @QueryParam( "c" ) String classifier )
+                                     @QueryParam( "c" ) String classifier,
+                                     @DefaultValue( "false" )
+                                     @QueryParam( "literalVersion" ) Boolean literalVersion)
         throws ArchivaRestServiceException;
 
 
index 68631041ea9bcd1d1bc4f87c68df207ec508721f..358fe99116aeced81e84aedeac938d5efdbbd4c7 100644 (file)
@@ -255,7 +255,7 @@ public class DefaultSearchService
 
     @Override
     public Response redirectToArtifactFile( String repositoryId, String groupId, String artifactId, String version,
-                                            String packaging, String classifier )
+                                            String packaging, String classifier, Boolean literalVersion )
         throws ArchivaRestServiceException
     {
         try
@@ -338,7 +338,7 @@ public class DefaultSearchService
             searchField.setGroupId( groupId );
             searchField.setArtifactId( artifactId );
             searchField.setPackaging( StringUtils.isBlank( packaging ) ? "jar" : packaging );
-            if ( !StringUtils.equals( version, LATEST_KEYWORD ) )
+            if ( literalVersion.booleanValue() || !StringUtils.equals( version, LATEST_KEYWORD ) )
             {
                 searchField.setVersion( version );
             }
index 559f332a63ccdcd30bce62df673a28b38d74c28e..a5f5000464e6efd52916249eb76a6b92dbe13287 100644 (file)
@@ -135,7 +135,7 @@ public class DownloadArtifactFromQueryTest
         {
             Response response =
                 getSearchService().redirectToArtifactFile( null, "org.apache.archiva", "archiva-test", "1.0", null,
-                                                           null );
+                                                           null, Boolean.FALSE );
 
         }
         catch ( RedirectionException e )
@@ -163,7 +163,7 @@ public class DownloadArtifactFromQueryTest
         {
             Response response =
                 getSearchService().redirectToArtifactFile( null, "org.apache.archiva", "archiva-test", "LATEST", null,
-                                                           null );
+                                                           null , Boolean.FALSE);
 
         }
         catch ( RedirectionException e )
@@ -190,7 +190,7 @@ public class DownloadArtifactFromQueryTest
         {
             Response response =
                 getSearchService().redirectToArtifactFile( null, "org.apache.archiva.beer", "archiva-wine", "LATEST",
-                                                           null, null );
+                                                           null, null, Boolean.FALSE );
 
             Assert.assertEquals( Response.Status.NO_CONTENT.getStatusCode(), response.getStatus() );