Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.
SOLVED

Workflow Model not working for parent folders and files

Avatar

Level 2

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);
1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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

View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

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

Avatar

Administrator

@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