How to know the folder which triggered action

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

How to know the folder which triggered action

Hello,

I'm using ECM 7.2 and I have a folder with a rule configured.

This rule triggers a custom java action and it can be configured in multiple folders.

Through the java API, when the action is running, is it possible to know which folder triggered this action?

-- EDIT

I forgot to mention that the rule is in a parent folder and has the option 'Apply to subfolders' checked. So, whenever this action is triggered, I would like to know if it was triggered in the most upper level folder or in one of its children.

 

4 Replies
robinp
Partner

Re: How to know the folder which triggered action

Hello,

Java actions usually have a method defined like this:

public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) { 
... your code ...
}

That "actionedUponNodeRef" is often a node child of your folder, so it should be easy for you to retrieve the parent folder(where the rule was triggered) using NodeService or similar.

I say "often" because there are cases where your rule is configured in a different way but you should apply this tip anyway for your scope.

openpj
Moderator
Moderator

Re: How to know the folder which triggered action

In your Java action you can retrieve the primary parent related to the current node where the action is executed following these steps:

  1. Get the primary parent from the current NodeRef returning a Child Association Reference
  2. Get the Parent Reference
  3. Store or log this information
//Assuming you are injecting the NodeService using Spring Dependency Injection
ChildAssociationRef childAssociationRef = nodeService.getPrimaryParent(actionedUponNodeRef); NodeRef parentRef = childAssociationRef.getParentRef(); log.info("Custom action triggered by folder node: " + parentRef);

Or if you want to display the path of the parent node see the following example:

//Assuming you are injecting the NodeService and the PermissionService using Spring Dependency Injection
Path currentPath = nodeService.getPath(actionedUponNodeRef);
String displayPath = currentPath.toDisplayPath(nodeService, permissionService); log.info("Custom action triggered from path: " + displayPath);

Hope this helps Smiley Wink

 

 

franciscoduarte
Member II

Re: How to know the folder which triggered action

Thanks for the answers. That really makes sense but I forgot to mention what I now added in the main post. This rule has the 'Apply to subfolders' option checked and what I really want to know is if it was triggered on the most upper level folder or in one of its subfolders.

robinp
Partner

Re: How to know the folder which triggered action

How do you want to know what is the folder where the rule triggered?

You can still use @openpj code snippets to log that folder.

If your problem is that you want to know the name of the folder you have to edit that code snippet in this way:

//Assuming you are injecting the NodeService using Spring Dependency Injection
ChildAssociationRef childAssociationRef = nodeService.getPrimaryParent(actionedUponNodeRef);
NodeRef parentRef = childAssociationRef.getParentRef();
String parentRefName = (String) nodeService.getProperty(parentRef, ContentModel.PROP_NAME);

log.info("Custom action triggered by folder " + parentRefName + " with nodeRef: " + parentRef);

 

Otherwise if you need to send this information somewhere else you should create a custom logic that sends it but still using this base mechanism inside your java action.