1 | /** |
---|
2 | * SimpleQueryController Controler |
---|
3 | * |
---|
4 | * Description of my controller |
---|
5 | * |
---|
6 | * @author vincent@ludden.nl |
---|
7 | * @since 20100526 |
---|
8 | * @package dbnp.query |
---|
9 | * |
---|
10 | * Revision information: |
---|
11 | * $Rev: 658 $ |
---|
12 | * $Author: vinlud $ |
---|
13 | * $Date: 2010-07-19 07:02:15 +0000 (ma, 19 jul 2010) $ |
---|
14 | */ |
---|
15 | package dbnp.query |
---|
16 | |
---|
17 | import dbnp.data.* |
---|
18 | import dbnp.studycapturing.Study |
---|
19 | import org.compass.core.engine.SearchEngineQueryParseException |
---|
20 | import dbnp.rest.common.CommunicationManager |
---|
21 | |
---|
22 | class SimpleQueryController { |
---|
23 | /** |
---|
24 | * index closure |
---|
25 | */ |
---|
26 | def index = { |
---|
27 | redirect( action:'pages') |
---|
28 | } |
---|
29 | |
---|
30 | def searchableService |
---|
31 | |
---|
32 | def pagesFlow = { |
---|
33 | |
---|
34 | // Starting simpleQuery flow, initialize variables |
---|
35 | onStart { |
---|
36 | println "Starting webflow simpleQuery" |
---|
37 | flow.search_term = null |
---|
38 | flow.search_sa_compounds = [] |
---|
39 | flow.search_sa_operators = [] |
---|
40 | flow.search_sa_values = [] |
---|
41 | flow.page = 0 |
---|
42 | flow.pages = [ |
---|
43 | [title: 'Query'], |
---|
44 | [title: 'Results'] |
---|
45 | ] |
---|
46 | } |
---|
47 | |
---|
48 | // Render the query page and handle its actions |
---|
49 | query { |
---|
50 | render(view: "/simpleQuery/mainPage") |
---|
51 | |
---|
52 | onRender { |
---|
53 | println "Rendering mainPage" |
---|
54 | flow.operators = ['>', '=', '<'] |
---|
55 | |
---|
56 | if (flow.search_sa_compounds.size() == 0) { |
---|
57 | flow.showFirstRowCompounds = true |
---|
58 | println "showRow true" |
---|
59 | } else { |
---|
60 | flow.showFirstRowCompounds = false |
---|
61 | println "showRow false" |
---|
62 | } |
---|
63 | |
---|
64 | flow.species = Term.findAll() |
---|
65 | flow.page = 1 |
---|
66 | } |
---|
67 | |
---|
68 | on("search") { |
---|
69 | println "Search!" |
---|
70 | if (!params.search_term.trim()) { |
---|
71 | return [:] |
---|
72 | } |
---|
73 | }.to "searching" |
---|
74 | |
---|
75 | on("refresh").to "query" |
---|
76 | } |
---|
77 | |
---|
78 | |
---|
79 | // Searching for results |
---|
80 | searching { |
---|
81 | action { |
---|
82 | println "Starting simpleQuery search..." |
---|
83 | def searchResult |
---|
84 | def searchGscfResult |
---|
85 | def searchSamResult = [] |
---|
86 | |
---|
87 | // TODO: walk parameters, remove empty entries |
---|
88 | |
---|
89 | // Map GSCF parameters |
---|
90 | flow.search_term = params.search_term // String |
---|
91 | |
---|
92 | // Map SAM parameters |
---|
93 | if (params.sa_compound instanceof String) { |
---|
94 | //flow.search_sam = [:] |
---|
95 | flow.search_sa_compounds = [] |
---|
96 | flow.search_sa_operators = [] |
---|
97 | flow.search_sa_values = [] |
---|
98 | |
---|
99 | flow.search_sa_compounds.add(params.sa_compound) |
---|
100 | flow.search_sa_operators.add(params.sa_operator) |
---|
101 | flow.search_sa_values.add(params.sa_value) |
---|
102 | } else { |
---|
103 | flow.search_sa_compounds = params.sa_compound as List |
---|
104 | flow.search_sa_operators = params.sa_operator as List |
---|
105 | flow.search_sa_values = params.sa_value as List |
---|
106 | } |
---|
107 | |
---|
108 | // Search the keyword with the Searchable plugin |
---|
109 | try { |
---|
110 | searchGscfResult = searchableService.search(flow.search_term) |
---|
111 | println "RESULT: " + searchGscfResult |
---|
112 | } catch (SearchEngineQueryParseException ex) { |
---|
113 | println ex |
---|
114 | return [parseException: true] |
---|
115 | } |
---|
116 | |
---|
117 | // Map non-study objects to Studies |
---|
118 | // ... todo when the plugin works and I can see the output |
---|
119 | |
---|
120 | // Search in the SAM module when a compound is entered |
---|
121 | // Todo: check whether the module is active and to be used |
---|
122 | // ... |
---|
123 | if (flow.search_sa_compounds.size() > 0) { |
---|
124 | def resultSAM = [] |
---|
125 | resultSAM = this.searchSAM(flow.search_sa_compounds) |
---|
126 | println "Sam result: " + resultSAM |
---|
127 | } |
---|
128 | |
---|
129 | // Merge the results of all searches |
---|
130 | if (searchGscfResult.size() > 0) { |
---|
131 | |
---|
132 | searchResult = searchSamResult + searchGscfResult |
---|
133 | } |
---|
134 | |
---|
135 | |
---|
136 | // Save the results in the flow |
---|
137 | flow.listStudies = searchGscfResult.results |
---|
138 | println flow.listStudies |
---|
139 | |
---|
140 | } |
---|
141 | |
---|
142 | on("error").to "query" |
---|
143 | on("success").to "results" |
---|
144 | } |
---|
145 | |
---|
146 | |
---|
147 | // Render result page including search options |
---|
148 | results { |
---|
149 | render(view: "/simpleQuery/mainPage") |
---|
150 | |
---|
151 | onRender { |
---|
152 | println "Rendering resultPage" |
---|
153 | flow.page = 2 |
---|
154 | |
---|
155 | flow.showFirstRowCompounds = false |
---|
156 | } |
---|
157 | |
---|
158 | on("reset") { |
---|
159 | flow.search_term = null |
---|
160 | flow.studies = null |
---|
161 | flow.search_sa_compounds = null |
---|
162 | flow.search_sa_values = null |
---|
163 | flow.search_tt_genepaths = null |
---|
164 | flow.search_tt_regulations = null |
---|
165 | println "Resetting query flow" |
---|
166 | }.to "query" |
---|
167 | |
---|
168 | on("search").to "searching" |
---|
169 | on("refresh").to "results" |
---|
170 | } |
---|
171 | |
---|
172 | } |
---|
173 | |
---|
174 | |
---|
175 | static Map searchSAM (List compounds) { |
---|
176 | if (compounds.size() == 1) { |
---|
177 | println "Single SAM call" |
---|
178 | def mapSamResult |
---|
179 | mapSamResult = CommunicationManager.getQueryResult(compounds.get(0)) |
---|
180 | println "CommMngr result: " + mapSamResult.assays.size() |
---|
181 | |
---|
182 | mapSamResult.assays.each { |
---|
183 | simpleAssay -> println simpleAssay.id |
---|
184 | |
---|
185 | } |
---|
186 | |
---|
187 | return mapSamResult |
---|
188 | |
---|
189 | } else { |
---|
190 | println "Multiple SAM calls" |
---|
191 | def tmpSamResult = [:] |
---|
192 | def mapSamResult = [studies:[], assays:[]] |
---|
193 | def i = 0 |
---|
194 | |
---|
195 | compounds.each { compound -> |
---|
196 | println "SAM Search with " + compound |
---|
197 | tmpSamResult = CommunicationManager.getQueryResult(compound) |
---|
198 | println tmpSamResult.assays.size() + " results " + compound |
---|
199 | |
---|
200 | if (i == 0) { |
---|
201 | mapSamResult.assays = tmpSamResult.assays |
---|
202 | mapSamResult.studies = tmpSamResult.studies |
---|
203 | } else { |
---|
204 | mapSamResult.assays = mapSamResult.assays.intersect(tmpSamResult.assays) |
---|
205 | mapSamResult.studies = mapSamResult.studies.intersect(tmpSamResult.studies) |
---|
206 | } |
---|
207 | |
---|
208 | i++ |
---|
209 | } |
---|
210 | |
---|
211 | return mapSamResult |
---|
212 | } |
---|
213 | |
---|
214 | } |
---|
215 | |
---|
216 | |
---|
217 | |
---|
218 | static List merge (List list1, List list2) { |
---|
219 | |
---|
220 | def resultList = [] |
---|
221 | resultList = list1.intersect(list2) |
---|
222 | |
---|
223 | return resultList |
---|
224 | } |
---|
225 | |
---|
226 | } |
---|