I have created a component class that listens for document created events so that I can set a unique id for a page.
My issue is that when a page is renamed/moved it calls the document created event which triggers generation of the id which is not what I want.
I need to be able to know when it is a rename so that I can keep the unique id for the page.
I thought I could user the xpage parameter but I don’t have access to the request parameters as the request object wraps a stub in the onEvent method.
Can anyone tell me how I can work our when the DocumentCreatedEvent is triggered due to a rename.
Yes that’s probably the safest way right now. You can get the current job trough org.xwiki.job.JobContext component (xwiki-commons-job module) and you can find rename job type name in org.xwiki.refactoring.job.RefactoringJobs (xwiki-platform-refactoring-api module).
I managed to get the job type from the JobContext as below. Unfortunately the job type is “refactoring/rename” for both copy and rename. How do I differentiate between a copy and a rename?
Indeed just notice that, not a great idea given the fact that the current behavior of rename is supposed to be a hack… As far as I can see the main difference is that the job request isDeleteSource() will return true for a rename and false for a copy (a difference that should be internal in theory).
In your code it should be something like job.status.request.isDeleteSource()
After several months of using these events to create a unique ID when a page has created I have discovered that the DocumentCreatedEvent is not called when an image is uploaded before the page is saved.
The upload of the image creates a revision of the document without calling the DocumentCreatedEvent. This sounds like a bug to me.