Hi @abhijeet_kumar
1.Create a workflow model that includes the necessary steps to validate the condition and activate the page if the condition is met. You can use the Workflow Modeler in AEM to create the workflow model.
2.Associate the workflow model with the page's blueprint or template. This can be done by adding the cq:workflowModel property to the blueprint or template node in the repository.
3.Create a custom event listener that listens for the beforeActivate event and triggers the workflow if the condition is met. Here's an example of how the listener code might look:
@Component(service = EventListener.class,
property = {
EventConstants.EVENT_TOPIC + "=" + ReplicationAction.EVENT_TOPIC
})
public class MyReplicationListener implements EventListener {
@Reference
private WorkflowService workflowService;
@Override
public void handleEvent(Event event) {
ReplicationAction action = ReplicationAction.fromEvent(event);
if (action.getType() == ReplicationActionType.ACTIVATE) {
Resource resource = action.getPath();
if (resource != null && resource.adaptTo(Page.class) != null) {
Page page = resource.adaptTo(Page.class);
if (shouldTriggerWorkflow(page)) {
triggerWorkflow(page);
}
}
}
}
private boolean shouldTriggerWorkflow(Page page) {
// Check if the condition is met
return true;
}
private void triggerWorkflow(Page page) {
// Start the workflow
WorkflowData workflowData = new WorkflowData(page.getPath(), null);
WorkflowStartOptions options = new WorkflowStartOptions();
options.setWorkflowModel("/etc/workflow/models/myworkflow");
workflowService.startWorkflow(options, workflowData);
}
}4.Deploy the listener code to your AEM instance and register it as an OSGi service.
5.When a user clicks the Publish button, the page will be moved to the workflow and the before Activate event will be triggered. If the condition is met, the workflow will be started and the page will be activated from the workflow. If the condition is not met, the page will remain in the workflow and will not be activated.