Workflow Model not working for parent folders and files | Community
Skip to main content
Level 2
May 23, 2024
Solved

Workflow Model not working for parent folders and files

  • May 23, 2024
  • 2 replies
  • 581 views

Issue with Publish workflow not working for parent folders.

I have used /var/workflow/models/activationmodel for the publishing.

I have programmatically added the activation of the workflow it seems to be recognizing the complete path of the file but if we give parent folders , it does not recognize it. Expectation is it would activate the parent folder alongwith all the files inside the folder. Please help suggest.

 

       
 
       String path=request.getParameter("path");
        ResourceResolver resourceResolver = request.getResourceResolver();
        Session session = resourceResolver.adaptTo(Session.class);
         String model = "/var/workflow/models/activationmodel";

        // Create a workflow session
        WorkflowSession wfSession = workflowService.getWorkflowSession(session);
              WorkflowModel wfModel = wfSession.getModel(model);                
            WorkflowData wfData = wfSession.newWorkflowData("JCR_PATH", path);
            wfSession.startWorkflow(wfModel, wfData);
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 TarunKumar

Hi @sonaliku ,

Try to create a list, which will eventually have all the paths that is being published. For that you will have to iterate a folder first where all the child nodes are residing.
Now in replicator you can replicate these paths.

Sample code that you can refer:

if (path.contains("<folder-path>")) { Resource resource = resourceResolver.getResource(path) if(resource != null && !ResourceUtil.isNonExistingResource(resource)) { Node node = resource.adaptTo(Node.class); NodeIterator nodeIterator = node.getNodes(); while (nodeIterator.hasNext()) { String contentPath = nodeIterator.nextNode().getPath().toString() myList.add(contentPath); } } }else{ logger.debug("Activate only single page."); myList.add(path); } AgentIdFilter filter = new com.day.cq.replication.AgentIdFilter(<replication-agent>); ReplicationOptions opts = new ReplicationOptions(); opts.setFilter(filter); replicator.replicate(session, ReplicationActionType.ACTIVATE, multiplePagePaths, opts); }

 

 

Hope it helps!

-Tarun

2 replies

TarunKumar
Community Advisor
TarunKumarCommunity AdvisorAccepted solution
Community Advisor
May 27, 2024

Hi @sonaliku ,

Try to create a list, which will eventually have all the paths that is being published. For that you will have to iterate a folder first where all the child nodes are residing.
Now in replicator you can replicate these paths.

Sample code that you can refer:

if (path.contains("<folder-path>")) { Resource resource = resourceResolver.getResource(path) if(resource != null && !ResourceUtil.isNonExistingResource(resource)) { Node node = resource.adaptTo(Node.class); NodeIterator nodeIterator = node.getNodes(); while (nodeIterator.hasNext()) { String contentPath = nodeIterator.nextNode().getPath().toString() myList.add(contentPath); } } }else{ logger.debug("Activate only single page."); myList.add(path); } AgentIdFilter filter = new com.day.cq.replication.AgentIdFilter(<replication-agent>); ReplicationOptions opts = new ReplicationOptions(); opts.setFilter(filter); replicator.replicate(session, ReplicationActionType.ACTIVATE, multiplePagePaths, opts); }

 

 

Hope it helps!

-Tarun

kautuk_sahni
Community Manager
Community Manager
June 10, 2024

@sonaliku Did you find the suggestion helpful? Please let us know if you require more information. Otherwise, please mark the answer as correct for posterity. If you've discovered a solution yourself, we would appreciate it if you could share it with the community. Thank you!

Kautuk Sahni