Ignore:
Timestamp:
Feb 4, 2011, 12:04:10 PM (13 years ago)
Author:
robert@…
Message:

Implemented pagination on study list pages

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/domain/dbnp/studycapturing/Study.groovy

    r1488 r1494  
    1414class Study extends TemplateEntity {
    1515        static searchable = true
    16        
     16
    1717        def moduleNotificationService
    1818
     
    3434
    3535        /**
    36         * UUID of this study
    37         */
     36         * UUID of this study
     37         */
    3838        String studyUUID
    3939
    40        
     40
    4141        static hasMany = [
    4242                subjects: Subject,
     
    8585        static final List<TemplateField> domainFields = [
    8686                new TemplateField(
    87                         name: 'title',
    88                         type: TemplateFieldType.STRING,
    89                         required: true),
     87                name: 'title',
     88                type: TemplateFieldType.STRING,
     89                required: true),
    9090                new TemplateField(
    91                         name: 'description',
    92                         type: TemplateFieldType.TEXT,
    93                         comment:'Give a brief synopsis of what your study is about',
    94                         required: true),
     91                name: 'description',
     92                type: TemplateFieldType.TEXT,
     93                comment:'Give a brief synopsis of what your study is about',
     94                required: true),
    9595                new TemplateField(
    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),
     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),
    101101                new TemplateField(
    102                         name: 'startDate',
    103                         type: TemplateFieldType.DATE,
    104                         comment: 'Fill out the official start date or date of first action',
    105                         required: true),
     102                name: 'startDate',
     103                type: TemplateFieldType.DATE,
     104                comment: 'Fill out the official start date or date of first action',
     105                required: true),
    106106                new TemplateField(
    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)
     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)
    111111        ]
    112112
     
    123123        def List<Event> getOrphanEvents() {
    124124                def orphans = events.findAll { event -> !event.belongsToGroup(eventGroups) } +
    125                         samplingEvents.findAll { event -> !event.belongsToGroup(eventGroups) }
     125                samplingEvents.findAll { event -> !event.belongsToGroup(eventGroups) }
    126126
    127127                return orphans
     
    349349                                this.samples.findAll { sample ->
    350350                                        (
    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                                                        })
    362364                                                        )
    363                                                 })
    364                                         )
    365365                                }.each() { sample ->
    366366                                        // remove sample from study
     
    458458                        return c.list {
    459459                                maxResults(max)
     460                                order("title", "asc")
     461                               
    460462                        }
    461463                }
     
    463465                return c.list {
    464466                        maxResults(max)
     467                        order("title", "asc")
    465468                        or {
    466469                                eq("owner", user)
     
    475478         * Returns a list of studies that are readable by the given user
    476479         */
    477         public static giveReadableStudies(SecUser user, int max) {
     480        public static giveReadableStudies(SecUser user, int max, int offset = 0) {
    478481                def c = Study.createCriteria()
    479482
     
    482485                        return c.list {
    483486                                maxResults(max)
     487                                firstResult(offset)
     488                                order("title", "asc")
    484489                                and {
    485490                                        eq("published", true)
     
    490495                        return c.list {
    491496                                maxResults(max)
     497                                firstResult(offset)
     498                                order("title", "asc")
    492499                        }
    493500                } else {
    494501                        return c.list {
    495502                                maxResults(max)
     503                                firstResult(offset)
     504                                order("title", "asc")
    496505                                or {
    497506                                        eq("owner", user)
     
    509518                }
    510519        }
    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
    512555        /**
    513556         * Returns the UUID of this study and generates one if needed
     
    520563                        }
    521564                }
    522                
     565
    523566                return this.studyUUID;
    524567        }
    525        
     568
    526569        /**
    527570         * Basic equals method to check whether objects are equals, by comparing the ids
     
    532575                if( o == null )
    533576                        return false;
    534                        
     577
    535578                if( !( o instanceof Study ) )
    536579                        return false
    537                
     580
    538581                Study s = (Study) o;
    539                
     582
    540583                return this.id == s.id
    541584        }
Note: See TracChangeset for help on using the changeset viewer.