[MRM-1288] move quickSearch from repository browsing to metadata content repository API

git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@885430 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Porter 2009-11-30 14:19:56 +00:00
parent bfc001b7e1
commit 3278cdc8ae
5 changed files with 67 additions and 80 deletions

View File

@ -43,7 +43,7 @@
<bean name="searchService" lazy-init="true" scope="singleton" class="org.apache.archiva.web.xmlrpc.services.SearchServiceImpl"> <bean name="searchService" lazy-init="true" scope="singleton" class="org.apache.archiva.web.xmlrpc.services.SearchServiceImpl">
<constructor-arg ref="xmlRpcUserRepositories"/> <constructor-arg ref="xmlRpcUserRepositories"/>
<constructor-arg ref="archivaDAO#jdo"/> <constructor-arg ref="archivaDAO#jdo"/>
<constructor-arg ref="repositoryBrowsing"/> <constructor-arg ref="metadataResolver"/>
<constructor-arg ref="nexusSearch"/> <constructor-arg ref="nexusSearch"/>
</bean> </bean>

View File

@ -70,6 +70,10 @@
<groupId>org.apache.archiva</groupId> <groupId>org.apache.archiva</groupId>
<artifactId>metadata-repository-api</artifactId> <artifactId>metadata-repository-api</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>maven2-repository</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.codehaus.plexus</groupId> <groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-spring</artifactId> <artifactId>plexus-spring</artifactId>

View File

@ -31,20 +31,17 @@ import org.apache.archiva.indexer.search.SearchResults;
import org.apache.archiva.metadata.model.ProjectVersionMetadata; import org.apache.archiva.metadata.model.ProjectVersionMetadata;
import org.apache.archiva.metadata.model.ProjectVersionReference; import org.apache.archiva.metadata.model.ProjectVersionReference;
import org.apache.archiva.metadata.repository.MetadataResolver; import org.apache.archiva.metadata.repository.MetadataResolver;
import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectFacet;
import org.apache.archiva.web.xmlrpc.api.SearchService; import org.apache.archiva.web.xmlrpc.api.SearchService;
import org.apache.archiva.web.xmlrpc.api.beans.Artifact; import org.apache.archiva.web.xmlrpc.api.beans.Artifact;
import org.apache.archiva.web.xmlrpc.api.beans.Dependency; import org.apache.archiva.web.xmlrpc.api.beans.Dependency;
import org.apache.archiva.web.xmlrpc.security.XmlRpcUserRepositories; import org.apache.archiva.web.xmlrpc.security.XmlRpcUserRepositories;
import org.apache.maven.archiva.common.utils.VersionUtil; import org.apache.maven.archiva.common.utils.VersionUtil;
import org.apache.maven.archiva.database.ArchivaDAO; import org.apache.maven.archiva.database.ArchivaDAO;
import org.apache.maven.archiva.database.ArchivaDatabaseException;
import org.apache.maven.archiva.database.ArtifactDAO; import org.apache.maven.archiva.database.ArtifactDAO;
import org.apache.maven.archiva.database.ObjectNotFoundException;
import org.apache.maven.archiva.database.browsing.RepositoryBrowsing;
import org.apache.maven.archiva.database.constraints.ArtifactsByChecksumConstraint; import org.apache.maven.archiva.database.constraints.ArtifactsByChecksumConstraint;
import org.apache.maven.archiva.database.constraints.UniqueVersionConstraint; import org.apache.maven.archiva.database.constraints.UniqueVersionConstraint;
import org.apache.maven.archiva.model.ArchivaArtifact; import org.apache.maven.archiva.model.ArchivaArtifact;
import org.apache.maven.archiva.model.ArchivaProjectModel;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -72,17 +69,13 @@ public class SearchServiceImpl
private ArchivaDAO archivaDAO; private ArchivaDAO archivaDAO;
private RepositoryBrowsing repoBrowsing;
private MetadataResolver metadataResolver; private MetadataResolver metadataResolver;
public SearchServiceImpl( XmlRpcUserRepositories xmlRpcUserRepositories, ArchivaDAO archivaDAO, public SearchServiceImpl( XmlRpcUserRepositories xmlRpcUserRepositories, ArchivaDAO archivaDAO,
RepositoryBrowsing repoBrowsing, MetadataResolver metadataResolver, MetadataResolver metadataResolver, RepositorySearch search )
RepositorySearch search )
{ {
this.xmlRpcUserRepositories = xmlRpcUserRepositories; this.xmlRpcUserRepositories = xmlRpcUserRepositories;
this.archivaDAO = archivaDAO; this.archivaDAO = archivaDAO;
this.repoBrowsing = repoBrowsing;
this.search = search; this.search = search;
this.metadataResolver = metadataResolver; this.metadataResolver = metadataResolver;
} }
@ -114,36 +107,35 @@ public class SearchServiceImpl
{ {
for ( String version : resultHitVersions ) for ( String version : resultHitVersions )
{ {
try
{
ArchivaProjectModel model =
repoBrowsing.selectVersion( "", observableRepos, resultHit.getGroupId(),
resultHit.getArtifactId(), version );
String repoId = repoBrowsing.getRepositoryId( "", observableRepos, resultHit.getGroupId(),
resultHit.getArtifactId(), version );
Artifact artifact = null; Artifact artifact = null;
if ( model == null ) for ( String repoId : observableRepos )
{ {
// slight behaviour change to previous implementation: instead of allocating "jar" when not
// found in the database, we can rely on the metadata repository to create it on the fly. We
// just allocate the default packaging if the Maven facet is not found.
ProjectVersionMetadata model =
metadataResolver.getProjectVersion( repoId, resultHit.getGroupId(),
resultHit.getArtifactId(), version );
if ( model != null )
{
String packaging = "jar";
MavenProjectFacet facet = (MavenProjectFacet) model.getFacet( MavenProjectFacet.FACET_ID );
if ( facet != null && facet.getPackaging() != null )
{
packaging = facet.getPackaging();
}
artifact = new Artifact( repoId, resultHit.getGroupId(), resultHit.getArtifactId(), version, artifact = new Artifact( repoId, resultHit.getGroupId(), resultHit.getArtifactId(), version,
"jar" ); packaging );
break;
} }
else }
if ( artifact != null )
{ {
artifact = new Artifact( repoId, model.getGroupId(), model.getArtifactId(), version,
model.getPackaging() );
}
artifacts.add( artifact ); artifacts.add( artifact );
} }
catch ( ObjectNotFoundException e )
{
log.debug( "Unable to find pom artifact : " + e.getMessage() );
}
catch ( ArchivaDatabaseException e )
{
log.debug( "Error occurred while getting pom artifact from database : " + e.getMessage() );
}
} }
} }
} }

