Changeset 1176
- Timestamp:
- Nov 19, 2010, 12:19:29 PM (13 years ago)
- Location:
- trunk/grails-app
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/dbnp/studycapturing/TermEditorController.groovy
r1157 r1176 58 58 } 59 59 on("add") { 60 // get ontology by ncboVersionedId 61 def ontology = Ontology.findByNcboVersionedId( params.get('term-ontology_id') as int ) 62 def strTerm = params.get('term') 60 println params 63 61 64 // do we have an ontology? 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 69 println ".ontology missing, first fetch ontology information" 62 def ncboId = params.get('term-ncbo_id') 63 def ncboVersionedId = params.get('term-ontology_id') 64 def ontology = null 70 65 71 // use the NCBO REST service to fetch ontology information 72 try { 73 // instantiate Ontology with the proper values 74 ontology = Ontology.getBioPortalOntologyByVersionedId( params.get('term-ontology_id') ) 66 try { 67 // got the ncboId? 68 if (ncboId && ncboId != "null") { 69 // find ontology by ncboId 70 ontology = Ontology.findByNcboId(ncboId as int) 71 } else if (ncboVersionedId && ncboVersionedId != "null") { 72 // find ontology by ncboId 73 ontology = Ontology.findByNcboVersionedId(ncboVersionedId as int) 74 } else { 75 // somehow we didn't get both the ncboId as well 76 // as the versioned id. Throw an error. 77 throw new Exception("We did not receive the ontology with your request, please try again") 78 } 75 79 76 // check if this is a newer version of an existing ontology 77 def checkOntology = Ontology.findByName( ontology.name ) 78 if ( checkOntology ) { 79 // this is a newer version of an existing Ontology, update 80 // the ontology to a newer version. This is not the best 81 // way to handle these updates as we don't know if terms 82 // have been updated. However, introducing different versions 83 // of Ontologies results into numerous difficulties as well: 84 // - what to do with studies that rely on an older ontology 85 // - when a new ontology is added, the existing terms of the 86 // older version are lacking in the new version 87 // - the webservice can only search on ontologyid, not on 88 // versions of ncboVersioned id's 89 // - if the name has changed between versions this check 90 // will not work anymore 91 // - etc :) 92 // So for now, we will just update the existing ontology with 93 // the new information until it becomes clear this needs a 94 // more thorough workaround... 95 // 96 // Jeroen, 20101026 80 // do we have the ontology? 81 if (!ontology) { 82 // no, try to instantiate by using the BioPortal 83 ontology = (ncboId && ncboId != "null") ? Ontology.getBioPortalOntology( ncboId as int ) : Ontology.getBioPortalOntologyByVersionedId( ncboVersionedId as String ) 97 84 98 // update ontology values 99 checkOntology.ncboVersionedId = ontology.ncboVersionedId 100 checkOntology.versionNumber = ontology.versionNumber 101 checkOntology.url = ontology.url 85 // validate and save ontology 86 if (!(ontology.validate() && ontology.save(flush:true))) { 87 if (ncboId && ncboId != "null") { 88 throw new Exception("An Ontology with ncboId ${ncboId} (= Ontology ID) does not seem valid. See http://bioportal.bioontology.org/ontologies") 89 } else { 90 throw new Exception("An Ontology with ncboVersionedId ${ncboVersionedId} (= URL id) does not seem valid. See http://bioportal.bioontology.org/ontologies") 91 } 92 } 93 } 102 94 103 // store the ontology104 if ( checkOntology.validate() ) {105 println ".updated ontology with new version information"106 checkOntology.save(flush:true)107 108 // and use this existing ontology109 ontology = checkOntology110 }111 } else if ( ontology.validate() ) {112 // store the ontology113 println ".adding new ontology"114 ontology.save(flush:true)115 }116 } catch (Exception e) {117 // something went wrong, probably the118 // ontology-id is invalid (hence, the term119 // is invalid)120 println ".oops? --> " + e.getMessage()121 flash.errors = ["We could not add the ontology for this term, please try again"]122 }123 }124 125 // got an error?126 if (!flash.errors) {127 95 // instantiate term with parameters 128 96 def term = new Term( 129 name: strTerm,97 name: params.get('term'), 130 98 ontology: ontology, 131 99 accession: params.get('term-concept_id') … … 135 103 if (term.validate()) { 136 104 // save the term to the database 137 if (term.save( flush:true)) {105 if (term.save()) { 138 106 flash.message = "'" + params.get('term') + "' was successfully added, either search for another term to add or close this window" 139 107 success() … … 145 113 } else { 146 114 // term did not validate properly 147 term.errors.each() { println it }148 115 if (term.errors =~ 'unique') { 149 116 flash.errors = ["'" + params.get('term') + "' already exists, either search for another term or close this window"] … … 154 121 error() 155 122 } 123 } catch (Exception e) { 124 flash.errors = ["${e.getMessage()}"] 125 126 error() 156 127 } 157 128 }.to "terms" -
trunk/grails-app/views/termEditor/pages/terms.gsp
r1005 r1176 84 84 $(document).ready(function() { 85 85 // initialize the ontology chooser 86 new OntologyChooser().init({showHide: $('div#button')}); 86 new OntologyChooser().init({ 87 showHide: $('div#button'), 88 spinner: "${resource(dir: 'images', file: 'spinner.gif')}" 89 }); 87 90 }); 88 91 </script>
Note: See TracChangeset
for help on using the changeset viewer.