source: trunk/grails-app/domain/dbnp/studycapturing/Subject.groovy

Last change on this file was 1922, checked in by work@…, 8 years ago
  • removed all default instance configuration in favor of just one default.properties file. Instance configuration should be on the server side, not within the code. The setup wizard will help you generate a configuration file...
  • removed obsolete references to searchable
  • removed obsolete references to grails melody
  • Property svn:keywords set to Rev Author Date
File size: 3.0 KB
Line 
1package dbnp.studycapturing
2
3import org.dbnp.gdt.*
4
5/**
6 * This domain class describes the subjects in a study.
7 *
8 * Revision information:
9 * $Rev: 1922 $
10 * $Author: work@osx.eu $
11 * $Date: 2011-06-09 12:10:44 +0000 (do, 09 jun 2011) $
12 */
13class Subject extends TemplateEntity {
14        // A Subject always belongs to one Study
15        static belongsTo = [parent: Study]
16
17        /** The name of the subject, which should be unique within the study   */
18        String name
19
20        /** The species of the subject. In the domainFields property, the ontologies from which this term may come are specified.   */
21        Term species
22
23        static constraints = {
24                // Ensure that the subject name is unique within the study
25                name(unique: ['parent'])
26        }
27
28        static mapping = {
29                name column: "subjectname"
30
31                // Workaround for bug http://jira.codehaus.org/browse/GRAILS-6754
32                templateTextFields type: 'text'
33        }
34
35        /**
36         * return the domain fields for this domain class
37         * @return List
38         */
39        static List<TemplateField> giveDomainFields() { return Subject.domainFields; }
40
41        // We have to specify an ontology list for the species property. However, at compile time, this ontology does of course not exist.
42        // Therefore, the ontology is added at runtime in the bootstrap, possibly downloading the ontology properties if it is not present in the database yet.
43        static List<TemplateField> domainFields = [
44                new TemplateField(
45                        name: 'name',
46                        type: TemplateFieldType.STRING,
47                        preferredIdentifier: true,
48                        comment: 'Use the local subject name or the pre-defined name',
49                        required: true),
50                new TemplateField(
51                        name: 'species',
52                        type: TemplateFieldType.ONTOLOGYTERM,
53                        comment: "The species name is based on the NCI Thesaurus / NCBI organismal classification ontology, a taxonomic classification of living organisms and associated artifacts. If a species is missing, please add it by using 'add more'",
54                        required: true)
55        ]
56
57        /**
58         * Return by default the name of the subject.
59         *
60         * @return name field
61         */
62        String toString() {
63                return name
64        }
65
66        /**
67         * Returns a human readable string of a list of subjects, with a maximum number
68         * of characters
69         *
70         * @param subjectList List with Subject objects
71         * @param maxChars maximum number of characters returned
72         * @return human readble string with at most maxChars characters, representing the subjects given.
73         */
74        public static String trimSubjectNames(ArrayList subjectList, Integer maxChars) {
75                def simpleSubjects = subjectList.name.join(', ');
76                def showSubjects
77
78                // If the subjects will fit, show them all
79                if (!maxChars || simpleSubjects.size() < maxChars) {
80                        showSubjects = simpleSubjects;
81                } else {
82                        // Always add the first name
83                        def subjectNames = subjectList[0]?.name;
84
85                        // Continue adding names until the length is to long
86                        def id = 0;
87                        subjectList.each { subject ->
88                                if (id > 0) {
89                                        if (subjectNames?.size() + subject.name?.size() < maxChars - 15) {
90                                                subjectNames += ", " + subject.name;
91                                        } else {
92                                                return;
93                                        }
94                                }
95                                id++;
96                        }
97
98                        // Add a postfix
99                        subjectNames += " and " + (subjectList?.size() - id) + " more";
100
101                        showSubjects = subjectNames;
102                }
103
104                return showSubjects
105        }
106}
Note: See TracBrowser for help on using the repository browser.