Changeset 2215
- Timestamp:
- Apr 5, 2012, 8:20:34 PM (10 years ago)
- Location:
- trunk/grails-app
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/api/ApiController.groovy
r2214 r2215 218 218 219 219 /** 220 * get all eventGroups for a study 221 * 222 * @param string deviceID 223 * @param string studyToken 224 * @param string validation md5 sum 225 */ 226 def getEventGroupsForStudy = { 227 println "api::getEventGroupsForStudy: ${params}" 228 229 // fetch study 230 String studyToken = (params.containsKey('studyToken')) ? params.studyToken : '' 231 def study = Study.findByStudyUUID(studyToken) 232 233 // wrap result in api call validator 234 apiService.executeApiCall(params,response,'study',study,{ 235 def eventGroups = apiService.flattenDomainData( study.eventGroups ) 236 237 // define result 238 def result = [ 239 'count' : eventGroups.size(), 240 'eventGroups' : eventGroups 241 ] 242 243 // set output headers 244 response.status = 200 245 response.contentType = 'application/json;charset=UTF-8' 246 247 if (params.containsKey('callback')) { 248 render "${params.callback}(${result as JSON})" 249 } else { 250 render result as JSON 251 } 252 }) 253 } 254 255 /** 256 * get all events for a study 257 * 258 * @param string deviceID 259 * @param string studyToken 260 * @param string validation md5 sum 261 */ 262 def getEventsForStudy = { 263 println "api::getEventsForStudy: ${params}" 264 265 // fetch study 266 String studyToken = (params.containsKey('studyToken')) ? params.studyToken : '' 267 def study = Study.findByStudyUUID(studyToken) 268 269 // wrap result in api call validator 270 apiService.executeApiCall(params,response,'study',study,{ 271 def events = apiService.flattenDomainData( study.events ) 272 273 // define result 274 def result = [ 275 'count' : events.size(), 276 'events': events 277 ] 278 279 // set output headers 280 response.status = 200 281 response.contentType = 'application/json;charset=UTF-8' 282 283 if (params.containsKey('callback')) { 284 render "${params.callback}(${result as JSON})" 285 } else { 286 render result as JSON 287 } 288 }) 289 } 290 291 /** 292 * get all samplingEvents for a study 293 * 294 * @param string deviceID 295 * @param string studyToken 296 * @param string validation md5 sum 297 */ 298 def getSamplingEventsForStudy = { 299 println "api::getSamplingEventsForStudy: ${params}" 300 301 // fetch study 302 String studyToken = (params.containsKey('studyToken')) ? params.studyToken : '' 303 def study = Study.findByStudyUUID(studyToken) 304 305 // wrap result in api call validator 306 apiService.executeApiCall(params,response,'study',study,{ 307 def samplingEvents = apiService.flattenDomainData( study.samplingEvents ) 308 println study.samplingEvents.dump() 309 310 // define result 311 def result = [ 312 'count' : samplingEvents.size(), 313 'samplingEvents': samplingEvents 314 ] 315 316 // set output headers 317 response.status = 200 318 response.contentType = 'application/json;charset=UTF-8' 319 320 if (params.containsKey('callback')) { 321 render "${params.callback}(${result as JSON})" 322 } else { 323 render result as JSON 324 } 325 }) 326 } 327 328 /** 220 329 * get all samples for an assay 221 330 * -
trunk/grails-app/services/api/ApiService.groovy
r2212 r2215 107 107 // iterate through elements 108 108 elements.each { 109 def fields = it.giveFields()109 def fields = (it.respondsTo('giveFields')) ? it.giveFields(): [] 110 110 def item = [:] 111 112 // check if element has a name 113 ['name','description'].each { checkName -> 114 if (it.hasProperty(checkName)) item[checkName] = it[checkName] 115 } 111 116 112 117 // add token
Note: See TracChangeset
for help on using the changeset viewer.