I am trying to put a condition in my code to check if given workitem ( in my custom workflow ) which is adapted in "resource" is whether content fragment or not.
I am not getting any specific method to do so.
For this I need to traverse to its jcr:cotnent and then check the property "content fragment" <boolean> is existed and if existed then whether value is true, which is making my code pretty big just to check if the resource is content fragment or not.
else if (workItemResource.adaptTo(ReplicationStatus.class).isDeactivated()
&& (workItemResource.adaptTo(Node.class).hasNode(JcrConstants.JCR_CONTENT)
&& workItemResource.adaptTo(Node.class).getNode(JcrConstants.JCR_CONTENT)
.hasProperty("contentFragment")
&& workItemResource.adaptTo(Node.class).getNode(JcrConstants.JCR_CONTENT)
.getProperty("contentFragment").equals(true)))
Please do let me know if any insights.
Solved! Go to Solution.
Views
Replies
Total Likes
Hey @KajalInamdarEy
So far, I am not aware of any method to check if an asset is content fragment or not . But we can traverse the "jcr:content" and find out if the "contentFragment" property exists and has a "true" value. You are probably doing this already.
Thanks for the reply. Really appreciate it.
Looking at this method ,it would only return if the resource is asset or not, how to determine whether its content fragment or not ?
To determine cf , am not sure of inbuilt method you can add custom method after checking isasset and iterating the path and check if it contains cq:model property.
Resource data = fragmentResource.getChild(JCR_CONTENT + "/data");
if (data == null || data.getValueMap().get("cq:model") == null) {
}
Thanks
@KajalInamdarEy It would be good to maintain all the content fragments in separate folder called content-fragments inside Assets folders instead of creating content fragments in regular assets folder.
Example folder structure: /content/dam/content-fragments/<folder structure as needed>
when you've different folder structure for regular assets, you can easily differentiate whether it's a CF or asset.
Incase if that's not possible at the moment in your case, then you can need to traverse to the jcr:content and check the property.
Hey @KajalInamdarEy
So far, I am not aware of any method to check if an asset is content fragment or not . But we can traverse the "jcr:content" and find out if the "contentFragment" property exists and has a "true" value. You are probably doing this already.
Yes. Thanks!