summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Stockhammer <martin_s@apache.org>2021-12-18 22:04:32 +0100
committerMartin Stockhammer <martin_s@apache.org>2021-12-18 22:04:32 +0100
commit51f9d7848e4a2532e90b4c36589f8af939ff0310 (patch)
tree04e8d30f216d0b434ed678a2397d3879e5ae40a3
parent91b979dcb9d3b3bbdc7f1c429839751f1aea2b1f (diff)
downloadarchiva-51f9d7848e4a2532e90b4c36589f8af939ff0310.tar.gz
archiva-51f9d7848e4a2532e90b4c36589f8af939ff0310.zip
Adding additional parameter for artifact search
-rw-r--r--archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/MavenRepositorySearch.java4
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/SearchService.java21
-rw-r--r--archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultSearchService.java4
-rw-r--r--archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/remotedownload/DownloadArtifactFromQueryTest.java6
4 files changed, 26 insertions, 9 deletions
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() );