Ignore:
Timestamp:
Aug 5, 2010, 10:58:09 PM (11 years ago)
Author:
duh
Message:
  • big refactoring of the Study Capture Wizard until the grouping page, removing all internal maps and directory work on the study object to
    • simplify internal representation and handling
    • added static incremental identifiers to TemplateEntity?, EventGroup? and Template for use in dynamic web forms
  • TODO: fix the sample page
  • TODO: check cascaded deletes, confirm database content
Location:
trunk/grails-app/domain/dbnp/studycapturing
Files:
4 edited

Legend:

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

    r754 r778  
    1010 */
    1111class EventGroup implements Serializable {
    12 
    13         static belongsTo = [parent : Study]
    14 
    1512        String name
    1613
     14        // keep an internal identifier for use in dynamic forms
     15        private int identifier = 0
     16        static int iterator = 0
     17
     18        static transients = [ "identifier", "iterator" ]
     19        static belongsTo = [parent : Study]
    1720        static hasMany = [
    1821                subjects: Subject,
     
    2326        static constraints = {
    2427        }
     28
     29        /**
     30         * Class constructor increments that static iterator
     31         * and sets the object's identifier (used in dynamic webforms)
     32         * @void
     33         */
     34        public EventGroup() {
     35                if (!identifier) identifier = iterator++
     36        }
     37
     38        /**
     39         * Return the identifier
     40         * @return int
     41         */
     42        final public int getIdentifier() {
     43                return identifier
     44        }
    2545}
  • trunk/grails-app/domain/dbnp/studycapturing/Study.groovy

    r774 r778  
    100100        }
    101101
     102
     103        /**
     104         * Return all subjects for a specific template
     105         * @param Template
     106         * @return ArrayList
     107         */
     108        def ArrayList<Subject> giveSubjectsForTemplate(Template template) {
     109                subjects.findAll { it.template.equals(template) }
     110        }
     111
    102112        /**
    103113         * Return the unique Event and SamplingEvent templates that are used in this study
     
    107117                // gives trouble when asking .size() to the result
    108118                // So we also use giveTemplates here
    109                 TemplateEntity.giveTemplates(events + samplingEvents)
     119                TemplateEntity.giveTemplates( ((events) ? events : []) + ((samplingEvents) ? samplingEvents : []) )
     120        }
     121
     122
     123        /**
     124         * Return all events and samplingEvenets for a specific template
     125         * @param Template
     126         * @return ArrayList
     127         */
     128        def ArrayList giveEventsForTemplate(Template template) {
     129                def events = events.findAll { it.template.equals(template) }
     130                def samplingEvents = samplingEvents.findAll { it.template.equals(template) }
     131
     132                return (events) ? events : samplingEvents
    110133        }
    111134
     
    138161
    139162
    140          /**
    141         * Delete a specific subject from this study, including all its relations
    142         * @param subject The subject to be deleted
    143         * @return A String which contains a (user-readable) message describing the changes to the database
    144         */
     163        /**
     164         * Delete a specific subject from this study, including all its relations
     165         * @param subject The subject to be deleted
     166         * @return A String which contains a (user-readable) message describing the changes to the database
     167         */
    145168        String deleteSubject(Subject subject) {
    146 
    147169                String msg = "Subject ${subject.name} was deleted"
    148170
     
    171193                return msg
    172194        }
     195
     196        /**
     197         * Delete an event from the study, including all its relations
     198         * @param Event
     199         * @return String
     200         */
     201        String deleteEvent(Event event) {
     202                String msg = "Event ${event} was deleted"
     203
     204                // remove event from the study
     205                this.removeFromEvents(event)
     206
     207                // remove event from eventGroups
     208                this.eventGroups.each() { eventGroup ->
     209                        eventGroup.removeFromEvents(event)
     210                }
     211
     212                return msg
     213        }
     214
     215        /**
     216         * Delete a samplingEvent from the study, including all its relations
     217         * @param SamplingEvent
     218         * @return String
     219         */
     220        String deleteSamplingEvent(SamplingEvent samplingEvent) {
     221                String msg = "SamplingEvent ${samplingEvent} was deleted"
     222
     223                // remove event from eventGroups
     224                this.eventGroups.each() { eventGroup ->
     225                        eventGroup.removeFromSamplingEvents(samplingEvent)
     226                }
     227
     228                // remove event from the study
     229                this.removeFromSamplingEvents(samplingEvent)
     230
     231                return msg
     232        }
     233        /**
     234         * Delete an eventGroup from the study, including all its relations
     235         * @param EventGroup
     236         * @return String
     237         */
     238        String deleteEventGroup(EventGroup eventGroup) {
     239                String msg = "EventGroup ${eventGroup} was deleted"
     240
     241                // remove the eventGroup from the study
     242                this.removeFromEventGroups(eventGroup)
     243
     244                return msg
     245        }
    173246}
  • trunk/grails-app/domain/dbnp/studycapturing/Template.groovy

    r754 r778  
    3333        /** The template fields which are the members of this template. This is a List to preserve the field order */
    3434        List fields
     35
     36        // keep an internal identifier for use in dynamic forms
     37        private int identifier = 0
     38        static int iterator = 0
     39
     40        // set transients
     41        static transients = [ "identifier", "iterator" ]
     42
    3543        static hasMany = [fields: TemplateField]
    3644
     
    7078                // which can co-exist with the same name. See also TemplateField
    7179                //      name(unique:['entity'])
     80        }
     81
     82        /**
     83         * Class constructor increments that static iterator
     84         * and sets the object's identifier (used in dynamic webforms)
     85         * @void
     86         */
     87        public Template() {
     88                if (!identifier) identifier = iterator++
     89                println ".instantiating [" + this.getClass() + "] ("+ identifier + ")"
     90        }
     91
     92        /**
     93         * Return the identifier
     94         * @return int
     95         */
     96        final public int getIdentifier() {
     97                return identifier
    7298        }
    7399
  • trunk/grails-app/domain/dbnp/studycapturing/TemplateEntity.groovy

    r754 r778  
    1818 */
    1919abstract class TemplateEntity implements Serializable {
    20 
    2120        /** The actual template of this TemplateEntity instance */
    2221        Template template
     
    3837        Map templateTermFields = [:]
    3938
     39        // keep an internal identifier for use in dynamic forms
     40        private int identifier = 0
     41        static int iterator = 0
     42
     43        // set transients
     44        static transients = [ "identifier", "iterator" ]
     45
     46        // define relationships
    4047        static hasMany = [
    4148                templateStringFields: String,
     
    5461
    5562        static mapping = {
    56 
    5763                // Specify that each TemplateEntity-subclassing entity should have its own tables to store TemplateField values.
    5864                // This results in a lot of tables, but performance is presumably better because in most queries, only values of
     
    324330                        return (!error)
    325331                })
     332        }
     333
     334        /**
     335         * Class constructor increments that static iterator
     336         * and sets the object's identifier (used in dynamic webforms)
     337         * @void
     338         */
     339        public TemplateEntity() {
     340                if (!identifier) identifier = iterator++
     341        }
     342
     343        /**
     344         * Return the identifier
     345         * @return int
     346         */
     347        final public int getIdentifier() {
     348                return identifier
    326349        }
    327350
     
    593616                        // it is unset if it is.
    594617                        if (value || value == 0 || ( field.type == TemplateFieldType.BOOLEAN && value == false)) {
    595                                 println ".setting [" + ((super) ? super.class : '??') + "] template field: [" + fieldName + "] ([" + value.toString() + "] of type [" + value.class + "])"
     618                                println ".setting [" + ((super) ? super.class : '??') + "] ("+getIdentifier()+") template field: [" + fieldName + "] ([" + value.toString() + "] of type [" + value.class + "])"
    596619
    597620                                // set value
    598621                                store[fieldName] = value
    599622                        } else if (store[fieldName]) {
    600                                 println ".unsetting [" + ((super) ? super.class : '??') + "] template field: [" + fieldName + "]"
     623                                println ".unsetting [" + ((super) ? super.class : '??') + "] ("+getIdentifier()+") template field: [" + fieldName + "]"
    601624
    602625                                // remove the item from the Map (if present)
Note: See TracChangeset for help on using the changeset viewer.