Hi All,
We have requirement were need to extract all Experience fragments details & its corresponding ID attribute present on it under a particular folder. Each and every Experience fragment consists of an unique ID attribute on them. Try with Query debugger but it fetches all XFs under a folder but not its ID, we require ID and its corresponding XF path details, need of groovy script to extract the details. Would really appreciate if anyone share there inputs on the same.
__PRESENT
Solved! Go to Solution.
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
Hi @rsl_lucky ,
try below snippet, update PROJECT_FOLDER with the folder name under which you need to get the fragments details. Here I'm getting jcr:uuid, if you have any specific property you can update the script accrodingly.
import javax.jcr.query.Query;
import javax.jcr.Node;
import java.util.List
import groovy.transform.Field
def query = createSQL2Query()
def result = query.execute();
def rows = result.rows
def total = 0
rows.each{ raw ->
Resource res = resourceResolver.getResource(raw.path)
Page page = pageManager.getContainingPage(res.path)
println raw.path
println page.getProperties().get("jcr:uuid", String.class)
total++
}
println "Total :: "+ total
def createSQL2Query(){
def queryManager = session.workspace.queryManager
def statement = "select page.[jcr:path] from [cq:Page] AS page INNER JOIN [cq:PageContent] AS jcrContent ON ISCHILDNODE(jcrContent, page) where ISDESCENDANTNODE(page, '/content/experience-fragments/{PROJECT_FOLDER}') and jcrContent.[jcr:uuid] IS NOT NULL";
//println statement
def query = queryManager.createQuery(statement,Query.JCR_SQL2)
query.setLimit(3000);
query.setOffset(0);
query
}
Hi @rsl_lucky ,
try below snippet, update PROJECT_FOLDER with the folder name under which you need to get the fragments details. Here I'm getting jcr:uuid, if you have any specific property you can update the script accrodingly.
import javax.jcr.query.Query;
import javax.jcr.Node;
import java.util.List
import groovy.transform.Field
def query = createSQL2Query()
def result = query.execute();
def rows = result.rows
def total = 0
rows.each{ raw ->
Resource res = resourceResolver.getResource(raw.path)
Page page = pageManager.getContainingPage(res.path)
println raw.path
println page.getProperties().get("jcr:uuid", String.class)
total++
}
println "Total :: "+ total
def createSQL2Query(){
def queryManager = session.workspace.queryManager
def statement = "select page.[jcr:path] from [cq:Page] AS page INNER JOIN [cq:PageContent] AS jcrContent ON ISCHILDNODE(jcrContent, page) where ISDESCENDANTNODE(page, '/content/experience-fragments/{PROJECT_FOLDER}') and jcrContent.[jcr:uuid] IS NOT NULL";
//println statement
def query = queryManager.createQuery(statement,Query.JCR_SQL2)
query.setLimit(3000);
query.setOffset(0);
query
}
Thanks @sravs for quick turn around on it. When ran the script can find few issues like in below screenshot.
Try to resolve the resource by addition of imports but it didn't resolve. Can you share inputs on it ?
Did some tweaks on it and can see the required results now. Thank you.
Views
Likes
Replies
Views
Likes
Replies