Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

workflow question

Avatar

Level 9

We use the valtech migration tool to update refactored components etc. automatically on deployment.  It uses the groovy console.

 

We would prefer to run this only on author, then publish the changed artifacts to publish.

 

The migration script might update components in hundreds of pages.

 

How could we publish the affected artifacts programmatically?

 

Someone mentioned a workflow might be able to do this.  Any ideas how?

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @TB3dock,

I think there are few prgramatic options you could take into account:

  • Run publication directly from your groovy script, simple use one of build in methods:
    activate(String path)
    //or
    activate(String path, ReplicationOptions options) ​
  • If you have publication workflow you can run it from groovy console as well, using workflow api, like this:
    import com.adobe.granite.workflow.WorkflowSession
    import com.adobe.granite.workflow.exec.WorkflowData
    import com.adobe.granite.workflow.model.WorkflowModel
    
    // workflow model path
    def model = "/var/workflow/models/metadata_map_example"
    
    // path to payload that will be processed by the workflow
    def payloadPath = "/content/we-retail/language-masters/en/equipment"
    
    def workflowSession = resolver.adaptTo(WorkflowSession.class)
    def workflowModel = workflowSession.getModel(model)
    def workflowData = workflowSession.newWorkflowData("JCR_PATH", payloadPath)
    
    // optional metadata
    Map<String, Object> workflowMetadata = new HashMap<>()
    workflowMetadata.put("anyData", "You Want")
    
    // start the workflow
    workflowSession.startWorkflow(workflowModel, workflowData, workflowMetadata)​

You can also consider some manually executed options, dedicated to handle publication or bulk workflow execution:

View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

Hi @TB3dock,

I think there are few prgramatic options you could take into account:

  • Run publication directly from your groovy script, simple use one of build in methods:
    activate(String path)
    //or
    activate(String path, ReplicationOptions options) ​
  • If you have publication workflow you can run it from groovy console as well, using workflow api, like this:
    import com.adobe.granite.workflow.WorkflowSession
    import com.adobe.granite.workflow.exec.WorkflowData
    import com.adobe.granite.workflow.model.WorkflowModel
    
    // workflow model path
    def model = "/var/workflow/models/metadata_map_example"
    
    // path to payload that will be processed by the workflow
    def payloadPath = "/content/we-retail/language-masters/en/equipment"
    
    def workflowSession = resolver.adaptTo(WorkflowSession.class)
    def workflowModel = workflowSession.getModel(model)
    def workflowData = workflowSession.newWorkflowData("JCR_PATH", payloadPath)
    
    // optional metadata
    Map<String, Object> workflowMetadata = new HashMap<>()
    workflowMetadata.put("anyData", "You Want")
    
    // start the workflow
    workflowSession.startWorkflow(workflowModel, workflowData, workflowMetadata)​

You can also consider some manually executed options, dedicated to handle publication or bulk workflow execution:

Avatar

Community Advisor

Hi @TB3dock,

 

You can make use of this interface to replicate programmatically - 

https://developer.adobe.com/experience-manager/reference-materials/6-5/javadoc/com/day/cq/replicatio...

 

Here are couple of examples to use this:

 

  1. If you want to replicate from the groovy script -           
def replicator = sling.getService(Replicator.class)
def rp = replicator.replicate(session, ReplicationActionType.ACTIVATE, parentNode.getPath());

   

    2.  If you want to replicate from a java class - 

          

@Reference
private Replicator replicator;

//replicate a page
replicator.replicate(session, ReplicationActionType.ACTIVATE, pagePath);

//replicate a node
replicator.replicate(node.getSession(), ReplicationActionType.ACTIVATE, node.getPath());

//Sample method
protected void activateNode(Node node) {
        try {
            LOG.info("ACTIVATE NODE {}", node.getPath());
            replicator.replicate(node.getSession(), ReplicationActionType.ACTIVATE, node.getPath());
            LOG.info("NODE HAS BEEN ACTIVATED {}", node.getPath());
        } catch (RepositoryException e) {
            LOG.error("RepositoryException", e);
        } catch (ReplicationException e) {
            LOG.error("ReplicationException", e);
        }
    }

 

Hope this helps!! Let me know if you have more questions on this.