Permalink
Browse files

Entity to Map coercion support.

  • Loading branch information...
1 parent 9e49a7f commit b28bd8dabc1fd76f6d0defef88a19ea7eebb1b87 @codeconsole codeconsole committed Feb 12, 2013
Showing with 22 additions and 16 deletions.
  1. +22 −16 core/src/main/groovyx/gaelyk/datastore/PogoEntityCoercion.groovy
@@ -176,32 +176,38 @@ class PogoEntityCoercion {
def entityProps = e.getProperties()
def o = clazz.newInstance()
- entityProps.each { String k, v ->
- if (o.metaClass.hasProperty(o, k)) {
+ if (o instanceof Map) {
+ entityProps.each { k, v ->
o[k] = v
+ }
+ o['id'] = e.key.name ?: e.key.id
+ } else {
+ entityProps.each { String k, v ->
+ if (o.metaClass.hasProperty(o, k)) {
+ o[k] = v
+ }
}
- }
- Map<String, PropertyDescriptor> classProps = props(o)
+ Map<String, PropertyDescriptor> classProps = props(o)
- String key = findKey(classProps)
+ String key = findKey(classProps)
- if (key) {
- o.metaClass.setProperty(o, key, e.key.name ?: e.key.id)
- }
+ if (key) {
+ o.metaClass.setProperty(o, key, e.key.name ?: e.key.id)
+ }
- String version = findVersion(classProps)
+ String version = findVersion(classProps)
- if (version) {
- try {
- if(e.key) {
- o.metaClass.setProperty(o, version, Entities.getVersionProperty(DatastoreExtensions.get(Entities.createEntityGroupKey(e.key))))
+ if (version) {
+ try {
+ if(e.key) {
+ o.metaClass.setProperty(o, version, Entities.getVersionProperty(DatastoreExtensions.get(Entities.createEntityGroupKey(e.key))))
+ }
+ } catch (EntityNotFoundException ex){
+ o.metaClass.setProperty(o, version, 0)
}
- } catch (EntityNotFoundException ex){
- o.metaClass.setProperty(o, version, 0)
}
}
-
return o
}
}

0 comments on commit b28bd8d

Please sign in to comment.