From af33a147e39cf2318f5df562a2824a48a78a52c3 Mon Sep 17 00:00:00 2001 From: Craig Tan Date: Tue, 10 Sep 2013 06:39:18 +0000 Subject: [PATCH] RM-936 Audit is producing too many 'object edited' entries. - To eliminate multiple audit maps from being generated when events with the same name are required to be fired multiple times in the same transaction, the code checks on existing auditedNode stacked for the same combination of nodeRef and eventName. If there exists such an auditNode, update its 'after' properties with the latest set of properties and leave its 'before' properties unchanged so that it retains the original set of properties. The first 'before' and last 'after' will be diff'ed when comes to building the auditMap later when the transaction commits. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@55154 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../RecordsManagementAuditServiceImpl.java | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/audit/RecordsManagementAuditServiceImpl.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/audit/RecordsManagementAuditServiceImpl.java index d8218b0595..d433ff7ca2 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/audit/RecordsManagementAuditServiceImpl.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/audit/RecordsManagementAuditServiceImpl.java @@ -433,13 +433,33 @@ public class RecordsManagementAuditServiceImpl extends AbstractLifecycleBean Set auditDetails = TransactionalResourceHelper.getSet(KEY_RM_AUDIT_NODE_RECORDS); AlfrescoTransactionSupport.bindListener(txnListener); - RMAuditNode auditedNode = new RMAuditNode(); - auditedNode.setNodeRef(nodeRef); - auditedNode.setEventName(eventName); - auditedNode.setNodePropertiesBefore(before); - auditedNode.setNodePropertiesAfter(after); - - auditDetails.add(auditedNode); + // RM-936: Eliminate multiple audit maps from being generated when events with the same name are required to be fired multiple times in the same transaction. + // Check if auditDetails already contains an auditedNode with the same combination of nodeRef and eventName. + boolean auditNodeAlreadyExists = false; + for (RMAuditNode existingRMAuditNode : auditDetails) + { + if (existingRMAuditNode.getNodeRef().equals(nodeRef) && existingRMAuditNode.getEventName().equals(eventName)) + { + // If there exists such an auditNode, update its 'after' properties with the latest set of properties and leave its 'before' properties unchanged so that it + // retains the original set of properties. The first 'before' and last 'after' will be diff'ed when comes to building the auditMap later when the transaction + // commits. + existingRMAuditNode.setNodePropertiesAfter(after); + auditNodeAlreadyExists = true; + break; + } + } + + if (auditNodeAlreadyExists == false) + { + // Create a new auditNode if it doesn't already exist + RMAuditNode auditedNode = new RMAuditNode(); + auditedNode.setNodeRef(nodeRef); + auditedNode.setEventName(eventName); + auditedNode.setNodePropertiesBefore(before); + auditedNode.setNodePropertiesAfter(after); + + auditDetails.add(auditedNode); + } } }