- Timestamp:
- Oct 26, 2010, 4:33:21 PM (12 years ago)
- Location:
- trunk/grails-app
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/conf/BootStrapStudies.groovy
r976 r997 90 90 91 91 def glucoseTerm = new Term( 92 name: ' Glucose',92 name: 'glucose', 93 93 ontology: chebiOntology, 94 94 accession: 'CHEBI:17234' -
trunk/grails-app/controllers/dbnp/studycapturing/TermEditorController.groovy
r959 r997 58 58 } 59 59 on("add") { 60 println params60 // get ontology by ncboVersionedId 61 61 def ontology = Ontology.findByNcboVersionedId( params.get('term-ontology_id') as int ) 62 62 def strTerm = params.get('term') … … 64 64 // do we have an ontology? 65 65 if (!ontology && params.get('term-ontology_id')) { 66 // no, so either this is a new ontology that does not yet 67 // exist in the database, or it is a new version of an 68 // ontology that is already present in the database 66 69 println ".ontology missing, first fetch ontology information" 67 70 … … 74 77 75 78 // instantiate Ontology with the proper values 76 ontology = Ontology.getBioPortalOntologyByVersionedId( params.get('term-ontology_id') ) .save(flush:true)79 ontology = Ontology.getBioPortalOntologyByVersionedId( params.get('term-ontology_id') ) 77 80 78 if (ontology.validate()) { 81 // check if this is a newer version of an existing ontology 82 def checkOntology = Ontology.findByName( ontology.name ) 83 if ( checkOntology ) { 84 // this is a newer version of an existing Ontology, update 85 // the ontology to a newer version. This is not the best 86 // way to handle these updates as we don't know if terms 87 // have been updated. However, introducing different versions 88 // of Ontologies results into numerous difficulties as well: 89 // - what to do with studies that rely on an older ontology 90 // - when a new ontology is added, the existing terms of the 91 // older version are lacking in the new version 92 // - the webservice can only search on ontologyid, not on 93 // versions of ncboVersioned id's 94 // - if the name has changed between versions this check 95 // will not work anymore 96 // - etc :) 97 // So for now, we will just update the existing ontology with 98 // the new information until it becomes clear this needs a 99 // more thorough workaround... 100 // 101 // Jeroen, 20101026 102 103 // update ontology values 104 checkOntology.ncboVersionedId = ontology.ncboVersionedId 105 checkOntology.versionNumber = ontology.versionNumber 106 checkOntology.url = ontology.url 107 108 // store the ontology 109 if ( checkOntology.validate() ) { 110 println ".updated ontology with new version information" 111 checkOntology.save(flush:true) 112 113 // and use this existing ontology 114 ontology = checkOntology 115 } 116 } else if ( ontology.validate() ) { 117 // store the ontology 118 println ".adding new ontology" 79 119 ontology.save(flush:true) 80 120 } … … 83 123 // ontology-id is invalid (hence, the term 84 124 // is invalid) 125 println ".oops? --> " + e.getMessage() 85 126 flash.errors = ["We could not add the ontology for this term, please try again"] 86 127 } 87 128 } 88 129 89 // instantiate term with parameters 90 def term = new Term( 91 name: strTerm, 92 ontology: ontology, 93 accession: params.get('term-concept_id') 94 ) 130 // got an error? 131 if (!flash.errors) { 132 // instantiate term with parameters 133 def term = new Term( 134 name: strTerm, 135 ontology: ontology, 136 accession: params.get('term-concept_id') 137 ) 95 138 96 // validate term 97 if (term.validate()) { 98 // save the term to the database 99 if (term.save(flush:true)) { 100 flash.message = "'" + params.get('term') + "' was successfully added, either search for another term to add or close this window" 101 success() 139 // validate term 140 if (term.validate()) { 141 // save the term to the database 142 if (term.save(flush:true)) { 143 flash.message = "'" + params.get('term') + "' was successfully added, either search for another term to add or close this window" 144 success() 145 } else { 146 flash.errors = ["We encountered a problem while storing the selected term. Please try again."] 147 term.errors.each() { println it } 148 error() 149 } 102 150 } else { 103 flash.errors = ["We encountered a problem while storing the selected term. Please try again."]151 // term did not validate properly 104 152 term.errors.each() { println it } 153 if (term.errors =~ 'unique') { 154 flash.errors = ["'" + params.get('term') + "' already exists, either search for another term or close this window"] 155 } else { 156 flash.errors = ["We encountered a problem while storing the selected term. Please try again."] 157 } 158 105 159 error() 106 160 } 107 } else {108 // term did not validate properly109 term.errors.each() { println it }110 if (term.errors =~ 'unique') {111 flash.errors = ["'" + params.get('term') + "' already exists, either search for another term or close this window"]112 } else {113 flash.errors = ["We encountered a problem while storing the selected term. Please try again."]114 }115 116 error()117 161 } 118 162 }.to "terms"
Note: See TracChangeset
for help on using the changeset viewer.