Conditionally disable/enable Auditable Aspect onCreateAssociation()

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Member II

Conditionally disable/enable Auditable Aspect onCreateAssociation()

I need to be able to disable the auditable aspect when creating associations so that I can manually set the modified property on the source and target nodes. However, I do not always want this behavior. I need to be able to disable the auditable aspect for some associations and not others. This would be dependent on the REST endpoint that is called and not the content itself.

Is there a way to do this?

3 Replies
Highlighted
Moderator
Moderator

Re: Conditionally disable/enable Auditable Aspect onCreateAssociation()

You can use org.alfresco.repo.policy.BehaviourFilter class to handle this case. It contract disabling and enabling policy behaviours.

In your behavior where you have implemented onCreateAssociation() method, you can add a check based on your requirement and call below method:

policyBehaviourFilter.disableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);

You can look at this project for reference, it has example of disabling aspect: https://github.com/aborroy/auditable-aspect-disable/blob/master/src/main/java/org/alfresco/behaviour...

~Abhinav
(ACSCE, AWS SAA-C02, GAIQ)
Highlighted
Member II

Re: Conditionally disable/enable Auditable Aspect onCreateAssociation()

Thank you for the reply. Unfortunately this does not get me exactly what I need. Basically I am simply attempting to prevent Alfresco from setting the cm:modified property on a node. I want to be able to set that property myself so that I can save multiple nodes that all share the same cm:modfied time.

From what I can tell, onCreateAssocation() acts as an event listener, getting called every time nodeService.createAssociation() is invoked.  What I would like to do is disable the auditable behavior from my code when I call nodeService.createAssociation() so that I can manually set the cm:modified time. It doesn't seem like I can do much from within the onCreateAssociation() method because it only takes an AssociationRef as a parameter. 

Is there a way to simply disable the auditable behavior one time and have it remain off indefinitely?

Highlighted
Moderator
Moderator

Re: Conditionally disable/enable Auditable Aspect onCreateAssociation()

You can still use org.alfresco.repo.policy.BehaviourFilter anywhere in your code to disable/enable auditable aspect. 

For example:

LOGGER.debug("Disabling auditable behaviour for node {}", srcNodeRef);
behaviourFilter.disableBehaviour(srcNodeRef, ContentModel.ASPECT_AUDITABLE);

//Creating an association
nodeService.createAssociation(srcNodeRef, targetNodeRef, MyContentModel.ASSOC_SupportDoc); 

// Enabling AUDITABLE ASPECT Behaviour for this node
LOGGER.debug("Enabling auditable behaviour for node {}", srcNodeRef);
behaviourFilter.enableBehaviour(srcNodeRef, ContentModel.ASPECT_AUDITABLE);

Your custom code could be as per your usecase but above code shows an example to disabling and enabling auditable aspect on a selected node.

Is there a way to simply disable the auditable behavior one time and have it remain off indefinitely? -- May be NO. 

Auditable aspect remains disabled during the same transaction until you enable it. In a new transaction it will be enabled until you disable it again on the same node.

~Abhinav
(ACSCE, AWS SAA-C02, GAIQ)