Is there any inbuilt method to check if dam: asset / any resource is Content fragment? | Community
Skip to main content
New Participant
January 16, 2023
Solved

Is there any inbuilt method to check if dam: asset / any resource is Content fragment?

  • January 16, 2023
  • 3 replies
  • 2357 views

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. 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Ankan_Ghosh

Hey @kajali 

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. 

3 replies

Ankan_Ghosh
Ankan_GhoshAccepted solution
New Participant
January 16, 2023

Hey @kajali 

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. 

KajalIAuthor
New Participant
January 17, 2023

Yes. Thanks!

Siva_Sogalapalli
New Participant
January 16, 2023

@kajali  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. 

New Participant
January 16, 2023
KajalIAuthor
New Participant
January 16, 2023

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 ?

New Participant
January 16, 2023

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