diff options
Diffstat (limited to 'archiva-modules')
2 files changed, 60 insertions, 12 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 204c6cbe4..466f92613 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 @@ -457,7 +457,10 @@ public abstract class AbstractMetadataRepositoryTest artifacts = repository.getArtifacts( TEST_REPO_ID ); assertEquals( Collections.singletonList( artifactMetadata ), new ArrayList<ArtifactMetadata>( artifacts ) ); - artifacts = repository.getArtifactsByChecksum( TEST_REPO_ID, artifactMetadata.getSha1() ); + artifacts = repository.getArtifactsByChecksum( TEST_REPO_ID, TEST_SHA1 ); + assertEquals( Collections.singletonList( artifactMetadata ), new ArrayList<ArtifactMetadata>( artifacts ) ); + + artifacts = repository.getArtifactsByChecksum( TEST_REPO_ID, TEST_MD5 ); assertEquals( Collections.singletonList( artifactMetadata ), new ArrayList<ArtifactMetadata>( artifacts ) ); artifacts = repository.getArtifactsByDateRange( TEST_REPO_ID, null, null ); @@ -827,6 +830,44 @@ public abstract class AbstractMetadataRepositoryTest assertEquals( Collections.singletonList( secondArtifact ), repository.getArtifacts( OTHER_REPO_ID ) ); } + public void testGetArtifactsByDateRangeMultipleCopies() + 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.getArtifactsByDateRange( TEST_REPO_ID, null, + null ) ); + assertEquals( Collections.singletonList( secondArtifact ), repository.getArtifactsByDateRange( OTHER_REPO_ID, + null, null ) ); + } + + public void testGetArtifactsByChecksumMultipleCopies() + 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.getArtifactsByChecksum( TEST_REPO_ID, + TEST_SHA1 ) ); + assertEquals( Collections.singletonList( secondArtifact ), repository.getArtifactsByChecksum( OTHER_REPO_ID, + TEST_SHA1 ) ); + assertEquals( Collections.singletonList( artifact ), repository.getArtifactsByChecksum( TEST_REPO_ID, + TEST_MD5 ) ); + assertEquals( Collections.singletonList( secondArtifact ), repository.getArtifactsByChecksum( OTHER_REPO_ID, + TEST_MD5 ) ); + } + public void testGetNamespacesWithSparseDepth() throws Exception { @@ -868,6 +909,8 @@ public abstract class AbstractMetadataRepositoryTest assertEquals( Collections.singletonList( artifact ), repository.getArtifactsByChecksum( TEST_REPO_ID, TEST_SHA1 ) ); + assertEquals( Collections.singletonList( artifact ), repository.getArtifactsByChecksum( TEST_REPO_ID, + TEST_MD5 ) ); } public void testGetArtifactsByChecksumMultipleResult() @@ -885,6 +928,10 @@ public abstract class AbstractMetadataRepositoryTest TEST_REPO_ID, TEST_SHA1 ) ); Collections.sort( artifacts, new ArtifactMetadataComparator() ); assertEquals( Arrays.asList( artifact2, artifact1 ), artifacts ); + + artifacts = new ArrayList<ArtifactMetadata>( repository.getArtifactsByChecksum( TEST_REPO_ID, TEST_MD5 ) ); + Collections.sort( artifacts, new ArtifactMetadataComparator() ); + assertEquals( Arrays.asList( artifact2, artifact1 ), artifacts ); } public void testGetArtifactsByChecksumNoResult() @@ -894,7 +941,7 @@ public abstract class AbstractMetadataRepositoryTest repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact ); assertEquals( Collections.<ArtifactMetadata>emptyList(), repository.getArtifactsByChecksum( TEST_REPO_ID, - "not a checksum" ) ); + "not checksum" ) ); } public void testDeleteArtifact() 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 22923eaba..4c329b39e 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,8 +79,6 @@ public class JcrMetadataRepository static final String FACET_NODE_TYPE = "archiva:facet"; - private static final String QUERY_ARTIFACTS = "SELECT * FROM [" + ARTIFACT_NODE_TYPE + "] AS artifact"; - private final Map<String, MetadataFacetFactory> metadataFacetFactories; private static final Logger log = LoggerFactory.getLogger( JcrMetadataRepository.class ); @@ -489,17 +487,15 @@ public class JcrMetadataRepository { List<ArtifactMetadata> artifacts; - String q = QUERY_ARTIFACTS; + String q = getArtifactQuery( repoId ); - String clause = " WHERE"; if ( startTime != null ) { - q += clause + " [whenGathered] >= $start"; - clause = " AND"; + q += " AND [whenGathered] >= $start"; } if ( endTime != null ) { - q += clause + " [whenGathered] <= $end"; + q += " AND [whenGathered] <= $end"; } try @@ -566,7 +562,7 @@ public class JcrMetadataRepository { List<ArtifactMetadata> artifacts; - String q = QUERY_ARTIFACTS + " WHERE [sha1] = $checksum OR [md5] = $checksum"; + String q = getArtifactQuery( repositoryId ) + " AND ([sha1] = $checksum OR [md5] = $checksum)"; try { @@ -630,8 +626,7 @@ public class JcrMetadataRepository { List<ArtifactMetadata> artifacts; - String q = QUERY_ARTIFACTS + " WHERE ISDESCENDANTNODE(artifact,'/" + getRepositoryContentPath( repositoryId ) + - "')"; + String q = getArtifactQuery( repositoryId ); try { @@ -654,6 +649,12 @@ public class JcrMetadataRepository return artifacts; } + private static String getArtifactQuery( String repositoryId ) + { + return "SELECT * FROM [" + ARTIFACT_NODE_TYPE + "] AS artifact WHERE ISDESCENDANTNODE(artifact,'/" + + getRepositoryContentPath( repositoryId ) + "')"; + } + public ProjectMetadata getProject( String repositoryId, String namespace, String projectId ) throws MetadataResolutionException { |