]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1327] make sure getArtifacts query is restricted to the right repository
authorBrett Porter <brett@apache.org>
Thu, 30 Dec 2010 01:29:50 +0000 (01:29 +0000)
committerBrett Porter <brett@apache.org>
Thu, 30 Dec 2010 01:29:50 +0000 (01:29 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1053780 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/metadata/metadata-repository-api/src/test/java/org/apache/archiva/metadata/repository/AbstractMetadataRepositoryTest.java
archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java

index e1348a2e23a26dd1a1a5524a47f5101255e7a9db..204c6cbe4d91da65425412566f3e64c87c87bce5 100644 (file)
@@ -812,6 +812,21 @@ public abstract class AbstractMetadataRepositoryTest
         assertEquals( Collections.singletonList( artifact ), repository.getArtifacts( TEST_REPO_ID ) );
     }
 
+    public void testGetArtifactsByRepoIdMultipleCopies()
+        throws Exception
+    {
+        ArtifactMetadata artifact = createArtifact();
+        repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
+
+        ArtifactMetadata secondArtifact = createArtifact();
+        secondArtifact.setRepositoryId( OTHER_REPO_ID );
+        repository.updateArtifact( OTHER_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, secondArtifact );
+
+        // test it restricts to the appropriate repository
+        assertEquals( Collections.singletonList( artifact ), repository.getArtifacts( TEST_REPO_ID ) );
+        assertEquals( Collections.singletonList( secondArtifact ), repository.getArtifacts( OTHER_REPO_ID ) );
+    }
+
     public void testGetNamespacesWithSparseDepth()
         throws Exception
     {
index 513237e406b92a4bc716ca60ffce53ddcccf06d1..22923eabaed5f9052c5840e8d0c41e44317dedb2 100644 (file)
@@ -79,7 +79,7 @@ public class JcrMetadataRepository
 
     static final String FACET_NODE_TYPE = "archiva:facet";
 
-    private static final String QUERY_ARTIFACTS = "SELECT * FROM [" + ARTIFACT_NODE_TYPE + "]";
+    private static final String QUERY_ARTIFACTS = "SELECT * FROM [" + ARTIFACT_NODE_TYPE + "] AS artifact";
 
     private final Map<String, MetadataFacetFactory> metadataFacetFactories;
 
@@ -630,7 +630,8 @@ public class JcrMetadataRepository
     {
         List<ArtifactMetadata> artifacts;
 
-        String q = QUERY_ARTIFACTS;
+        String q = QUERY_ARTIFACTS + " WHERE ISDESCENDANTNODE(artifact,'/" + getRepositoryContentPath( repositoryId ) +
+            "')";
 
         try
         {