In a previous blog I described how to build an audit rule in JDeveloper 12c, besides the audit rule, you can also write a fix for this rule. In this example, the fix isn’t anything fancy, but it gives you an idea on how to write more complex fixes. The rule we created in the previous blog was one to check if there was an iterator in a pagedefinition file that has the attribute cacheResults set to false.
The fix for this rule will be to set the value back to true.
First we open the Extension.xml, in the Extension.xml insert a transform definition inside the audit-hook:
The result in the extension file should like something like this:
JSF nl.olrichs.audits.IterCacheTransform sample-category true warning transform-iter-cache nl.olrichs.audits.IterCacheAnalyzer
In the
resource bundle, create a property for the label to display, take the
transform-definition id and add .label behind it. In this case:
Next we need to create the actual Java Transform class.
/** * Default no-arg constructor. * Calls the super with new XmlTransformAdapter. */ public IterCacheTransform() { super(new XmlTransformAdapter()); } /** * Set the attribute value (cacheResults) to true. */ public void apply(XmlTransformContext xmlTransformContext, Attr attr) { attr.setValue("true"); }
As we've seen for the audit rule with the enter and exit methods, you can write a fix (apply) for different levels (for example: Document, Element, Attr) as well. In this case we only need an fix on the Attr, so we only create an apply on this level.
Don’t forget to deploy to the Target Platform before running your extension. The result is not only a warning in the pageDef, it is also a suggestion for a fix with the label we defined in the bundle.
When you click the fix, you will see the value toggle from false to true.
For more information about creating Audit Rules, please check out my index page on topics around this subject.