We've a eventHandler that does some task on activate/deactivate. Now we've a preview server as well in place and want to understand on how to restrict tasks if destination server is preview server instead of publish server.
Solved! Go to Solution.
Views
Replies
Total Likes
AEM preview servers repliaction is nothing more than replication to custom agents.
Inside the handleEvent function of EventHandler use,
event.getProperty("agentIds")
It will return you array which has Publish as an entry if the replication event is trigegrd for publish and preview if the page is just previewd.
Hello @amargupt
You can check the runmode before triggering the event.
You can get runmode in js in this way then you can decide what to do with the event handler. Is your runmode is satisfied to trigger the event or not.
var SlingSettingsService = Packages.org.apache.sling.settings.SlingSettingsService;
use(function () {
// Get runmodes and transform them into an object that is easier to read for Sightly
var runmodesObj = {};
var runmodesSet = sling.getService(SlingSettingsService).getRunModes();
var iterator = runmodesSet.iterator();
var isauthor=sling.getService(SlingSettingsService).getRunModes().contains("author");
var ispublish=sling.getService(SlingSettingsService).getRunModes().contains("publish");
while (iterator.hasNext()) {
runmodesObj[iterator.next()] = true;
}
return {
runmodes: runmodesObj,
author: isauthor,
publish: ispublish
}
});
My eventHandler will be executed in author server. Is there a way to find the destination server based on "Event".
Hi @amargupt ,
you can set run mode configuration through an OSGi configurations and check for the server before triggering the handler. I would suggest the server name as an attribute to your handler triggers.
@AsifChowdhury SlignSettingsService is deprecated and no longer to be used under best practices clause. The alternative for that is yet to be decided and can be followed here : https://github.com/Adobe-Consulting-Services/acs-aem-commons/issues/2476
Regards,
Sravan
You can create one OSGI config and add 'policy = ConfigurationPolicy.REQUIRE' in the code.
After that, add OSGI configurations in all required AEM instances.
The event handler will be active only in those AEM instances where it will be able to find out osgi configs.
Since you only need to restrict it in the preview instances, you can skip these OSGI configs there.
ACS commons has a similar code, please find the link for your reference.
I hope it helps!
I don't think that this is possible right now. Can you raise a feature request with Adobe support for that?
AEM preview servers repliaction is nothing more than replication to custom agents.
Inside the handleEvent function of EventHandler use,
event.getProperty("agentIds")
It will return you array which has Publish as an entry if the replication event is trigegrd for publish and preview if the page is just previewd.
Views
Likes
Replies
Views
Likes
Replies