source: trunk/grails-app/controllers/dbnp/studycapturing/TermEditorController.groovy @ 456

Last change on this file since 456 was 456, checked in by vinlud, 13 years ago

Messaging & checks ontology selector

  • Property svn:keywords set to Date Author Rev
File size: 2.2 KB
Line 
1/**
2 * TermEditorController Controller
3 *
4 * Webflow driven term editor
5 *
6 * @author  Jeroen Wesbeek
7 * @since       20100420
8 * @package     studycapturing
9 *
10 * Revision information:
11 * $Rev: 456 $
12 * $Author: vinlud $
13 * $Date: 2010-05-25 07:17:18 +0000 (di, 25 mei 2010) $
14 */
15package dbnp.studycapturing
16
17import dbnp.data.Term
18import dbnp.data.Ontology
19
20class TermEditorController {
21        /**
22         * index closure
23         */
24    def index = {
25                // got a ontology get parameter?
26                def ontologies = (params.ontologies) ? params.ontologies : null
27
28                // enter the flow!
29        redirect(action: 'pages', params:["ontologies":ontologies])
30    }
31
32        /**
33         * Webflow
34         */
35        def pagesFlow = {
36                // start the flow
37                onStart {
38                        println "start term / ontology editor flow"
39
40                        if (params.ontologies) {
41                                flow.ontologies         = params.ontologies
42                                flow.ontologiesList     = []
43                                params.ontologies.split(/\,/).each() { ncboId ->
44                                        // trim the id
45                                        ncboId.trim()
46
47                                        // and add to the flow scope
48                                        flow.ontologiesList[ flow.ontologies.size() ] = ncboId
49                                }
50
51                                /*** EXAMPLE OF HOW TO FETCH ONTOLOGY INSTANCES
52                                 * ontologies.each() {
53                                 *       println Ontology.findAllByNcboId( it )
54                                 * }
55                                 */
56                        }
57                }
58
59                // main term editor page
60                terms {
61                        render(view: "terms")
62                        onRender {
63                                println "Rendering term selection popup"
64                        }
65                        on("add") {
66                                println params
67                                def ontology = Ontology.findByNcboVersionedId( params.get('term-ontology_id') as int )
68
69                                // do we have an ontology?
70                                if (!ontology) {
71                                        // TODO: if ontology is missing, create it
72                    // pending possible addition to OntoCAT BioportalOntologyService API of search by versioned Ontology Id
73                                }
74
75                                // instantiate term with parameters
76                                def term = new Term(
77                                        name: params.get('term'),
78                                        ontology: ontology,
79                                        accession: params.get('term-concept_id')
80                                )
81
82                                // validate term
83                                if (term.validate()) {
84                                        println "Term validated correctly"
85                                        term.save()
86                                        success()
87                    flash.message = "Term addition succeeded"
88                                } else {
89                                        println "Term validation failed"
90                                        println "errors:"
91                                        term.errors.getAllErrors().each() {
92                                                println it
93                                        }
94                                        flash.errors = term.errors
95                                        error()
96                    flash.message = "Term addition failed"
97                                }
98                        }.to "terms"
99                }
100        }
101}
Note: See TracBrowser for help on using the repository browser.