Java/AEM: How to trigger an EventListener (javax.jcr.observation.EventListener)?
I'm trying to debug a existing code where it's supposed to trigger when "Event.PROPERTY_CHANGED+Event.PROPERTY_ADDED" events happened but I don't think it's triggering.
Any ideas on how to help debug the code? (I want my breakpoint inside "onEvent" function to stop the execution)
Some info/observations:
- My PDF is located in "/content/dam/files/careers/factsheets/Recruitment-Q-and-A-Factsheet.pdf"
- I inspected the PDF in CRX/DE and this path "/content/dam/files/careers/factsheets/Recruitment-Q-and-A-Factsheet.pdf/jcr:content" has this property "jcr:primaryType=dam:AssetContent".
- If I edit the metadata (example title), the parent path for the attributes/properties is located in "/content/dam/files/careers/factsheets/Recruitment-Q-and-A-Factsheet.pdf/jcr:content/metadata"
- I put a breakpoint in this line "session = commonService.getSession();" and execution stops here when my AEM instance is starting (either starting it up for the first time or restarting the instance). I didn't encounter any errors/exceptions inside "activate" function.
- To test my breakpoint inside the "onEvent" function, I changed the metadata of the PDF. I also tried publishing it. I also manually created 2 new nodes of types "nt:unstructed" and "nt:folder" inside "/content/dam/files/careers" folder (via CRX/DE). None of these actions triggered my breakpoint.
- This is my code
protected void activate() {
try {
session = commonService.getSession(); //this is a custom service created by 3rd party
observationManager = session.getWorkspace().getObservationManager();
final String[] types = { "dam:Asset", "dam:AssetContent", "nt:unstructured", "nt:folder" };
final String path = "/content/dam/files";
final int events1 = Event.PROPERTY_CHANGED | Event.PROPERTY_ADDED | Event.NODE_ADDED;
observationManager.addEventListener(this, events1, path, true, null, types, false);
} catch(Exception e) {
log.error("bad stuff happened",e);
}
}
public void onEvent(EventIterator eventIterator) {
while (eventIterator.hasNext()){
Event event = eventIterator.nextEvent();
//insert more code here
}
}