From d6c5ea064e90818d7a27ff00b68cf262371a8b74 Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Mon, 30 Nov 2009 03:10:40 +0000 Subject: [PATCH] [MRM-1288] migrate getDependees() to new API git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@885319 13f79535-47bb-0310-9956-ffa450edef68 --- .../web/xmlrpc/api/beans/Artifact.java | 49 ++++++++++++ .../archiva-xmlrpc-services/pom.xml | 4 + .../xmlrpc/services/SearchServiceImpl.java | 23 ++++-- .../services/SearchServiceImplTest.java | 77 +++++++++---------- 4 files changed, 106 insertions(+), 47 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 7c1176cac..8ea155574 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 @@ -45,6 +45,55 @@ public class Artifact } + @Override + public boolean equals( Object o ) + { + if ( this == o ) + { + return true; + } + if ( o == null || getClass() != o.getClass() ) + { + return false; + } + + Artifact artifact = (Artifact) o; + + if ( !artifactId.equals( artifact.artifactId ) ) + { + return false; + } + if ( !groupId.equals( artifact.groupId ) ) + { + return false; + } + if ( !repositoryId.equals( artifact.repositoryId ) ) + { + return false; + } + if ( type != null ? !type.equals( artifact.type ) : artifact.type != null ) + { + return false; + } + if ( !version.equals( artifact.version ) ) + { + return false; + } + + return true; + } + + @Override + public int hashCode() + { + int result = repositoryId.hashCode(); + result = 31 * result + groupId.hashCode(); + result = 31 * result + artifactId.hashCode(); + result = 31 * result + version.hashCode(); + result = 31 * result + ( type != null ? type.hashCode() : 0 ); + return result; + } + public Artifact( String repositoryId, String groupId, String artifactId, String version, String type ) // String type, Date whenGathered ) { diff --git a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/pom.xml b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/pom.xml index d960bdab9..97687d330 100644 --- a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/pom.xml +++ b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/pom.xml @@ -66,6 +66,10 @@ org.apache.archiva archiva-security + + org.apache.archiva + metadata-repository-api + org.codehaus.plexus plexus-spring 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 30d819100..3f91f6849 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 @@ -20,6 +20,7 @@ package org.apache.archiva.web.xmlrpc.services; */ import java.util.ArrayList; +import java.util.Collection; import java.util.Date; import java.util.List; @@ -27,6 +28,8 @@ import org.apache.archiva.indexer.search.RepositorySearch; import org.apache.archiva.indexer.search.SearchResultHit; import org.apache.archiva.indexer.search.SearchResultLimits; import org.apache.archiva.indexer.search.SearchResults; +import org.apache.archiva.metadata.model.ProjectVersionReference; +import org.apache.archiva.metadata.repository.MetadataResolver; 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; @@ -71,13 +74,17 @@ public class SearchServiceImpl private RepositoryBrowsing repoBrowsing; + private MetadataResolver metadataResolver; + public SearchServiceImpl( XmlRpcUserRepositories xmlRpcUserRepositories, ArchivaDAO archivaDAO, - RepositoryBrowsing repoBrowsing, RepositorySearch search ) + RepositoryBrowsing repoBrowsing, MetadataResolver metadataResolver, + RepositorySearch search ) { this.xmlRpcUserRepositories = xmlRpcUserRepositories; this.archivaDAO = archivaDAO; this.repoBrowsing = repoBrowsing; this.search = search; + this.metadataResolver = metadataResolver; } @SuppressWarnings("unchecked") @@ -263,13 +270,15 @@ public class SearchServiceImpl List artifacts = new ArrayList(); List observableRepos = xmlRpcUserRepositories.getObservableRepositories(); - List dependees = - repoBrowsing.getUsedBy( "", observableRepos, groupId, artifactId, version ); - for ( ArchivaProjectModel model : dependees ) + for ( String repoId : observableRepos ) { - Artifact artifact = new Artifact( "", model.getGroupId(), model.getArtifactId(), model.getVersion(), "" ); - //model.getWhenIndexed() ); - artifacts.add( artifact ); + Collection refs = + metadataResolver.getProjectReferences( repoId, groupId, artifactId, version ); + for ( ProjectVersionReference ref : refs ) + { + artifacts.add( + new Artifact( repoId, ref.getNamespace(), ref.getProjectId(), ref.getProjectVersion(), "" ) ); + } } return artifacts; 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 8ef4b076d..062aaf2af 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 @@ -29,6 +29,8 @@ import org.apache.archiva.indexer.search.SearchResultHit; import org.apache.archiva.indexer.search.SearchResultLimits; import org.apache.archiva.indexer.search.SearchResults; import org.apache.archiva.indexer.util.SearchUtil; +import org.apache.archiva.metadata.model.ProjectVersionReference; +import org.apache.archiva.metadata.repository.MetadataResolver; 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; @@ -80,6 +82,10 @@ public class SearchServiceImplTest private static final String ARCHIVA_TEST_GROUP_ID = "org.apache.archiva"; + private MockControl metadataResolverControl; + + private MetadataResolver metadataResolver; + @Override public void setUp() throws Exception @@ -98,7 +104,10 @@ public class SearchServiceImplTest searchControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER ); search = (RepositorySearch) searchControl.getMock(); - searchService = new SearchServiceImpl( userRepos, archivaDAO, repoBrowsing, search ); + 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(); @@ -624,41 +633,42 @@ public class SearchServiceImplTest public void testGetDependees() throws Exception { - Date date = new Date(); List observableRepoIds = new ArrayList(); - observableRepoIds.add( "repo1.mirror" ); - observableRepoIds.add( "public.releases" ); - - List dependeeModels = new ArrayList(); - ArchivaProjectModel dependeeModel = new ArchivaProjectModel(); - dependeeModel.setGroupId( ARCHIVA_TEST_GROUP_ID ); - dependeeModel.setArtifactId( "archiva-dependee-one" ); - dependeeModel.setVersion( "1.0" ); - dependeeModel.setWhenIndexed( date ); + String repoId = "repo1.mirror"; + observableRepoIds.add( repoId ); + + List dependeeModels = new ArrayList(); + ProjectVersionReference dependeeModel = new ProjectVersionReference(); + dependeeModel.setNamespace( ARCHIVA_TEST_GROUP_ID ); + dependeeModel.setProjectId( "archiva-dependee-one" ); + dependeeModel.setProjectVersion( "1.0" ); dependeeModels.add( dependeeModel ); - dependeeModel = new ArchivaProjectModel(); - dependeeModel.setGroupId( ARCHIVA_TEST_GROUP_ID ); - dependeeModel.setArtifactId( "archiva-dependee-two" ); - dependeeModel.setVersion( "1.0" ); - dependeeModel.setWhenIndexed( date ); + dependeeModel = new ProjectVersionReference(); + dependeeModel.setNamespace( ARCHIVA_TEST_GROUP_ID ); + dependeeModel.setProjectId( "archiva-dependee-two" ); + dependeeModel.setProjectVersion( "1.0" ); dependeeModels.add( dependeeModel ); userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds ); - repoBrowsingControl.expectAndReturn( - repoBrowsing.getUsedBy( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ), + metadataResolverControl.expectAndReturn( + metadataResolver.getProjectReferences( repoId, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ), dependeeModels ); - repoBrowsingControl.replay(); + metadataResolverControl.replay(); userReposControl.replay(); List dependees = searchService.getDependees( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ); - repoBrowsingControl.verify(); + metadataResolverControl.verify(); userReposControl.verify(); assertNotNull( dependees ); assertEquals( 2, dependees.size() ); + assertEquals( new Artifact( repoId, ARCHIVA_TEST_GROUP_ID, "archiva-dependee-one", "1.0", "" ), + dependees.get( 0 ) ); + assertEquals( new Artifact( repoId, ARCHIVA_TEST_GROUP_ID, "archiva-dependee-two", "1.0", "" ), + dependees.get( 1 ) ); } public void testGetDependeesArtifactDoesNotExist() @@ -669,33 +679,20 @@ public class SearchServiceImplTest observableRepoIds.add( "repo1.mirror" ); observableRepoIds.add( "public.releases" ); - List dependeeModels = new ArrayList(); - ArchivaProjectModel dependeeModel = new ArchivaProjectModel(); - dependeeModel.setGroupId( ARCHIVA_TEST_GROUP_ID ); - dependeeModel.setArtifactId( "archiva-dependee-one" ); - dependeeModel.setVersion( "1.0" ); - dependeeModel.setWhenIndexed( date ); - dependeeModels.add( dependeeModel ); - - dependeeModel = new ArchivaProjectModel(); - dependeeModel.setGroupId( ARCHIVA_TEST_GROUP_ID ); - dependeeModel.setArtifactId( "archiva-dependee-two" ); - dependeeModel.setVersion( "1.0" ); - dependeeModel.setWhenIndexed( date ); - dependeeModels.add( dependeeModel ); - userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds ); - repoBrowsingControl.expectAndReturn( - repoBrowsing.getUsedBy( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ), - null ); + metadataResolverControl.expectAndReturn( + metadataResolver.getProjectReferences( "repo1.mirror", ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, + "1.0" ), null ); + metadataResolverControl.expectAndReturn( + metadataResolver.getProjectReferences( "public.releases", ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, + "1.0" ), null ); repoBrowsingControl.replay(); userReposControl.replay(); try { - List dependees = - searchService.getDependees( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ); + searchService.getDependees( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ); fail( "An exception should have been thrown." ); } catch ( Exception e ) -- 2.39.5