Don't fear the Audit -- Part 2
By John 'JB' Brock on Aug 16, 2011
In Part One of this topic, I covered the basics of creating an extension that will implement the audit framework and find a specific value for the FetchSize property of a ViewObject. Once we found the value, we sent a Warning to the Editor if the value was greater then 100.
In this part, I'll cover how to create a Transform, or fix, that the end user can select to reset the value to the recommended value of 100, automatically.
An updated .zip of the sample project, with the transform code added, can be downloaded from here.
Just as with Part One, we will work with two separate areas of code.
The declarative entries in extension.xml and the code itself in the Transform class and the Transaction class.
Previously I setup the <audit-hook> element in the extension.xml file, and I added a <rule-definition> to define what I wanted to report, when I found it.
Similarly, I will add a <transform-definition> element to the audit-hook to define what the transform will be called, and where the transform class is located.
As you can see, the <transform-definition has one parameter of "id". This must be a unique value. As with the <rule-definition> I've set the label and description for this element in the resource file, instead of directly in the extension.xml.
Inside of the transform-definition is the <transform-class>. I've added the entry that points to the class that I will be using to extend Transform.
Once you have the transform defined, you have to bind the rule to the transform, so that the IDE know which transform to display in the Editor.
Inside of the <rule-definition>, I've added a <transform-binding> element and the <transform> element which points to the ID of the transform definition that we set above.
That's it for the extension.xml. Let's take a look at the Transform and Transaction classes now.
The transform class must be a subclass of oracle.jdeveloper.audit.transform.Transform .
I'm going to be transforming an xml document so I'll make an explicit superclass constructor invocation of XmlTransformAdapter (for Java I would use JavaTransformAdapter).
To make sure all of this is done in a transaction, that can be undone by the end user, I've created the class FixFetchSize and called teh run() method to make everything happen.
The transaction class is a subclass of oracle.bali.xml.model.task.FixedNameTransactionTask.
I've overwritten the performTask() method to do the actual value replacement.
The Final Look
Once you have everything completed, if you run the extension from within the IDE (remember for 11gR2 you have to: Build, Deploy to Target Platform, then Run Extension) you should find the audit available in the Tools >> Preferences >> Audits >> Profiles and if you run the audit against something like the Storefront demo, you will see something like this
Setting up the extension.xml to point at and use a transform is pretty simple. Getting the proper values from the file and making the modifications is where the real work is at. In this particular example it took a lot more work to understand how to work with the XML document model and what to look for and replace, then it did to add the few lines in the extension.xml file. Hopefully this example will provide enough information to get you pointed in the right direction.
If you are going to be working with a Java file instead of XML, please take a look at the existing Extension SDK sample project called AuditRefactor for an example on how to work with java files. It shows how to implement a transform by using the RefactoringManager, which can be very useful.
As with all my posts, if you have any comments, experiences, or questions, please add them to the post so everyone can learn from each other.