aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules/plugins/audit
diff options
context:
space:
mode:
authorMartin Stockhammer <martin_s@apache.org>2019-08-04 22:40:04 +0200
committerMartin Stockhammer <martin_s@apache.org>2019-08-04 22:40:04 +0200
commiteca0097d857aa4739a6387c67d22a9a355a46fa1 (patch)
tree48752d7b63424b3e8b2bf47d11a692bfa69a6ff5 /archiva-modules/plugins/audit
parentee2c1a7b2b623cf76c8a5deff5e8ddb836de2eaa (diff)
downloadarchiva-eca0097d857aa4739a6387c67d22a9a355a46fa1.tar.gz
archiva-eca0097d857aa4739a6387c67d22a9a355a46fa1.zip
Changing session handling for metadata API
Diffstat (limited to 'archiva-modules/plugins/audit')
-rw-r--r--archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/DefaultAuditManager.java20
-rw-r--r--archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/MetadataAuditListener.java14
-rw-r--r--archiva-modules/plugins/audit/src/test/java/org/apache/archiva/audit/AuditManagerTest.java96
3 files changed, 71 insertions, 59 deletions
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 510dc8191..cff05aaa8 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
@@ -58,7 +58,7 @@ public class DefaultAuditManager
List<AuditRecord> records = new ArrayList<>();
for ( String repositoryId : repositoryIds )
{
- List<String> names = metadataRepository.getMetadataFacets( repositoryId, AuditEvent.FACET_ID );
+ List<String> names = metadataRepository.getMetadataFacets( , repositoryId, AuditEvent.FACET_ID );
for ( String name : names )
{
records.add( new AuditRecord( repositoryId, name ) );
@@ -70,9 +70,9 @@ public class DefaultAuditManager
List<AuditEvent> events = new ArrayList<>( records.size() );
for ( AuditRecord record : records )
{
- AuditEvent auditEvent = (AuditEvent) metadataRepository.getMetadataFacet( record.repositoryId,
- AuditEvent.FACET_ID,
- record.name );
+ AuditEvent auditEvent = (AuditEvent) metadataRepository.getMetadataFacet( ,
+ record.repositoryId,
+ AuditEvent.FACET_ID, record.name );
events.add( auditEvent );
}
return events;
@@ -85,7 +85,7 @@ public class DefaultAuditManager
// ignore those with no repository - they will still be logged to the textual audit log
if ( event.getRepositoryId() != null )
{
- repository.addMetadataFacet( event.getRepositoryId(), event );
+ repository.addMetadataFacet( , event.getRepositoryId(), event );
}
}
@@ -93,7 +93,7 @@ public class DefaultAuditManager
public void deleteAuditEvents( MetadataRepository metadataRepository, String repositoryId )
throws MetadataRepositoryException
{
- metadataRepository.removeMetadataFacets( repositoryId, AuditEvent.FACET_ID );
+ metadataRepository.removeMetadataFacets( , repositoryId, AuditEvent.FACET_ID );
}
@Override
@@ -113,7 +113,7 @@ public class DefaultAuditManager
List<AuditEvent> results = new ArrayList<>();
for ( String repositoryId : repositoryIds )
{
- List<String> list = metadataRepository.getMetadataFacets( repositoryId, AuditEvent.FACET_ID );
+ List<String> list = metadataRepository.getMetadataFacets( , repositoryId, AuditEvent.FACET_ID );
for ( String name : list )
{
try
@@ -122,9 +122,9 @@ public class DefaultAuditManager
if ( ( startTime == null || !date.before( startTime ) ) && ( endTime == null || !date.after(
endTime ) ) )
{
- AuditEvent event = (AuditEvent) metadataRepository.getMetadataFacet( repositoryId,
- AuditEvent.FACET_ID,
- name );
+ AuditEvent event = (AuditEvent) metadataRepository.getMetadataFacet( ,
+ repositoryId,
+ AuditEvent.FACET_ID, name );
if ( resource == null || event.getResource().startsWith( resource ) )
{
diff --git a/archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/MetadataAuditListener.java b/archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/MetadataAuditListener.java
index 8406bbb7a..ea535fd2e 100644
--- a/archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/MetadataAuditListener.java
+++ b/archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/MetadataAuditListener.java
@@ -59,7 +59,15 @@ public class MetadataAuditListener
if ( event.getAction().equals( AuditEvent.CREATE_FILE ) || event.getAction().equals( AuditEvent.UPLOAD_FILE ) ||
event.getAction().equals( AuditEvent.MERGING_REPOSITORIES ) )
{
- RepositorySession repositorySession = repositorySessionFactory.createSession();
+ RepositorySession repositorySession = null;
+ try
+ {
+ repositorySession = repositorySessionFactory.createSession();
+ }
+ catch ( MetadataRepositoryException e )
+ {
+ e.printStackTrace( );
+ }
try
{
auditManager.addAuditEvent( repositorySession.getRepository(), event );
@@ -73,6 +81,10 @@ public class MetadataAuditListener
{
repositorySession.close();
}
+ catch ( org.apache.archiva.metadata.repository.MetadataSessionException e )
+ {
+ e.printStackTrace( );
+ }
}
}
}
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 8119ba4e9..da40c6853 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
@@ -104,13 +104,13 @@ public class AuditManagerTest
expectedEvents.add( event );
}
- EasyMock.expect( metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ) ).andReturn(
+ EasyMock.expect( metadataRepository.getMetadataFacets( , TEST_REPO_ID, AuditEvent.FACET_ID ) ).andReturn(
getEventNames( expectedEvents ) );
for ( AuditEvent event : expectedEvents.subList( 1, expectedEvents.size() ) )
{
EasyMock.expect(
- metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, event.getName() ) ).andReturn(
+ metadataRepository.getMetadataFacet( , TEST_REPO_ID, AuditEvent.FACET_ID, event.getName() ) ).andReturn(
event );
}
metadataRepositoryControl.replay();
@@ -141,12 +141,12 @@ public class AuditManagerTest
expectedEvents.add( createEvent( AUDIT_EVENT_BASE + MILLIS_FORMAT.format( i ) ) );
}
- EasyMock.expect( metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ) ).andReturn(
+ EasyMock.expect( metadataRepository.getMetadataFacets( , TEST_REPO_ID, AuditEvent.FACET_ID ) ).andReturn(
getEventNames( expectedEvents ) );
for ( AuditEvent event : expectedEvents )
{
EasyMock.expect(
- metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, event.getName() ) ).andReturn(
+ metadataRepository.getMetadataFacet( , TEST_REPO_ID, AuditEvent.FACET_ID, event.getName() ) ).andReturn(
event );
}
metadataRepositoryControl.replay();
@@ -184,15 +184,15 @@ public class AuditManagerTest
eventNames.get( repositoryId ).add( event.getName() );
}
- EasyMock.expect( metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ) ).andReturn(
+ EasyMock.expect( metadataRepository.getMetadataFacets( , TEST_REPO_ID, AuditEvent.FACET_ID ) ).andReturn(
eventNames.get( TEST_REPO_ID ) );
- EasyMock.expect( metadataRepository.getMetadataFacets( TEST_REPO_ID_2, AuditEvent.FACET_ID ) ).andReturn(
+ EasyMock.expect( metadataRepository.getMetadataFacets( , TEST_REPO_ID_2, AuditEvent.FACET_ID ) ).andReturn(
eventNames.get( TEST_REPO_ID_2 ) );
for ( AuditEvent event : events.subList( 1, events.size() ) )
{
- EasyMock.expect( metadataRepository.getMetadataFacet( event.getRepositoryId(), AuditEvent.FACET_ID,
- event.getName() ) ).andReturn( event );
+ EasyMock.expect( metadataRepository.getMetadataFacet( , event.getRepositoryId(),
+ AuditEvent.FACET_ID, event.getName() ) ).andReturn( event );
}
metadataRepositoryControl.replay();
@@ -218,7 +218,7 @@ public class AuditManagerTest
{
- EasyMock.expect( metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ) ).andReturn(
+ EasyMock.expect( metadataRepository.getMetadataFacets( , TEST_REPO_ID, AuditEvent.FACET_ID ) ).andReturn(
Collections.<String>emptyList() );
metadataRepositoryControl.replay();
@@ -235,7 +235,7 @@ public class AuditManagerTest
{
AuditEvent event = createEvent( new Date() );
- metadataRepository.addMetadataFacet( TEST_REPO_ID, event );
+ metadataRepository.addMetadataFacet( , TEST_REPO_ID, event );
metadataRepositoryControl.replay();
@@ -265,7 +265,7 @@ public class AuditManagerTest
throws Exception
{
- metadataRepository.removeMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID );
+ metadataRepository.removeMetadataFacets( , TEST_REPO_ID, AuditEvent.FACET_ID );
metadataRepositoryControl.replay();
@@ -286,12 +286,12 @@ public class AuditManagerTest
AuditEvent expectedEvent = createEvent( expectedTimestamp );
AuditEvent event3 = createEvent( new Date( current.getTime() - 1000 ) );
- EasyMock.expect( metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ) ).andReturn(
+ EasyMock.expect( metadataRepository.getMetadataFacets( , TEST_REPO_ID, AuditEvent.FACET_ID ) ).andReturn(
Arrays.asList( event1.getName(), expectedEvent.getName(), event3.getName() ) );
// only match the middle one
- EasyMock.expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID,
- expectedEvent.getName() ) ).andReturn( expectedEvent );
+ EasyMock.expect( metadataRepository.getMetadataFacet( , TEST_REPO_ID,
+ AuditEvent.FACET_ID, expectedEvent.getName() ) ).andReturn( expectedEvent );
metadataRepositoryControl.replay();
@@ -318,13 +318,13 @@ public class AuditManagerTest
Date ts3 = new Date( current.getTime() - 1000 );
AuditEvent expectedEvent3 = createEvent( ts3 );
- EasyMock.expect( metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ) ).andReturn(
+ EasyMock.expect( metadataRepository.getMetadataFacets( , TEST_REPO_ID, AuditEvent.FACET_ID ) ).andReturn(
Arrays.asList( event1.getName(), expectedEvent2.getName(), expectedEvent3.getName() ) );
- EasyMock.expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID,
- expectedEvent2.getName() ) ).andReturn( expectedEvent2 );
- EasyMock.expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID,
- expectedEvent3.getName() ) ).andReturn( expectedEvent3 );
+ EasyMock.expect( metadataRepository.getMetadataFacet( , TEST_REPO_ID,
+ AuditEvent.FACET_ID, expectedEvent2.getName() ) ).andReturn( expectedEvent2 );
+ EasyMock.expect( metadataRepository.getMetadataFacet( , TEST_REPO_ID,
+ AuditEvent.FACET_ID, expectedEvent3.getName() ) ).andReturn( expectedEvent3 );
metadataRepositoryControl.replay();
List<AuditEvent> events =
@@ -350,14 +350,14 @@ public class AuditManagerTest
AuditEvent expectedEvent2 = createEvent( expectedTimestamp );
AuditEvent event3 = createEvent( new Date( current.getTime() - 1000 ) );
- EasyMock.expect( metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ) ).andReturn(
+ EasyMock.expect( metadataRepository.getMetadataFacets( , TEST_REPO_ID, AuditEvent.FACET_ID ) ).andReturn(
Arrays.asList( expectedEvent1.getName(), expectedEvent2.getName(), event3.getName() ) );
- EasyMock.expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID,
- expectedEvent1.getName() ) ).andReturn( expectedEvent1 );
+ EasyMock.expect( metadataRepository.getMetadataFacet( , TEST_REPO_ID,
+ AuditEvent.FACET_ID, expectedEvent1.getName() ) ).andReturn( expectedEvent1 );
- EasyMock.expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID,
- expectedEvent2.getName() ) ).andReturn( expectedEvent2 );
+ EasyMock.expect( metadataRepository.getMetadataFacet( , TEST_REPO_ID,
+ AuditEvent.FACET_ID, expectedEvent2.getName() ) ).andReturn( expectedEvent2 );
metadataRepositoryControl.replay();
@@ -386,17 +386,17 @@ public class AuditManagerTest
Date ts3 = new Date( current.getTime() - 1000 );
AuditEvent expectedEvent3 = createEvent( ts3 );
- EasyMock.expect( metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ) ).andReturn(
+ EasyMock.expect( metadataRepository.getMetadataFacets( , TEST_REPO_ID, AuditEvent.FACET_ID ) ).andReturn(
Arrays.asList( expectedEvent1.getName(), expectedEvent2.getName(), expectedEvent3.getName() ) );
- EasyMock.expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID,
- expectedEvent1.getName() ) ).andReturn( expectedEvent1 );
+ EasyMock.expect( metadataRepository.getMetadataFacet( , TEST_REPO_ID,
+ AuditEvent.FACET_ID, expectedEvent1.getName() ) ).andReturn( expectedEvent1 );
- EasyMock.expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID,
- expectedEvent2.getName() ) ).andReturn( expectedEvent2 );
+ EasyMock.expect( metadataRepository.getMetadataFacet( , TEST_REPO_ID,
+ AuditEvent.FACET_ID, expectedEvent2.getName() ) ).andReturn( expectedEvent2 );
- EasyMock.expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID,
- expectedEvent3.getName() ) ).andReturn( expectedEvent3 );
+ EasyMock.expect( metadataRepository.getMetadataFacet( , TEST_REPO_ID,
+ AuditEvent.FACET_ID, expectedEvent3.getName() ) ).andReturn( expectedEvent3 );
metadataRepositoryControl.replay();
List<AuditEvent> events =
@@ -426,18 +426,18 @@ public class AuditManagerTest
AuditEvent expectedEvent3 = createEvent( ts3 );
- EasyMock.expect( metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ) ).andReturn(
+ EasyMock.expect( metadataRepository.getMetadataFacets( , TEST_REPO_ID, AuditEvent.FACET_ID ) ).andReturn(
Arrays.asList( expectedEvent1.getName(), expectedEvent2.getName(), expectedEvent3.getName() ) );
- EasyMock.expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID,
- expectedEvent1.getName() ) ).andReturn( expectedEvent1 );
+ EasyMock.expect( metadataRepository.getMetadataFacet( , TEST_REPO_ID,
+ AuditEvent.FACET_ID, expectedEvent1.getName() ) ).andReturn( expectedEvent1 );
- EasyMock.expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID,
- expectedEvent2.getName() ) ).andReturn( expectedEvent2 );
+ EasyMock.expect( metadataRepository.getMetadataFacet( , TEST_REPO_ID,
+ AuditEvent.FACET_ID, expectedEvent2.getName() ) ).andReturn( expectedEvent2 );
- EasyMock.expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID,
- expectedEvent3.getName() ) ).andReturn( expectedEvent3 );
+ EasyMock.expect( metadataRepository.getMetadataFacet( , TEST_REPO_ID,
+ AuditEvent.FACET_ID, expectedEvent3.getName() ) ).andReturn( expectedEvent3 );
metadataRepositoryControl.replay();
List<AuditEvent> events =
@@ -464,15 +464,15 @@ public class AuditManagerTest
AuditEvent expectedEvent3 = createEvent( new Date( current.getTime() - 1000 ) );
- EasyMock.expect( metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ) ).andReturn(
+ EasyMock.expect( metadataRepository.getMetadataFacets( , TEST_REPO_ID, AuditEvent.FACET_ID ) ).andReturn(
Arrays.asList( expectedEvent1.getName(), expectedEvent2.getName(), expectedEvent3.getName() ) );
- EasyMock.expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent1.getName() ) ).andReturn( expectedEvent1 );
+ EasyMock.expect( metadataRepository.getMetadataFacet( , TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent1.getName() ) ).andReturn( expectedEvent1 );
- EasyMock.expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent2.getName() ) ).andReturn( expectedEvent2 );
+ EasyMock.expect( metadataRepository.getMetadataFacet( , TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent2.getName() ) ).andReturn( expectedEvent2 );
- EasyMock.expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent3.getName() ) ).andReturn( expectedEvent3 );
+ EasyMock.expect( metadataRepository.getMetadataFacet( , TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent3.getName() ) ).andReturn( expectedEvent3 );
metadataRepositoryControl.replay();
@@ -500,20 +500,20 @@ public class AuditManagerTest
AuditEvent expectedEvent3 = createEvent( ts3 );
- EasyMock.expect( metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ) )
+ EasyMock.expect( metadataRepository.getMetadataFacets( , TEST_REPO_ID, AuditEvent.FACET_ID ) )
.andReturn( Arrays.asList( expectedEvent1.getName(), expectedEvent3.getName() ) );
- EasyMock.expect( metadataRepository.getMetadataFacets( TEST_REPO_ID_2, AuditEvent.FACET_ID ) )
+ EasyMock.expect( metadataRepository.getMetadataFacets( , TEST_REPO_ID_2, AuditEvent.FACET_ID ) )
.andReturn( Arrays.asList( expectedEvent2.getName() ) );
- EasyMock.expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent1.getName() ) )
+ EasyMock.expect( metadataRepository.getMetadataFacet( , TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent1.getName() ) )
.andReturn( expectedEvent1 );
- EasyMock.expect( metadataRepository.getMetadataFacet( TEST_REPO_ID_2, AuditEvent.FACET_ID, expectedEvent2.getName() ) )
+ EasyMock.expect( metadataRepository.getMetadataFacet( , TEST_REPO_ID_2, AuditEvent.FACET_ID, expectedEvent2.getName() ) )
.andReturn( expectedEvent2 );
- EasyMock.expect( metadataRepository.getMetadataFacet( TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent3.getName() ) )
+ EasyMock.expect( metadataRepository.getMetadataFacet( , TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent3.getName() ) )
.andReturn( expectedEvent3 );
metadataRepositoryControl.replay();
@@ -542,7 +542,7 @@ public class AuditManagerTest
String name2 = createEvent( expectedTimestamp ).getName();
String name3 = createEvent( new Date( current.getTime() - 1000 ) ).getName();
- EasyMock.expect( metadataRepository.getMetadataFacets( TEST_REPO_ID, AuditEvent.FACET_ID ) )
+ EasyMock.expect( metadataRepository.getMetadataFacets( , TEST_REPO_ID, AuditEvent.FACET_ID ) )
.andReturn( Arrays.asList( name1, name2, name3 ) );
metadataRepositoryControl.replay();