mehandih / grails-jaxrs

Automatically exported from code.google.com/p/grails-jaxrs
0 stars 0 forks source link

ResourceService update method should not overwrite dateCreated #68

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. During a PUT operation send and try to overwrite the dateCreated field
2. Since the update operation in the ResourceService copies the full property, 
the dateCreate is updated

What is the expected output? What do you see instead?
dateCreated is replaced with what is passed in.  This should not happen

What version of the product are you using? On what operating system?
jaxrs-06 - Mac OSX

Please provide any additional information below.
I copy the system dateCreated to the object passed in prior to overwriting it:
dto.dateCreated = obj.dateCreated
Don't know if you can do that by default as you'll need to examine the domain 
object to see if it has the dateCreated field.

Original issue reported on code.google.com by mlim1...@gmail.com on 10 Aug 2012 at 7:43

GoogleCodeExporter commented 8 years ago
Thanks for reporting, that's definitely a bug. Would you like to fix that 
yourself and send a pull request? I'd highly appreciate it. 

Cheers,
Martin

Original comment by krass...@googlemail.com on 11 Aug 2012 at 7:54

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
I replaced the "update" method of the scaffolding template 
"ResourceService.groovy" with the following:

    def update(${resourceName} dto) {
        def obj = ${resourceName}.get(dto.id)
    if (obj.hasProperty('dateCreated')) {  // preserve the initial dateCreated
            def dc=obj.dateCreated
        }
        if (!obj) {
            throw new DomainObjectNotFoundException(${resourceName}.class, dto.id)
        }
        obj.properties = dto.properties
    if (obj.hasProperty('lastUpdated')) {obj.lastUpdated=new Date()}
        if (obj.hasProperty('dateCreated')) {obj.dateCreated=dc}
        obj
    }

Original comment by ncaramol...@gmail.com on 23 Jun 2013 at 8:45