Programatically add entries to a document's History tab
Is there a way to programatically add entries to a document's History tab, in a similar fashion to putting text into the Comment field at the bottom of the document's edit tab?
I can see that these records end up in the nxp_logs table. Is there an proper way to interact with this data?
We can first say, the Nuxeo audit system is simply implemented into database as a simple table that manage main fields audit entries (nxp_logs) and a second table that stores extended infos (nxp_logs_extinfo). Entries are simply manage by Hibernate framework.
There is two ways to add an audit entry:
- throw custom event and ask to audit it. With this approach you can also attach listeners to your event.
- directly add the audit entry into the audit tables using hibernate.
For the first point, Nuxeo source code give examples of audit management. You can find these examples into unit tests here. You will find how to create events. To audit them (add a line into the audit table), you will just need to create a contribution that will ask to audit your type of events. see here. If you need to add extended information you will find example, here.
For the second point, you will find example here
You can also use the operation http://explorer.nuxeo.org/nuxeo/site/distribution/current/viewOperation/Audit.Log
You can use it from Studio, in an automation chain, or programmatically (calling the chain in java).