Open radoslaw-czarnecki-wttech opened 2 years ago
Thanks for filing this issue so clearly.
1: submit a a PR to make List<Triple<Asset, String, Date>> getXdmObjectActorDateTriples(Event event, ResourceResolverWrapper resourceResolverWrapper)
protected
instead
2: I'm guessing your com.proj.core.eventhandler.CustomHandler
is not exported by your osgi bundle, see for instance, how we configured it in our events_osgi_mapping
bundle:
Thanks for your response.
Ad. 2: Maybe I missing something, but it looks like the error message from the logs comes from the AdobeIOEventHandlerFactory.java
. Looking in this class I see if/else statements and there is no place for the custom handler.
In our case when we are using a custom handler, we are ending in the last else statement with ends which the following exception LINK
Are you sure, in the current implementation, we are able to add our custom handler in our project, which will be visible for this framework?
Would it be possible to create a registration mechanism for adding new event handlers. The factory can use a map of factories to instantiate the handler of need.
Wondering if another way to deal with the OP's concern, is to allow for configuring additional asset metadata fields to be included in the event payload. This would probably satisfy 95% of the customization needs that would call for a custom event handler. May be the event mapping config could enhanced to provide an optional list of metadata fields to be included in the payload for asset based events. The same would be nice for page properties of a page based event.
oh my bad, I now see the root cause of point 2
Technically it could be as simple as doing dynamic class loading based on the handler class name, but Adobe Cloud Manager code scan does not allow this...
if you have an idea on how to load these using map of factories, your PR is welcome.
another approach indeed would be to accept a modification of our code to allow users to configure an optional list of metadata fields to be included in the payload, I like the idea a lot see https://github.com/adobe/aio-lib-java/issues/90
Question
How to make a custom Event Handler that will be registered and has an additional custom field in the event's request payload?
Expected Behaviour
We want a custom Page Publish event which has custom fields in the event's request payload.
Create com.adobe.aio.aem.event.osgimapping.internal.OsgiEventMappingSupplierImpl-custom.cfg.json file in config.author directory containing the following:
{ "aio.event.code": "custom_published", "aio.event.label": "Custom Page Published", "aio.event.description": "Custom Page Published Event", "aio.xdm.event.type": "com.adobe.xdm.event.AemPagePublishedEvent", "osgi.event.handler.type": "com.proj.core.eventhandler.CustomHandler", "osgi.topic": "com/day/cq/replication", "osgi.filter": "(&(type=ACTIVATE)(!(event.application=*)))", "osgi.jcr.path.filter": "/content/" }
CustomHandler inherits from one of the abstract classes like ReplicationEventHandler (and puts CustomPage inheriting from Page) or something else which will give access to add custom fields to the event's request payload.
Handler is registered and the event's request payload has defined by CustomHandler additional fields.
Actual Behaviour
1) When tried to inherit from ReplicationEventHandler\<CustomPage> (where CustomPage inherits from com.adobe.xdm.content.Page) and AdobeIoEventHandler\<CustomPage>, there was a problem, because List<Triple<Asset, String, Date>> getXdmObjectActorDateTriples(Event event, ResourceResolverWrapper resourceResolverWrapper) is package-private and there cannot be a class created outside this package and implements this method. 2) When inheriting eg. from PageReplicationEventHandler custom handler does not work and logs say: