Changeset 1494 for trunk/grails-app/domain
- Timestamp:
- Feb 4, 2011, 12:04:10 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/domain/dbnp/studycapturing/Study.groovy
r1488 r1494 14 14 class Study extends TemplateEntity { 15 15 static searchable = true 16 16 17 17 def moduleNotificationService 18 18 … … 34 34 35 35 /** 36 * UUID of this study37 */36 * UUID of this study 37 */ 38 38 String studyUUID 39 39 40 40 41 41 static hasMany = [ 42 42 subjects: Subject, … … 85 85 static final List<TemplateField> domainFields = [ 86 86 new TemplateField( 87 88 89 87 name: 'title', 88 type: TemplateFieldType.STRING, 89 required: true), 90 90 new TemplateField( 91 92 93 94 91 name: 'description', 92 type: TemplateFieldType.TEXT, 93 comment:'Give a brief synopsis of what your study is about', 94 required: true), 95 95 new TemplateField( 96 97 98 99 100 96 name: 'code', 97 type: TemplateFieldType.STRING, 98 preferredIdentifier: true, 99 comment: 'Fill out the code by which many people will recognize your study', 100 required: true), 101 101 new TemplateField( 102 103 104 105 102 name: 'startDate', 103 type: TemplateFieldType.DATE, 104 comment: 'Fill out the official start date or date of first action', 105 required: true), 106 106 new TemplateField( 107 108 109 110 107 name: 'published', 108 type: TemplateFieldType.BOOLEAN, 109 comment: 'Determines whether this study is published (accessible for the study readers and, if the study is public, for anonymous users). A study can only be published if it meets certain quality criteria, which will be checked upon save.', 110 required: false) 111 111 ] 112 112 … … 123 123 def List<Event> getOrphanEvents() { 124 124 def orphans = events.findAll { event -> !event.belongsToGroup(eventGroups) } + 125 125 samplingEvents.findAll { event -> !event.belongsToGroup(eventGroups) } 126 126 127 127 return orphans … … 349 349 this.samples.findAll { sample -> 350 350 ( 351 (eventGroup.subjects.findAll { 352 it.equals(sample.parentSubject) 353 }) 354 && 355 (eventGroup.samplingEvents.findAll { 356 ( 357 (it.id && sample.parentEvent.id && it.id == sample.parentEvent.id) 358 || 359 (it.getIdentifier() == sample.parentEvent.getIdentifier()) 360 || 361 it.equals(sample.parentEvent) 351 (eventGroup.subjects.findAll { 352 it.equals(sample.parentSubject) 353 }) 354 && 355 (eventGroup.samplingEvents.findAll { 356 ( 357 (it.id && sample.parentEvent.id && it.id == sample.parentEvent.id) 358 || 359 (it.getIdentifier() == sample.parentEvent.getIdentifier()) 360 || 361 it.equals(sample.parentEvent) 362 ) 363 }) 362 364 ) 363 })364 )365 365 }.each() { sample -> 366 366 // remove sample from study … … 458 458 return c.list { 459 459 maxResults(max) 460 order("title", "asc") 461 460 462 } 461 463 } … … 463 465 return c.list { 464 466 maxResults(max) 467 order("title", "asc") 465 468 or { 466 469 eq("owner", user) … … 475 478 * Returns a list of studies that are readable by the given user 476 479 */ 477 public static giveReadableStudies(SecUser user, int max ) {480 public static giveReadableStudies(SecUser user, int max, int offset = 0) { 478 481 def c = Study.createCriteria() 479 482 … … 482 485 return c.list { 483 486 maxResults(max) 487 firstResult(offset) 488 order("title", "asc") 484 489 and { 485 490 eq("published", true) … … 490 495 return c.list { 491 496 maxResults(max) 497 firstResult(offset) 498 order("title", "asc") 492 499 } 493 500 } else { 494 501 return c.list { 495 502 maxResults(max) 503 firstResult(offset) 504 order("title", "asc") 496 505 or { 497 506 eq("owner", user) … … 509 518 } 510 519 } 511 520 521 /** 522 * Returns the number of studies that are readable by the given user 523 */ 524 public static countReadableStudies(SecUser user) { 525 def c = Study.createCriteria() 526 527 // Administrators are allowed to read everything 528 if (user == null) { 529 return c.count { 530 and { 531 eq("published", true) 532 eq("publicstudy", true) 533 } 534 } 535 } else if (user.hasAdminRights()) { 536 return Study.count(); 537 } else { 538 return c.count { 539 or { 540 eq("owner", user) 541 writers { 542 eq("id", user.id) 543 } 544 and { 545 readers { 546 eq("id", user.id) 547 } 548 eq("published", true) 549 } 550 } 551 } 552 } 553 } 554 512 555 /** 513 556 * Returns the UUID of this study and generates one if needed … … 520 563 } 521 564 } 522 565 523 566 return this.studyUUID; 524 567 } 525 568 526 569 /** 527 570 * Basic equals method to check whether objects are equals, by comparing the ids … … 532 575 if( o == null ) 533 576 return false; 534 577 535 578 if( !( o instanceof Study ) ) 536 579 return false 537 580 538 581 Study s = (Study) o; 539 582 540 583 return this.id == s.id 541 584 }
Note: See TracChangeset
for help on using the changeset viewer.