Boolean Custom » History » Version 1
Anonymous, 05/06/2012 17:20
1 | 1 | Anonymous | h1. Boolean Custom |
---|---|---|---|
2 | 1 | Anonymous | |
3 | 1 | Anonymous | Le Boolean Custom permet de faire une requête en prenant en compte ou non certaines observations d'après leurs spécificité : long/short run, anti/center, windescriptor ou non ... |
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 | |
11 | 1 | Anonymous | /*************************************** |
12 | 1 | Anonymous | * Copyright 2011 CNES - CENTRE NATIONAL d'ETUDES SPATIALES |
13 | 1 | Anonymous | * |
14 | 1 | Anonymous | * This file is part of SITools2. |
15 | 1 | Anonymous | * |
16 | 1 | Anonymous | * SITools2 is free software: you can redistribute it and/or modify |
17 | 1 | Anonymous | * it under the terms of the GNU General Public License as published by |
18 | 1 | Anonymous | * the Free Software Foundation, either version 3 of the License, or |
19 | 1 | Anonymous | * (at your option) any later version. |
20 | 1 | Anonymous | * |
21 | 1 | Anonymous | * SITools2 is distributed in the hope that it will be useful, |
22 | 1 | Anonymous | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
23 | 1 | Anonymous | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
24 | 1 | Anonymous | * GNU General Public License for more details. |
25 | 1 | Anonymous | * |
26 | 1 | Anonymous | * You should have received a copy of the GNU General Public License |
27 | 1 | Anonymous | * along with SITools2. If not, see <http://www.gnu.org/licenses/>. |
28 | 1 | Anonymous | ***************************************/ |
29 | 1 | Anonymous | Ext.namespace('sitools.component.forms.multiParam'); |
30 | 1 | Anonymous | |
31 | 1 | Anonymous | sitools.component.forms.multiParam.BooleanCustom = Ext.extend(sitools.component.forms.multiParam.abstractForm, { |
32 | 1 | Anonymous | height : 330, |
33 | 1 | Anonymous | id : "sitools.component.forms.definitionId", |
34 | 1 | Anonymous | initComponent : function () { |
35 | 1 | Anonymous | this.winPropComponent.specificHeight = 430; |
36 | 1 | Anonymous | this.winPropComponent.specificWidth = 380; |
37 | 1 | Anonymous | sitools.component.forms.multiParam.BooleanCustom.superclass.initComponent.call(this); |
38 | 1 | Anonymous | |
39 | 1 | Anonymous | var labels = ['Column']; |
40 | 1 | Anonymous | var i = 1; |
41 | 1 | Anonymous | this['mapParam' + i] = new Ext.form.ComboBox({ |
42 | 1 | Anonymous | fieldLabel : labels[i - 1], |
43 | 1 | Anonymous | triggerAction : 'all', |
44 | 1 | Anonymous | name : "PARAM" + i, |
45 | 1 | Anonymous | specificType : "mapParam", |
46 | 1 | Anonymous | columnIndex : i, |
47 | 1 | Anonymous | lazyRender : true, |
48 | 1 | Anonymous | mode : 'local', |
49 | 1 | Anonymous | store : this.storeColumn, |
50 | 1 | Anonymous | valueField : 'columnAlias', |
51 | 1 | Anonymous | displayField : 'header', |
52 | 1 | Anonymous | anchor : '100%', |
53 | 1 | Anonymous | allowBlank : true |
54 | 1 | Anonymous | |
55 | 1 | Anonymous | }); |
56 | 1 | Anonymous | |
57 | 1 | Anonymous | if (this.action == "modify") { |
58 | 1 | Anonymous | Ext.apply(this['mapParam' + i], { |
59 | 1 | Anonymous | value : this.selectedRecord.data.code[i - 1] |
60 | 1 | Anonymous | }); |
61 | 1 | Anonymous | } |
62 | 1 | Anonymous | |
63 | 1 | Anonymous | this.insert(i, this['mapParam' + i]); |
64 | 1 | Anonymous | |
65 | 1 | Anonymous | |
66 | 1 | Anonymous | this.componentUncheckedValue = new Ext.form.TextField({ |
67 | 1 | Anonymous | fieldLabel : i18n.get('label.defaultValue') + 'Uncheked Value', |
68 | 1 | Anonymous | name : 'componentUncheckedValue', |
69 | 1 | Anonymous | anchor : '100%' |
70 | 1 | Anonymous | }); |
71 | 1 | Anonymous | this.componentCheckedValue = new Ext.form.TextField({ |
72 | 1 | Anonymous | fieldLabel : i18n.get('label.defaultValue') + 'Cheked Value', |
73 | 1 | Anonymous | name : 'componentCheckedValue', |
74 | 1 | Anonymous | anchor : '100%' |
75 | 1 | Anonymous | }); |
76 | 1 | Anonymous | this.add(this.componentUncheckedValue); |
77 | 1 | Anonymous | this.add(this.componentCheckedValue); |
78 | 1 | Anonymous | this.cb = new Ext.form.Checkbox ({ |
79 | 1 | Anonymous | fieldLabel : i18n.get('label.defaultValue') + 'Default State', |
80 | 1 | Anonymous | name : 'defaultStatus', |
81 | 1 | Anonymous | allowBlank : true, |
82 | 1 | Anonymous | checked : false, |
83 | 1 | Anonymous | value : false |
84 | 1 | Anonymous | }); |
85 | 1 | Anonymous | this.add(this.cb); |
86 | 1 | Anonymous | |
87 | 1 | Anonymous | |
88 | 1 | Anonymous | |
89 | 1 | Anonymous | }, |
90 | 1 | Anonymous | onRender : function () { |
91 | 1 | Anonymous | sitools.component.forms.multiParam.BooleanCustom.superclass.onRender.apply(this, arguments); |
92 | 1 | Anonymous | if (this.action == 'modify') { |
93 | 1 | Anonymous | if (!Ext.isEmpty(this.selectedRecord.data.defaultValues)) { |
94 | 1 | Anonymous | this.componentUncheckedValue.setValue(this.selectedRecord.data.defaultValues[0]); |
95 | 1 | Anonymous | this.componentCheckedValue.setValue(this.selectedRecord.data.defaultValues[1]); |
96 | 1 | Anonymous | this.cb.setValue(this.selectedRecord.data.defaultValues[2]); |
97 | 1 | Anonymous | } |
98 | 1 | Anonymous | } |
99 | 1 | Anonymous | }, |
100 | 1 | Anonymous | _onValidate : function (action, gridFormComponents) { |
101 | 1 | Anonymous | var f = this.getForm(); |
102 | 1 | Anonymous | if (!f.isValid()) { |
103 | 1 | Anonymous | Ext.Msg.alert(i18n.get('label.error'), i18n.get('warning.invalidForm')); |
104 | 1 | Anonymous | return false; |
105 | 1 | Anonymous | } |
106 | 1 | Anonymous | var param1, UncheckedValue, CheckedValue, code, defaultState; // defaultValue; |
107 | 1 | Anonymous | if (action == 'modify') { |
108 | 1 | Anonymous | var rec = gridFormComponents.getSelectionModel().getSelected(); |
109 | 1 | Anonymous | param1 = Ext.isEmpty(f.findField('PARAM1')) ? "" : f.findField('PARAM1').getValue(); |
110 | 1 | Anonymous | code = [param1]; |
111 | 1 | Anonymous | var labelParam1 = Ext.isEmpty(f.findField('LABEL_PARAM1')) ? "" : f.findField('LABEL_PARAM1').getValue(); |
112 | 1 | Anonymous | var css = Ext.isEmpty(f.findField('CSS')) ? "" : f.findField('CSS').getValue(); |
113 | 1 | Anonymous | UncheckedValue = Ext.isEmpty(f.findField('componentUncheckedValue')) ? "" : f.findField('componentUncheckedValue').getValue(); |
114 | 1 | Anonymous | CheckedValue = Ext.isEmpty(f.findField('componentCheckedValue')) ? "" : f.findField('componentCheckedValue').getValue(); |
115 | 1 | Anonymous | defaultState = Ext.isEmpty(f.findField('defaultStatus')) ? "" : f.findField('defaultStatus').getValue(); |
116 | 1 | Anonymous | |
117 | 1 | Anonymous | rec.set('label', labelParam1); |
118 | 1 | Anonymous | rec.set('code', code); |
119 | 1 | Anonymous | rec.set('css', css); |
120 | 1 | Anonymous | rec.set('componentDefaultHeight', f.findField('componentDefaultHeight').getValue()); |
121 | 1 | Anonymous | rec.set('componentDefaultWidth', f.findField('componentDefaultWidth').getValue()); |
122 | 1 | Anonymous | |
123 | 1 | Anonymous | rec.set('defaultValues', [ UncheckedValue, CheckedValue, defaultState ]); |
124 | 1 | Anonymous | } else { |
125 | 1 | Anonymous | var formComponentsStore = gridFormComponents.getStore(); |
126 | 1 | Anonymous | defaultState = Ext.isEmpty(f.findField('defaultStatus')) ? "" : f.findField('defaultStatus').getValue(); |
127 | 1 | Anonymous | UncheckedValue = Ext.isEmpty(f.findField('componentUncheckedValue')) ? "" : f.findField('componentUncheckedValue').getValue(); |
128 | 1 | Anonymous | CheckedValue = Ext.isEmpty(f.findField('componentCheckedValue')) ? "" : f.findField('componentCheckedValue').getValue(); |
129 | 1 | Anonymous | |
130 | 1 | Anonymous | // Génération de l'id |
131 | 1 | Anonymous | var lastId = 0; |
132 | 1 | Anonymous | var greatY = 0; |
133 | 1 | Anonymous | formComponentsStore.each(function (component) { |
134 | 1 | Anonymous | if (component.data.id > lastId) { |
135 | 1 | Anonymous | lastId = parseInt(component.data.id, 10); |
136 | 1 | Anonymous | } |
137 | 1 | Anonymous | if (component.data.ypos > greatY) { |
138 | 1 | Anonymous | greatY = parseInt(component.data.ypos, 10) + parseInt(component.data.height, 10); |
139 | 1 | Anonymous | } |
140 | 1 | Anonymous | |
141 | 1 | Anonymous | }); |
142 | 1 | Anonymous | var componentId = lastId + 1; |
143 | 1 | Anonymous | componentId = componentId.toString(); |
144 | 1 | Anonymous | var componentYpos = greatY + 10; |
145 | 1 | Anonymous | param1 = Ext.isEmpty(f.findField('PARAM1')) ? "" : f.findField('PARAM1').getValue(); |
146 | 1 | Anonymous | code = [param1]; |
147 | 1 | Anonymous | formComponentsStore.add(new Ext.data.Record({ |
148 | 1 | Anonymous | label : f.findField('LABEL_PARAM1').getValue(), |
149 | 1 | Anonymous | type : this.ctype, |
150 | 1 | Anonymous | code : code, |
151 | 1 | Anonymous | width : f.findField('componentDefaultWidth').getValue(), |
152 | 1 | Anonymous | height : f.findField('componentDefaultHeight').getValue(), |
153 | 1 | Anonymous | id : componentId, |
154 | 1 | Anonymous | ypos : componentYpos, |
155 | 1 | Anonymous | css : f.findField('CSS').getValue(), |
156 | 1 | Anonymous | jsAdminObject : this.jsAdminObject, |
157 | 1 | Anonymous | jsUserObject : this.jsUserObject, |
158 | 1 | Anonymous | defaultValues : [ UncheckedValue, CheckedValue, defaultState ] |
159 | 1 | Anonymous | })); |
160 | 1 | Anonymous | } |
161 | 1 | Anonymous | return true; |
162 | 1 | Anonymous | } |
163 | 1 | Anonymous | |
164 | 1 | Anonymous | }); |
165 | 1 | Anonymous | |
166 | 1 | Anonymous | </code></pre> |
167 | 1 | Anonymous | |
168 | 1 | Anonymous | |
169 | 1 | Anonymous | Côté CLIENT : |
170 | 1 | Anonymous | |
171 | 1 | Anonymous | |
172 | 1 | Anonymous | <pre><code class="javascript"> |
173 | 1 | Anonymous | /*************************************** |
174 | 1 | Anonymous | * Copyright 2011 CNES - CENTRE NATIONAL d'ETUDES SPATIALES |
175 | 1 | Anonymous | * |
176 | 1 | Anonymous | * This file is part of SITools2. |
177 | 1 | Anonymous | * |
178 | 1 | Anonymous | * SITools2 is free software: you can redistribute it and/or modify |
179 | 1 | Anonymous | * it under the terms of the GNU General Public License as published by |
180 | 1 | Anonymous | * the Free Software Foundation, either version 3 of the License, or |
181 | 1 | Anonymous | * (at your option) any later version. |
182 | 1 | Anonymous | * |
183 | 1 | Anonymous | * SITools2 is distributed in the hope that it will be useful, |
184 | 1 | Anonymous | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
185 | 1 | Anonymous | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
186 | 1 | Anonymous | * GNU General Public License for more details. |
187 | 1 | Anonymous | * |
188 | 1 | Anonymous | * You should have received a copy of the GNU General Public License |
189 | 1 | Anonymous | * along with SITools2. If not, see <http://www.gnu.org/licenses/>. |
190 | 1 | Anonymous | ***************************************/ |
191 | 1 | Anonymous | |
192 | 1 | Anonymous | Ext.ns('sitools.component.users.SubSelectionParameters.SingleSelection'); |
193 | 1 | Anonymous | |
194 | 1 | Anonymous | sitools.component.users.SubSelectionParameters.SingleSelection.BooleanCustom = Ext.extend(Ext.Container, { |
195 | 1 | Anonymous | |
196 | 1 | Anonymous | initComponent : function () { |
197 | 1 | Anonymous | this.cbv = new Ext.form.Checkbox ({ |
198 | 1 | Anonymous | allowBlank : true, |
199 | 1 | Anonymous | checked : eval(this.defaultValues[2]), |
200 | 1 | Anonymous | value : eval(this.defaultValues[2]) |
201 | 1 | Anonymous | }); |
202 | 1 | Anonymous | Ext.apply(this, { |
203 | 1 | Anonymous | layout : "hbox", |
204 | 1 | Anonymous | stype : "sitoolsFormContainer", |
205 | 1 | Anonymous | items : [new Ext.Container({ |
206 | 1 | Anonymous | border : false, |
207 | 1 | Anonymous | html : this.label, |
208 | 1 | Anonymous | width : 100 |
209 | 1 | Anonymous | }), this.cbv] |
210 | 1 | Anonymous | }); |
211 | 1 | Anonymous | sitools.component.users.SubSelectionParameters.SingleSelection.BooleanCustom.superclass.initComponent.apply( |
212 | 1 | Anonymous | this, arguments); |
213 | 1 | Anonymous | }, |
214 | 1 | Anonymous | |
215 | 1 | Anonymous | getSelectedValue : function () { |
216 | 1 | Anonymous | if (this.cbv.getValue()) { |
217 | 1 | Anonymous | return this.defaultValues[1]; |
218 | 1 | Anonymous | } else { |
219 | 1 | Anonymous | return this.defaultValues[0]; |
220 | 1 | Anonymous | } |
221 | 1 | Anonymous | |
222 | 1 | Anonymous | }, |
223 | 1 | Anonymous | getParameterValue : function () { |
224 | 1 | Anonymous | var value = this.getSelectedValue(); |
225 | 1 | Anonymous | return this.type + "|" + this.code + "|" + value; |
226 | 1 | Anonymous | } |
227 | 1 | Anonymous | |
228 | 1 | Anonymous | }); |
229 | 1 | Anonymous | |
230 | 1 | Anonymous | </code></pre> |
231 | 1 | Anonymous | |
232 | 1 | Anonymous | Le code JAVA correspondant : |
233 | 1 | Anonymous | |
234 | 1 | Anonymous | <pre><code class="java"> |
235 | 1 | Anonymous | /******************************************************************************* |
236 | 1 | Anonymous | * Copyright 2011 CNES - CENTRE NATIONAL d'ETUDES SPATIALES |
237 | 1 | Anonymous | * |
238 | 1 | Anonymous | * This file is part of SITools2. |
239 | 1 | Anonymous | * |
240 | 1 | Anonymous | * SITools2 is free software: you can redistribute it and/or modify |
241 | 1 | Anonymous | * it under the terms of the GNU General Public License as published by |
242 | 1 | Anonymous | * the Free Software Foundation, either version 3 of the License, or |
243 | 1 | Anonymous | * (at your option) any later version. |
244 | 1 | Anonymous | * |
245 | 1 | Anonymous | * SITools2 is distributed in the hope that it will be useful, |
246 | 1 | Anonymous | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
247 | 1 | Anonymous | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
248 | 1 | Anonymous | * GNU General Public License for more details. |
249 | 1 | Anonymous | * |
250 | 1 | Anonymous | * You should have received a copy of the GNU General Public License |
251 | 1 | Anonymous | * along with SITools2. If not, see <http://www.gnu.org/licenses/>. |
252 | 1 | Anonymous | ******************************************************************************/ |
253 | 1 | Anonymous | package fr.cnes.sitools.filter.basic; |
254 | 1 | Anonymous | |
255 | 1 | Anonymous | import java.util.HashMap; |
256 | 1 | Anonymous | import java.util.List; |
257 | 1 | Anonymous | import java.util.Set; |
258 | 1 | Anonymous | |
259 | 1 | Anonymous | import org.restlet.Request; |
260 | 1 | Anonymous | import org.restlet.data.Form; |
261 | 1 | Anonymous | import org.restlet.ext.wadl.ParameterInfo; |
262 | 1 | Anonymous | import org.restlet.ext.wadl.ParameterStyle; |
263 | 1 | Anonymous | |
264 | 1 | Anonymous | import fr.cnes.sitools.common.validator.ConstraintViolation; |
265 | 1 | Anonymous | import fr.cnes.sitools.common.validator.Validator; |
266 | 1 | Anonymous | import fr.cnes.sitools.dataset.DataSetApplication; |
267 | 1 | Anonymous | import fr.cnes.sitools.dataset.filter.business.AbstractFilter; |
268 | 1 | Anonymous | import fr.cnes.sitools.dataset.model.Column; |
269 | 1 | Anonymous | import fr.cnes.sitools.dataset.model.DataSet; |
270 | 1 | Anonymous | import fr.cnes.sitools.dataset.model.Operator; |
271 | 1 | Anonymous | import fr.cnes.sitools.dataset.model.Predicat; |
272 | 1 | Anonymous | import fr.cnes.sitools.util.SQLUtils; |
273 | 1 | Anonymous | |
274 | 1 | Anonymous | /** |
275 | 1 | Anonymous | * Filter defined for Single Value Component |
276 | 1 | Anonymous | * |
277 | 1 | Anonymous | * |
278 | 1 | Anonymous | * @author d.arpin |
279 | 1 | Anonymous | */ |
280 | 1 | Anonymous | public final class BooleanCustom extends AbstractFilter { |
281 | 1 | Anonymous | /** |
282 | 1 | Anonymous | * The index of TYPE |
283 | 1 | Anonymous | */ |
284 | 1 | Anonymous | private static final int TYPE = 0; |
285 | 1 | Anonymous | /** |
286 | 1 | Anonymous | * The index of COLUMN |
287 | 1 | Anonymous | */ |
288 | 1 | Anonymous | private static final int COLUMN = 1; |
289 | 1 | Anonymous | /** |
290 | 1 | Anonymous | * The index of Values |
291 | 1 | Anonymous | */ |
292 | 1 | Anonymous | private static final int VALUES = 2; |
293 | 1 | Anonymous | |
294 | 1 | Anonymous | /** |
295 | 1 | Anonymous | * The list of component that uses this filter |
296 | 1 | Anonymous | */ |
297 | 1 | Anonymous | private enum TYPE_COMPONENT { |
298 | 1 | Anonymous | /** Boolean Custom type */ |
299 | 1 | Anonymous | BOOLEAN_CUSTOM |
300 | 1 | Anonymous | } |
301 | 1 | Anonymous | |
302 | 1 | Anonymous | /** The TEMPLATE_PARAM */ |
303 | 1 | Anonymous | private static final String TEMPLATE_PARAM = "p[#]"; |
304 | 1 | Anonymous | |
305 | 1 | Anonymous | /** |
306 | 1 | Anonymous | * Default constructor |
307 | 1 | Anonymous | */ |
308 | 1 | Anonymous | public BooleanCustom() { |
309 | 1 | Anonymous | |
310 | 1 | Anonymous | super(); |
311 | 1 | Anonymous | this.setName("BooleanCustom"); |
312 | 1 | Anonymous | this.setDescription("Required when using Boolean Custom Component"); |
313 | 1 | Anonymous | |
314 | 1 | Anonymous | this.setAuthor("Matthieu Husson"); |
315 | 1 | Anonymous | this.setClassAuthor("IAS"); |
316 | 1 | Anonymous | this.setClassOwner("MH@IAS"); |
317 | 1 | Anonymous | this.setVersion("0.1"); |
318 | 1 | Anonymous | this.setDefaultFilter(true); |
319 | 1 | Anonymous | |
320 | 1 | Anonymous | HashMap<String, ParameterInfo> rpd = new HashMap<String, ParameterInfo>(); |
321 | 1 | Anonymous | |
322 | 1 | Anonymous | ParameterInfo paramInfo; |
323 | 1 | Anonymous | paramInfo = new ParameterInfo("p[#]", false, "xs:string", ParameterStyle.QUERY, "BOOLEAN_CUSTOM|columnAlias|value"); |
324 | 1 | Anonymous | rpd.put("0", paramInfo); |
325 | 1 | Anonymous | this.setRequestParamsDescription(rpd); |
326 | 1 | Anonymous | // |
327 | 1 | Anonymous | |
328 | 1 | Anonymous | } |
329 | 1 | Anonymous | |
330 | 1 | Anonymous | @Override |
331 | 1 | Anonymous | public List<Predicat> createPredicats(Request request, List<Predicat> predicats) throws Exception { |
332 | 1 | Anonymous | DataSetApplication dsApplication = null; |
333 | 1 | Anonymous | DataSet ds = null; |
334 | 1 | Anonymous | |
335 | 1 | Anonymous | Form params = request.getResourceRef().getQueryAsForm(); |
336 | 1 | Anonymous | boolean filterExists = true; |
337 | 1 | Anonymous | int i = 0; |
338 | 1 | Anonymous | // Build predicat for filters param |
339 | 1 | Anonymous | while (filterExists) { |
340 | 1 | Anonymous | String index = TEMPLATE_PARAM.replace("#", Integer.toString(i++)); |
341 | 1 | Anonymous | String formParam = params.getFirstValue(index); |
342 | 1 | Anonymous | if (formParam != null) { |
343 | 1 | Anonymous | String[] parameters = formParam.split("\\|"); |
344 | 1 | Anonymous | TYPE_COMPONENT[] types = TYPE_COMPONENT.values(); |
345 | 1 | Anonymous | Boolean trouve = false; |
346 | 1 | Anonymous | for (TYPE_COMPONENT typeCmp : types) { |
347 | 1 | Anonymous | if (typeCmp.name().equals(parameters[TYPE])) { |
348 | 1 | Anonymous | trouve = true; |
349 | 1 | Anonymous | } |
350 | 1 | Anonymous | } |
351 | 1 | Anonymous | if (trouve) { |
352 | 1 | Anonymous | if (dsApplication == null) { |
353 | 1 | Anonymous | dsApplication = (DataSetApplication) getContext().getAttributes().get("DataSetApplication"); |
354 | 1 | Anonymous | ds = dsApplication.getDataSet(); |
355 | 1 | Anonymous | } |
356 | 1 | Anonymous | String columnAlias = null; |
357 | 1 | Anonymous | if (parameters.length >= VALUES) { |
358 | 1 | Anonymous | |
359 | 1 | Anonymous | /* |
360 | 1 | Anonymous | * columnsAlias = parameters[COLUMN].split(","); ArrayList<Column> columns = new ArrayList<Column>(); for |
361 | 1 | Anonymous | * (String columnAlias : columnsAlias) { Column col = ds.findByColumnAlias(columnAlias); if (col != null) { |
362 | 1 | Anonymous | * columns.add(col); } |
363 | 1 | Anonymous | * |
364 | 1 | Anonymous | * } |
365 | 1 | Anonymous | */ |
366 | 1 | Anonymous | columnAlias = parameters[COLUMN]; |
367 | 1 | Anonymous | Column col = ds.findByColumnAlias(columnAlias); |
368 | 1 | Anonymous | if (col != null && col.getFilter() != null && col.getFilter()) { |
369 | 1 | Anonymous | // get the value and escape it to avoid SQL injection |
370 | 1 | Anonymous | String value = SQLUtils.escapeString(parameters[VALUES]); |
371 | 1 | Anonymous | Predicat predicat = new Predicat(); |
372 | 1 | Anonymous | if (value != null) { |
373 | 1 | Anonymous | predicat.setLeftAttribute(col); |
374 | 1 | Anonymous | predicat.setNbOpenedParanthesis(0); |
375 | 1 | Anonymous | predicat.setNbClosedParanthesis(0); |
376 | 1 | Anonymous | predicat.setCompareOperator(Operator.EQ.value()); |
377 | 1 | Anonymous | predicat.setRightValue("'" + value + "'"); |
378 | 1 | Anonymous | |
379 | 1 | Anonymous | |
380 | 1 | Anonymous | if(value.equalsIgnoreCase("false")){ |
381 | 1 | Anonymous | predicats.add(predicat); |
382 | 1 | Anonymous | } |
383 | 1 | Anonymous | } |
384 | 1 | Anonymous | } |
385 | 1 | Anonymous | |
386 | 1 | Anonymous | } |
387 | 1 | Anonymous | } |
388 | 1 | Anonymous | } |
389 | 1 | Anonymous | |
390 | 1 | Anonymous | else { |
391 | 1 | Anonymous | filterExists = false; |
392 | 1 | Anonymous | } |
393 | 1 | Anonymous | } |
394 | 1 | Anonymous | |
395 | 1 | Anonymous | return predicats; |
396 | 1 | Anonymous | } |
397 | 1 | Anonymous | |
398 | 1 | Anonymous | /** |
399 | 1 | Anonymous | * Gets the validator for this Filter |
400 | 1 | Anonymous | * |
401 | 1 | Anonymous | * @return the validator for the filter |
402 | 1 | Anonymous | */ |
403 | 1 | Anonymous | @Override |
404 | 1 | Anonymous | public Validator<AbstractFilter> getValidator() { |
405 | 1 | Anonymous | return new Validator<AbstractFilter>() { |
406 | 1 | Anonymous | @Override |
407 | 1 | Anonymous | public Set<ConstraintViolation> validate(AbstractFilter item) { |
408 | 1 | Anonymous | // TODO Auto-generated method stub |
409 | 1 | Anonymous | return null; |
410 | 1 | Anonymous | } |
411 | 1 | Anonymous | }; |
412 | 1 | Anonymous | } |
413 | 1 | Anonymous | |
414 | 1 | Anonymous | } |
415 | 1 | Anonymous | </code></pre> |