From e28ae522d1ce049848d2a30fa4e2371b0b4be706 Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Thu, 30 Dec 2010 01:29:50 +0000 Subject: [PATCH] [MRM-1327] make sure getArtifacts query is restricted to the right repository git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1053780 13f79535-47bb-0310-9956-ffa450edef68 --- .../AbstractMetadataRepositoryTest.java | 15 +++++++++++++++ .../repository/jcr/JcrMetadataRepository.java | 5 +++-- 2 files changed, 18 insertions(+), 2 deletions(-) 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 e1348a2e2..204c6cbe4 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 @@ -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 { 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 513237e40..22923eaba 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 @@ -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 metadataFacetFactories; @@ -630,7 +630,8 @@ public class JcrMetadataRepository { List artifacts; - String q = QUERY_ARTIFACTS; + String q = QUERY_ARTIFACTS + " WHERE ISDESCENDANTNODE(artifact,'/" + getRepositoryContentPath( repositoryId ) + + "')"; try { -- 2.39.5