Skip to content

Commit

Permalink
Merge pull request #162 from robertoschwald/3.x_docs
Browse files Browse the repository at this point in the history
#161 Extended plugin docs
  • Loading branch information
robertoschwald authored Feb 15, 2018
2 parents ec8b082 + 3ea7139 commit bceba75
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 3 deletions.
9 changes: 9 additions & 0 deletions plugin/src/docs/implementation.adoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
== Implementation
Most of the plugin code is marked as @CompileStatic.

=== AuditLogEventListener
The Audit Logging plugin registers a PersistenceEventListener (`AuditLogListener`) bean per datasource, which listens to GORM events.
Expand All @@ -11,3 +12,11 @@ The Plugin Descriptor (AuditLogListenerGrailsPlugin) configures the plugin durin

* Configures the plugin either by default values - see DefaultAuditLogConfig.groovy - or by user configured settings.
* Registers a PersistenceEventListener bean per datasource

=== Auditable trait
Enabling auditing on a Domain class is done by implementing the `Auditable` trait.

=== Stampable trait
Enabling stamping on a Domain class is done by implementing the `Stampable` trait.
This trait adds the properties dateCreated, lastUpdated, createdBy, lastUpdatedBy
to the domain class.
31 changes: 30 additions & 1 deletion plugin/src/docs/installation.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,33 @@ This will create the Audit Domain class as well as configure:

Once created, you should open the generated file to adjust the `mappings` and `constraints` to suit your needs.

WARNING: Be sure to respect the existing nullability constraints or the plugin may not work correctly
WARNING: Be sure to respect the existing nullability constraints or the plugin may not work correctly

=== Prepare your Domain classes for Auditing

For every Domain class you want to be audited, implement the Auditable Trait.

For example:

```groovy

import grails.plugins.orm.auditable.Auditable

class MyDomain implements Auditable {
String whatever
...
}
```


If you additionally want to enable stamping, implement the Stampable Trait:

```groovy

import grails.plugins.orm.auditable.Auditable

class MyDomain implements Auditable, Stampable {
String whatever
...
}
```
21 changes: 20 additions & 1 deletion plugin/src/docs/stamping.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ The attributes will assume the default constraints, which should be fine for mos
You can configure the `constraints` and `mappings` block as usual in your domain class to customize the stampable properties.

=== Stamping Configuration
Previous versions used an AST transformation to apply the stamping and could allow more configuration. For now, the stamping support has been boiled down to just the basic trait attributes and the ability to disable the plugin globally.
Previous versions used an AST transformation to apply the stamping and could allow more configuration.
For now, the stamping support has been boiled down to just the basic trait attributes and the ability to disable the plugin globally.

[source,groovy]
----
Expand All @@ -26,3 +27,21 @@ grails.plugin.auditLog.stampEnabled = true
----

WARNING: If you disable stamping but have `Stampable` entities, they will likely fail validation since the plugin will not be populating the fields which are still added to the domain objects. The main reason to disable stamping is to prevent the listener registration in the case that you just aren't using the `Stampable` support.

If you want to mark *all* of your domain objects as stampable, you could define the following `TraitInjector`:

[source,groovy]
----
@CompileStatic
class StampableTraitInjector implements TraitInjector {
@Override
Class getTrait() {
Stampable
}
@Override
String[] getArtefactTypes() {
['Domain'] as String[]
}
}
----
12 changes: 11 additions & 1 deletion plugin/src/docs/upgrading.adoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
== Upgrading

The 3.0.0 version of the plugin is a major rewrite of the codebase. Therefore you need to upgrade your code for this version.

=== Domain Classes
Prior versions of the plugin used a static property syntax to enable and customize logging:
[source,groovy]
Expand All @@ -11,10 +13,18 @@ static auditable = true
static auditable = [auditableProperties: ['name', 'famous', 'lastUpdated']]
----

Starting with version 3.0.0, the plugin uses an `Auditable` trait as both a marker as well as a way to configure and override auditing behavior.
Starting with version 3.0.0, the plugin uses an `Auditable` trait and/or a `Stampable` trait as both a marker as well as a way to configure and override auditing behavior.

For the first example, just adding `implements Auditable` will enable the default behavior.

[source,groovy]
----
import grails.plugins.orm.auditable.Auditable
class MyDomain implements Auditable {
..
}
----

For the second example above, you simply override the appropriate method on the `Auditable` trait, in this case the method is `getLogIncluded()`:

[source,groovy]
Expand Down

0 comments on commit bceba75

Please sign in to comment.