mirror of https://github.com/apache/archiva.git
[MRM-1490] REST services : search now returns classifier : fix new services based on this
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1171015 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7b51409788
commit
979fee6e57
|
@ -406,6 +406,7 @@ public class NexusRepositorySearch
|
||||||
hit.setGoals( artifactInfo.goals );
|
hit.setGoals( artifactInfo.goals );
|
||||||
hit.setPrefix( artifactInfo.prefix );
|
hit.setPrefix( artifactInfo.prefix );
|
||||||
hit.setPackaging( artifactInfo.packaging );
|
hit.setPackaging( artifactInfo.packaging );
|
||||||
|
hit.setClassifier( artifactInfo.classifier );
|
||||||
// sure ??
|
// sure ??
|
||||||
hit.setUrl( artifactInfo.remoteUrl );
|
hit.setUrl( artifactInfo.remoteUrl );
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,6 +125,8 @@ public class Artifact
|
||||||
|
|
||||||
private String classifier;
|
private String classifier;
|
||||||
|
|
||||||
|
private String packaging;
|
||||||
|
|
||||||
|
|
||||||
public Artifact()
|
public Artifact()
|
||||||
{
|
{
|
||||||
|
@ -321,6 +323,18 @@ public class Artifact
|
||||||
this.classifier = classifier;
|
this.classifier = classifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getPackaging()
|
||||||
|
{
|
||||||
|
return packaging;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPackaging( String packaging )
|
||||||
|
{
|
||||||
|
this.packaging = packaging;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
|
@ -345,6 +359,7 @@ public class Artifact
|
||||||
sb.append( ", bundleImportPackage='" ).append( bundleImportPackage ).append( '\'' );
|
sb.append( ", bundleImportPackage='" ).append( bundleImportPackage ).append( '\'' );
|
||||||
sb.append( ", bundleRequireBundle='" ).append( bundleRequireBundle ).append( '\'' );
|
sb.append( ", bundleRequireBundle='" ).append( bundleRequireBundle ).append( '\'' );
|
||||||
sb.append( ", classifier='" ).append( classifier ).append( '\'' );
|
sb.append( ", classifier='" ).append( classifier ).append( '\'' );
|
||||||
|
sb.append( ", packaging='" ).append( packaging ).append( '\'' );
|
||||||
sb.append( '}' );
|
sb.append( '}' );
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,8 @@ public interface SearchService
|
||||||
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
|
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
|
||||||
@RedbackAuthorization( noPermission = true, noRestriction = true )
|
@RedbackAuthorization( noPermission = true, noRestriction = true )
|
||||||
List<Artifact> getArtifactVersions( @QueryParam( "groupId" ) String groupId,
|
List<Artifact> getArtifactVersions( @QueryParam( "groupId" ) String groupId,
|
||||||
@QueryParam( "artifactId" ) String artifactId )
|
@QueryParam( "artifactId" ) String artifactId,
|
||||||
|
@QueryParam( "packaging" ) String packaging )
|
||||||
throws ArchivaRestServiceException;
|
throws ArchivaRestServiceException;
|
||||||
|
|
||||||
@Path( "searchArtifacts" )
|
@Path( "searchArtifacts" )
|
||||||
|
|
|
@ -30,6 +30,8 @@ import org.apache.archiva.rest.api.model.Dependency;
|
||||||
import org.apache.archiva.rest.api.model.SearchRequest;
|
import org.apache.archiva.rest.api.model.SearchRequest;
|
||||||
import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
|
import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
|
||||||
import org.apache.archiva.rest.api.services.SearchService;
|
import org.apache.archiva.rest.api.services.SearchService;
|
||||||
|
import org.apache.archiva.rest.services.searchfilter.ArtifactFiler;
|
||||||
|
import org.apache.archiva.rest.services.searchfilter.NoClassifierArtifactFiler;
|
||||||
import org.apache.archiva.security.AccessDeniedException;
|
import org.apache.archiva.security.AccessDeniedException;
|
||||||
import org.apache.archiva.security.ArchivaSecurityException;
|
import org.apache.archiva.security.ArchivaSecurityException;
|
||||||
import org.apache.archiva.security.PrincipalNotFoundException;
|
import org.apache.archiva.security.PrincipalNotFoundException;
|
||||||
|
@ -78,7 +80,8 @@ public class DefaultSearchService
|
||||||
SearchResults searchResults =
|
SearchResults searchResults =
|
||||||
repositorySearch.search( getPrincipal(), getObservableRepos(), queryString, limits,
|
repositorySearch.search( getPrincipal(), getObservableRepos(), queryString, limits,
|
||||||
Collections.<String>emptyList() );
|
Collections.<String>emptyList() );
|
||||||
return getArtifacts( searchResults );
|
return getArtifacts( searchResults, new ArrayList<ArtifactFiler>( NoClassifierArtifactFiler.LIST ) );
|
||||||
|
|
||||||
}
|
}
|
||||||
catch ( RepositorySearchException e )
|
catch ( RepositorySearchException e )
|
||||||
{
|
{
|
||||||
|
@ -87,7 +90,7 @@ public class DefaultSearchService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Artifact> getArtifactVersions( String groupId, String artifactId )
|
public List<Artifact> getArtifactVersions( String groupId, String artifactId, String packaging )
|
||||||
throws ArchivaRestServiceException
|
throws ArchivaRestServiceException
|
||||||
{
|
{
|
||||||
if ( StringUtils.isBlank( groupId ) || StringUtils.isBlank( artifactId ) )
|
if ( StringUtils.isBlank( groupId ) || StringUtils.isBlank( artifactId ) )
|
||||||
|
@ -97,12 +100,12 @@ public class DefaultSearchService
|
||||||
SearchFields searchField = new SearchFields();
|
SearchFields searchField = new SearchFields();
|
||||||
searchField.setGroupId( groupId );
|
searchField.setGroupId( groupId );
|
||||||
searchField.setArtifactId( artifactId );
|
searchField.setArtifactId( artifactId );
|
||||||
SearchResultLimits limits = new SearchResultLimits( 0 );
|
searchField.setPackaging( StringUtils.isBlank( packaging ) ? "jar" : packaging );
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
SearchResults searchResults = repositorySearch.search( getPrincipal(), searchField, limits );
|
SearchResults searchResults = repositorySearch.search( getPrincipal(), searchField, null );
|
||||||
return getArtifacts( searchResults );
|
return getArtifacts( searchResults, Collections.<ArtifactFiler>emptyList() );
|
||||||
}
|
}
|
||||||
catch ( RepositorySearchException e )
|
catch ( RepositorySearchException e )
|
||||||
{
|
{
|
||||||
|
@ -124,7 +127,7 @@ public class DefaultSearchService
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
SearchResults searchResults = repositorySearch.search( getPrincipal(), searchField, limits );
|
SearchResults searchResults = repositorySearch.search( getPrincipal(), searchField, limits );
|
||||||
return getArtifacts( searchResults );
|
return getArtifacts( searchResults, Collections.<ArtifactFiler>emptyList() );
|
||||||
}
|
}
|
||||||
catch ( RepositorySearchException e )
|
catch ( RepositorySearchException e )
|
||||||
{
|
{
|
||||||
|
@ -179,7 +182,7 @@ public class DefaultSearchService
|
||||||
: redbackRequestInformation.getUser().getUsername() );
|
: redbackRequestInformation.getUser().getUsername() );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected List<Artifact> getArtifacts( SearchResults searchResults )
|
protected List<Artifact> getArtifacts( SearchResults searchResults, List<ArtifactFiler> artifactFilers )
|
||||||
{
|
{
|
||||||
if ( searchResults == null || searchResults.isEmpty() )
|
if ( searchResults == null || searchResults.isEmpty() )
|
||||||
{
|
{
|
||||||
|
@ -223,11 +226,34 @@ public class DefaultSearchService
|
||||||
if ( StringUtils.isNotBlank( version ) )
|
if ( StringUtils.isNotBlank( version ) )
|
||||||
{
|
{
|
||||||
versionned.setVersion( version );
|
versionned.setVersion( version );
|
||||||
|
if ( applyFiltering( versionned, artifactFilers, artifacts ) )
|
||||||
|
{
|
||||||
artifacts.add( versionned );
|
artifacts.add( versionned );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return artifacts;
|
return artifacts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean applyFiltering( Artifact artifact, List<ArtifactFiler> artifactFilers, List<Artifact> artifacts )
|
||||||
|
{
|
||||||
|
if ( artifact == null )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ( artifactFilers == null || artifactFilers.isEmpty() )
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
for ( ArtifactFiler filter : artifactFilers )
|
||||||
|
{
|
||||||
|
if ( !filter.addArtifactInResult( artifact, artifacts ) )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ import org.apache.commons.io.FileUtils;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -56,7 +57,8 @@ public class SearchServiceTest
|
||||||
List<Artifact> artifacts = searchService.quickSearch( "commons-logging" );
|
List<Artifact> artifacts = searchService.quickSearch( "commons-logging" );
|
||||||
|
|
||||||
assertNotNull( artifacts );
|
assertNotNull( artifacts );
|
||||||
assertTrue( " empty results for commons-logging search", artifacts.size() == 6 );
|
assertTrue( " not 6 results for commons-logging search but " + artifacts.size() + ":" + artifacts,
|
||||||
|
artifacts.size() == 6 );
|
||||||
log.info( "artifacts for commons-logging size {} search {}", artifacts.size(), artifacts );
|
log.info( "artifacts for commons-logging size {} search {}", artifacts.size(), artifacts );
|
||||||
|
|
||||||
deleteTestRepo( testRepoId, targetRepo );
|
deleteTestRepo( testRepoId, targetRepo );
|
||||||
|
@ -78,17 +80,18 @@ public class SearchServiceTest
|
||||||
|
|
||||||
SearchService searchService = getSearchService( authorizationHeader );
|
SearchService searchService = getSearchService( authorizationHeader );
|
||||||
|
|
||||||
List<Artifact> artifacts = searchService.getArtifactVersions( "commons-logging", "commons-logging" );
|
List<Artifact> artifacts = searchService.getArtifactVersions( "commons-logging", "commons-logging", "jar" );
|
||||||
|
|
||||||
assertNotNull( artifacts );
|
assertNotNull( artifacts );
|
||||||
assertTrue( " empty results for commons-logging search", artifacts.size() == 6 );
|
assertTrue( " not 3 results for commons-logging search but " + artifacts.size() + ":" + artifacts,
|
||||||
|
artifacts.size() == 13 );
|
||||||
log.info( "artifacts for commons-logging size {} search {}", artifacts.size(), artifacts );
|
log.info( "artifacts for commons-logging size {} search {}", artifacts.size(), artifacts );
|
||||||
|
|
||||||
deleteTestRepo( testRepoId, targetRepo );
|
deleteTestRepo( testRepoId, targetRepo );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void searchWithSearchRequestGroupIdAndArtifactId()
|
public void searchWithSearchRequestGroupIdAndArtifactIdAndClassifier()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -111,7 +114,8 @@ public class SearchServiceTest
|
||||||
List<Artifact> artifacts = searchService.searchArtifacts( searchRequest );
|
List<Artifact> artifacts = searchService.searchArtifacts( searchRequest );
|
||||||
|
|
||||||
assertNotNull( artifacts );
|
assertNotNull( artifacts );
|
||||||
assertTrue( " empty results for commons-logging search", artifacts.size() == 6 );
|
assertTrue( " not 2 results for commons-logging search but " + artifacts.size() + ":" + artifacts,
|
||||||
|
artifacts.size() == 2 );
|
||||||
log.info( "artifacts for commons-logging size {} search {}", artifacts.size(), artifacts );
|
log.info( "artifacts for commons-logging size {} search {}", artifacts.size(), artifacts );
|
||||||
|
|
||||||
deleteTestRepo( testRepoId, targetRepo );
|
deleteTestRepo( testRepoId, targetRepo );
|
||||||
|
@ -120,6 +124,10 @@ public class SearchServiceTest
|
||||||
private File createAndIndexRepo( String testRepoId )
|
private File createAndIndexRepo( String testRepoId )
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
if ( getManagedRepositoriesService( authorizationHeader ).getManagedRepository( testRepoId ) != null )
|
||||||
|
{
|
||||||
|
getManagedRepositoriesService( authorizationHeader ).deleteManagedRepository( testRepoId, true );
|
||||||
|
}
|
||||||
File targetRepo = new File( System.getProperty( "targetDir", "./target" ), "test-repo" );
|
File targetRepo = new File( System.getProperty( "targetDir", "./target" ), "test-repo" );
|
||||||
cleanupFiles( targetRepo );
|
cleanupFiles( targetRepo );
|
||||||
|
|
||||||
|
@ -132,11 +140,11 @@ public class SearchServiceTest
|
||||||
managedRepository.setName( "test repo" );
|
managedRepository.setName( "test repo" );
|
||||||
|
|
||||||
managedRepository.setLocation( targetRepo.getPath() );
|
managedRepository.setLocation( targetRepo.getPath() );
|
||||||
|
managedRepository.setIndexDirectory( targetRepo.getPath() + "/index-" + Long.toString( new Date().getTime() ) );
|
||||||
|
|
||||||
ManagedRepositoriesService service = getManagedRepositoriesService( authorizationHeader );
|
ManagedRepositoriesService service = getManagedRepositoriesService( authorizationHeader );
|
||||||
service.addManagedRepository( managedRepository );
|
service.addManagedRepository( managedRepository );
|
||||||
|
|
||||||
|
|
||||||
getRepositoriesService( authorizationHeader ).scanRepositoryNow( testRepoId, true );
|
getRepositoriesService( authorizationHeader ).scanRepositoryNow( testRepoId, true );
|
||||||
|
|
||||||
return targetRepo;
|
return targetRepo;
|
||||||
|
|
Loading…
Reference in New Issue