Adding additional parameter for artifact search

This commit is contained in:
Martin Stockhammer 2021-12-18 22:04:32 +01:00
parent 91b979dcb9
commit 51f9d7848e
4 changed files with 26 additions and 9 deletions

View File

@ -182,8 +182,8 @@ public SearchResults search( String principal, SearchFields searchFields, Search
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() ) )

View File

@ -27,6 +27,7 @@
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 @@ List<Dependency> getDependencies( @QueryParam( "groupId" ) String groupId,
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 @@ Response redirectToArtifactFile( @QueryParam( "r" ) String repositoryId, //
@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;

View File

@ -255,7 +255,7 @@ public StringList getObservablesRepoIds()
@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 String getReasonPhrase()
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 );
}

View File

@ -135,7 +135,7 @@ public void downloadFixedVersion()
{
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 void downloadLatestVersion()
{
Response response =
getSearchService().redirectToArtifactFile( null, "org.apache.archiva", "archiva-test", "LATEST", null,
null );
null , Boolean.FALSE);
}
catch ( RedirectionException e )
@ -190,7 +190,7 @@ public void download_no_content()
{
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() );