diff --git a/config/alfresco/ibatis/org.hibernate.dialect.Dialect/audit-common-SqlMap.xml b/config/alfresco/ibatis/org.hibernate.dialect.Dialect/audit-common-SqlMap.xml index 13970d1188..f5ed597d55 100644 --- a/config/alfresco/ibatis/org.hibernate.dialect.Dialect/audit-common-SqlMap.xml +++ b/config/alfresco/ibatis/org.hibernate.dialect.Dialect/audit-common-SqlMap.xml @@ -149,6 +149,12 @@ + + = #{auditFromId}]]> + + + + diff --git a/source/java/org/alfresco/repo/audit/AuditComponent.java b/source/java/org/alfresco/repo/audit/AuditComponent.java index 01b29b8716..036d77d5d2 100644 --- a/source/java/org/alfresco/repo/audit/AuditComponent.java +++ b/source/java/org/alfresco/repo/audit/AuditComponent.java @@ -1,34 +1,34 @@ -/* - * #%L - * Alfresco Repository - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - * #L% - */ +/* + * #%L + * Alfresco Repository + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ package org.alfresco.repo.audit; import java.io.Serializable; import java.util.List; import java.util.Map; - + import org.alfresco.repo.audit.model.AuditApplication; import org.alfresco.repo.audit.model.AuditModelRegistry; import org.alfresco.repo.audit.model._3.AuditPath; @@ -108,7 +108,7 @@ public interface AuditComponent /** * Delete audit entries for the given application and time range * - * @param applicationName the name of the application being logged to + * @param applicationName the name of the application * @param fromTime the start time of entries to remove (inclusive and optional) * @param toTime the end time of entries to remove (exclusive and optional) * @return Returns the number of entries deleted @@ -116,7 +116,19 @@ public interface AuditComponent * @since 3.2 */ int deleteAuditEntries(String applicationName, Long fromTime, Long toTime); - + + /** + * Delete audit entries for the given application and id range + * + * @param applicationName the name of the application + * @param fromId the start time of entries to remove (inclusive and optional) + * @param toId the end time of entries to remove (exclusive and optional) + * @return Returns the number of entries deleted + * + * @since 5.2.2 + */ + int deleteAuditEntriesByIdRange(String applicationName, Long fromId, Long toId); + /** * Delete a discrete list of audit entries based on ID * @@ -232,9 +244,9 @@ public interface AuditComponent * * @param callback the data callback per entry * @param parameters the parameters for the query (may not be null) - * @param maxResults the maximum number of results to retrieve (must be greater than 0) - * - * @throws IllegalArgumentException if maxResults less or equal to zero + * @param maxResults the maximum number of results to retrieve (must be greater than 0) + * + * @throws IllegalArgumentException if maxResults less or equal to zero * * @since 3.2 */ diff --git a/source/java/org/alfresco/repo/audit/AuditComponentImpl.java b/source/java/org/alfresco/repo/audit/AuditComponentImpl.java index 98325ffccc..ce0788acc4 100644 --- a/source/java/org/alfresco/repo/audit/AuditComponentImpl.java +++ b/source/java/org/alfresco/repo/audit/AuditComponentImpl.java @@ -148,21 +148,12 @@ public class AuditComponentImpl implements AuditComponent */ public int deleteAuditEntries(String applicationName, Long fromTime, Long toTime) { - ParameterCheck.mandatory("applicationName", applicationName); - AlfrescoTransactionSupport.checkTransactionReadState(true); - - AuditApplication application = auditModelRegistry.getAuditApplicationByName(applicationName); - if (application == null) + Long applicationId = getApplicationId(applicationName); + if (applicationId == null) { - if (logger.isDebugEnabled()) - { - logger.debug("No audit application named '" + applicationName + "' has been registered."); - } return 0; } - - Long applicationId = application.getApplicationId(); - + int deleted = auditDAO.deleteAuditEntries(applicationId, fromTime, toTime); // Done if (logger.isDebugEnabled()) @@ -174,6 +165,47 @@ public class AuditComponentImpl implements AuditComponent return deleted; } + /** + * {@inheritDoc} + * @since 5.2.2 + */ + public int deleteAuditEntriesByIdRange(String applicationName, Long fromId, Long toId) + { + Long applicationId = getApplicationId(applicationName); + if (applicationId == null) + { + return 0; + } + + int deleted = auditDAO.deleteAuditEntriesByIdRange(applicationId, fromId, toId); + // Done + if (logger.isDebugEnabled()) + { + logger.debug( + "Delete audit " + deleted + " entries for " + applicationName + + " (" + fromId + " to " + toId); + } + return deleted; + } + + private Long getApplicationId(String applicationName) + { + ParameterCheck.mandatory("applicationName", applicationName); + AlfrescoTransactionSupport.checkTransactionReadState(true); + + AuditApplication application = auditModelRegistry.getAuditApplicationByName(applicationName); + if (application == null) + { + if (logger.isDebugEnabled()) + { + logger.debug("No audit application named '" + applicationName + "' has been registered."); + } + return null; + } + + return application.getApplicationId(); + } + /** * {@inheritDoc} * @since 3.2 diff --git a/source/java/org/alfresco/repo/audit/AuditServiceImpl.java b/source/java/org/alfresco/repo/audit/AuditServiceImpl.java index 48e6eb72b8..7cc8903184 100644 --- a/source/java/org/alfresco/repo/audit/AuditServiceImpl.java +++ b/source/java/org/alfresco/repo/audit/AuditServiceImpl.java @@ -1,28 +1,28 @@ -/* - * #%L - * Alfresco Repository - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - * #L% - */ +/* + * #%L + * Alfresco Repository + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ package org.alfresco.repo.audit; import java.util.List; @@ -140,6 +140,16 @@ public class AuditServiceImpl implements AuditService return auditComponent.deleteAuditEntries(applicationName, fromTime, toTime); } + /** + * {@inheritDoc} + * @since 5.2.2 + */ + @Override + public int clearAuditByIdRange(String applicationName, Long fromId, Long toId) + { + return auditComponent.deleteAuditEntriesByIdRange(applicationName, fromId, toId); + } + /** * {@inheritDoc} * @since 3.4 diff --git a/source/java/org/alfresco/repo/domain/audit/AuditDAO.java b/source/java/org/alfresco/repo/domain/audit/AuditDAO.java index 3ba1cbaeaa..490379af0e 100644 --- a/source/java/org/alfresco/repo/domain/audit/AuditDAO.java +++ b/source/java/org/alfresco/repo/domain/audit/AuditDAO.java @@ -1,28 +1,28 @@ -/* - * #%L - * Alfresco Repository - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - * #L% - */ +/* + * #%L + * Alfresco Repository + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ package org.alfresco.repo.domain.audit; import java.io.Serializable; @@ -30,7 +30,7 @@ import java.net.URL; import java.util.List; import java.util.Map; import java.util.Set; - + import org.alfresco.service.cmr.audit.AuditService.AuditQueryCallback; import org.alfresco.service.cmr.repository.ContentData; import org.alfresco.util.Pair; @@ -110,13 +110,13 @@ public interface AuditDAO } } - /** - * Creates a new audit model entry or finds an existing one - * - * @param url the URL of the configuration - * @return Returns the ID of the config matching the input stream and the - * content storage details - * @since 3.2 + /** + * Creates a new audit model entry or finds an existing one + * + * @param url the URL of the configuration + * @return Returns the ID of the config matching the input stream and the + * content storage details + * @since 3.2 */ Pair getOrCreateAuditModel(URL url); @@ -165,15 +165,27 @@ public interface AuditDAO /** * Delete audit entries for the application, possibly limiting the time range. * - * @param applicationId and existing audit application ID - * @param from the minimum entry time (inclusive, optional) - * @param to the maximum entry time (exclusive, optional) + * @param applicationId an existing audit application ID + * @param fromTime the minimum entry time (inclusive, optional) + * @param toTime the maximum entry time (exclusive, optional) * @return Returns the number of entries deleted * * @since 3.2 */ - int deleteAuditEntries(Long applicationId, Long from, Long to); - + int deleteAuditEntries(Long applicationId, Long fromTime, Long toTime); + + /** + * Delete audit entries for the application for given id range. + * + * @param applicationId an existing audit application ID + * @param fromId the minimum fromId (inclusive, optional) + * @param toId the maximum toId (exclusive, optional) + * @return Returns the number of entries deleted + * + * @since 5.2.2 + */ + int deleteAuditEntriesByIdRange(Long applicationId, Long fromId, Long toId); + /** * Delete a discrete list of audit entries. Duplicate entries are collapsed * and the number of entries deleted will match the count of unique IDs in @@ -203,9 +215,9 @@ public interface AuditDAO * * @param callback the data callback per entry * @param parameters the parameters for the query (may not be null) - * @param maxResults the maximum number of results to retrieve (must be greater than 0) - * - * @throws IllegalArgumentException if maxResults less or equal to zero + * @param maxResults the maximum number of results to retrieve (must be greater than 0) + * + * @throws IllegalArgumentException if maxResults less or equal to zero */ void findAuditEntries( AuditQueryCallback callback, diff --git a/source/java/org/alfresco/repo/domain/audit/AuditDeleteParameters.java b/source/java/org/alfresco/repo/domain/audit/AuditDeleteParameters.java index 44f00d2b45..ef772d439e 100644 --- a/source/java/org/alfresco/repo/domain/audit/AuditDeleteParameters.java +++ b/source/java/org/alfresco/repo/domain/audit/AuditDeleteParameters.java @@ -1,28 +1,28 @@ -/* - * #%L - * Alfresco Repository - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - * #L% - */ +/* + * #%L + * Alfresco Repository + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ package org.alfresco.repo.domain.audit; import java.util.Date; @@ -39,6 +39,8 @@ public class AuditDeleteParameters private Long auditApplicationId; private Long auditFromTime; private Long auditToTime; + private Long auditFromId; + private Long auditToId; private List auditEntryIds; public AuditDeleteParameters() @@ -53,6 +55,8 @@ public class AuditDeleteParameters .append("[ auditApplicationId=").append(auditApplicationId) .append(", auditFromTime").append(auditFromTime == null ? null : new Date(auditFromTime)) .append(", auditToTime").append(auditToTime == null ? null : new Date(auditToTime)) + .append(", auditFromId").append(auditFromId) + .append(", auditToId").append(auditToId) .append(", auditEntryIds").append(auditEntryIds == null ? null : auditEntryIds.size()) .append("]"); return sb.toString(); @@ -88,6 +92,26 @@ public class AuditDeleteParameters this.auditToTime = auditToTime; } + public Long getAuditFromId() + { + return auditFromId; + } + + public void setAuditFromId(Long auditFromId) + { + this.auditFromId = auditFromId; + } + + public Long getAuditToId() + { + return auditToId; + } + + public void setAuditToId(Long auditToId) + { + this.auditToId = auditToId; + } + public List getAuditEntryIds() { return auditEntryIds; diff --git a/source/java/org/alfresco/repo/domain/audit/ibatis/AuditDAOImpl.java b/source/java/org/alfresco/repo/domain/audit/ibatis/AuditDAOImpl.java index 2342dd2522..38a80a5ee2 100644 --- a/source/java/org/alfresco/repo/domain/audit/ibatis/AuditDAOImpl.java +++ b/source/java/org/alfresco/repo/domain/audit/ibatis/AuditDAOImpl.java @@ -1,47 +1,47 @@ -/* - * #%L - * Alfresco Repository - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - * #L% - */ +/* + * #%L + * Alfresco Repository + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ package org.alfresco.repo.domain.audit.ibatis; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.alfresco.repo.domain.audit.AbstractAuditDAOImpl; -import org.alfresco.repo.domain.audit.AuditApplicationEntity; -import org.alfresco.repo.domain.audit.AuditDeleteParameters; -import org.alfresco.repo.domain.audit.AuditEntryEntity; -import org.alfresco.repo.domain.audit.AuditModelEntity; -import org.alfresco.repo.domain.audit.AuditQueryParameters; -import org.alfresco.repo.domain.audit.AuditQueryResult; -import org.alfresco.repo.domain.propval.PropertyValueDAO.PropertyFinderCallback; -import org.alfresco.util.Pair; -import org.apache.ibatis.session.RowBounds; -import org.mybatis.spring.SqlSessionTemplate; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.alfresco.repo.domain.audit.AbstractAuditDAOImpl; +import org.alfresco.repo.domain.audit.AuditApplicationEntity; +import org.alfresco.repo.domain.audit.AuditDeleteParameters; +import org.alfresco.repo.domain.audit.AuditEntryEntity; +import org.alfresco.repo.domain.audit.AuditModelEntity; +import org.alfresco.repo.domain.audit.AuditQueryParameters; +import org.alfresco.repo.domain.audit.AuditQueryResult; +import org.alfresco.repo.domain.propval.PropertyValueDAO.PropertyFinderCallback; +import org.alfresco.util.Pair; +import org.apache.ibatis.session.RowBounds; +import org.mybatis.spring.SqlSessionTemplate; import org.springframework.dao.ConcurrencyFailureException; /** @@ -181,6 +181,15 @@ public class AuditDAOImpl extends AbstractAuditDAOImpl return template.delete(DELETE_ENTRIES, params); } + public int deleteAuditEntriesByIdRange(Long applicationId, Long fromId, Long toId) + { + AuditDeleteParameters params = new AuditDeleteParameters(); + params.setAuditApplicationId(applicationId); + params.setAuditFromId(fromId); + params.setAuditToId(toId); + return template.delete(DELETE_ENTRIES, params); + } + @Override protected int deleteAuditEntriesImpl(List auditEntryIds) { @@ -312,8 +321,8 @@ public class AuditDAOImpl extends AbstractAuditDAOImpl } } else - { - throw new IllegalArgumentException("maxResults must be greater than 0"); + { + throw new IllegalArgumentException("maxResults must be greater than 0"); } } } diff --git a/source/java/org/alfresco/service/cmr/audit/AuditService.java b/source/java/org/alfresco/service/cmr/audit/AuditService.java index 892c4cfd93..85a2149764 100644 --- a/source/java/org/alfresco/service/cmr/audit/AuditService.java +++ b/source/java/org/alfresco/service/cmr/audit/AuditService.java @@ -1,33 +1,33 @@ -/* - * #%L - * Alfresco Repository - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - * #L% - */ +/* + * #%L + * Alfresco Repository + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ package org.alfresco.service.cmr.audit; -import java.io.Serializable; -import java.util.List; -import java.util.Map; +import java.io.Serializable; +import java.util.List; +import java.util.Map; /** * The public API by which applications can query the audit logs and enable or disable auditing. @@ -149,7 +149,19 @@ public interface AuditService * @since 3.4 */ int clearAudit(String applicationName, Long fromTime, Long toTime); - + + /** + * Remove audit entries for the given application between the audit entry ids. + * + * @param applicationName the name of the application for which to remove entries + * @param fromId the start time of entries to remove (inclusive and optional) + * @param toId the end time of entries to remove (exclusive and optional) + * @return Returns the number of audit entries deleted + * + * @since 5.2.2 + */ + int clearAuditByIdRange(String applicationName, Long fromId, Long toId); + /** * Delete a discrete list of audit entries. *

