Changeset 267

Show
Ignore:
Timestamp:
15-03-10 16:59:34 (4 years ago)
Author:
jahn
Message:

Added convenience function that creates a Term if it does not exist in the db. This should be updated in accordance with the Ontologies.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/domain/dbnp/data/Term.groovy

    r247 r267  
    2525                return name 
    2626        } 
     27 
     28 
     29        // Covenenice method for delivering Terms. 
     30        // if the term is already defined, use it. 
     31        // otherwise, create it. 
     32        // should be removed when ontologies work. 
     33        static getTerm( string ) { 
     34            def term = Term.find("from Term as t where t.name = '${string}'") 
     35            if( term==null ) { term = new Term() 
     36                    term.name=string 
     37                    term.ontology = Ontology.find('from Ontology as o') 
     38                    term.accession = '' 
     39                    println string 
     40                    if( term.save(flush:true) ) { println "okay, saved" } 
     41                    else { 
     42                            term.errors.each{ println it } 
     43                            println "not okay, not saved" } 
     44            } 
     45            return term 
     46        } 
    2747}