diff options
author | Maria Odea B. Ching <oching@apache.org> | 2009-11-22 08:32:36 +0000 |
---|---|---|
committer | Maria Odea B. Ching <oching@apache.org> | 2009-11-22 08:32:36 +0000 |
commit | 07080653194785b6fddce0e2b088938aeaeed114 (patch) | |
tree | ddf4bc9d4662ed5afc50ac66646644826982102e | |
parent | 9a8138a5a2bfdac142f7b61019198b3c1cc303a7 (diff) | |
download | archiva-07080653194785b6fddce0e2b088938aeaeed114.tar.gz archiva-07080653194785b6fddce0e2b088938aeaeed114.zip |
[MRM-1274] SearchService.quickSearch returns artifacts with null as repositoryId
o get repo id from db since it's not set in search result
o set repositoryId as bean field in Artifact obj so it's included when bean is converted
o updated unit tests
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@883046 13f79535-47bb-0310-9956-ffa450edef68
3 files changed, 50 insertions, 32 deletions
diff --git a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/src/main/java/org/apache/archiva/web/xmlrpc/api/beans/Artifact.java b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/src/main/java/org/apache/archiva/web/xmlrpc/api/beans/Artifact.java index d55c978f5..7c1176cac 100644 --- a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/src/main/java/org/apache/archiva/web/xmlrpc/api/beans/Artifact.java +++ b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/src/main/java/org/apache/archiva/web/xmlrpc/api/beans/Artifact.java @@ -75,6 +75,11 @@ public class Artifact { return type; } + + public String getRepositoryId() + { + return repositoryId; + } /*public Date getWhenGathered() { @@ -104,20 +109,16 @@ public class Artifact { this.type = type; } + + @ServiceBeanField( "repositoryId" ) + public void setRepositoryId( String repositoryId ) + { + this.repositoryId = repositoryId; + } /*@ServiceBeanField( "whenGathered" ) public void setWhenGathered( Date whenGathered ) { this.whenGathered = whenGathered; - }*/ - - public String getRepositoryId() - { - return repositoryId; - } - - public void setRepositoryId( String repositoryId ) - { - this.repositoryId = repositoryId; - } + }*/ } diff --git a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImpl.java b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImpl.java index 16974f12e..539fd7a66 100644 --- a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImpl.java +++ b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImpl.java @@ -104,33 +104,35 @@ public class SearchServiceImpl resultHit.setVersion( null ); resultHit.setVersions( filterTimestampedSnapshots( versions ) ); } - + List<String> resultHitVersions = resultHit.getVersions(); if( resultHitVersions != null ) { 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; if( model == null ) { - artifact = new Artifact( resultHit.getRepositoryId(), resultHit.getGroupId(), resultHit.getArtifactId(), version, "jar" ); + artifact = new Artifact( repoId, resultHit.getGroupId(), resultHit.getArtifactId(), version, "jar" ); } else { - artifact = new Artifact( resultHit.getRepositoryId(), model.getGroupId(), model.getArtifactId(), version, model.getPackaging() ); + artifact = new Artifact( repoId, model.getGroupId(), model.getArtifactId(), version, model.getPackaging() ); } 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() ); } } diff --git a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImplTest.java b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImplTest.java index 6f28bf008..6d7bdf5aa 100644 --- a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImplTest.java +++ b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImplTest.java @@ -117,8 +117,8 @@ public class SearchServiceImplTest SearchResultHit resultHit = new SearchResultHit(); resultHit.setGroupId( "org.apache.archiva" ); resultHit.setArtifactId( "archiva-webapp" ); - resultHit.setRepositoryId("repo1.mirror"); resultHit.setVersions( versions ); + resultHit.setRepositoryId( null ); results.addHit( SearchUtil.getHitId( "org.apache.archiva", "archiva-webapp" ), resultHit ); @@ -136,6 +136,8 @@ public class SearchServiceImplTest model.setPackaging( "war" ); repoBrowsingControl.expectAndReturn( repoBrowsing.selectVersion( "", observableRepoIds, "org.apache.archiva", "archiva-webapp", "1.0" ), model ); + + repoBrowsingControl.expectAndReturn( repoBrowsing.getRepositoryId( "", observableRepoIds, "org.apache.archiva", "archiva-webapp", "1.0" ), "repo1.mirror" ); userReposControl.replay(); searchControl.replay(); @@ -152,12 +154,13 @@ public class SearchServiceImplTest assertNotNull( artifacts ); assertEquals( 1, artifacts.size() ); - Artifact hit = artifacts.get( 0 ); - assertEquals( "org.apache.archiva", hit.getGroupId() ); - assertEquals( "archiva-webapp", hit.getArtifactId() ); - assertEquals( "1.0", hit.getVersion() ); - assertEquals( "war", hit.getType() ); - assertEquals( "repo1.mirror", hit.getRepositoryId() ); + Artifact artifact = artifacts.get( 0 ); + assertEquals( "org.apache.archiva", artifact.getGroupId() ); + assertEquals( "archiva-webapp", artifact.getArtifactId() ); + assertEquals( "1.0", artifact.getVersion() ); + assertEquals( "war", artifact.getType() ); + assertNotNull( "Repository should not be null!", artifact.getRepositoryId() ); + assertEquals( "repo1.mirror", artifact.getRepositoryId() ); } // returned model is null! @@ -175,7 +178,7 @@ public class SearchServiceImplTest versions.add( "1.0" ); SearchResultHit resultHit = new SearchResultHit(); - resultHit.setRepositoryId( "repo1.mirror" ); + resultHit.setRepositoryId( null ); resultHit.setGroupId( "org.apache.archiva" ); resultHit.setArtifactId( "archiva-test" ); resultHit.setVersions( versions ); @@ -191,6 +194,8 @@ public class SearchServiceImplTest repoBrowsingControl.expectAndReturn( repoBrowsing.selectVersion( "", observableRepoIds, "org.apache.archiva", "archiva-test", "1.0" ), null ); + repoBrowsingControl.expectAndReturn( repoBrowsing.getRepositoryId( "", observableRepoIds, "org.apache.archiva", "archiva-test", "1.0" ), null ); + userReposControl.replay(); searchControl.replay(); repoBrowsingControl.replay(); @@ -206,12 +211,12 @@ public class SearchServiceImplTest assertNotNull( artifacts ); assertEquals( 1, artifacts.size() ); - Artifact hit = artifacts.get( 0 ); - assertEquals( "org.apache.archiva", hit.getGroupId() ); - assertEquals( "archiva-test", hit.getArtifactId() ); - assertEquals( "1.0", hit.getVersion() ); - assertEquals( "jar", hit.getType() ); - assertEquals( "repo1.mirror", hit.getRepositoryId() ); + Artifact artifact = artifacts.get( 0 ); + assertEquals( "org.apache.archiva", artifact.getGroupId() ); + assertEquals( "archiva-test", 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() ); } /* @@ -290,7 +295,7 @@ public class SearchServiceImplTest resultHit.setGroupId( "org.apache.archiva" ); resultHit.setArtifactId( "archiva-test" ); resultHit.setVersions( versions ); - resultHit.setRepositoryId("repo1.mirror"); + resultHit.setRepositoryId( null ); results.addHit( SearchUtil.getHitId( resultHit.getGroupId(), resultHit.getArtifactId() ), resultHit ); @@ -309,6 +314,8 @@ public class SearchServiceImplTest repoBrowsingControl.expectAndReturn( repoBrowsing.selectVersion( "", observableRepoIds, "org.apache.archiva", "archiva-test", "1.0" ), model ); + repoBrowsingControl.expectAndReturn( repoBrowsing.getRepositoryId( "", observableRepoIds, "org.apache.archiva", "archiva-test", "1.0" ), "repo1.mirror" ); + userReposControl.replay(); searchControl.replay(); archivaDAOControl.replay(); @@ -323,6 +330,14 @@ public class SearchServiceImplTest assertNotNull( artifacts ); assertEquals( 1, artifacts.size() ); + + Artifact artifact = artifacts.get( 0 ); + assertEquals( "org.apache.archiva", artifact.getGroupId() ); + assertEquals( "archiva-test", artifact.getArtifactId() ); + assertEquals( "1.0", artifact.getVersion() ); + assertEquals( "jar", artifact.getType() ); + assertNotNull( "Repository should not be null!", artifact.getRepositoryId() ); + assertEquals( "repo1.mirror", artifact.getRepositoryId() ); } public void testQuickSearchNoResults( ) |