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 );
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
{
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()
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()
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()
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 );
{
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
{
List<ArtifactMetadata> artifacts;
- String q = QUERY_ARTIFACTS + " WHERE [sha1] = $checksum OR [md5] = $checksum";
+ String q = getArtifactQuery( repositoryId ) + " AND ([sha1] = $checksum OR [md5] = $checksum)";
try
{
{
List<ArtifactMetadata> artifacts;
- String q = QUERY_ARTIFACTS + " WHERE ISDESCENDANTNODE(artifact,'/" + getRepositoryContentPath( repositoryId ) +
- "')";
+ String q = getArtifactQuery( repositoryId );
try
{
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
{