source: trunk/grails-app/domain/dbnp/data/Term.groovy @ 640

Last change on this file since 640 was 640, checked in by vinlud, 11 years ago

Setting Searchable only to search in known string fields

  • Property svn:keywords set to Date Rev Author
File size: 2.1 KB
Line 
1package dbnp.data
2
3import dbnp.data.Ontology
4
5/**
6 * The Term object describes a term in the ontology that is referred to in other entities such as events.
7 * The Term object should point to an existing term in an online ontology, therefore instances of this class can also
8 * be seen as a cache of elements of the external ontology.
9 * BioPortal example: Mus musculus: http://rest.bioontology.org/bioportal/concepts/38802/NCBITaxon:10090
10 *
11 * Revision information:
12 * $Rev: 640 $
13 * $Author: vinlud $
14 * $Date: 2010-07-02 07:38:49 +0000 (vr, 02 jul 2010) $
15 */
16class Term implements Serializable {
17    static searchable = {
18           [only: ['name']]
19    }
20
21        String name             // BioPortal: label (preferred name)
22        Ontology ontology       // Parent ontology. To enable the unique constraints, we describe the Ontology-Term relation here
23        String accession        // BioPortal: conceptId
24
25        static constraints = {
26                accession(unique: 'ontology')   // Accession should be unique within an ontology
27                name(unique: 'ontology')        // Preferred name should be unique within an ontology
28        name(size: 1..255)              // Name should be a non-empty string
29        }
30
31        def String toString() {
32                return name
33        }
34
35        /**
36         * Return all terms for a string of comma separated ontology ncboId's.
37         * @see Ontology.groovy
38         * @param ontologies
39         * @return
40         */
41        def giveAllByOntologies( ontologies ) {
42                // this method does not seem to work (see taglibrary:termSelect)
43                // i'll try to get it working later, or delete this altogether
44                // - Jeroen
45                def data = []
46                def terms = []
47
48                // got a string?
49                if (ontologies instanceof String) {
50                        // split the ontologies string
51                        ontologies.split(/\,/).each() { ncboId ->
52                                // trim the id
53                                ncboId.trim()
54
55                                // fetch all terms for this ontology
56                                def ontology = Ontology.findAllByNcboId(ncboId)
57
58                                // does this ontology exist?
59                                if (ontology) {
60                                        ontology.each() {
61                                                data[ data.size() ] = it
62                                        }
63                                }
64                        }
65
66                        ontologies = data
67                }
68
69                // iterate through ontologies
70                ontologies.each() { ontology ->
71                        Term.findAllByOntology( ontology ).each() { term ->
72                                terms[ terms.size() ] = term
73                        }
74                }
75
76                // sort alphabetically
77                terms.sort()
78        }
79}
Note: See TracBrowser for help on using the repository browser.