mirror of https://github.com/apache/archiva.git
[MRM-1327] make sure getArtifactsByDateRange and getArtifactsByChecksum query is restricted to the right repository
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1053783 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e28ae522d1
commit
de23f7ef3f
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue