04-16-2024 04:48 AM
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.
04-17-2024 09:11 AM
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.
04-17-2024 11:47 AM
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.
04-18-2024 04:49 AM
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.
04-17-2024 10:03 AM
In your Java action you can retrieve the primary parent related to the current node where the action is executed following these steps:
//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
Explore our Alfresco products with the links below. Use labels to filter content by product module.