View File

@ -34,13 +34,13 @@ import org.apache.archiva.indexer.util.SearchUtil;
import org.apache.archiva.metadata.model.ProjectVersionMetadata; import org.apache.archiva.metadata.model.ProjectVersionMetadata;
import org.apache.archiva.metadata.model.ProjectVersionReference; import org.apache.archiva.metadata.model.ProjectVersionReference;
import org.apache.archiva.metadata.repository.MetadataResolver; import org.apache.archiva.metadata.repository.MetadataResolver;
import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectFacet;
import org.apache.archiva.web.xmlrpc.api.SearchService; import org.apache.archiva.web.xmlrpc.api.SearchService;
import org.apache.archiva.web.xmlrpc.api.beans.Artifact; import org.apache.archiva.web.xmlrpc.api.beans.Artifact;
import org.apache.archiva.web.xmlrpc.api.beans.Dependency; import org.apache.archiva.web.xmlrpc.api.beans.Dependency;
import org.apache.archiva.web.xmlrpc.security.XmlRpcUserRepositories; import org.apache.archiva.web.xmlrpc.security.XmlRpcUserRepositories;
import org.apache.maven.archiva.database.ArchivaDAO; import org.apache.maven.archiva.database.ArchivaDAO;
import org.apache.maven.archiva.database.ArtifactDAO; import org.apache.maven.archiva.database.ArtifactDAO;
import org.apache.maven.archiva.database.browsing.RepositoryBrowsing;
import org.apache.maven.archiva.database.constraints.ArtifactsByChecksumConstraint; import org.apache.maven.archiva.database.constraints.ArtifactsByChecksumConstraint;
import org.apache.maven.archiva.database.constraints.UniqueVersionConstraint; import org.apache.maven.archiva.database.constraints.UniqueVersionConstraint;
import org.apache.maven.archiva.model.ArchivaArtifact; import org.apache.maven.archiva.model.ArchivaArtifact;
@ -75,10 +75,6 @@ public class SearchServiceImplTest
private ArtifactDAO artifactDAO; private ArtifactDAO artifactDAO;
private MockControl repoBrowsingControl;
private RepositoryBrowsing repoBrowsing;
private static final String ARCHIVA_TEST_ARTIFACT_ID = "archiva-xmlrpc-test"; private static final String ARCHIVA_TEST_ARTIFACT_ID = "archiva-xmlrpc-test";
private static final String ARCHIVA_TEST_GROUP_ID = "org.apache.archiva"; private static final String ARCHIVA_TEST_GROUP_ID = "org.apache.archiva";
@ -98,9 +94,6 @@ public class SearchServiceImplTest
archivaDAOControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER ); archivaDAOControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
archivaDAO = (ArchivaDAO) archivaDAOControl.getMock(); archivaDAO = (ArchivaDAO) archivaDAOControl.getMock();
repoBrowsingControl = MockControl.createControl( RepositoryBrowsing.class );
repoBrowsing = (RepositoryBrowsing) repoBrowsingControl.getMock();
searchControl = MockControl.createControl( RepositorySearch.class ); searchControl = MockControl.createControl( RepositorySearch.class );
searchControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER ); searchControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
search = (RepositorySearch) searchControl.getMock(); search = (RepositorySearch) searchControl.getMock();
@ -108,10 +101,10 @@ public class SearchServiceImplTest
metadataResolverControl = MockControl.createControl( MetadataResolver.class ); metadataResolverControl = MockControl.createControl( MetadataResolver.class );
metadataResolver = (MetadataResolver) metadataResolverControl.getMock(); metadataResolver = (MetadataResolver) metadataResolverControl.getMock();
searchService = new SearchServiceImpl( userRepos, archivaDAO, repoBrowsing, metadataResolver, search );
artifactDAOControl = MockControl.createControl( ArtifactDAO.class ); artifactDAOControl = MockControl.createControl( ArtifactDAO.class );
artifactDAO = (ArtifactDAO) artifactDAOControl.getMock(); artifactDAO = (ArtifactDAO) artifactDAOControl.getMock();
searchService = new SearchServiceImpl( userRepos, archivaDAO, metadataResolver, search );
} }
// MRM-1230 // MRM-1230
@ -145,30 +138,26 @@ public class SearchServiceImplTest
new UniqueVersionConstraint( observableRepoIds, resultHit.getGroupId(), resultHit.getArtifactId() ) ), new UniqueVersionConstraint( observableRepoIds, resultHit.getGroupId(), resultHit.getArtifactId() ) ),
null ); null );
ArchivaProjectModel model = new ArchivaProjectModel(); ProjectVersionMetadata model = new ProjectVersionMetadata();
model.setGroupId( ARCHIVA_TEST_GROUP_ID ); model.setId( "1.0" );
model.setArtifactId( "archiva-webapp" ); MavenProjectFacet facet = new MavenProjectFacet();
model.setVersion( "1.0" ); facet.setPackaging( "war" );
model.setPackaging( "war" ); model.addFacet( facet );
repoBrowsingControl.expectAndReturn( metadataResolverControl.expectAndReturn(
repoBrowsing.selectVersion( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, "archiva-webapp", "1.0" ), metadataResolver.getProjectVersion( "repo1.mirror", ARCHIVA_TEST_GROUP_ID, "archiva-webapp", "1.0" ),
model ); model );
repoBrowsingControl.expectAndReturn(
repoBrowsing.getRepositoryId( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, "archiva-webapp", "1.0" ),
"repo1.mirror" );
userReposControl.replay(); userReposControl.replay();
searchControl.replay(); searchControl.replay();
repoBrowsingControl.replay(); metadataResolverControl.replay();
archivaDAOControl.replay(); archivaDAOControl.replay();
List<Artifact> artifacts = searchService.quickSearch( "archiva" ); List<Artifact> artifacts = searchService.quickSearch( "archiva" );
userReposControl.verify(); userReposControl.verify();
searchControl.verify(); searchControl.verify();
repoBrowsingControl.verify(); metadataResolverControl.verify();
archivaDAOControl.verify(); archivaDAOControl.verify();
assertNotNull( artifacts ); assertNotNull( artifacts );
@ -213,24 +202,26 @@ public class SearchServiceImplTest
new UniqueVersionConstraint( observableRepoIds, resultHit.getGroupId(), resultHit.getArtifactId() ) ), new UniqueVersionConstraint( observableRepoIds, resultHit.getGroupId(), resultHit.getArtifactId() ) ),
null ); null );
repoBrowsingControl.expectAndReturn( metadataResolverControl.expectAndReturn(
repoBrowsing.selectVersion( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ), metadataResolver.getProjectVersion( "repo1.mirror", ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID,
null );
repoBrowsingControl.expectAndReturn(
repoBrowsing.getRepositoryId( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID,
"1.0" ), null ); "1.0" ), null );
ProjectVersionMetadata model = new ProjectVersionMetadata();
model.setId( "1.0" );
metadataResolverControl.expectAndReturn(
metadataResolver.getProjectVersion( "public.releases", ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID,
"1.0" ), model );
userReposControl.replay(); userReposControl.replay();
searchControl.replay(); searchControl.replay();
repoBrowsingControl.replay(); metadataResolverControl.replay();
archivaDAOControl.replay(); archivaDAOControl.replay();
List<Artifact> artifacts = searchService.quickSearch( "archiva" ); List<Artifact> artifacts = searchService.quickSearch( "archiva" );
userReposControl.verify(); userReposControl.verify();
searchControl.verify(); searchControl.verify();
repoBrowsingControl.verify(); metadataResolverControl.verify();
archivaDAOControl.verify(); archivaDAOControl.verify();
assertNotNull( artifacts ); assertNotNull( artifacts );
@ -241,8 +232,7 @@ public class SearchServiceImplTest
assertEquals( ARCHIVA_TEST_ARTIFACT_ID, artifact.getArtifactId() ); assertEquals( ARCHIVA_TEST_ARTIFACT_ID, artifact.getArtifactId() );
assertEquals( "1.0", artifact.getVersion() ); assertEquals( "1.0", artifact.getVersion() );
assertEquals( "jar", artifact.getType() ); assertEquals( "jar", artifact.getType() );
assertNull( "Repository should be null since the model was not found in the database!", assertEquals( "public.releases", artifact.getRepositoryId() );
artifact.getRepositoryId() );
} }
public void testQuickSearchArtifactRegularSearch() public void testQuickSearchArtifactRegularSearch()
@ -275,31 +265,27 @@ public class SearchServiceImplTest
searchControl.expectAndDefaultReturn( search.search( "", observableRepoIds, "archiva", limits, null ), searchControl.expectAndDefaultReturn( search.search( "", observableRepoIds, "archiva", limits, null ),
results ); results );
ArchivaProjectModel model = new ArchivaProjectModel(); ProjectVersionMetadata model = new ProjectVersionMetadata();
model.setGroupId( ARCHIVA_TEST_GROUP_ID ); model.setId( "1.0" );
model.setArtifactId( ARCHIVA_TEST_ARTIFACT_ID ); MavenProjectFacet facet = new MavenProjectFacet();
model.setVersion( "1.0" ); facet.setPackaging( "jar" );
model.setPackaging( "jar" ); model.addFacet( facet );
repoBrowsingControl.expectAndReturn( metadataResolverControl.expectAndReturn(
repoBrowsing.selectVersion( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ), metadataResolver.getProjectVersion( "repo1.mirror", ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID,
model ); "1.0" ), model );
repoBrowsingControl.expectAndReturn(
repoBrowsing.getRepositoryId( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID,
"1.0" ), "repo1.mirror" );
userReposControl.replay(); userReposControl.replay();
searchControl.replay(); searchControl.replay();
archivaDAOControl.replay(); archivaDAOControl.replay();
repoBrowsingControl.replay(); metadataResolverControl.replay();
List<Artifact> artifacts = searchService.quickSearch( "archiva" ); List<Artifact> artifacts = searchService.quickSearch( "archiva" );
userReposControl.verify(); userReposControl.verify();
searchControl.verify(); searchControl.verify();
archivaDAOControl.verify(); archivaDAOControl.verify();
repoBrowsingControl.verify(); metadataResolverControl.verify();
assertNotNull( artifacts ); assertNotNull( artifacts );
assertEquals( 1, artifacts.size() ); assertEquals( 1, artifacts.size() );

View File

@ -303,6 +303,11 @@
<artifactId>metadata-repository-file</artifactId> <artifactId>metadata-repository-file</artifactId>
<version>1.3-SNAPSHOT</version> <version>1.3-SNAPSHOT</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>maven2-repository</artifactId>
<version>1.3-SNAPSHOT</version>
</dependency>
<dependency> <dependency>
<groupId>org.apache.archiva</groupId> <groupId>org.apache.archiva</groupId>
<artifactId>archiva-applet</artifactId> <artifactId>archiva-applet</artifactId>