I am creating a resource listener that checks on the creation of a content fragment, it will automatically create the relevant page in the correct location and attach the fragment to the page so it can be rendered by the template.
This is on AEMaaCS:
I want to make it so that the page is automatically published to the preview server so that i can then create a workflow passing the preview server details as part of a review process.
I can't see how using the replication service I can publish to the preview server.
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @taggatmerkle,
According to official documentation:
To support the preview functionality, a new agent called “preview” has been added, which is not active by default. This agent is used to connect the author to the preview tier. If you want to replicate only by way of the preview agent, you must explicitly select this preview agent by way of anAgentFilter
....
In case you do not provide such a filter and only use the “publish” agent, the “preview” agent is not used and the replication action does not affect the preview tier.
Having above knowledge you can use Replication API, setting preview agent as a target. Please have a look into below code snippet.
package com.platform.aem.core.replication;
import com.day.cq.replication.Agent;
import com.day.cq.replication.AgentFilter;
import com.day.cq.replication.ReplicationActionType;
import com.day.cq.replication.ReplicationException;
import com.day.cq.replication.ReplicationOptions;
import com.day.cq.replication.Replicator;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import javax.jcr.Session;
@Component
public class PreviewPublishReplication {
private static final String PREVIEW_AGENT = "preview";
@Reference
private Replicator replicator;
public void replicateToPreview(Session session, String pagePath) throws ReplicationException {
ReplicationOptions options = new ReplicationOptions();
options.setFilter(new AgentFilter() {
@Override
public boolean isIncluded (Agent agent) {
return agent.getId().equals(PREVIEW_AGENT);
}
});
replicator.replicate(session, ReplicationActionType.ACTIVATE, pagePath, options);
}
}
Hi @taggatmerkle,
According to official documentation:
To support the preview functionality, a new agent called “preview” has been added, which is not active by default. This agent is used to connect the author to the preview tier. If you want to replicate only by way of the preview agent, you must explicitly select this preview agent by way of anAgentFilter
....
In case you do not provide such a filter and only use the “publish” agent, the “preview” agent is not used and the replication action does not affect the preview tier.
Having above knowledge you can use Replication API, setting preview agent as a target. Please have a look into below code snippet.
package com.platform.aem.core.replication;
import com.day.cq.replication.Agent;
import com.day.cq.replication.AgentFilter;
import com.day.cq.replication.ReplicationActionType;
import com.day.cq.replication.ReplicationException;
import com.day.cq.replication.ReplicationOptions;
import com.day.cq.replication.Replicator;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import javax.jcr.Session;
@Component
public class PreviewPublishReplication {
private static final String PREVIEW_AGENT = "preview";
@Reference
private Replicator replicator;
public void replicateToPreview(Session session, String pagePath) throws ReplicationException {
ReplicationOptions options = new ReplicationOptions();
options.setFilter(new AgentFilter() {
@Override
public boolean isIncluded (Agent agent) {
return agent.getId().equals(PREVIEW_AGENT);
}
});
replicator.replicate(session, ReplicationActionType.ACTIVATE, pagePath, options);
}
}
Views
Likes
Replies
Views
Likes
Replies