From: Brett Porter Date: Wed, 29 Dec 2010 23:23:28 +0000 (+0000) Subject: [MRM-1327] prevent facets being returned as artifact versions X-Git-Tag: archiva-1.4-M1~849 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=201306c67923d61cd091e1892a8e0ad443e0e7e8;p=archiva.git [MRM-1327] prevent facets being returned as artifact versions git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1053767 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-modules/metadata/metadata-repository-api/src/test/java/org/apache/archiva/metadata/repository/AbstractMetadataRepositoryTest.java b/archiva-modules/metadata/metadata-repository-api/src/test/java/org/apache/archiva/metadata/repository/AbstractMetadataRepositoryTest.java index f9f13c1b4..e1348a2e2 100644 --- a/archiva-modules/metadata/metadata-repository-api/src/test/java/org/apache/archiva/metadata/repository/AbstractMetadataRepositoryTest.java +++ b/archiva-modules/metadata/metadata-repository-api/src/test/java/org/apache/archiva/metadata/repository/AbstractMetadataRepositoryTest.java @@ -437,6 +437,33 @@ public abstract class AbstractMetadataRepositoryTest assertFalse( testFacet.toProperties().containsKey( "deleteKey" ) ); } + public void testGetArtifactsDoesntReturnProjectVersionMetadataFacets() + throws Exception + { + ProjectVersionMetadata versionMetadata = new ProjectVersionMetadata(); + versionMetadata.setId( TEST_PROJECT_VERSION ); + + MetadataFacet facet = new TestMetadataFacet( TEST_FACET_ID, "baz" ); + versionMetadata.addFacet( facet ); + repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, versionMetadata ); + + ArtifactMetadata artifactMetadata = createArtifact(); + repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifactMetadata ); + + Collection artifacts = repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, + TEST_PROJECT_VERSION ); + assertEquals( Collections.singletonList( artifactMetadata ), new ArrayList( artifacts ) ); + + artifacts = repository.getArtifacts( TEST_REPO_ID ); + assertEquals( Collections.singletonList( artifactMetadata ), new ArrayList( artifacts ) ); + + artifacts = repository.getArtifactsByChecksum( TEST_REPO_ID, artifactMetadata.getSha1() ); + assertEquals( Collections.singletonList( artifactMetadata ), new ArrayList( artifacts ) ); + + artifacts = repository.getArtifactsByDateRange( TEST_REPO_ID, null, null ); + assertEquals( Collections.singletonList( artifactMetadata ), new ArrayList( artifacts ) ); + } + public void testUpdateArtifactMetadataWithExistingFacetsFacetPropertyWasRemoved() throws Exception { @@ -449,8 +476,10 @@ public abstract class AbstractMetadataRepositoryTest metadata.addFacet( facet ); repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata ); - metadata = repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, - TEST_PROJECT_VERSION ).iterator().next(); + Collection artifacts = repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, + TEST_PROJECT_VERSION ); + assertEquals( 1, artifacts.size() ); + metadata = artifacts.iterator().next(); assertEquals( Collections.singleton( TEST_FACET_ID ), metadata.getFacetIds() ); TestMetadataFacet testFacet = (TestMetadataFacet) metadata.getFacet( TEST_FACET_ID ); @@ -465,8 +494,9 @@ public abstract class AbstractMetadataRepositoryTest repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, metadata ); - metadata = repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, - TEST_PROJECT_VERSION ).iterator().next(); + artifacts = repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ); + assertEquals( 1, artifacts.size() ); + metadata = artifacts.iterator().next(); assertEquals( Collections.singleton( TEST_FACET_ID ), metadata.getFacetIds() ); testFacet = (TestMetadataFacet) metadata.getFacet( TEST_FACET_ID ); assertFalse( testFacet.toProperties().containsKey( "deleteKey" ) ); @@ -523,14 +553,12 @@ public abstract class AbstractMetadataRepositoryTest public void testGetMetadataFacetWhenEmpty() throws Exception - { assertNull( repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) ); } public void testGetMetadataFacetWhenUnknownName() throws Exception - { repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) ); @@ -539,7 +567,6 @@ public abstract class AbstractMetadataRepositoryTest public void testGetMetadataFacetWhenDefaultValue() throws Exception - { repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( null ) ); @@ -550,14 +577,12 @@ public abstract class AbstractMetadataRepositoryTest public void testGetMetadataFacetWhenUnknownFacetId() throws Exception - { assertNull( repository.getMetadataFacet( TEST_REPO_ID, UNKNOWN, TEST_NAME ) ); } public void testGetMetadataFacets() throws Exception - { repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) ); @@ -590,7 +615,6 @@ public abstract class AbstractMetadataRepositoryTest public void testRemoveFacetsWhenEmpty() throws Exception - { List facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID ); assertTrue( facets.isEmpty() ); @@ -603,7 +627,6 @@ public abstract class AbstractMetadataRepositoryTest public void testRemoveFacetsWhenUnknown() throws Exception - { // testing no exception repository.removeMetadataFacets( TEST_REPO_ID, UNKNOWN ); @@ -611,7 +634,6 @@ public abstract class AbstractMetadataRepositoryTest public void testRemoveFacetWhenUnknown() throws Exception - { // testing no exception repository.removeMetadataFacet( TEST_REPO_ID, UNKNOWN, TEST_NAME ); @@ -619,7 +641,6 @@ public abstract class AbstractMetadataRepositoryTest public void testRemoveFacet() throws Exception - { TestMetadataFacet metadataFacet = new TestMetadataFacet( TEST_VALUE ); repository.addMetadataFacet( TEST_REPO_ID, metadataFacet ); @@ -637,7 +658,6 @@ public abstract class AbstractMetadataRepositoryTest public void testRemoveFacetWhenEmpty() throws Exception - { List facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID ); assertTrue( facets.isEmpty() ); diff --git a/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java b/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java index 2d3688bb0..513237e40 100644 --- a/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java +++ b/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java @@ -640,7 +640,10 @@ public class JcrMetadataRepository artifacts = new ArrayList(); for ( Node n : JcrUtils.getNodes( result ) ) { - artifacts.add( getArtifactFromNode( repositoryId, n ) ); + if ( n.isNodeType( ARTIFACT_NODE_TYPE ) ) + { + artifacts.add( getArtifactFromNode( repositoryId, n ) ); + } } } catch ( RepositoryException e ) @@ -984,7 +987,10 @@ public class JcrMetadataRepository for ( Node n : JcrUtils.getChildNodes( node ) ) { - artifacts.add( getArtifactFromNode( repositoryId, n ) ); + if ( n.isNodeType( ARTIFACT_NODE_TYPE ) ) + { + artifacts.add( getArtifactFromNode( repositoryId, n ) ); + } } } }