Execute workflow process step only if the payload is having only one level of child or no child.
otherwise display error message to author that "Node is having grand child pages"
Example :
Scene 1 [true]: if we pass payload : /content/we-retail/ca/en/experience/arctic-surfing-in-lofoten to workflow it will check the payload is having only one level of child, then execute the logic.
Scene 2 [true]: if we pass payload : /content/we-retail/ca/en/experience/arctic-surfing-in-lofoten/men to workflow it will check the payload is having only one level or no level of child, then execute the logic
Scene 3 [false]: if we pass payload : /content/we-retail/ca/en/experience to workflow it will check the payload is having only one level or no level of child, then execute the logic otherwise display error message to author that "Node is having grand child pages"
@Override
public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) throws WorkflowException {
String payload = workItem.getWorkflowData().getPayload().toString();
ResourceResolver resourceResolver = resourceResolverUtil.getResourceResolver();
Session session = resourceResolver.adaptTo(Session.class);
Page rootPage = resourceResolver.getResource(payload).adaptTo(Page.class);
//TODO check page is having only one level or no child and update the values.
if (rootPage != null && payload.startsWith(ROOT_PATH) && "Check if node is having one level or no child") {
// code logic here..
}
}
Thanks
@arunpatidar @lukasz-m @kautuk_sahni
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @Marcos_aem,
You can use getDepth() method from Page object and simply compare depth value of root and child pages. Here is a sample method that is doing it.
@Override
public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) throws WorkflowException {
String payload = workItem.getWorkflowData().getPayload().toString();
ResourceResolver resourceResolver = resourceResolverUtil.getResourceResolver();
Session session = resourceResolver.adaptTo(Session.class);
Page rootPage = resourceResolver.getResource(payload).adaptTo(Page.class);
//TODO check page is having only one level or no child and update the values.
if (rootPage != null && payload.startsWith(ROOT_PATH) && accept(rootPage)) {
// code logic here..
}
}
private boolean accept(Page rootPage) {
int rootPageDepth = rootPage.getDepth();
// getting entire strucutre of childeren, grandchildren etc
Iterator<Page> childPages = rootPage.listChildren(null, true);
while (childPages.hasNext()) {
Page page = childPages.next();
if (page.getDepth() - rootPageDepth > 1) {
return false;
}
}
return true;
}
Hi @Marcos_aem,
You can use getDepth() method from Page object and simply compare depth value of root and child pages. Here is a sample method that is doing it.
@Override
public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) throws WorkflowException {
String payload = workItem.getWorkflowData().getPayload().toString();
ResourceResolver resourceResolver = resourceResolverUtil.getResourceResolver();
Session session = resourceResolver.adaptTo(Session.class);
Page rootPage = resourceResolver.getResource(payload).adaptTo(Page.class);
//TODO check page is having only one level or no child and update the values.
if (rootPage != null && payload.startsWith(ROOT_PATH) && accept(rootPage)) {
// code logic here..
}
}
private boolean accept(Page rootPage) {
int rootPageDepth = rootPage.getDepth();
// getting entire strucutre of childeren, grandchildren etc
Iterator<Page> childPages = rootPage.listChildren(null, true);
while (childPages.hasNext()) {
Page page = childPages.next();
if (page.getDepth() - rootPageDepth > 1) {
return false;
}
}
return true;
}
Views
Likes
Replies