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.setPrefix( artifactInfo.prefix );
|
||||
hit.setPackaging( artifactInfo.packaging );
|
||||
hit.setClassifier( artifactInfo.classifier );
|
||||
// sure ??
|
||||
hit.setUrl( artifactInfo.remoteUrl );
|
||||
}
|
||||
|
|
|
@ -125,6 +125,8 @@ public class Artifact
|
|||
|
||||
private String classifier;
|
||||
|
||||
private String packaging;
|
||||
|
||||
|
||||
public Artifact()
|
||||
{
|
||||
|
@ -321,6 +323,18 @@ public class Artifact
|
|||
this.classifier = classifier;
|
||||
}
|
||||
|
||||
|
||||
public String getPackaging()
|
||||
{
|
||||
return packaging;
|
||||
}
|
||||
|
||||
public void setPackaging( String packaging )
|
||||
{
|
||||
this.packaging = packaging;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
|
@ -345,6 +359,7 @@ public class Artifact
|
|||
sb.append( ", bundleImportPackage='" ).append( bundleImportPackage ).append( '\'' );
|
||||
sb.append( ", bundleRequireBundle='" ).append( bundleRequireBundle ).append( '\'' );
|
||||
sb.append( ", classifier='" ).append( classifier ).append( '\'' );
|
||||
sb.append( ", packaging='" ).append( packaging ).append( '\'' );
|
||||
sb.append( '}' );
|
||||
return sb.toString();
|
||||
}
|
||||
|
|
|
@ -57,7 +57,8 @@ public interface SearchService
|
|||
@Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } )
|
||||
@RedbackAuthorization( noPermission = true, noRestriction = true )
|
||||
List<Artifact> getArtifactVersions( @QueryParam( "groupId" ) String groupId,
|
||||
@QueryParam( "artifactId" ) String artifactId )
|
||||
@QueryParam( "artifactId" ) String artifactId,
|
||||
@QueryParam( "packaging" ) String packaging )
|
||||
throws ArchivaRestServiceException;
|
||||
|
||||
@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.services.ArchivaRestServiceException;
|
||||
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.ArchivaSecurityException;
|
||||
import org.apache.archiva.security.PrincipalNotFoundException;
|
||||
|
@ -78,7 +80,8 @@ public class DefaultSearchService
|
|||
SearchResults searchResults =
|
||||
repositorySearch.search( getPrincipal(), getObservableRepos(), queryString, limits,
|
||||
Collections.<String>emptyList() );
|
||||
return getArtifacts( searchResults );
|
||||
return getArtifacts( searchResults, new ArrayList<ArtifactFiler>( NoClassifierArtifactFiler.LIST ) );
|
||||
|
||||
}
|
||||
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
|
||||
{
|
||||
if ( StringUtils.isBlank( groupId ) || StringUtils.isBlank( artifactId ) )
|
||||
|
@ -97,12 +100,12 @@ public class DefaultSearchService
|
|||
SearchFields searchField = new SearchFields();
|
||||
searchField.setGroupId( groupId );
|
||||
searchField.setArtifactId( artifactId );
|
||||
SearchResultLimits limits = new SearchResultLimits( 0 );
|
||||
searchField.setPackaging( StringUtils.isBlank( packaging ) ? "jar" : packaging );
|
||||
|
||||
try
|
||||
{
|
||||
SearchResults searchResults = repositorySearch.search( getPrincipal(), searchField, limits );
|
||||
return getArtifacts( searchResults );
|
||||
SearchResults searchResults = repositorySearch.search( getPrincipal(), searchField, null );
|
||||
return getArtifacts( searchResults, Collections.<ArtifactFiler>emptyList() );
|
||||
}
|
||||
catch ( RepositorySearchException e )
|
||||
{
|
||||
|
@ -124,7 +127,7 @@ public class DefaultSearchService
|
|||
try
|
||||
{
|
||||
SearchResults searchResults = repositorySearch.search( getPrincipal(), searchField, limits );
|
||||
return getArtifacts( searchResults );
|
||||
return getArtifacts( searchResults, Collections.<ArtifactFiler>emptyList() );
|
||||
}
|
||||
catch ( RepositorySearchException e )
|
||||
{
|
||||
|
@ -179,7 +182,7 @@ public class DefaultSearchService
|
|||
: redbackRequestInformation.getUser().getUsername() );
|
||||
}
|
||||
|
||||
protected List<Artifact> getArtifacts( SearchResults searchResults )
|
||||
protected List<Artifact> getArtifacts( SearchResults searchResults, List<ArtifactFiler> artifactFilers )
|
||||
{
|
||||
if ( searchResults == null || searchResults.isEmpty() )
|
||||
{
|
||||
|
@ -223,11 +226,34 @@ public class DefaultSearchService
|
|||
if ( StringUtils.isNotBlank( version ) )
|
||||
{
|
||||
versionned.setVersion( version );
|
||||
if ( applyFiltering( versionned, artifactFilers, artifacts ) )
|
||||
{
|
||||
artifacts.add( versionned );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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 java.io.File;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -56,7 +57,8 @@ public class SearchServiceTest
|
|||
List<Artifact> artifacts = searchService.quickSearch( "commons-logging" );
|
||||
|
||||
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 );
|
||||
|
||||
deleteTestRepo( testRepoId, targetRepo );
|
||||
|
@ -78,17 +80,18 @@ public class SearchServiceTest
|
|||
|
||||
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 );
|
||||
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 );
|
||||
|
||||
deleteTestRepo( testRepoId, targetRepo );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void searchWithSearchRequestGroupIdAndArtifactId()
|
||||
public void searchWithSearchRequestGroupIdAndArtifactIdAndClassifier()
|
||||
throws Exception
|
||||
{
|
||||
|
||||
|
@ -103,7 +106,7 @@ public class SearchServiceTest
|
|||
|
||||
SearchService searchService = getSearchService( authorizationHeader );
|
||||
|
||||
SearchRequest searchRequest = new SearchRequest( );
|
||||
SearchRequest searchRequest = new SearchRequest();
|
||||
searchRequest.setGroupId( "commons-logging" );
|
||||
searchRequest.setArtifactId( "commons-logging" );
|
||||
searchRequest.setClassifier( "sources" );
|
||||
|
@ -111,7 +114,8 @@ public class SearchServiceTest
|
|||
List<Artifact> artifacts = searchService.searchArtifacts( searchRequest );
|
||||
|
||||
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 );
|
||||
|
||||
deleteTestRepo( testRepoId, targetRepo );
|
||||
|
@ -120,6 +124,10 @@ public class SearchServiceTest
|
|||
private File createAndIndexRepo( String testRepoId )
|
||||
throws Exception
|
||||
{
|
||||
if ( getManagedRepositoriesService( authorizationHeader ).getManagedRepository( testRepoId ) != null )
|
||||
{
|
||||
getManagedRepositoriesService( authorizationHeader ).deleteManagedRepository( testRepoId, true );
|
||||
}
|
||||
File targetRepo = new File( System.getProperty( "targetDir", "./target" ), "test-repo" );
|
||||
cleanupFiles( targetRepo );
|
||||
|
||||
|
@ -132,11 +140,11 @@ public class SearchServiceTest
|
|||
managedRepository.setName( "test repo" );
|
||||
|
||||
managedRepository.setLocation( targetRepo.getPath() );
|
||||
managedRepository.setIndexDirectory( targetRepo.getPath() + "/index-" + Long.toString( new Date().getTime() ) );
|
||||
|
||||
ManagedRepositoriesService service = getManagedRepositoriesService( authorizationHeader );
|
||||
service.addManagedRepository( managedRepository );
|
||||
|
||||
|
||||
getRepositoriesService( authorizationHeader ).scanRepositoryNow( testRepoId, true );
|
||||
|
||||
return targetRepo;
|
||||
|
@ -153,7 +161,7 @@ public class SearchServiceTest
|
|||
|
||||
}
|
||||
|
||||
private void cleanupFiles(File targetRepo)
|
||||
private void cleanupFiles( File targetRepo )
|
||||
throws Exception
|
||||
{
|
||||
|
||||
|
|
Loading…
Reference in New Issue