Deleting a single audit entry for an audit app uses the deleteAuditEntry method of the AuditApi.
For more information about this ReST API endpoint, see Delete an Audit Entry (Log) for an Audit Application.
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 DeleteAuditLogCmd { static final Logger LOGGER = LoggerFactory.getLogger(DeleteAuditLogCmd.class); @Autowired AuditApi auditApi; public void execute(String auditAppId, String auditLogId) throws IOException { HttpEntity<Void> response = auditApi.deleteAuditEntry(auditAppId, auditLogId); LOGGER.info("Deleted audit log: app {} log id {} response {}", auditAppId, auditLogId, response); } }
Executing this code will delete an audit log with passed in id for audit app with passed in id:
% java -jar target/rest-api-0.0.1-SNAPSHOT.jar delete-audit-log alfresco-access 80 2021-05-10 10:14:54.941 INFO 52102 --- [ main] o.a.tutorial.restapi.RestApiApplication : Started RestApiApplication in 3.736 seconds (JVM running for 4.24) 2021-05-10 10:14:54.943 INFO 52102 --- [ main] o.a.tutorial.restapi.RestApiApplication : args[0]: delete-audit-log 2021-05-10 10:14:54.944 INFO 52102 --- [ main] o.a.tutorial.restapi.RestApiApplication : args[1]: alfresco-access 2021-05-10 10:14:54.944 INFO 52102 --- [ main] o.a.tutorial.restapi.RestApiApplication : args[2]: 80 2021-05-10 10:14:55.050 INFO 52102 --- [ main] o.a.tutorial.restapi.DeleteAuditLogCmd : Deleted audit log: app alfresco-access log id 80 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:14:55 GMT", expires:"Thu, 01 Jan 1970 00:00:00 GMT", pragma:"no-cache", server:"nginx/1.18.0", x-frame-options:"SAMEORIGIN"]>