Deleting Audit Entries (Logs) for an Audit Application - Alfresco Content Services - 23.4 - 23.4 - Ready - Alfresco - external

Alfresco Content Services

Platform
Alfresco
Product
Alfresco Content Services
Release
23.4
License

Deleting audit logs for an audit app uses the deleteAuditEntriesForAuditApp method of the AuditApi.

For more information about this ReST API endpoint, see Delete Audit Entries (Logs) for an Audit Application.

For a description of the common parameters, such as where, see Common Parameters.

import org.alfresco.core.handler.AuditApi;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class DeleteAuditLogsForAppCmd {
    static final Logger LOGGER = LoggerFactory.getLogger(DeleteAuditLogsForAppCmd.class);

    @Autowired
    AuditApi auditApi;

    public void execute(String auditAppId) throws IOException {
        // Delete all logs with ids between 1 and 79
        String where = "(id BETWEEN ('1', '79'))";

        HttpEntity<Void> response = auditApi.deleteAuditEntriesForAuditApp(auditAppId, where);
        LOGGER.info("Deleted audit logs for app {} where {} response {}", auditAppId, where, response);
    }
}

Note that you have to supply a where clause to be able to delete any audit logs.

Executing this code will delete audit logs for passed in audit app id and where clause:

% java -jar target/rest-api-0.0.1-SNAPSHOT.jar delete-audit-logs-for-app alfresco-access

2021-05-10 10:05:22.248  INFO 51942 --- [           main] o.a.tutorial.restapi.RestApiApplication  : Started RestApiApplication in 4.116 seconds (JVM running for 4.615)
2021-05-10 10:05:22.250  INFO 51942 --- [           main] o.a.tutorial.restapi.RestApiApplication  : args[0]: delete-audit-logs-for-app
2021-05-10 10:05:22.251  INFO 51942 --- [           main] o.a.tutorial.restapi.RestApiApplication  : args[1]: alfresco-access
2021-05-10 10:05:22.357  INFO 51942 --- [           main] o.a.t.restapi.DeleteAuditLogsForAppCmd   : Deleted audit logs for app alfresco-access where (id BETWEEN ('1', '79')) response <204 NO_CONTENT No Content,[cache-control:"no-cache", connection:"keep-alive", content-type:"application/json;charset=UTF-8", date:"Mon, 10 May 2021 09:05:22 GMT", expires:"Thu, 01 Jan 1970 00:00:00 GMT", pragma:"no-cache", server:"nginx/1.18.0", x-frame-options:"SAMEORIGIN"]