Search in sources :

Example 11 with AuditEvent

use of org.apache.archiva.metadata.model.facets.AuditEvent in project archiva by apache.

the class ArchivaDavResource method triggerAuditEvent.

private void triggerAuditEvent(DavResource member, String action) throws DavException {
    String path = logicalResource + "/" + member.getDisplayName();
    ArchivaDavResource resource = checkDavResourceIsArchivaDavResource(member);
    AuditEvent auditEvent = new AuditEvent(locator.getRepositoryId(), resource.principal, path, action);
    auditEvent.setRemoteIP(resource.remoteAddr);
    for (AuditListener listener : auditListeners) {
        listener.auditEvent(auditEvent);
    }
}
Also used : AuditEvent(org.apache.archiva.metadata.model.facets.AuditEvent) AuditListener(org.apache.archiva.repository.events.AuditListener)

Example 12 with AuditEvent

use of org.apache.archiva.metadata.model.facets.AuditEvent in project archiva by apache.

the class ArchivaDavResourceFactory method triggerAuditEvent.

// TODO: remove?
private void triggerAuditEvent(String remoteIP, String repositoryId, String resource, String action, String principal) {
    AuditEvent event = new AuditEvent(repositoryId, principal, resource, action);
    event.setRemoteIP(remoteIP);
    for (AuditListener listener : auditListeners) {
        listener.auditEvent(event);
    }
}
Also used : AuditEvent(org.apache.archiva.metadata.model.facets.AuditEvent) AuditListener(org.apache.archiva.repository.events.AuditListener)

Example 13 with AuditEvent

use of org.apache.archiva.metadata.model.facets.AuditEvent in project archiva by apache.

the class AbstractRestService method triggerAuditEvent.

protected void triggerAuditEvent(String repositoryId, String filePath, String action) {
    AuditEvent auditEvent = new AuditEvent(repositoryId, getPrincipal(), filePath, action);
    AuditInformation auditInformation = getAuditInformation();
    auditEvent.setUserId(auditInformation.getUser() == null ? "" : auditInformation.getUser().getUsername());
    auditEvent.setRemoteIP(auditInformation.getRemoteAddr());
    for (AuditListener auditListener : getAuditListeners()) {
        auditListener.auditEvent(auditEvent);
    }
}
Also used : AuditInformation(org.apache.archiva.admin.model.AuditInformation) AuditEvent(org.apache.archiva.metadata.model.facets.AuditEvent) AuditListener(org.apache.archiva.repository.events.AuditListener)

Example 14 with AuditEvent

use of org.apache.archiva.metadata.model.facets.AuditEvent in project archiva by apache.

the class DefaultAuditManager method getMostRecentAuditEvents.

@Override
public List<AuditEvent> getMostRecentAuditEvents(MetadataRepository metadataRepository, List<String> repositoryIds) throws MetadataRepositoryException {
    // TODO: consider a more efficient implementation that directly gets the last ten from the content repository
    List<AuditRecord> records = new ArrayList<>();
    for (String repositoryId : repositoryIds) {
        List<String> names = metadataRepository.getMetadataFacets(repositoryId, AuditEvent.FACET_ID);
        for (String name : names) {
            records.add(new AuditRecord(repositoryId, name));
        }
    }
    Collections.sort(records);
    records = records.subList(0, records.size() < NUM_RECENT_EVENTS ? records.size() : NUM_RECENT_EVENTS);
    List<AuditEvent> events = new ArrayList<>(records.size());
    for (AuditRecord record : records) {
        AuditEvent auditEvent = (AuditEvent) metadataRepository.getMetadataFacet(record.repositoryId, AuditEvent.FACET_ID, record.name);
        events.add(auditEvent);
    }
    return events;
}
Also used : ArrayList(java.util.ArrayList) AuditEvent(org.apache.archiva.metadata.model.facets.AuditEvent)

Example 15 with AuditEvent

use of org.apache.archiva.metadata.model.facets.AuditEvent in project archiva by apache.

the class AuditManagerTest method testGetMostRecentEventsLessThan10.

@Test
public void testGetMostRecentEventsLessThan10() throws Exception {
    int numEvents = 5;
    List<AuditEvent> expectedEvents = new ArrayList<>(numEvents);
    for (int i = 0; i < numEvents; i++) {
        expectedEvents.add(createEvent(AUDIT_EVENT_BASE + MILLIS_FORMAT.format(i)));
    }
    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(event);
    }
    metadataRepositoryControl.replay();
    List<AuditEvent> events = auditManager.getMostRecentAuditEvents(metadataRepository, Collections.singletonList(TEST_REPO_ID));
    assertNotNull(events);
    assertEquals(numEvents, events.size());
    int expectedTimestampCounter = numEvents - 1;
    for (AuditEvent event : events) {
        String num = MILLIS_FORMAT.format(expectedTimestampCounter);
        assertTestEvent(event, AUDIT_EVENT_BASE + num, getDefaultTestResourceName(num));
        expectedTimestampCounter--;
    }
    metadataRepositoryControl.verify();
}
Also used : ArrayList(java.util.ArrayList) AuditEvent(org.apache.archiva.metadata.model.facets.AuditEvent) Test(org.junit.Test)

Aggregations

AuditEvent (org.apache.archiva.metadata.model.facets.AuditEvent)21 Test (org.junit.Test)13 Date (java.util.Date)11 ArrayList (java.util.ArrayList)5 AuditListener (org.apache.archiva.repository.events.AuditListener)5 ParseException (java.text.ParseException)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 AuditInformation (org.apache.archiva.admin.model.AuditInformation)1 User (org.apache.archiva.redback.users.User)1