Changeset 2190
- Timestamp:
- Mar 30, 2012, 11:14:36 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/api/ApiController.groovy
r2188 r2190 18 18 import grails.converters.JSON 19 19 import dbnp.studycapturing.Study 20 import dbnp.studycapturing.Assay 20 21 import dbnp.authentication.SecUser 21 22 import org.dbnp.gdt.TemplateFieldType … … 23 24 class ApiController { 24 25 def authenticationService 26 def moduleCommunicationService 25 27 def ApiService 26 28 … … 201 203 } 202 204 } 205 206 def getAssayData = { 207 println "api:getAssayData: ${params}" 208 209 String deviceID = (params.containsKey('deviceID')) ? params.deviceID : '' 210 String validation = (params.containsKey('validation')) ? params.validation : '' 211 String assayToken = (params.containsKey('assayToken')) ? params.assayToken : '' 212 213 // fetch user and study 214 def user = Token.findByDeviceID(deviceID)?.user 215 def assay = Assay.findByAssayUUID(assayToken) 216 217 // check 218 if (!apiService.validateRequest(deviceID,validation)) { 219 response.sendError(401, 'Unauthorized') 220 } else if (!assay) { 221 response.sendError(400, 'No such assay') 222 } else if (!assay.parent.canRead(user)) { 223 response.sendError(401, 'Unauthorized') 224 } else { 225 // def assays = apiService.flattenDomainData( study.assays ) 226 227 def serviceURL = "${assay.module.url}/rest/getMeasurements" 228 def serviceArguments = "assayToken=${assayToken}" 229 230 def json = moduleCommunicationService.callModuleMethod( 231 assay.module.url, 232 serviceURL, 233 serviceArguments, 234 "POST" 235 ); 236 237 238 // define result 239 def result = [ 240 'bla': 'hoi', 241 'json' : json 242 ] 243 244 // set output headers 245 response.status = 200 246 response.contentType = 'application/json;charset=UTF-8' 247 248 if (params.containsKey('callback')) { 249 render "${params.callback}(${result as JSON})" 250 } else { 251 render result as JSON 252 } 253 } 254 } 203 255 }
Note: See TracChangeset
for help on using the changeset viewer.