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.
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.
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
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.
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.
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.