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: 486 $ |
---|
12 | * $Author: duh $ |
---|
13 | * $Date: 2010-05-27 13:57:41 +0000 (do, 27 mei 2010) $ |
---|
14 | */ |
---|
15 | package dbnp.studycapturing |
---|
16 | |
---|
17 | import dbnp.data.Term |
---|
18 | import dbnp.data.Ontology |
---|
19 | |
---|
20 | class 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 | def strTerm = params.get('term') |
---|
69 | |
---|
70 | // do we have an ontology? |
---|
71 | if (!ontology) { |
---|
72 | // TODO: if ontology is missing, create it |
---|
73 | // pending possible addition to OntoCAT BioportalOntologyService API of search by versioned Ontology Id |
---|
74 | println "Ontology is empty" |
---|
75 | } |
---|
76 | |
---|
77 | // instantiate term with parameters |
---|
78 | def term = new Term( |
---|
79 | name: strTerm, |
---|
80 | ontology: ontology, |
---|
81 | accession: params.get('term-concept_id') |
---|
82 | ) |
---|
83 | |
---|
84 | // validate term |
---|
85 | if (term.validate()) { |
---|
86 | println "Term validated correctly" |
---|
87 | if (term.save(flush:true)) { |
---|
88 | println ".term save ok" |
---|
89 | } else { |
---|
90 | println ".term save failed?" |
---|
91 | } |
---|
92 | success() |
---|
93 | flash.message = "Term addition succeeded" |
---|
94 | } else { |
---|
95 | println "Term validation failed" |
---|
96 | println "errors:" |
---|
97 | term.errors.getAllErrors().each() { |
---|
98 | println it |
---|
99 | } |
---|
100 | error() |
---|
101 | flash.message = "Term addition failed" |
---|
102 | } |
---|
103 | }.to "terms" |
---|
104 | } |
---|
105 | } |
---|
106 | } |
---|