[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">
<constructor-arg ref="xmlRpcUserRepositories"/>
<constructor-arg ref="archivaDAO#jdo"/>
<constructor-arg ref="repositoryBrowsing"/>
<constructor-arg ref="metadataResolver"/>
<constructor-arg ref="nexusSearch"/>
</bean>

View File

@ -70,6 +70,10 @@
<groupId>org.apache.archiva</groupId>
<artifactId>metadata-repository-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>maven2-repository</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<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.ProjectVersionReference;
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.beans.Artifact;
import org.apache.archiva.web.xmlrpc.api.beans.Dependency;
import org.apache.archiva.web.xmlrpc.security.XmlRpcUserRepositories;
import org.apache.maven.archiva.common.utils.VersionUtil;
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.ObjectNotFoundException;
import org.apache.maven.archiva.database.browsing.RepositoryBrowsing;
import org.apache.maven.archiva.database.constraints.ArtifactsByChecksumConstraint;
import org.apache.maven.archiva.database.constraints.UniqueVersionConstraint;
import org.apache.maven.archiva.model.ArchivaArtifact;
import org.apache.maven.archiva.model.ArchivaProjectModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -72,17 +69,13 @@ public class SearchServiceImpl
private ArchivaDAO archivaDAO;
private RepositoryBrowsing repoBrowsing;
private MetadataResolver metadataResolver;
public SearchServiceImpl( XmlRpcUserRepositories xmlRpcUserRepositories, ArchivaDAO archivaDAO,
RepositoryBrowsing repoBrowsing, MetadataResolver metadataResolver,
RepositorySearch search )
MetadataResolver metadataResolver, RepositorySearch search )
{
this.xmlRpcUserRepositories = xmlRpcUserRepositories;
this.archivaDAO = archivaDAO;
this.repoBrowsing = repoBrowsing;
this.search = search;
this.metadataResolver = metadataResolver;
}
@ -114,36 +107,35 @@ public class SearchServiceImpl
{
for ( String version : resultHitVersions )
{
try
Artifact artifact = null;
for ( String repoId : observableRepos )
{
ArchivaProjectModel model =
repoBrowsing.selectVersion( "", observableRepos, resultHit.getGroupId(),
resultHit.getArtifactId(), version );
// 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 );
String repoId = repoBrowsing.getRepositoryId( "", observableRepos, resultHit.getGroupId(),
resultHit.getArtifactId(), version );
Artifact artifact = null;
if ( model == null )
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,
"jar" );
}
else
{
artifact = new Artifact( repoId, model.getGroupId(), model.getArtifactId(), version,
model.getPackaging() );
packaging );
break;
}
}
if ( artifact != null )
{
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.ProjectVersionReference;
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.beans.Artifact;
import org.apache.archiva.web.xmlrpc.api.beans.Dependency;
import org.apache.archiva.web.xmlrpc.security.XmlRpcUserRepositories;
import org.apache.maven.archiva.database.ArchivaDAO;
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.UniqueVersionConstraint;
import org.apache.maven.archiva.model.ArchivaArtifact;
@ -75,10 +75,6 @@ public class SearchServiceImplTest
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_GROUP_ID = "org.apache.archiva";
@ -98,9 +94,6 @@ public class SearchServiceImplTest
archivaDAOControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
archivaDAO = (ArchivaDAO) archivaDAOControl.getMock();
repoBrowsingControl = MockControl.createControl( RepositoryBrowsing.class );
repoBrowsing = (RepositoryBrowsing) repoBrowsingControl.getMock();
searchControl = MockControl.createControl( RepositorySearch.class );
searchControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
search = (RepositorySearch) searchControl.getMock();
@ -108,10 +101,10 @@ public class SearchServiceImplTest
metadataResolverControl = MockControl.createControl( MetadataResolver.class );
metadataResolver = (MetadataResolver) metadataResolverControl.getMock();
searchService = new SearchServiceImpl( userRepos, archivaDAO, repoBrowsing, metadataResolver, search );
artifactDAOControl = MockControl.createControl( ArtifactDAO.class );
artifactDAO = (ArtifactDAO) artifactDAOControl.getMock();
searchService = new SearchServiceImpl( userRepos, archivaDAO, metadataResolver, search );
}
// MRM-1230
@ -145,30 +138,26 @@ public class SearchServiceImplTest
new UniqueVersionConstraint( observableRepoIds, resultHit.getGroupId(), resultHit.getArtifactId() ) ),
null );
ArchivaProjectModel model = new ArchivaProjectModel();
model.setGroupId( ARCHIVA_TEST_GROUP_ID );
model.setArtifactId( "archiva-webapp" );
model.setVersion( "1.0" );
model.setPackaging( "war" );
ProjectVersionMetadata model = new ProjectVersionMetadata();
model.setId( "1.0" );
MavenProjectFacet facet = new MavenProjectFacet();
facet.setPackaging( "war" );
model.addFacet( facet );
repoBrowsingControl.expectAndReturn(
repoBrowsing.selectVersion( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, "archiva-webapp", "1.0" ),
metadataResolverControl.expectAndReturn(
metadataResolver.getProjectVersion( "repo1.mirror", ARCHIVA_TEST_GROUP_ID, "archiva-webapp", "1.0" ),
model );
repoBrowsingControl.expectAndReturn(
repoBrowsing.getRepositoryId( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, "archiva-webapp", "1.0" ),
"repo1.mirror" );
userReposControl.replay();
searchControl.replay();
repoBrowsingControl.replay();
metadataResolverControl.replay();
archivaDAOControl.replay();
List<Artifact> artifacts = searchService.quickSearch( "archiva" );
userReposControl.verify();
searchControl.verify();
repoBrowsingControl.verify();
metadataResolverControl.verify();
archivaDAOControl.verify();
assertNotNull( artifacts );
@ -213,24 +202,26 @@ public class SearchServiceImplTest
new UniqueVersionConstraint( observableRepoIds, resultHit.getGroupId(), resultHit.getArtifactId() ) ),
null );
repoBrowsingControl.expectAndReturn(
repoBrowsing.selectVersion( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ),
null );
metadataResolverControl.expectAndReturn(
metadataResolver.getProjectVersion( "repo1.mirror", ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID,
"1.0" ), null );
repoBrowsingControl.expectAndReturn(
repoBrowsing.getRepositoryId( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID,
"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();
searchControl.replay();
repoBrowsingControl.replay();
metadataResolverControl.replay();
archivaDAOControl.replay();
List<Artifact> artifacts = searchService.quickSearch( "archiva" );
userReposControl.verify();
searchControl.verify();
repoBrowsingControl.verify();
metadataResolverControl.verify();
archivaDAOControl.verify();
assertNotNull( artifacts );
@ -241,8 +232,7 @@ public class SearchServiceImplTest
assertEquals( ARCHIVA_TEST_ARTIFACT_ID, artifact.getArtifactId() );
assertEquals( "1.0", artifact.getVersion() );
assertEquals( "jar", artifact.getType() );
assertNull( "Repository should be null since the model was not found in the database!",
artifact.getRepositoryId() );
assertEquals( "public.releases", artifact.getRepositoryId() );
}
public void testQuickSearchArtifactRegularSearch()
@ -275,31 +265,27 @@ public class SearchServiceImplTest
searchControl.expectAndDefaultReturn( search.search( "", observableRepoIds, "archiva", limits, null ),
results );
ArchivaProjectModel model = new ArchivaProjectModel();
model.setGroupId( ARCHIVA_TEST_GROUP_ID );
model.setArtifactId( ARCHIVA_TEST_ARTIFACT_ID );
model.setVersion( "1.0" );
model.setPackaging( "jar" );
ProjectVersionMetadata model = new ProjectVersionMetadata();
model.setId( "1.0" );
MavenProjectFacet facet = new MavenProjectFacet();
facet.setPackaging( "jar" );
model.addFacet( facet );
repoBrowsingControl.expectAndReturn(
repoBrowsing.selectVersion( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ),
model );
repoBrowsingControl.expectAndReturn(
repoBrowsing.getRepositoryId( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID,
"1.0" ), "repo1.mirror" );
metadataResolverControl.expectAndReturn(
metadataResolver.getProjectVersion( "repo1.mirror", ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID,
"1.0" ), model );
userReposControl.replay();
searchControl.replay();
archivaDAOControl.replay();
repoBrowsingControl.replay();
metadataResolverControl.replay();
List<Artifact> artifacts = searchService.quickSearch( "archiva" );
userReposControl.verify();
searchControl.verify();
archivaDAOControl.verify();
repoBrowsingControl.verify();
metadataResolverControl.verify();
assertNotNull( artifacts );
assertEquals( 1, artifacts.size() );

View File

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