import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
- /**
- * SearchServiceImpl
- *
- * quick/general text search which returns a list of artifacts
- * query for an artifact based on a checksum
- * query for all available versions of an artifact, sorted in version significance order
- * query for all available versions of an artifact since a given date
- * query for an artifact's direct dependencies
- * query for an artifact's dependency tree (as with mvn dependency:tree - no duplicates should be included)
- * query for all artifacts that depend on a given artifact
- *
- * @version $Id: SearchServiceImpl.java
- */
public class SearchServiceImpl
implements SearchService
-{
+{
private Logger log = LoggerFactory.getLogger( SearchServiceImpl.class );
-
+
private RepositorySearch search;
-
+
private XmlRpcUserRepositories xmlRpcUserRepositories;
-
+
private ArchivaDAO archivaDAO;
-
- private RepositoryBrowsing repoBrowsing;
-
+
+ private MetadataResolver metadataResolver;
+
public SearchServiceImpl( XmlRpcUserRepositories xmlRpcUserRepositories, ArchivaDAO archivaDAO,
- RepositoryBrowsing repoBrowsing, RepositorySearch search )
+ MetadataResolver metadataResolver, RepositorySearch search )
{
this.xmlRpcUserRepositories = xmlRpcUserRepositories;
- this.archivaDAO = archivaDAO;
- this.repoBrowsing = repoBrowsing;
+ this.archivaDAO = archivaDAO;
this.search = search;
+ this.metadataResolver = metadataResolver;
}
-
- @SuppressWarnings( "unchecked" )
+
+ @SuppressWarnings("unchecked")
public List<Artifact> quickSearch( String queryString )
throws Exception
- {
+ {
List<Artifact> artifacts = new ArrayList<Artifact>();
List<String> observableRepos = xmlRpcUserRepositories.getObservableRepositories();
SearchResultLimits limits = new SearchResultLimits( SearchResultLimits.ALL_PAGES );
throws Exception
{
List<Artifact> artifacts = new ArrayList<Artifact>();
-
+
// 1. get observable repositories
- // 2. use metadata repository to query uniqueVersions? (but with date)
+ // 2. use RepositoryBrowsing method to query uniqueVersions? (but with date)
+
+ throw new UnsupportedOperationException( "getArtifactVersionsByDate not yet implemented" );
- return artifacts;
+ // return artifacts;
}
-
- public List<Dependency> getDependencies( String groupId, String artifactId, String version )
+
+ public List<Dependency> getDependencies( String groupId, String artifactId, String version )
throws Exception
- {
- List<Dependency> dependencies = new ArrayList<Dependency>();
+ {
List<String> observableRepos = xmlRpcUserRepositories.getObservableRepositories();
-
- try
+
+ for ( String repoId : observableRepos )
{
- ArchivaProjectModel model = repoBrowsing.selectVersion( "", observableRepos, groupId, artifactId, version );
- List<org.apache.maven.archiva.model.Dependency> modelDeps = model.getDependencies();
- for( org.apache.maven.archiva.model.Dependency dep : modelDeps )
+ ProjectVersionMetadata model = metadataResolver.getProjectVersion( repoId, groupId, artifactId, version );
+ if ( model != null )
{
- Dependency dependency = new Dependency(
- dep.getGroupId(), dep.getArtifactId(), dep.getVersion(), dep.getClassifier(), dep.getType(), dep.getScope() );
- dependencies.add( dependency );
+ List<Dependency> dependencies = new ArrayList<Dependency>();
+ List<org.apache.archiva.metadata.model.Dependency> modelDeps = model.getDependencies();
+ for ( org.apache.archiva.metadata.model.Dependency dep : modelDeps )
+ {
+ Dependency dependency =
+ new Dependency( dep.getGroupId(), dep.getArtifactId(), dep.getVersion(), dep.getClassifier(),
+ dep.getType(), dep.getScope() );
+ dependencies.add( dependency );
+ }
+ return dependencies;
}
}
- catch ( ObjectNotFoundException oe )
- {
- throw new Exception( "Artifact does not exist." );
- }
-
- return dependencies;
+ throw new Exception( "Artifact does not exist." );
}
-
- public List<Artifact> getDependencyTree( String groupId, String artifactId, String version )
+
+ public List<Artifact> getDependencyTree( String groupId, String artifactId, String version )
throws Exception
{
List<Artifact> a = new ArrayList<Artifact>();
-
- return a;
+
+ throw new UnsupportedOperationException( "getDependencyTree not yet implemented" );
+ // return a;
}
-
- //get artifacts that depend on a given artifact
+
public List<Artifact> getDependees( String groupId, String artifactId, String version )
throws Exception
{
assertEquals( ARCHIVA_TEST_ARTIFACT_ID, artifact.getArtifactId() );
assertEquals( "1.0", artifact.getVersion() );
assertEquals( "jar", artifact.getType() );
- assertEquals( "public.releases", artifact.getRepositoryId() );
+ assertNull( "Repository should be null since the model was not found in the database!", artifact.getRepositoryId() );
}
-
- /*
- * quick/general text search which returns a list of artifacts
- * query for an artifact based on a checksum
- * query for all available versions of an artifact, sorted in version significance order
- * query for all available versions of an artifact since a given date
- * query for an artifact's direct dependencies
- * query for an artifact's dependency tree (as with mvn dependency:tree - no duplicates should be included)
- * query for all artifacts that depend on a given artifact
- */
-
- /* quick search */
-
-// public void testQuickSearchArtifactBytecodeSearch()
-// throws Exception
-// {
-// // 1. check whether bytecode search or ordinary search
-// // 2. get observable repos
-// // 3. convert results to a list of Artifact objects
-//
-// List<String> observableRepoIds = new ArrayList<String>();
-// observableRepoIds.add( "repo1.mirror" );
-// observableRepoIds.add( "public.releases" );
-//
-// userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds );
-//
-// Date whenGathered = new Date();
-// SearchResults results = new SearchResults();
-// ArchivaArtifact artifact = new ArchivaArtifact( "org.apache.archiva", "archiva-test", "1.0", "", "jar", "public.releases" );
-// artifact.getModel().setWhenGathered( whenGathered );
-//
-// SearchResultHit resultHit = new SearchResultHit();
-// resultHit.setArtifact(artifact);
-// resultHit.setRepositoryId("repo1.mirror");
-//
-// results.addHit(SearchUtil.getHitId(artifact.getGroupId(), artifact.getArtifactId()), resultHit);
-//
-// SearchResultLimits limits = new SearchResultLimits( SearchResultLimits.ALL_PAGES );
-//
-// searchControl.expectAndDefaultReturn( search.search( "", observableRepoIds, "MyClassName", limits, null ), results );
-//
-// archivaDAOControl.expectAndReturn( archivaDAO.getArtifactDAO(), artifactDAO );
-// artifactDAOControl.expectAndReturn( artifactDAO.getArtifact( "org.apache.archiva", "archiva-test", "1.0", "", "pom", "public.releases" ), artifact );
-//
-// userReposControl.replay();
-// searchControl.replay();
-// archivaDAOControl.replay();
-// artifactDAOControl.replay();
-//
-// List<Artifact> artifacts = searchService.quickSearch( "bytecode:MyClassName" );
-//
-// userReposControl.verify();
-// searchControl.verify();
-// archivaDAOControl.verify();
-// artifactDAOControl.verify();
-//
-// assertNotNull( artifacts );
-// assertEquals( 1, artifacts.size() );
-// }
-
+
public void testQuickSearchArtifactRegularSearch()
throws Exception
{