Changeset 255 for trunk/grails-app/services
- Timestamp:
- Jan 4, 2010, 8:13:03 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/services/AssignedPersonService.groovy
r251 r255 4 4 5 5 def personService 6 7 def list(params) {8 def result = [:]9 def fail = { Map m ->10 result.error = [ code: m.code, args: ["AssignedPerson"] ]11 return result12 }13 14 params.max = Math.min( params.max ? params.max.toInteger() : 10, 100)15 result.assignedPersonInstanceList = AssignedPerson.list(params)16 result.assignedPersonInstanceTotal = AssignedPerson.count()17 18 if(!result.assignedPersonInstanceList || !result.assignedPersonInstanceTotal)19 return fail(code:"default.list.failure")20 21 // Success.22 return result23 }24 25 def show(params) {26 def result = [:]27 def fail = { Map m ->28 result.error = [ code: m.code, args: ["AssignedPerson", params.id] ]29 return result30 }31 32 result.assignedPersonInstance = AssignedPerson.get(params.id)33 34 if(!result.assignedPersonInstance)35 return fail(code:"default.not.found")36 37 // Success.38 return result39 }40 6 41 7 def delete(params) { … … 86 52 return fail(code:"default.not.found") 87 53 54 result.person = result.assignedPersonInstance.person 55 result.groupsForPerson = result.person.personGroups.sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name) } 56 88 57 // Success. 89 58 return result … … 101 70 return result 102 71 } 72 73 result.person = Person.get(params.person.id) 74 75 // Prevent a null property reference. 76 if(!result.person) 77 return fail(code:"person.not.found") 78 79 result.groupsForPerson = result.person.personGroups.sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name) } 103 80 104 81 result.assignedPersonInstance = AssignedPerson.get(params.id) … … 144 121 result.assignedPersonInstance.properties = params 145 122 146 // success 123 result.person = Person.list().sort { p1, p2 -> p1.firstName.compareToIgnoreCase(p2.firstName) }[0] // Get the first result. 124 result.groupsForPerson = result.person.personGroups.sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name) } 125 126 // Success. 147 127 return result 148 128 } … … 153 133 154 134 def fail = { Map m -> 135 status.setRollbackOnly() 155 136 if(result.assignedPersonInstance && m.field) 156 137 result.assignedPersonInstance.errors.rejectValue(m.field, m.code) … … 159 140 } 160 141 161 result.assignedPersonInstance = new AssignedPerson(params) 142 result.person = Person.get(params.person.id) 143 144 // Prevent a null property reference. 145 if(!result.person) 146 return fail(code:"person.not.found") 147 148 result.groupsForPerson = result.person.personGroups.sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name) } 149 150 result.assignedPersonInstance = new AssignedPerson() 151 result.assignedPersonInstance.properties = params 162 152 163 153 if(result.assignedPersonInstance.hasErrors() || !result.assignedPersonInstance.save()) … … 180 170 } // end save() 181 171 172 def groupsForPerson(params) { 173 def result = [:] 174 175 def fail = { Map m -> 176 result.error = [ code: m.code, args: ["Person", params.person?.id] ] 177 return result 178 } 179 180 result.person = Person.get(params.person?.id) 181 182 if(!result.person) 183 return fail(code:"default.not.found") 184 185 result.groupsForPerson = result.person.personGroups.sort { p1, p2 -> p1.name.compareToIgnoreCase(p2.name) } 186 187 // Success. 188 return result 189 } 190 182 191 } // end class
Note: See TracChangeset
for help on using the changeset viewer.