Recording different states of domain object

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Recording different states of domain object

John Moore
I may be just having a bit of a mental block, but I cannot think of a straightforward way of doing something which I would imagine would be fairly simple, and seem to be swimming against the flow of Grails. I need, somehow, to record the state of a domain object (with associations) at different points, such that I can compare the current state with the previous. Effectively I need to maintain a record of the multiple versions of this object, historically.

Maybe it would help if I explained why I have the requirement. I am working on a system for an insurance company, and the domain object in question is a Policy (which contains a couple of 'hasMany' relations I need to track, too). So, a customer purchases a policy, and the total is calculated and they are invoiced. Subsequently they need to make a change (possibly chargeable) or addition to the policy. At this point they need to have one or more endorsement documents generated and the total recalculated. They pay any extra at this point (or are reimbursed, if less).

So, in order to do this properly, I need to be able to preserve somehow the state of the Policy as it was when originally purchased, so that I can compare it with how it now is after the changes, and generate the appropriate documentation, showing only what has been added, modified or deleted, and charging accordingly.

What I'm thinking about at the moment is creating and persisting some kind of JSON deep serialization of the object at each billing point, which I can compare with the previous version. But this feels a little kludgy to me. I'm wondering whether I've missed something more obvious? If starting from scratch, I might be tempted to have a PolicyVersion class, with a many-to-one relationship to Policy, and have all the changeable data in that. But I'd prefer not to have to do such a level of refactoring at this point.

Any ideas, anyone?
Reply | Threaded
Open this post in threaded view
|

Re: Recording different states of domain object

Bob Brown
Sounds like envers might help you: http://docs.jboss.org/envers/docs/index.html

There exists a plugin: http://grails.org/plugin/envers

Hth

Bob

Sent from my iPad

On 03/10/2013, at 1:19, John Moore <[hidden email]> wrote:

> I may be just having a bit of a mental block, but I cannot think of a
> straightforward way of doing something which I would imagine would be fairly
> simple, and seem to be swimming against the flow of Grails. I need, somehow,
> to record the state of a domain object (with associations) at different
> points, such that I can compare the current state with the previous.
> Effectively I need to maintain a record of the multiple versions of this
> object, historically.
>
> Maybe it would help if I explained why I have the requirement. I am working
> on a system for an insurance company, and the domain object in question is a
> Policy (which contains a couple of 'hasMany' relations I need to track,
> too). So, a customer purchases a policy, and the total is calculated and
> they are invoiced. Subsequently they need to make a change (possibly
> chargeable) or addition to the policy. At this point they need to have one
> or more endorsement documents generated and the total recalculated. They pay
> any extra at this point (or are reimbursed, if less).
>
> So, in order to do this properly, I need to be able to preserve somehow the
> state of the Policy as it was when originally purchased, so that I can
> compare it with how it now is after the changes, and generate the
> appropriate documentation, showing only what has been added, modified or
> deleted, and charging accordingly.
>
> What I'm thinking about at the moment is creating and persisting some kind
> of JSON deep serialization of the object at each billing point, which I can
> compare with the previous version. But this feels a little kludgy to me. I'm
> wondering whether I've missed something more obvious? If starting from
> scratch, I might be tempted to have a PolicyVersion class, with a
> many-to-one relationship to Policy, and have all the changeable data in
> that. But I'd prefer not to have to do such a level of refactoring at this
> point.
>
> Any ideas, anyone?
>
>
>
> --
> View this message in context: http://grails.1312388.n4.nabble.com/Recording-different-states-of-domain-object-tp4649851.html
> Sent from the Grails - user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Recording different states of domain object

John Moore
Thanks, that looks very interesting. I'll take a look at it.
Reply | Threaded
Open this post in threaded view
|

Re: Recording different states of domain object

jolo
This post was updated on .
Hi,

Envers should do the job.

Here are some information about Envers with grails:

http://www.lucasward.net/2013/04/grails-envers-plugin-update.html

If you have any troubles with the plugin, these two instructions describe the use of Envers with Grails without the use of a plugin:

http://mra.io/2012/10/12/hibernate-envers-and-grails-without-a-plug-in/
http://jolorenz.wordpress.com/2013/09/13/using-envers4-with-hibernate4-and-grails-2-3-0/

I use Envers quite successfully.

HTH Johannes