From: Martin Stockhammer Date: Sat, 18 Dec 2021 21:04:32 +0000 (+0100) Subject: Adding additional parameter for artifact search X-Git-Tag: archiva-2.2.7~3 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=51f9d7848e4a2532e90b4c36589f8af939ff0310;p=archiva.git Adding additional parameter for artifact search --- diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/MavenRepositorySearch.java b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/MavenRepositorySearch.java index 848ca78c1..906f3579d 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/MavenRepositorySearch.java +++ b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/MavenRepositorySearch.java @@ -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() ) ) 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 1b3fa08b5..9fb6c126f 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 @@ -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; 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 68631041e..358fe9911 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 @@ -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 ); } diff --git a/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/remotedownload/DownloadArtifactFromQueryTest.java b/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/remotedownload/DownloadArtifactFromQueryTest.java index 559f332a6..a5f500046 100644 --- a/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/remotedownload/DownloadArtifactFromQueryTest.java +++ b/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/remotedownload/DownloadArtifactFromQueryTest.java @@ -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() );