workflow question | Community
Skip to main content
Level 8
January 6, 2023
Solved

workflow question

  • January 6, 2023
  • 2 replies
  • 947 views

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?

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 lukasz-m

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:

2 replies

lukasz-m
Community Advisor
lukasz-mCommunity AdvisorAccepted solution
Community Advisor
January 6, 2023

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:

ChitraMadan
Community Advisor
Community Advisor
January 8, 2023

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/replication/Replicator.html

 

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.