@@ -212,9 +224,9 @@ public interface AuditService * * @param callback the callback that will handle results * @param parameters the parameters for the query (may not be null) - * @param maxResults the maximum number of results to retrieve (must be greater than 0) - * - * @throws IllegalArgumentException if maxResults less or equal to zero + * @param maxResults the maximum number of results to retrieve (must be greater than 0) + * + * @throws IllegalArgumentException if maxResults less or equal to zero * * @since 3.3 */ diff --git a/source/test-java/org/alfresco/repo/audit/AuditComponentTest.java b/source/test-java/org/alfresco/repo/audit/AuditComponentTest.java index d746ad40a9..3ee846124c 100644 --- a/source/test-java/org/alfresco/repo/audit/AuditComponentTest.java +++ b/source/test-java/org/alfresco/repo/audit/AuditComponentTest.java @@ -684,12 +684,32 @@ public class AuditComponentTest extends TestCase logger.debug(sb.toString()); assertEquals("Incorrect number of audit entries after failed login", iterations, results.size()); - - // Check that we can delete explicit entries + + + Collections.sort(results); + long minId = results.get(0); + long maxId = results.get(100); + + List remainingResults = new ArrayList<>(results.subList(100, results.size())); + + // Check that we can delete entries based on range of ids long before = System.currentTimeMillis(); - deleteAuditEntries(results); + int deleted = deleteAuditEntries(APPLICATION_API_TEST, minId, maxId); System.out.println( - "Clearing " + results.size() + " entries by ID took " + (System.currentTimeMillis() - before) + "ms."); + "Clearing " + deleted + " entries by from/to ID took " + (System.currentTimeMillis() - before) + "ms."); + results.clear(); + sb.delete(0, sb.length()); + queryAuditLog(auditQueryCallback, params, Integer.MAX_VALUE); + logger.debug(sb.toString()); + assertEquals("Range of audit entries were not deleted", remainingResults.size(), results.size()); + + // delete the rest ... + + // Check that we can delete set of explicit entries + before = System.currentTimeMillis(); + deleteAuditEntries(remainingResults); + System.out.println( + "Clearing " + remainingResults.size() + " entries by set of IDs took " + (System.currentTimeMillis() - before) + "ms."); results.clear(); sb.delete(0, sb.length()); queryAuditLog(auditQueryCallback, params, Integer.MAX_VALUE); @@ -1081,7 +1101,7 @@ public class AuditComponentTest extends TestCase } /** - * Clearn the audit log as 'admin' + * Clear the audit log as 'admin' */ private void clearAuditLog(final String applicationName) { @@ -1098,7 +1118,7 @@ public class AuditComponentTest extends TestCase } /** - * Clearn the audit log as 'admin' + * Clear the audit log as 'admin' */ private void deleteAuditEntries(final List auditEntryIds) { @@ -1115,7 +1135,23 @@ public class AuditComponentTest extends TestCase } /** - * Clearn the audit log as 'admin' + * Clear the audit log as 'admin' + */ + private Integer deleteAuditEntries(final String applicationName, final long fromId, final long toId) + { + RunAsWork work = new RunAsWork() + { + @Override + public Integer doWork() throws Exception + { + return new Integer(auditService.clearAuditByIdRange(applicationName, fromId, toId)); + } + }; + return AuthenticationUtil.runAs(work, AuthenticationUtil.getAdminRoleName()); + } + + /** + * Query the audit log as 'admin' */ private void queryAuditLog(final AuditQueryCallback callback, final AuditQueryParameters parameters, final int maxResults) {