SAIL-390 (SAIL-294): NodeDAO: Allow cm:auditable to be set

- Added test and guard against client code wiping out cm:auditable by not passing in any values
 - If the cm:auditable behaviour is off and NO cm:auditable properties are passed in, then do nothing


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@21192 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2010-07-15 10:37:56 +00:00
parent 546fb81b59
commit 37e0b65814
2 changed files with 28 additions and 3 deletions

View File

@@ -39,6 +39,7 @@ import org.alfresco.service.namespace.QName;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.ApplicationContextHelper;
import org.alfresco.util.debug.NodeStoreInspector;
import org.apache.chemistry.tck.atompub.fixture.AssertNotExistVisitor;
import org.springframework.context.ApplicationContext;
/**
@@ -259,8 +260,12 @@ public class AuditableAspectTest extends TestCase
// Now modify the node so that the auditable values advance
nodeService.setProperty(nodeRef, ContentModel.PROP_FIRSTNAME, "TEST-FIRST-NAME-" + System.currentTimeMillis());
String modifiedBy = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_MODIFIER);
assertEquals(
"The modifier should have changed to reflect the current user",
AuthenticationUtil.getRunAsUser(), modifiedBy);
RetryingTransactionCallback<Void> setAuditableCallback = new RetryingTransactionCallback<Void>()
RetryingTransactionCallback<Void> setAuditableCallback1 = new RetryingTransactionCallback<Void>()
{
public Void execute() throws Throwable
{
@@ -272,7 +277,22 @@ public class AuditableAspectTest extends TestCase
return null;
}
};
transactionService.getRetryingTransactionHelper().doInTransaction(setAuditableCallback);
transactionService.getRetryingTransactionHelper().doInTransaction(setAuditableCallback1);
// Check
assertAuditableProperties(nodeRef, auditableProps);
RetryingTransactionCallback<Void> setAuditableCallback2 = new RetryingTransactionCallback<Void>()
{
public Void execute() throws Throwable
{
behaviourFilter.disableBehaviour(ContentModel.ASPECT_AUDITABLE); // Lasts for txn
// Set some other property and ensure that the cm:auditable does not change
nodeService.setProperty(nodeRef, ContentModel.PROP_FIRSTNAME, "TEST-FIRST-NAME-" + System.currentTimeMillis());
// Done
return null;
}
};
transactionService.getRetryingTransactionHelper().doInTransaction(setAuditableCallback2);
// Check
assertAuditableProperties(nodeRef, auditableProps);
}

View File

@@ -1600,7 +1600,12 @@ public abstract class AbstractNodeDAOImpl implements NodeDAO, BatchingDAO
if (!policyBehaviourFilter.isEnabled(node.getNodeRef(), ContentModel.ASPECT_AUDITABLE))
{
auditableProps = new AuditablePropertiesEntity();
auditableProps.setAuditValues(null, null, newProps);
boolean containedAuditProperties = auditableProps.setAuditValues(null, null, newProps);
if (!containedAuditProperties)
{
// The behaviour is disabled, but no audit properties were passed in
auditableProps = null;
}
}
// Remove cm:auditable