Author: oching
Date: Sun Nov 22 08:32:36 2009
New Revision: 883046

URL: http://svn.apache.org/viewvc?rev=883046&view=rev
Log:
[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

Modified:
    
archiva/trunk/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/src/main/java/org/apache/archiva/web/xmlrpc/api/beans/Artifact.java
    
archiva/trunk/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImpl.java
    
archiva/trunk/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImplTest.java

Modified: 
archiva/trunk/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/src/main/java/org/apache/archiva/web/xmlrpc/api/beans/Artifact.java
URL: 
http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/src/main/java/org/apache/archiva/web/xmlrpc/api/beans/Artifact.java?rev=883046&r1=883045&r2=883046&view=diff
==============================================================================
--- 
archiva/trunk/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/src/main/java/org/apache/archiva/web/xmlrpc/api/beans/Artifact.java
 (original)
+++ 
archiva/trunk/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-api/src/main/java/org/apache/archiva/web/xmlrpc/api/beans/Artifact.java
 Sun Nov 22 08:32:36 2009
@@ -75,6 +75,11 @@
     {
         return type;
     }
+    
+    public String getRepositoryId()
+    {
+        return repositoryId;
+    }
 
     /*public Date getWhenGathered()
     {
@@ -104,20 +109,16 @@
     {
         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;
-    }
+    }*/    
 }

Modified: 
archiva/trunk/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImpl.java
URL: 
http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImpl.java?rev=883046&r1=883045&r2=883046&view=diff
==============================================================================
--- 
archiva/trunk/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImpl.java
 (original)
+++ 
archiva/trunk/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImpl.java
 Sun Nov 22 08:32:36 2009
@@ -104,33 +104,35 @@
                 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() );
                     }
                 }

Modified: 
archiva/trunk/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImplTest.java
URL: 
http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImplTest.java?rev=883046&r1=883045&r2=883046&view=diff
==============================================================================
--- 
archiva/trunk/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImplTest.java
 (original)
+++ 
archiva/trunk/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImplTest.java
 Sun Nov 22 08:32:36 2009
@@ -117,8 +117,8 @@
         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 @@
         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 @@
         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 @@
         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 @@
           
         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 @@
         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 @@
         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 @@
           
         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 @@
       
         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( )


Reply via email to