Ignore:
Timestamp:
Feb 15, 2011, 3:05:23 PM (13 years ago)
Author:
robert@…
Message:

Refactored some of the querying stuff and built in 'check all' checkboxes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/groovy/dbnp/query/StudySearch.groovy

    r1501 r1524  
    1414 */
    1515package dbnp.query
     16
     17import groovy.lang.Closure;
    1618
    1719import java.util.List;
     
    144146
    145147        /**
    146          * Filters the given list of studies on the study criteria
    147          * @param studies       Original list of studies
    148          * @return                      List with all studies that match the Study criteria
    149          */
    150         protected List filterOnStudyCriteria( List studies ) {
    151                 return filterOnTemplateEntityCriteria(studies, "Study", { study, criterion -> return criterion.getFieldValue( study ) })
    152         }
    153 
    154         /**
    155          * Filters the given list of studies on the subject criteria
    156          * @param studies       Original list of studies
    157          * @return                      List with all studies that match the Subject-criteria
    158          */
    159         protected List filterOnSubjectCriteria( List studies ) {
    160                 return filterOnTemplateEntityCriteria(studies, "Subject", { study, criterion ->
    161                         return study.subjects?.collect { criterion.getFieldValue( it ); }
    162                 })
    163         }
    164 
    165         /**
    166          * Filters the given list of studies on the sample criteria
    167          * @param studies       Original list of studies
    168          * @return                      List with all studies that match the sample-criteria
    169          */
    170         protected List filterOnSampleCriteria( List studies ) {
    171                 return filterOnTemplateEntityCriteria(studies, "Sample", { study, criterion ->
    172                         return study.samples?.collect { criterion.getFieldValue( it ); }
    173                 })
    174         }
    175 
    176         /**
    177          * Filters the given list of studies on the event criteria
    178          * @param studies       Original list of studies
    179          * @return                      List with all studies that match the event-criteria
    180          */
    181         protected List filterOnEventCriteria( List studies ) {
    182                 return filterOnTemplateEntityCriteria(studies, "Event", { study, criterion ->
    183                         return study.events?.collect { criterion.getFieldValue( it ); }
    184                 })
    185         }
    186 
    187         /**
    188          * Filters the given list of studies on the sampling event criteria
    189          * @param studies       Original list of studies
    190          * @return                      List with all studies that match the event-criteria
    191          */
    192         protected List filterOnSamplingEventCriteria( List studies ) {
    193                 return filterOnTemplateEntityCriteria(studies, "SamplingEvent", { study, criterion ->
    194                         return study.samplingEvents?.collect { criterion.getFieldValue( it ); }
    195                 })
    196         }
    197 
    198         /**
    199          * Filters the given list of studies on the assay criteria
    200          * @param studies       Original list of studies
    201          * @return                      List with all studies that match the assay-criteria
    202          */
    203         protected List filterOnAssayCriteria( List studies ) {
    204                 return filterOnTemplateEntityCriteria(studies, "Assay", { study, criterion ->
    205                         return study.assays?.collect { criterion.getFieldValue( it ); }
    206                 })
    207         }
     148        * Returns a closure for the given entitytype that determines the value for a criterion
     149        * on the given object. The closure receives two parameters: the object and a criterion.
     150        *
     151        * This method should be implemented by all searches
     152        *
     153        * For example:
     154        *               For a study search, the object given is a study. How to determine the value for that study of
     155        *               the criterion field of type sample? This is done by returning the field values for all
     156        *               samples in the study
     157        *                       { study, criterion -> return study.samples?.collect { criterion.getFieldValue( it ); } }
     158        * @return
     159        */
     160   protected Closure valueCallback( String entity ) {
     161           switch( entity ) {
     162                   case "Study":
     163                           return { study, criterion -> return criterion.getFieldValue( study ) }
     164                   case "Subject":
     165                           return { study, criterion -> return study.subjects?.collect { criterion.getFieldValue( it ); } }
     166                   case "Sample":
     167                           return { study, criterion -> return study.samples?.collect { criterion.getFieldValue( it ); } }
     168                   case "Event":
     169                           return { study, criterion -> return study.events?.collect { criterion.getFieldValue( it ); } }
     170                   case "SamplingEvent":
     171                           return { study, criterion -> return study.samplingEvents?.collect { criterion.getFieldValue( it ); } }
     172                   case "Assay":
     173                           return { study, criterion -> return study.assays?.collect { criterion.getFieldValue( it ); } }
     174                   default:
     175                           return super.valueCallback( entity );
     176           }
     177   }
    208178
    209179        /**
Note: See TracChangeset for help on using the changeset viewer.