Changeset 1176


Ignore:
Timestamp:
Nov 19, 2010, 12:19:29 PM (13 years ago)
Author:
work@…
Message:
  • resolved issue #187 by refactoring the TermEditor? to support the ncboId change Robert made in r1156
Location:
trunk/grails-app
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/controllers/dbnp/studycapturing/TermEditorController.groovy

    r1157 r1176  
    5858                        }
    5959                        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
    6361
    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
    7065
    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                                        }
    7579
    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 )
    9784
    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                                        }
    10294
    103                                                         // store the ontology
    104                                                         if ( checkOntology.validate() ) {
    105                                                                 println ".updated ontology with new version information"
    106                                                                 checkOntology.save(flush:true)
    107 
    108                                                                 // and use this existing ontology
    109                                                                 ontology = checkOntology
    110                                                         }
    111                                                 } else if ( ontology.validate() ) {
    112                                                         // store the ontology
    113                                                         println ".adding new ontology"
    114                                                         ontology.save(flush:true)
    115                                                 }
    116                                         } catch (Exception e) {
    117                                                 // something went wrong, probably the
    118                                                 // ontology-id is invalid (hence, the term
    119                                                 // 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) {
    12795                                        // instantiate term with parameters
    12896                                        def term = new Term(
    129                                                 name: strTerm,
     97                                                name: params.get('term'),
    13098                                                ontology: ontology,
    13199                                                accession: params.get('term-concept_id')
     
    135103                                        if (term.validate()) {
    136104                                                // save the term to the database
    137                                                 if (term.save(flush:true)) {
     105                                                if (term.save()) {
    138106                                                        flash.message = "'" + params.get('term') + "' was successfully added, either search for another term to add or close this window"
    139107                                                        success()
     
    145113                                        } else {
    146114                                                // term did not validate properly
    147                                                 term.errors.each() { println it }
    148115                                                if (term.errors =~ 'unique') {
    149116                                                        flash.errors = ["'" + params.get('term') + "' already exists, either search for another term or close this window"]
     
    154121                                                error()
    155122                                        }
     123                                } catch (Exception e) {
     124                                        flash.errors = ["${e.getMessage()}"]
     125
     126                                        error()
    156127                                }
    157128                        }.to "terms"
  • trunk/grails-app/views/termEditor/pages/terms.gsp

    r1005 r1176  
    8484                $(document).ready(function() {
    8585                // 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                    });
    8790                });
    8891        </script>
Note: See TracChangeset for help on using the changeset viewer.