Hello,
I have created AEM page. At this time, there will not be any entry for cq:lastReplicationAction. I have created ReplicationEventHandler that will trigger during page activation, deactivation, deletion time.
Now, I have 2 scenario's. 1: Page is deleted before any publishing the page (Not even published single time) . 2: Page is deleted After publishing earlier.
Now, I have deleted this page. When I Read the "cq:lastReplicationAction" from page Properties in my ReplicationEventHandler file, for both scenario's it gives me: "Delete" . Actually, for the 1st scenario I was expecting null and for the 2nd scenario I was expecting some value, since that page is published earlier.
Thanks in advance.
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @Mahesh_Gunaje, Actually, EventHandler gets triggered after the event occurs, so by that time the "cq:lastReplicationAction" property value is already assigned.
In your case, you need to use a preprocessor to process the replication action before it happens.
Here is an example for your convenience:
@Component(
service = Preprocessor.class,
immediate = true,
property = {Constants.SERVICE_RANKING + ":Integer=1"}
)
public class ReplicationPreprocessor implements Preprocessor {
@Reference
private ResourceResolverFactory resourceResolverFactory;
@Override
public void preprocess(ReplicationAction action, ReplicationOptions options) {
ResourceResolver resourceResolver = resourceResolverFactory.getThreadResourceResolver();
PageManager pageManager;
if (resourceResolver != null) {
pageManager = resourceResolver.adaptTo(PageManager.class);
if (pageManager != null) {
Page currentPage = pageManager.getPage(action.getPath());
if(currentPage != null) {
ValueMap properties = currentPage.getProperties();
String lastReplicationAction = properties.get("cq:lastReplicationAction", "");
// Work with this 'lastReplicationAction' value
}
}
}
}
}
Let me know if this works for you.
Thanks
Views
Replies
Total Likes
Hi @Mahesh_Gunaje, Actually, EventHandler gets triggered after the event occurs, so by that time the "cq:lastReplicationAction" property value is already assigned.
In your case, you need to use a preprocessor to process the replication action before it happens.
Here is an example for your convenience:
@Component(
service = Preprocessor.class,
immediate = true,
property = {Constants.SERVICE_RANKING + ":Integer=1"}
)
public class ReplicationPreprocessor implements Preprocessor {
@Reference
private ResourceResolverFactory resourceResolverFactory;
@Override
public void preprocess(ReplicationAction action, ReplicationOptions options) {
ResourceResolver resourceResolver = resourceResolverFactory.getThreadResourceResolver();
PageManager pageManager;
if (resourceResolver != null) {
pageManager = resourceResolver.adaptTo(PageManager.class);
if (pageManager != null) {
Page currentPage = pageManager.getPage(action.getPath());
if(currentPage != null) {
ValueMap properties = currentPage.getProperties();
String lastReplicationAction = properties.get("cq:lastReplicationAction", "");
// Work with this 'lastReplicationAction' value
}
}
}
}
}
Let me know if this works for you.
Thanks
Views
Replies
Total Likes
Hi @Mahesh_Gunaje
When you delete the page(using UI or pageMagaer api), the page is unpublished automatically , so you don't need to explicitly write any event listener to listen delete/unpublish events.
Views
Replies
Total Likes