Ignore:
Timestamp:
Aug 16, 2010, 6:04:00 PM (10 years ago)
Author:
keesvb
Message:

added Sample tests for deleting samples via parent sampling event and event group, corrected some small errors, updated BootStrap? to find out why Sample.parentEvent gets serialized into the db, still no luck...

Location:
trunk/grails-app/domain/dbnp/studycapturing
Files:
3 edited

Legend:

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

    r784 r812  
    1212
    1313        // A Sample always belongs to one study.
    14         static belongsTo = [parent : Study]
     14        static belongsTo = [parent : Study, parentSubject : Subject, parentEvent : SamplingEvent]
    1515
    1616        // A Sample optionally has a parent Subject from which it was taken, this Subject should be in the same parent study.
    17         Subject parentSubject
     17        //long parentSubject
    1818
    1919        // Also, it has a parent SamplingEvent describing the actual sampling, also within the same parent study.
    20         SamplingEvent parentEvent
     20        // Strange enough, we need to define parentEvent as a long here, otherwise the SamplingEvent gets serialized into the database (?!!)
     21        //long parentEvent
    2122
    2223        String name             // should be unique with respect to the parent study (which can be inferred)
  • trunk/grails-app/domain/dbnp/studycapturing/SamplingEvent.groovy

    r803 r812  
    8989                return samples == null ? [] : samples
    9090        }
     91
     92        def String toString() {
     93                return fieldExists('Description') ? getFieldValue('Description') : ""
     94        }
     95       
    9196}
  • trunk/grails-app/domain/dbnp/studycapturing/Study.groovy

    r811 r812  
    237237                }
    238238
    239                 // remove event from the study
     239                // Delete the samples that have this sampling event as parent
     240                this.samples.findAll { it.parentEvent.equals(samplingEvent) }.each {
     241                        // This should remove the sample itself too, because of the cascading belongsTo relation
     242                        this.removeFromSamples(it)
     243                        // But apparently it needs an explicit delete() too
     244                        it.delete()
     245                        msg += ", sample '${it.name}' was deleted"
     246                }
     247
     248                // Remove event from the study
     249                // This should remove the event group itself too, because of the cascading belongsTo relation
    240250                this.removeFromSamplingEvents(samplingEvent)
     251                // But apparently it needs an explicit delete() too
     252                // (Which can be verified by outcommenting this line, then SampleTests.testDeleteViaParentSamplingEvent fails
     253                samplingEvent.delete()
    241254
    242255                return msg
     
    300313                                // -------
    301314
    302                                 println ".removing sample '${it.name}' from study '${this.name}'"
     315                                println ".removing sample '${it.name}' from study '${this.title}'"
    303316                                msg += ", sample '${it.name}' was deleted"
    304317                                this.removeFromSamples( it )
     
    321334
    322335                // remove the eventGroup from the study
    323                 println ".remove eventGroup '${eventGroup.name}' from study '${this.name}'"
     336                println ".remove eventGroup '${eventGroup.name}' from study '${this.title}'"
    324337                this.removeFromEventGroups(eventGroup)
    325338
Note: See TracChangeset for help on using the changeset viewer.