Changeset 835
- Timestamp:
- Aug 24, 2010, 5:26:25 PM (13 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/conf/BootStrapStudies.groovy
r834 r835 388 388 .setFieldValue('Fasting period','8h'); 389 389 390 391 def bloodSamplingEvent = new SamplingEvent( 390 def bloodSamplingEventBefore = new SamplingEvent( 391 startTime: 0, 392 template: bloodSamplingEventTemplate, 393 sampleTemplate: humanBloodSampleTemplate) 394 .setFieldValue('Sample volume',4.5F); 395 396 def bloodSamplingEventAfter = new SamplingEvent( 392 397 startTime: 3 * 24 * 3600 + 30 * 3600, 393 398 template: bloodSamplingEventTemplate, … … 396 401 397 402 rootGroup.addToEvents fastingEvent 398 rootGroup.addToSamplingEvents bloodSamplingEvent 403 rootGroup.addToSamplingEvents bloodSamplingEventBefore 404 rootGroup.addToSamplingEvents bloodSamplingEventAfter 399 405 rootGroup.save() 400 406 … … 424 430 template: humanBloodSampleTemplate, 425 431 parentSubject: currentSubject, 426 parentEvent: bloodSamplingEvent 432 parentEvent: bloodSamplingEventBefore 433 ); 434 435 humanStudy.addToSamples(currentSample) 436 currentSample.with { if (!validate()) { errors.each { println it} } else save()} 437 currentSample.setFieldValue( "Text on vial", "T" + (Math.random() * 100L) ) 438 439 currentSample = new Sample( 440 name: currentSubject.name + '_A', 441 material: bloodTerm, 442 template: humanBloodSampleTemplate, 443 parentSubject: currentSubject, 444 parentEvent: bloodSamplingEventAfter 427 445 ); 428 446 … … 433 451 434 452 humanStudy.addToEvents(fastingEvent) 435 humanStudy.addToSamplingEvents(bloodSamplingEvent) 453 humanStudy.addToSamplingEvents(bloodSamplingEventBefore) 454 humanStudy.addToSamplingEvents(bloodSamplingEventAfter) 436 455 humanStudy.addToEventGroups rootGroup 437 456 … … 446 465 println ".adding assay references to mouse example study..." 447 466 448 // Add SAM assay reference s467 // Add SAM assay reference 449 468 def clinicalModule = new AssayModule( 450 469 name: 'SAM module for clinical data', … … 453 472 ).with { if (!validate()) { errors.each { println it} } else save()} 454 473 474 // Add metabolomics assay reference 475 def metabolomicsModule = new AssayModule( 476 name: 'Metabolomics module', 477 platform: 'GCMS/LCMS', 478 url: 'http://localhost:8080/nmcdsp' 479 ).with { if (!validate()) { errors.each { println it} } else save()} 480 455 481 def lipidAssayRef = new Assay( 456 482 name: 'Lipid profiling', … … 459 485 ) 460 486 487 def metAssayRef = new Assay( 488 name: 'Lipidomics profile', 489 module: metabolomicsModule, 490 externalAssayID: 'PPS3_Lipidomics' 491 ) 492 461 493 mouseStudy.samples*.each { 462 494 lipidAssayRef.addToSamples(it) 495 metAssayRef.addToSamples(it) 463 496 } 464 497 465 498 mouseStudy.addToAssays(lipidAssayRef); 466 mouseStudy.save() 467 468 //lipidAssayRef.with { if (!validate()) { errors.each { println it} } else save()} 499 mouseStudy.addToAssays(metAssayRef); 500 mouseStudy.save(flush:true) 469 501 470 502 println ".adding assay references to human example study..." 471 503 472 def glucoseAssay 2Ref = new Assay(473 name: 'Glucose assay 2',504 def glucoseAssayBRef = new Assay( 505 name: 'Glucose assay before', 474 506 module: clinicalModule, 475 externalAssayID: 'PPSH- 2'476 ) 477 478 def glucoseAssay 3Ref = new Assay(479 name: 'Glucose assay 3',507 externalAssayID: 'PPSH-Glu-B' 508 ) 509 510 def glucoseAssayARef = new Assay( 511 name: 'Glucose assay after', 480 512 module: clinicalModule, 481 externalAssayID: 'PPSH-3' 482 ) 483 513 externalAssayID: 'PPSH-Glu-A' 514 ) 515 516 def metAssayRefB = new Assay( 517 name: 'Lipidomics profile before', 518 module: metabolomicsModule, 519 externalAssayID: 'PPSH_Lipidomics_start' 520 ) 521 522 def metAssayRefA = new Assay( 523 name: 'Lipidomics profile after', 524 module: metabolomicsModule, 525 externalAssayID: 'PPSH_Lipidomics_end' 526 ) 484 527 humanStudy.samples*.each { 485 glucoseAssay2Ref.addToSamples(it) 486 glucoseAssay3Ref.addToSamples(it) 528 if (it.parentEvent.startTime == 0) { 529 glucoseAssayBRef.addToSamples(it) 530 metAssayRefB.addToSamples(it) 531 } 532 else { 533 glucoseAssayARef.addToSamples(it) 534 metAssayRefA.addToSamples(it) 535 } 487 536 } 488 537 489 538 490 humanStudy.addToAssays(glucoseAssay2Ref) 491 humanStudy.addToAssays(glucoseAssay3Ref) 492 humanStudy.save() 493 494 //glucoseAssay2Ref.with { if (!validate()) { errors.each { println it} } else save()} 495 //glucoseAssay3Ref.with { if (!validate()) { errors.each { println it} } else save()} 539 humanStudy.addToAssays(glucoseAssayARef) 540 humanStudy.addToAssays(glucoseAssayBRef) 541 humanStudy.addToAssays(metAssayRefA) 542 humanStudy.addToAssays(metAssayRefB) 543 humanStudy.save(flush:true) 496 544 497 545 } -
trunk/grails-app/controllers/RestController.groovy
r834 r835 31 31 32 32 def authService 33 def beforeInterceptor = [action:this.&auth ]33 def beforeInterceptor = [action:this.&auth,except:["isUser"]] 34 34 def credentials 35 35 def requestUser 36 // defined as a regular method so its private37 36 38 37 /** … … 42 41 * @return 43 42 */ 44 def auth() {43 private def auth() { 45 44 credentials = BasicAuthentication.credentialsFromRequest(request) 46 45 requestUser = authService.authUser(credentials.u,credentials.p) … … 54 53 } 55 54 56 55 /** 56 * REST resource for data modules. 57 * Username and password should be supplied via HTTP Basic Authentication. 58 * Determines whether the given user/password combination is a valid GSCF account. 59 * 60 * @return bool True when user/password is a valid GSCF account, false otherwise. 61 */ 62 def isUser= { 63 boolean isUser 64 def reqUser = authService.authUser(credentials.u,credentials.p) 65 if (reqUser) { 66 isUser = true 67 } 68 else { 69 isUser = false 70 } 71 render isUser as JSON 72 } 57 73 58 74 /** 59 * REST resource for the Simple Assay Module. 60 * Provide a list of all studies. 75 * REST resource for data modules. 76 * Username and password should be supplied via HTTP Basic Authentication. 77 * Provide a list of all studies owned by the supplied user. 61 78 * 62 * 63 * @return as JSON object list of members externalStudyID, and title for all studies 79 * @return JSON object list containing 'externalStudyID', and 'name' (title) for each study 64 80 */ 65 81 def getStudies = { … … 73 89 74 90 /** 75 * REST resource for the Simple Assay Module. 76 * Provide a list of all subjects belonging to a study. 91 * REST resource for data modules. 92 * Username and password should be supplied via HTTP Basic Authentication. 93 * Provide a list of all subjects belonging to a study. 77 94 * 78 * @param externalStudyID79 * @return as JSON object list of subject names95 * @param externalStudyID String The external study id (code) of the target GSCF Study object 96 * @return JSON object list of subject names 80 97 */ 81 98 def getSubjects = { … … 91 108 92 109 /** 93 * REST resource for the Simple Assay Module. 110 * REST resource for data modules. 111 * Username and password should be supplied via HTTP Basic Authentication. 94 112 * Provide a list of all assays for a given study 95 113 * 96 114 * Example call of the getAssays REST resource: http://localhost:8080/gscf/rest/getAssays?externalStudyID=PPSH&moduleURL=http://localhost:8182/sam 97 115 * 98 * @param externalStudyID The external study id (code) of the target GSCF Study object99 * @param moduleURL The base URL of the calling dbNP module100 * @return list of assays in the study as JSON object , filtered to only contain assays for the specified module116 * @param externalStudyID String The external study id (code) of the target GSCF Study object 117 * @param moduleURL String The base URL of the calling dbNP module 118 * @return list of assays in the study as JSON object list, filtered to only contain assays for the specified module, with 'externalAssayID' and 'name' for each assay 101 119 */ 102 120 def getAssays = { … … 116 134 117 135 /** 118 * REST resource for the Simple Assay Module. 119 * Provide all samples of a given Assay. The result is an enriched list with additional informatin on a sample. 136 * REST resource for data modules. 137 * Username and password should be supplied via HTTP Basic Authentication. 138 * Provide all samples of a given Assay. The result is an enriched list with additional information for each sample. 120 139 * 121 * @param assayID (externalAssayID of some Assay in GSCF) 122 * @return list of element of Sample.name x Sample.material x Sample.subject.name x Sample.Event.name x Sample.Event.time 140 * @param externalAssayID String (externalAssayID of some Assay in GSCF) 141 * @return As a JSON object list, for each sample in that assay: 142 * @return 'name' (Sample name, which is unique) 143 * @return 'material' (Sample material) 144 * @return 'subject' (The name of the subject from which the sample was taken) 145 * @return 'event' (the name of the template of the SamplingEvent describing the sampling) 146 * @return 'startTime' (the time the sample was taken relative to the start of the study, as a string) 123 147 */ 124 148 def getSamples = { … … 132 156 'subject' : sample.parentSubject.name, 133 157 'event' : sample.parentEvent.template.name, 134 'startTime' : sample.parentEvent.getStartTimeString(), 135 'externalSampleId': sample.externalSampleId 136 ] 158 'startTime' : sample.parentEvent.getStartTimeString() 159 ] 137 160 items.push item 138 161 } … … 142 165 143 166 144 145 146 147 /****************************/148 /** Rest resources for DSP **/149 /****************************/150 151 152 /* still not complete!! */153 154 /**155 * REST resource for DSP.156 * call: gscf/rest/isUser/?username=username&password=password157 *158 * @param String username159 * @param String password160 * @return bool161 */162 def isUser= {163 def isUser = isVerifiedUser( params )164 render isUser as JSON165 }166 167 168 /* still not complete!! */169 /**170 * REST resource for DSP.171 * call: gscf/rest/listStudies/?username=username&password=password172 *173 * @param String username174 * @param String password175 * @return list of studies176 */177 def listStudies = {178 179 if( !isVerifiedUser( params ) ) {180 render [:] as JSON181 return182 }183 184 List studies = []185 186 // add code for filtering studies that belong to given user187 // (use Study.findAll( ... )188 // ...189 Study.list().each {190 def map = ["study_token":it.code, "name":it.name]191 studies.add( map )192 }193 194 render studies as JSON195 }196 197 198 199 /* still not complete!! */200 /**201 * REST resource for DSP.202 * call: gscf/rest/getStudy/?username=username&password=password&study_token=studytoken203 *204 * @param String username205 * @param String password206 * @param String study_token207 * @return list of studies208 */209 def getStudy = {210 211 if( !isVerifiedUser( params ) ) {212 render [:] as JSON213 return214 }215 216 List studyResult = [:]217 def code = params.study_token218 219 def query = "from Study as s where s.code = ?"220 def study = Study.find( query, code )221 studyResult = [ 'study_token' : study.code, 'name' : study.name ]222 /* still not complete!!223 Add features224 ... study_token:âGHyJeR#gâ,225 ... created: â20/06/2010 22:34:52â,226 ... meta: [227 ... greenhouse_id: âGH010938.AB.5â,228 ... greenhouse_type: âlean-to, detached, and ridge and gutter connectedâ ]229 */230 231 render studyResult as JSON232 }233 234 235 236 237 /* still not complete!! */238 /**239 * REST resource for DSP.240 * call: gscf/rest/listStudySamples/?username=username&password=password&study_token=studytoken241 *242 * @param String user name243 * @param String password244 * @param String a valid GSCF Study.code245 * @return List of pairs; each pair is a map with keys sample_token and name and values Study.code and Sample.name.246 */247 def listStudySamples = {248 249 if( !isVerifiedUser( params ) ) {250 render [:] as JSON251 return252 }253 254 List samples = [:]255 def code = params.study_token256 def query = "from Samples as s where s.study = ?"257 def study = Study.find( query, code )258 if(study) study.samples.each { sample ->259 def map = [ sample_token:code, name:sample.name ]260 samples.add( map )261 }262 263 render samples as JSON264 }265 266 267 268 /* still not complete!! */269 /**270 * REST resource for DSP.271 * call: getStudySample/?username=me&password=123&study_token=GHyJeR#g&sample_name=âAHVJwRâ)272 *273 * @param String username274 * @param String password275 * @param String study_token276 * @param String sample_name277 * @return list of studies278 */279 def getStudySample = {280 281 if( !isVerifiedUser( params ) ) {282 render [:] as JSON283 return284 }285 286 List sample = [:]287 def code = params.study_token288 def name = params.sample_name289 290 def query = "from Sample as s where s.name = ? AND s.parentStudy "291 def study = Sample.find( query, name )292 sample = [ 'study_token' : sample.code, 'name' : sample.name ]293 // samples will have unique identifier strings294 /* still not complete!!295 Add features296 [297 study_token:âGHyJeR#gâ,298 sample_token:âAHVJwRâ,299 name: âSample SMPL002â,300 created: â25/06/2010 09:14:32â,301 meta: [ subject: âSUB000294-34942.Aâ, subject_bmi: â29.3â, ... study_token:âGHyJeR#gâ,302 ... created: â20/06/2010 22:34:52â, greenhouse_id: âGH010938.AB.5â,303 greenhouse_type: âlean-to, detached, and ridge and gutter connectedâ304 ]305 */306 render sample as JSON307 }308 309 310 311 312 /* still not complete!! */313 /** Convenience method for isUser and listStudies.314 * Verify user and password.315 * @param params object with two map keys: (1) 'username', (2) 'password'316 * @param String password317 * @return bool318 */319 private isVerifiedUser( params ) {320 def isVerified = false321 def user = params?.username322 def pass = params?.password323 324 if( user && pass ) {325 // insert code for verification of user and326 // ...327 isVerified = true328 }329 return isVerified330 }331 332 333 334 167 /* this is just for testing! */ 335 def test = {168 /*def test = { 336 169 render( dbnp.rest.common.CommunicationManager.getQueryResultWithOperator("Insulin",">",200) ) 337 } 170 }*/ 338 171 } -
trunk/grails-app/views/study/show.gsp
r830 r835 616 616 <th width="100">Assay Name</th> 617 617 <th width="100">Module</th> 618 <th>Type</th>619 618 <th width="150">Platform</th> 620 <th> Url</th>619 <th>Link</th> 621 620 <th>Samples</th> 622 621 </tr> … … 635 634 <td>${assay.module.name}</td> 636 635 <td>${assay.module.platform}</td> 637 <td> ${assay.module.url}</td>636 <td><a href="${dbnp.rest.common.CommunicationManager.getAssayShowURL(assay.externalAssayID)}">view</a></td> 638 637 <td> 639 638 <% sortedAssaySamples = assay.samples.sort( { a, b -> a.name <=> b.name } as Comparator ) %> -
trunk/src/groovy/dbnp/rest/common/CommunicationManager.groovy
r773 r835 173 173 // register method that links to the SAM view for showing a SimpleAssay 174 174 // parameters: externalAssayID 175 addViewWrapper( 'getAssayShowURL', url, 'simpleAssay/show ', ['externalAssayID'] )175 addViewWrapper( 'getAssayShowURL', url, 'simpleAssay/showByExternalID', ['externalAssayID'] ) 176 176 177 177 // register method that links to the SAM view for editing a SimpleAssay
Note: See TracChangeset
for help on using the changeset viewer.