CoRoT N3 Variability » History » Version 1
Anonymous, 05/06/2012 17:36
1 | 1 | Anonymous | h1. CoRoT N3 Variability |
---|---|---|---|
2 | 1 | Anonymous | |
3 | 1 | Anonymous | Le CoRoT N3 Variability permet de faire une requête en prenant en compte ou non certaines observations d'après leur probabilité N3 : delta scuti, etc... et la valeur de la probabilité entre 0 et 1. |
4 | 1 | Anonymous | |
5 | 1 | Anonymous | Le code javascript correspondant : |
6 | 1 | Anonymous | |
7 | 1 | Anonymous | Côté ADMIN : |
8 | 1 | Anonymous | |
9 | 1 | Anonymous | <pre><code class="javascript"> |
10 | 1 | Anonymous | /*global Ext, sitools, ID, i18n, document, showResponse, alertFailure, LOCALE, ImageChooser, |
11 | 1 | Anonymous | showHelp*/ |
12 | 1 | Anonymous | Ext.namespace('sitools.component.forms.multiParam'); |
13 | 1 | Anonymous | |
14 | 1 | Anonymous | sitools.component.forms.multiParam.NthreeVariability = Ext.extend(sitools.component.forms.multiParam.abstractForm, { |
15 | 1 | Anonymous | height : 250, |
16 | 1 | Anonymous | id : 'sitools.component.forms.definitionId', |
17 | 1 | Anonymous | initComponent : function () { |
18 | 1 | Anonymous | this.winPropComponent.specificHeight = 350; |
19 | 1 | Anonymous | this.winPropComponent.specificWidth = 450; |
20 | 1 | Anonymous | sitools.component.forms.multiParam.NthreeVariability.superclass.initComponent.call(this); |
21 | 1 | Anonymous | this.componentDefaultValue1 = new Ext.form.NumberField({ |
22 | 1 | Anonymous | fieldLabel : i18n.get('label.defaultValue') + ' (Proba)', |
23 | 1 | Anonymous | name : 'componentDefaultValue1', |
24 | 1 | Anonymous | anchor : '100%', |
25 | 1 | Anonymous | allowBlank : true |
26 | 1 | Anonymous | }); |
27 | 1 | Anonymous | this.add(this.componentDefaultValue1); |
28 | 1 | Anonymous | |
29 | 1 | Anonymous | }, |
30 | 1 | Anonymous | onRender : function () { |
31 | 1 | Anonymous | sitools.component.forms.multiParam.NthreeVariability.superclass.onRender.apply(this, arguments); |
32 | 1 | Anonymous | if (this.action == 'modify') { |
33 | 1 | Anonymous | if (!Ext.isEmpty(this.selectedRecord.data.defaultValues)) { |
34 | 1 | Anonymous | if (Ext.isString(this.selectedRecord.data.defaultValues[0])) { |
35 | 1 | Anonymous | this.componentDefaultValue1.setValue(this.selectedRecord.data.defaultValues[0]); |
36 | 1 | Anonymous | } |
37 | 1 | Anonymous | } |
38 | 1 | Anonymous | } |
39 | 1 | Anonymous | }, |
40 | 1 | Anonymous | afterRender : function () { |
41 | 1 | Anonymous | sitools.component.forms.multiParam.NthreeVariability.superclass.afterRender.apply(this, arguments); |
42 | 1 | Anonymous | if (this.action == 'modify') { |
43 | 1 | Anonymous | if (!Ext.isEmpty(this.selectedRecord.data.defaultValues)) { |
44 | 1 | Anonymous | this.componentDefaultValue1.setValue(this.selectedRecord.data.defaultValues[0]); |
45 | 1 | Anonymous | |
46 | 1 | Anonymous | } |
47 | 1 | Anonymous | } |
48 | 1 | Anonymous | |
49 | 1 | Anonymous | }, |
50 | 1 | Anonymous | _onValidate : function (action, gridFormComponents) { |
51 | 1 | Anonymous | var f = this.getForm(); |
52 | 1 | Anonymous | if (!f.isValid()) { |
53 | 1 | Anonymous | Ext.Msg.alert(i18n.get('label.error'), i18n.get('warning.invalidForm')); |
54 | 1 | Anonymous | return false; |
55 | 1 | Anonymous | } |
56 | 1 | Anonymous | var defaultValue1 = Ext.isEmpty(f.findField('componentDefaultValue1')) ? "" : f.findField('componentDefaultValue1').getValue(); |
57 | 1 | Anonymous | var columnObjects = this.find('specificType', 'mapParam'); |
58 | 1 | Anonymous | var code = []; |
59 | 1 | Anonymous | Ext.each(columnObjects, function (columnObject) { |
60 | 1 | Anonymous | code.push(columnObject.getValue()); |
61 | 1 | Anonymous | }); |
62 | 1 | Anonymous | if (action == 'modify') { |
63 | 1 | Anonymous | var rec = gridFormComponents.getSelectionModel().getSelected(); |
64 | 1 | Anonymous | |
65 | 1 | Anonymous | var labelParam1 = Ext.isEmpty(f.findField('LABEL_PARAM1')) ? "" : f.findField('LABEL_PARAM1').getValue(); |
66 | 1 | Anonymous | var css = Ext.isEmpty(f.findField('CSS')) ? "" : f.findField('CSS').getValue(); |
67 | 1 | Anonymous | |
68 | 1 | Anonymous | rec.set('label', labelParam1); |
69 | 1 | Anonymous | rec.set('code', code); |
70 | 1 | Anonymous | rec.set('css', css); |
71 | 1 | Anonymous | rec.set('componentDefaultHeight', f.findField('componentDefaultHeight').getValue()); |
72 | 1 | Anonymous | rec.set('componentDefaultWidth', f.findField('componentDefaultWidth').getValue()); |
73 | 1 | Anonymous | |
74 | 1 | Anonymous | rec.set('defaultValues', [ defaultValue1 ]); |
75 | 1 | Anonymous | } else { |
76 | 1 | Anonymous | var formComponentsStore = gridFormComponents.getStore(); |
77 | 1 | Anonymous | |
78 | 1 | Anonymous | // Génération de l'id |
79 | 1 | Anonymous | var lastId = 0; |
80 | 1 | Anonymous | var greatY = 0; |
81 | 1 | Anonymous | formComponentsStore.each(function (component) { |
82 | 1 | Anonymous | if (component.data.id > lastId) { |
83 | 1 | Anonymous | lastId = parseInt(component.data.id, 10); |
84 | 1 | Anonymous | } |
85 | 1 | Anonymous | if (component.data.ypos > greatY) { |
86 | 1 | Anonymous | greatY = parseInt(component.data.ypos, 10) + parseInt(component.data.height, 10); |
87 | 1 | Anonymous | } |
88 | 1 | Anonymous | |
89 | 1 | Anonymous | }); |
90 | 1 | Anonymous | var componentId = lastId + 1; |
91 | 1 | Anonymous | componentId = componentId.toString(); |
92 | 1 | Anonymous | var componentYpos = greatY + 10; |
93 | 1 | Anonymous | |
94 | 1 | Anonymous | formComponentsStore.add(new Ext.data.Record({ |
95 | 1 | Anonymous | label : f.findField('LABEL_PARAM1').getValue(), |
96 | 1 | Anonymous | type : this.ctype, |
97 | 1 | Anonymous | code : code, |
98 | 1 | Anonymous | width : f.findField('componentDefaultWidth').getValue(), |
99 | 1 | Anonymous | height : f.findField('componentDefaultHeight').getValue(), |
100 | 1 | Anonymous | id : componentId, |
101 | 1 | Anonymous | ypos : componentYpos, |
102 | 1 | Anonymous | css : f.findField('CSS').getValue(), |
103 | 1 | Anonymous | jsAdminObject : this.jsAdminObject, |
104 | 1 | Anonymous | jsUserObject : this.jsUserObject, |
105 | 1 | Anonymous | defaultValues : [ defaultValue1 ] |
106 | 1 | Anonymous | })); |
107 | 1 | Anonymous | } |
108 | 1 | Anonymous | return true; |
109 | 1 | Anonymous | } |
110 | 1 | Anonymous | |
111 | 1 | Anonymous | }); |
112 | 1 | Anonymous | </pre></code> |
113 | 1 | Anonymous | |
114 | 1 | Anonymous | Côté CLIENT : |
115 | 1 | Anonymous | |
116 | 1 | Anonymous | <pre><code class="javascript"> |
117 | 1 | Anonymous | /*************************************** |
118 | 1 | Anonymous | * Copyright 2011 CNES - CENTRE NATIONAL d'ETUDES SPATIALES |
119 | 1 | Anonymous | * |
120 | 1 | Anonymous | * This file is part of SITools2. |
121 | 1 | Anonymous | * |
122 | 1 | Anonymous | * SITools2 is free software: you can redistribute it and/or modify |
123 | 1 | Anonymous | * it under the terms of the GNU General Public License as published by |
124 | 1 | Anonymous | * the Free Software Foundation, either version 3 of the License, or |
125 | 1 | Anonymous | * (at your option) any later version. |
126 | 1 | Anonymous | * |
127 | 1 | Anonymous | * SITools2 is distributed in the hope that it will be useful, |
128 | 1 | Anonymous | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
129 | 1 | Anonymous | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
130 | 1 | Anonymous | * GNU General Public License for more details. |
131 | 1 | Anonymous | * |
132 | 1 | Anonymous | * You should have received a copy of the GNU General Public License |
133 | 1 | Anonymous | * along with SITools2. If not, see <http://www.gnu.org/licenses/>. |
134 | 1 | Anonymous | ***************************************/ |
135 | 1 | Anonymous | /*global Ext, sitools*/ |
136 | 1 | Anonymous | Ext.ns('sitools.component.users.SubSelectionParameters.SingleSelection'); |
137 | 1 | Anonymous | |
138 | 1 | Anonymous | sitools.component.users.SubSelectionParameters.SingleSelection.NthreeVariability = Ext.extend(Ext.Container, { |
139 | 1 | Anonymous | |
140 | 1 | Anonymous | initComponent : function () { |
141 | 1 | Anonymous | var defaultValue = "", value, items=[]; |
142 | 1 | Anonymous | items.push(['pvsg', 'Periodically variable supergiants']); |
143 | 1 | Anonymous | items.push(['be', 'Variable Be-stars']); |
144 | 1 | Anonymous | items.push(['bcep', 'Beta-Cephei stars']); |
145 | 1 | Anonymous | items.push(['clcep', 'Classical Cepheids']); |
146 | 1 | Anonymous | items.push(['cp', 'Chemically peculiar stars']); |
147 | 1 | Anonymous | items.push(['dscut', 'Delta-Scuti stars']); |
148 | 1 | Anonymous | items.push(['ell', 'Ellipsoidal variables']); |
149 | 1 | Anonymous | items.push(['gdor', 'Gamma-Doradus stars']); |
150 | 1 | Anonymous | items.push(['haebe', 'Herbig Ae/Be stars']); |
151 | 1 | Anonymous | items.push(['xb', 'X-ray binaries']); |
152 | 1 | Anonymous | items.push(['lboo', 'Lambda-Bootis variables']); |
153 | 1 | Anonymous | items.push(['lbv', 'Luminous Blue variables']); |
154 | 1 | Anonymous | items.push(['mira', 'Mira variables']); |
155 | 1 | Anonymous | items.push(['ptcep', 'Population II Cepheids']); |
156 | 1 | Anonymous | items.push(['spds', 'Short Period Delta-Scuti']); |
157 | 1 | Anonymous | items.push(['rrab', 'RR-Lyrae stars, subtype ab']); |
158 | 1 | Anonymous | items.push(['rrc', 'RR-Lyrae stars, subtype c']); |
159 | 1 | Anonymous | items.push(['rvtau', 'RV-Tauri stars']); |
160 | 1 | Anonymous | items.push(['sr', 'Semi-regular variables']); |
161 | 1 | Anonymous | items.push(['spb', 'Slowly Pulsating B-stars']); |
162 | 1 | Anonymous | items.push(['sxphe', 'SX-Phe stars']); |
163 | 1 | Anonymous | items.push(['ttau', 'T-Tauri stars']); |
164 | 1 | Anonymous | items.push(['wr', 'Wolf-Rayet stars']); |
165 | 1 | Anonymous | items.push(['fuori', 'FU-Ori stars']); |
166 | 1 | Anonymous | items.push(['sdbv', 'Pulsating subdwarf B-stars']); |
167 | 1 | Anonymous | items.push(['ecl', 'Eclipsing binaries (all types)']); |
168 | 1 | Anonymous | items.push(['rrd', 'Double mode RR-Lyrae stars']); |
169 | 1 | Anonymous | items.push(['dmcep', 'Double-mode Cepheids']); |
170 | 1 | Anonymous | items.push(['lapv', 'Low-Amplitude Periodic Variables']); |
171 | 1 | Anonymous | |
172 | 1 | Anonymous | var defaultProba = this.defaultValues[0]; |
173 | 1 | Anonymous | |
174 | 1 | Anonymous | var store; |
175 | 1 | Anonymous | store = new Ext.data.ArrayStore({ |
176 | 1 | Anonymous | fields : [ 'id', 'value' ], |
177 | 1 | Anonymous | data : items |
178 | 1 | Anonymous | }); |
179 | 1 | Anonymous | |
180 | 1 | Anonymous | this.combo = new Ext.form.ComboBox ({ |
181 | 1 | Anonymous | store : store, |
182 | 1 | Anonymous | parameterId : this.parameterId, |
183 | 1 | Anonymous | sParentParam : this.parentParam, |
184 | 1 | Anonymous | valueField : 'id', |
185 | 1 | Anonymous | displayField : 'value', |
186 | 1 | Anonymous | typeAhead : true, |
187 | 1 | Anonymous | mode : 'local', |
188 | 1 | Anonymous | triggerAction : 'all', |
189 | 1 | Anonymous | selectOnFocus : true, |
190 | 1 | Anonymous | allowBlank : true, |
191 | 1 | Anonymous | editable : false, |
192 | 1 | Anonymous | autoSelect : false, |
193 | 1 | Anonymous | height : this.height, |
194 | 1 | Anonymous | value : defaultValue, |
195 | 1 | Anonymous | tpl : '<tpl for="."><div class="x-combo-list-item comboItem">{value}</div></tpl>', |
196 | 1 | Anonymous | stype : "sitoolsFormItem", |
197 | 1 | Anonymous | /** |
198 | 1 | Anonymous | * The Parent Window. |
199 | 1 | Anonymous | */ |
200 | 1 | Anonymous | parent : "panelResultForm" + this.formId, |
201 | 1 | Anonymous | |
202 | 1 | Anonymous | /** |
203 | 1 | Anonymous | * The code of the parameter to notify changed event. |
204 | 1 | Anonymous | */ |
205 | 1 | Anonymous | code : this.code, |
206 | 1 | Anonymous | anchor : '90%', |
207 | 1 | Anonymous | listeners : { |
208 | 1 | Anonymous | scope : this, |
209 | 1 | Anonymous | 'select' : function () { |
210 | 1 | Anonymous | var parentPanel = this.ownerCt.ownerCt; |
211 | 1 | Anonymous | parentPanel.fireEvent('componentChanged', parentPanel, this); |
212 | 1 | Anonymous | } |
213 | 1 | Anonymous | } |
214 | 1 | Anonymous | }); |
215 | 1 | Anonymous | |
216 | 1 | Anonymous | this.probaParam = new Ext.form.NumberField({ |
217 | 1 | Anonymous | fieldLabel : "proba", |
218 | 1 | Anonymous | allowBlank : true, |
219 | 1 | Anonymous | decimalPrecision : 20, |
220 | 1 | Anonymous | anchor : "98%", |
221 | 1 | Anonymous | value : defaultProba, |
222 | 1 | Anonymous | }); |
223 | 1 | Anonymous | |
224 | 1 | Anonymous | Ext.apply(this, { |
225 | 1 | Anonymous | stype : "sitoolsFormContainer", |
226 | 1 | Anonymous | layout : "hbox", |
227 | 1 | Anonymous | items : [new Ext.Container({ |
228 | 1 | Anonymous | border : false, |
229 | 1 | Anonymous | html : this.label, |
230 | 1 | Anonymous | width : 70 |
231 | 1 | Anonymous | }), this.combo, new Ext.Container({border : false, |
232 | 1 | Anonymous | html : ' '}), new Ext.Container({ |
233 | 1 | Anonymous | border : false, |
234 | 1 | Anonymous | html : 'Probabilité (0.0 -> 1.0) : ', |
235 | 1 | Anonymous | width : 70 |
236 | 1 | Anonymous | }), this.probaParam, |
237 | 1 | Anonymous | new Ext.Container({ |
238 | 1 | Anonymous | border : false, |
239 | 1 | Anonymous | html : ' ' |
240 | 1 | Anonymous | }) |
241 | 1 | Anonymous | ] |
242 | 1 | Anonymous | }); |
243 | 1 | Anonymous | sitools.component.users.SubSelectionParameters.SingleSelection.NthreeVariability.superclass.initComponent.apply(this, |
244 | 1 | Anonymous | arguments); |
245 | 1 | Anonymous | }, |
246 | 1 | Anonymous | |
247 | 1 | Anonymous | notifyValueSelected : function () { |
248 | 1 | Anonymous | this.parent.notifyValueChanged(this.code); |
249 | 1 | Anonymous | }, |
250 | 1 | Anonymous | |
251 | 1 | Anonymous | isValueDefined : function () { |
252 | 1 | Anonymous | if (this.combo.getValue() && this.combo.getValue() !== "") { |
253 | 1 | Anonymous | return true; |
254 | 1 | Anonymous | } else { |
255 | 1 | Anonymous | return false; |
256 | 1 | Anonymous | } |
257 | 1 | Anonymous | }, |
258 | 1 | Anonymous | getSelectedValue : function () { |
259 | 1 | Anonymous | if (this.combo.getValue() && this.combo.getValue() !== "") { |
260 | 1 | Anonymous | return this.combo.getValue(); |
261 | 1 | Anonymous | } else { |
262 | 1 | Anonymous | return null; |
263 | 1 | Anonymous | } |
264 | 1 | Anonymous | }, |
265 | 1 | Anonymous | setSelectedValue : function (value) { |
266 | 1 | Anonymous | this.combo.setValue(value); |
267 | 1 | Anonymous | }, |
268 | 1 | Anonymous | getParameterValue : function () { |
269 | 1 | Anonymous | var value = this.getSelectedValue(); |
270 | 1 | Anonymous | if (Ext.isEmpty(value)) { |
271 | 1 | Anonymous | return null; |
272 | 1 | Anonymous | } |
273 | 1 | Anonymous | var probaval = this.probaParam.getValue(); |
274 | 1 | Anonymous | if(Ext.isEmpty(probaval) || probaval == ""){ |
275 | 1 | Anonymous | probaval='0.0'; |
276 | 1 | Anonymous | } |
277 | 1 | Anonymous | |
278 | 1 | Anonymous | return this.type + "|" + value + "|" + probaval; |
279 | 1 | Anonymous | } |
280 | 1 | Anonymous | }); |
281 | 1 | Anonymous | </pre></code> |
282 | 1 | Anonymous | |
283 | 1 | Anonymous | Code JAVA à inclure dans workspace/fr.cnes.sitools.extensions/src/fr/cnes/sitools/filter et référencer la classe dans le fichier fr.cnes.sitools.filter.FilterHelper |
284 | 1 | Anonymous | |
285 | 1 | Anonymous | <pre><code class="java"> |
286 | 1 | Anonymous | /******************************************************************************* |
287 | 1 | Anonymous | * Copyright 2011 CNES - CENTRE NATIONAL d'ETUDES SPATIALES |
288 | 1 | Anonymous | * |
289 | 1 | Anonymous | * This file is part of SITools2. |
290 | 1 | Anonymous | * |
291 | 1 | Anonymous | * SITools2 is free software: you can redistribute it and/or modify |
292 | 1 | Anonymous | * it under the terms of the GNU General Public License as published by |
293 | 1 | Anonymous | * the Free Software Foundation, either version 3 of the License, or |
294 | 1 | Anonymous | * (at your option) any later version. |
295 | 1 | Anonymous | * |
296 | 1 | Anonymous | * SITools2 is distributed in the hope that it will be useful, |
297 | 1 | Anonymous | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
298 | 1 | Anonymous | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
299 | 1 | Anonymous | * GNU General Public License for more details. |
300 | 1 | Anonymous | * |
301 | 1 | Anonymous | * You should have received a copy of the GNU General Public License |
302 | 1 | Anonymous | * along with SITools2. If not, see <http://www.gnu.org/licenses/>. |
303 | 1 | Anonymous | ******************************************************************************/ |
304 | 1 | Anonymous | package fr.cnes.sitools.filter.basic; |
305 | 1 | Anonymous | |
306 | 1 | Anonymous | import java.util.HashMap; |
307 | 1 | Anonymous | import java.util.List; |
308 | 1 | Anonymous | import java.util.Set; |
309 | 1 | Anonymous | |
310 | 1 | Anonymous | import org.restlet.Request; |
311 | 1 | Anonymous | import org.restlet.data.Form; |
312 | 1 | Anonymous | import org.restlet.ext.wadl.ParameterInfo; |
313 | 1 | Anonymous | import org.restlet.ext.wadl.ParameterStyle; |
314 | 1 | Anonymous | |
315 | 1 | Anonymous | import fr.cnes.sitools.common.validator.ConstraintViolation; |
316 | 1 | Anonymous | import fr.cnes.sitools.common.validator.Validator; |
317 | 1 | Anonymous | import fr.cnes.sitools.dataset.DataSetApplication; |
318 | 1 | Anonymous | import fr.cnes.sitools.dataset.filter.business.AbstractFilter; |
319 | 1 | Anonymous | import fr.cnes.sitools.dataset.model.Column; |
320 | 1 | Anonymous | import fr.cnes.sitools.dataset.model.DataSet; |
321 | 1 | Anonymous | import fr.cnes.sitools.dataset.model.Operator; |
322 | 1 | Anonymous | import fr.cnes.sitools.dataset.model.Predicat; |
323 | 1 | Anonymous | import fr.cnes.sitools.util.SQLUtils; |
324 | 1 | Anonymous | |
325 | 1 | Anonymous | /** |
326 | 1 | Anonymous | * Filter defined for Single Value Component |
327 | 1 | Anonymous | * |
328 | 1 | Anonymous | * |
329 | 1 | Anonymous | * @author d.arpin |
330 | 1 | Anonymous | */ |
331 | 1 | Anonymous | public final class NThreeVariability extends AbstractFilter { |
332 | 1 | Anonymous | /** |
333 | 1 | Anonymous | * The index of TYPE |
334 | 1 | Anonymous | */ |
335 | 1 | Anonymous | private static final int TYPE = 0; |
336 | 1 | Anonymous | /** |
337 | 1 | Anonymous | * The index of COLUMN |
338 | 1 | Anonymous | */ |
339 | 1 | Anonymous | private static final int COLUMN = 1; |
340 | 1 | Anonymous | /** |
341 | 1 | Anonymous | * The index of Values |
342 | 1 | Anonymous | */ |
343 | 1 | Anonymous | private static final int VALUES = 2; |
344 | 1 | Anonymous | |
345 | 1 | Anonymous | /** |
346 | 1 | Anonymous | * The list of component that uses this filter |
347 | 1 | Anonymous | */ |
348 | 1 | Anonymous | private enum TYPE_COMPONENT { |
349 | 1 | Anonymous | /** Boolean Custom type */ |
350 | 1 | Anonymous | NTHREE_VARIABILITY |
351 | 1 | Anonymous | } |
352 | 1 | Anonymous | |
353 | 1 | Anonymous | /** The TEMPLATE_PARAM */ |
354 | 1 | Anonymous | private static final String TEMPLATE_PARAM = "p[#]"; |
355 | 1 | Anonymous | |
356 | 1 | Anonymous | /** |
357 | 1 | Anonymous | * Default constructor |
358 | 1 | Anonymous | */ |
359 | 1 | Anonymous | public NThreeVariability() { |
360 | 1 | Anonymous | |
361 | 1 | Anonymous | super(); |
362 | 1 | Anonymous | this.setName("NThreeVariability"); |
363 | 1 | Anonymous | this.setDescription("Required when using NThreeVariability Component"); |
364 | 1 | Anonymous | |
365 | 1 | Anonymous | this.setAuthor("Matthieu Husson"); |
366 | 1 | Anonymous | this.setClassAuthor("IAS"); |
367 | 1 | Anonymous | this.setClassOwner("MH@IAS"); |
368 | 1 | Anonymous | this.setVersion("0.1"); |
369 | 1 | Anonymous | this.setDefaultFilter(true); |
370 | 1 | Anonymous | |
371 | 1 | Anonymous | HashMap<String, ParameterInfo> rpd = new HashMap<String, ParameterInfo>(); |
372 | 1 | Anonymous | |
373 | 1 | Anonymous | ParameterInfo paramInfo; |
374 | 1 | Anonymous | paramInfo = new ParameterInfo("p[#]", false, "xs:string", ParameterStyle.QUERY, "NTHREE_VARIABILITY|columnAlias|value"); |
375 | 1 | Anonymous | rpd.put("0", paramInfo); |
376 | 1 | Anonymous | this.setRequestParamsDescription(rpd); |
377 | 1 | Anonymous | } |
378 | 1 | Anonymous | |
379 | 1 | Anonymous | @Override |
380 | 1 | Anonymous | public List<Predicat> createPredicats(Request request, List<Predicat> predicats) throws Exception { |
381 | 1 | Anonymous | DataSetApplication dsApplication = null; |
382 | 1 | Anonymous | DataSet ds = null; |
383 | 1 | Anonymous | |
384 | 1 | Anonymous | Form params = request.getResourceRef().getQueryAsForm(); |
385 | 1 | Anonymous | boolean filterExists = true; |
386 | 1 | Anonymous | int i = 0; |
387 | 1 | Anonymous | // Build predicat for filters param |
388 | 1 | Anonymous | while (filterExists) { |
389 | 1 | Anonymous | String index = TEMPLATE_PARAM.replace("#", Integer.toString(i++)); |
390 | 1 | Anonymous | String formParam = params.getFirstValue(index); |
391 | 1 | Anonymous | if (formParam != null) { |
392 | 1 | Anonymous | String[] parameters = formParam.split("\\|"); |
393 | 1 | Anonymous | TYPE_COMPONENT[] types = TYPE_COMPONENT.values(); |
394 | 1 | Anonymous | Boolean trouve = false; |
395 | 1 | Anonymous | for (TYPE_COMPONENT typeCmp : types) { |
396 | 1 | Anonymous | if (typeCmp.name().equals(parameters[TYPE])) { |
397 | 1 | Anonymous | trouve = true; |
398 | 1 | Anonymous | } |
399 | 1 | Anonymous | } |
400 | 1 | Anonymous | if (trouve) { |
401 | 1 | Anonymous | if (dsApplication == null) { |
402 | 1 | Anonymous | dsApplication = (DataSetApplication) getContext().getAttributes().get("DataSetApplication"); |
403 | 1 | Anonymous | ds = dsApplication.getDataSet(); |
404 | 1 | Anonymous | } |
405 | 1 | Anonymous | String columnAlias = null; |
406 | 1 | Anonymous | if (parameters.length >= VALUES) { |
407 | 1 | Anonymous | columnAlias = parameters[COLUMN]; |
408 | 1 | Anonymous | System.out.println("\ncolumn : " + columnAlias); |
409 | 1 | Anonymous | Column col = ds.findByColumnAlias(columnAlias); |
410 | 1 | Anonymous | if (col != null && col.getFilter() != null && col.getFilter()) { |
411 | 1 | Anonymous | // get the value and escape it to avoid SQL injection |
412 | 1 | Anonymous | String value = SQLUtils.escapeString(parameters[VALUES]); |
413 | 1 | Anonymous | Predicat predicat = new Predicat(); |
414 | 1 | Anonymous | if (value != null) { |
415 | 1 | Anonymous | predicat.setLeftAttribute(col); |
416 | 1 | Anonymous | predicat.setNbOpenedParanthesis(0); |
417 | 1 | Anonymous | predicat.setNbClosedParanthesis(0); |
418 | 1 | Anonymous | predicat.setCompareOperator(Operator.GT.value()); |
419 | 1 | Anonymous | predicat.setRightValue("'" + value + "'"); |
420 | 1 | Anonymous | System.out.println("\nvalue : " + value); |
421 | 1 | Anonymous | |
422 | 1 | Anonymous | predicats.add(predicat); |
423 | 1 | Anonymous | } |
424 | 1 | Anonymous | } |
425 | 1 | Anonymous | |
426 | 1 | Anonymous | } |
427 | 1 | Anonymous | } |
428 | 1 | Anonymous | } |
429 | 1 | Anonymous | |
430 | 1 | Anonymous | else { |
431 | 1 | Anonymous | filterExists = false; |
432 | 1 | Anonymous | } |
433 | 1 | Anonymous | } |
434 | 1 | Anonymous | |
435 | 1 | Anonymous | return predicats; |
436 | 1 | Anonymous | } |
437 | 1 | Anonymous | |
438 | 1 | Anonymous | /** |
439 | 1 | Anonymous | * Gets the validator for this Filter |
440 | 1 | Anonymous | * |
441 | 1 | Anonymous | * @return the validator for the filter |
442 | 1 | Anonymous | */ |
443 | 1 | Anonymous | @Override |
444 | 1 | Anonymous | public Validator<AbstractFilter> getValidator() { |
445 | 1 | Anonymous | return new Validator<AbstractFilter>() { |
446 | 1 | Anonymous | @Override |
447 | 1 | Anonymous | public Set<ConstraintViolation> validate(AbstractFilter item) { |
448 | 1 | Anonymous | return null; |
449 | 1 | Anonymous | } |
450 | 1 | Anonymous | }; |
451 | 1 | Anonymous | } |
452 | 1 | Anonymous | |
453 | 1 | Anonymous | } |
454 | 1 | Anonymous | |
455 | 1 | Anonymous | </pre></code> |