aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules/plugins/audit
diff options
context:
space:
mode:
authorBrett Porter <brett@apache.org>2010-01-19 11:21:10 +0000
committerBrett Porter <brett@apache.org>2010-01-19 11:21:10 +0000
commit93f9e26408d1fb72a22e31cb19640cdca2de2e9f (patch)
tree449a142e1cb61519de1d6c3495ad4a96cc7b7ddf /archiva-modules/plugins/audit
parent9a1c82e9af392b51e265c0a285e0a3ee8304dff2 (diff)
downloadarchiva-93f9e26408d1fb72a22e31cb19640cdca2de2e9f.tar.gz
archiva-93f9e26408d1fb72a22e31cb19640cdca2de2e9f.zip
[MRM-1269] restore pseudo-search by artifact in audit logs
git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@900726 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/plugins/audit')
-rw-r--r--archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/AuditManager.java20
-rw-r--r--archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/DefaultAuditManager.java12
-rw-r--r--archiva-modules/plugins/audit/src/test/java/org/apache/archiva/audit/AuditManagerTest.java78
3 files changed, 105 insertions, 5 deletions
diff --git a/archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/AuditManager.java b/archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/AuditManager.java
index 137e0a83f..3b3448efb 100644
--- a/archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/AuditManager.java
+++ b/archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/AuditManager.java
@@ -33,5 +33,25 @@ public interface AuditManager
void deleteAuditEvents( String repositoryId );
+ /**
+ * Get all audit events from the given repositories that match a certain range
+ *
+ * @param repositoryIds the repositories to retrieve events for
+ * @param startTime find events only after this time
+ * @param endTime find events only before this time
+ * @return the list of events found
+ */
List<AuditEvent> getAuditEventsInRange( Collection<String> repositoryIds, Date startTime, Date endTime );
+
+ /**
+ * Get all audit events from the given repositories that match a certain range and resource pattern
+ *
+ * @param repositoryIds the repositories to retrieve events for
+ * @param resourcePattern find all events whose resources start with this string
+ * @param startTime find events only after this time
+ * @param endTime find events only before this time
+ * @return the list of events found
+ */
+ List<AuditEvent> getAuditEventsInRange( Collection<String> repositoryIds, String resourcePattern, Date startTime,
+ Date endTime );
} \ No newline at end of file
diff --git a/archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/DefaultAuditManager.java b/archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/DefaultAuditManager.java
index 2ddd3a3ee..96065838e 100644
--- a/archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/DefaultAuditManager.java
+++ b/archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/DefaultAuditManager.java
@@ -93,6 +93,12 @@ public class DefaultAuditManager
public List<AuditEvent> getAuditEventsInRange( Collection<String> repositoryIds, Date startTime, Date endTime )
{
+ return getAuditEventsInRange( repositoryIds, null, startTime, endTime );
+ }
+
+ public List<AuditEvent> getAuditEventsInRange( Collection<String> repositoryIds, String resource, Date startTime,
+ Date endTime )
+ {
List<AuditEvent> results = new ArrayList<AuditEvent>();
for ( String repositoryId : repositoryIds )
{
@@ -107,7 +113,11 @@ public class DefaultAuditManager
{
AuditEvent event =
(AuditEvent) metadataRepository.getMetadataFacet( repositoryId, AuditEvent.FACET_ID, name );
- results.add( event );
+
+ if ( resource == null || event.getResource().startsWith( resource ) )
+ {
+ results.add( event );
+ }
}
}
catch ( ParseException e )
diff --git a/archiva-modules/plugins/audit/src/test/java/org/apache/archiva/audit/AuditManagerTest.java b/archiva-modules/plugins/audit/src/test/java/org/apache/archiva/audit/AuditManagerTest.java
index 152b86887..2bb3399a8 100644
--- a/archiva-modules/plugins/audit/src/test/java/org/apache/archiva/audit/AuditManagerTest.java
+++ b/archiva-modules/plugins/audit/src/test/java/org/apache/archiva/audit/AuditManagerTest.java
@@ -68,7 +68,7 @@ public class AuditManagerTest
private static SimpleDateFormat createTimestampFormat()
{
SimpleDateFormat fmt = new SimpleDateFormat( AuditEvent.TIMESTAMP_FORMAT );
- fmt.setTimeZone( TimeZone.getTimeZone( "UTC" ));
+ fmt.setTimeZone( TimeZone.getTimeZone( "UTC" ) );
return fmt;
}
@@ -434,6 +434,79 @@ public class AuditManagerTest
metadataRepositoryControl.verify();
}
+ public void testGetEventsWithResource()
+ throws ParseException
+ {
+ Date current = new Date();
+
+ String name1 = TIMESTAMP_FORMAT.format( new Date( current.getTime() - 12345 ) );
+ AuditEvent expectedEvent1 = createTestEvent( name1 );
+ Date expectedTimestamp = new Date( current.getTime() - 3000 );
+ String name2 = TIMESTAMP_FORMAT.format( expectedTimestamp );
+ AuditEvent expectedEvent2 = createTestEvent( name2 );
+ expectedEvent2.setResource( "different-resource" );
+ String name3 = TIMESTAMP_FORMAT.format( new Date( current.getTime() - 1000 ) );
+ AuditEvent expectedEvent3 = createTestEvent( name3 );
+
+ metadataRepositoryControl.expectAndReturn(
+ metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ),
+ Arrays.asList( name1, name2, name3 ) );
+
+ metadataRepositoryControl.expectAndReturn(
+ metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, name1 ), expectedEvent1 );
+ metadataRepositoryControl.expectAndReturn(
+ metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, name2 ), expectedEvent2 );
+ metadataRepositoryControl.expectAndReturn(
+ metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, name3 ), expectedEvent3 );
+
+ metadataRepositoryControl.replay();
+
+ List<AuditEvent> events =
+ auditManager.getAuditEventsInRange( Collections.singletonList( TEST_REPO_ID ), TEST_RESOURCE_BASE,
+ new Date( current.getTime() - 20000 ), current );
+
+ assertEquals( 2, events.size() );
+ assertEvent( events.get( 0 ), name3, expectedEvent3.getResource() );
+ assertEvent( events.get( 1 ), name1, expectedEvent1.getResource() );
+
+ metadataRepositoryControl.verify();
+ }
+
+ public void testGetEventsWithNonExistantResource()
+ throws ParseException
+ {
+ Date current = new Date();
+
+ String name1 = TIMESTAMP_FORMAT.format( new Date( current.getTime() - 12345 ) );
+ AuditEvent expectedEvent1 = createTestEvent( name1 );
+ Date expectedTimestamp = new Date( current.getTime() - 3000 );
+ String name2 = TIMESTAMP_FORMAT.format( expectedTimestamp );
+ AuditEvent expectedEvent2 = createTestEvent( name2 );
+ expectedEvent2.setResource( "different-resource" );
+ String name3 = TIMESTAMP_FORMAT.format( new Date( current.getTime() - 1000 ) );
+ AuditEvent expectedEvent3 = createTestEvent( name3 );
+
+ metadataRepositoryControl.expectAndReturn(
+ metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ),
+ Arrays.asList( name1, name2, name3 ) );
+
+ metadataRepositoryControl.expectAndReturn(
+ metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, name1 ), expectedEvent1 );
+ metadataRepositoryControl.expectAndReturn(
+ metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, name2 ), expectedEvent2 );
+ metadataRepositoryControl.expectAndReturn(
+ metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, name3 ), expectedEvent3 );
+
+ metadataRepositoryControl.replay();
+
+ List<AuditEvent> events = auditManager.getAuditEventsInRange( Collections.singletonList( TEST_REPO_ID ), "foo",
+ new Date( current.getTime() - 20000 ), current );
+
+ assertEquals( 0, events.size() );
+
+ metadataRepositoryControl.verify();
+ }
+
public void testGetEventsRangeMultipleRepositories()
throws ParseException
{
@@ -478,12 +551,9 @@ public class AuditManagerTest
Date current = new Date();
String name1 = TIMESTAMP_FORMAT.format( new Date( current.getTime() - 12345 ) );
- AuditEvent expectedEvent1 = createTestEvent( name1 );
Date expectedTimestamp = new Date( current.getTime() - 3000 );
String name2 = TIMESTAMP_FORMAT.format( expectedTimestamp );
- AuditEvent expectedEvent2 = createTestEvent( name2 );
String name3 = TIMESTAMP_FORMAT.format( new Date( current.getTime() - 1000 ) );
- AuditEvent expectedEvent3 = createTestEvent( name3 );
metadataRepositoryControl.expectAndReturn(
metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ),