Project

General

Profile

Corot » History » Version 13

Anonymous, 05/06/2012 17:14

1 1 Anonymous
h1. Corot
2 1 Anonymous
3 1 Anonymous
4 11 Anonymous
h2. [[Scripts de création des imagettes]]
5 8 Anonymous
6 12 Anonymous
h2. [[Gestion des imagettes dans le Detail]]
7 2 Anonymous
8 13 Anonymous
h2. [[Export VOTABLE]]
9 9 Anonymous
10 9 Anonymous
h2. Les composants de formulaire : 
11 9 Anonymous
12 9 Anonymous
Le Date Begin-end : qui permet de faire une requête sur deux colonnes différentes, "date de début" et "date de fin". On récupère ainsi les observations dont la date de début est intervenu après "date de début" et dont la fin est intervenu avant la "date de fin".
13 9 Anonymous
14 9 Anonymous
Le code javascript correspondant : 
15 9 Anonymous
16 9 Anonymous
Partie ADMIN : 
17 9 Anonymous
18 9 Anonymous
<pre><code class="javascript">
19 9 Anonymous
20 9 Anonymous
/*global Ext, sitools, ID, i18n, document, showResponse, alertFailure, LOCALE, ImageChooser, 
21 9 Anonymous
 showHelp*/
22 9 Anonymous
Ext.namespace('sitools.component.forms.multiParam');
23 9 Anonymous
24 9 Anonymous
sitools.component.forms.multiParam.DateBeginEnd = Ext.extend(sitools.component.forms.multiParam.abstractForm, {
25 9 Anonymous
    height : 250,
26 9 Anonymous
    id : 'sitools.component.forms.definitionId',
27 9 Anonymous
    initComponent : function () {
28 9 Anonymous
        this.winPropComponent.specificHeight = 350;
29 9 Anonymous
        this.winPropComponent.specificWidth = 400;
30 9 Anonymous
        sitools.component.forms.multiParam.DateBeginEnd.superclass.initComponent.call(this);
31 9 Anonymous
     
32 9 Anonymous
33 9 Anonymous
        
34 9 Anonymous
    /*
35 9 Anonymous
     * Build all the Columns mapping for the configuration, 
36 9 Anonymous
     * this object needs three columns
37 9 Anonymous
     */
38 9 Anonymous
    var labels = ['DATE FROM', 'DATE TO'];
39 9 Anonymous
    for (var i = 1; i <= 2; i++) {
40 9 Anonymous
		this['mapParam' + i] = new Ext.form.ComboBox({
41 9 Anonymous
		    fieldLabel : labels[i - 1],
42 9 Anonymous
		    triggerAction : 'all',
43 9 Anonymous
		    name : "PARAM" + i,
44 9 Anonymous
		    specificType : "mapParam", 
45 9 Anonymous
		    columnIndex : i, 
46 9 Anonymous
		    lazyRender : true,
47 9 Anonymous
		    mode : 'local',
48 9 Anonymous
		    store : this.storeColumn,
49 9 Anonymous
		    valueField : 'columnAlias',
50 9 Anonymous
		    displayField : 'header',
51 9 Anonymous
		    anchor : '100%', 
52 9 Anonymous
		    allowBlank : false 
53 9 Anonymous
		    
54 9 Anonymous
		}); 
55 9 Anonymous
		
56 9 Anonymous
		if (this.action == "modify") {
57 9 Anonymous
			Ext.apply(this['mapParam' + i], {
58 9 Anonymous
				value : this.selectedRecord.data.code[i - 1]
59 9 Anonymous
			});
60 9 Anonymous
		}
61 9 Anonymous
       
62 9 Anonymous
		this.insert(i, this['mapParam' + i]);
63 9 Anonymous
    }
64 9 Anonymous
65 9 Anonymous
    this.componentDefaultValue1 = new Ext.form.DateField({
66 9 Anonymous
        fieldLabel : i18n.get('label.defaultValue') + ' (DATE FROM)',
67 9 Anonymous
        name : 'componentDefaultValue1',
68 9 Anonymous
        anchor : '100%',
69 9 Anonymous
        format : DEFAULT_DATE_FORMAT
70 9 Anonymous
    });
71 9 Anonymous
    this.componentDefaultValue2 = new Ext.form.DateField({
72 9 Anonymous
        fieldLabel : i18n.get('label.defaultValue') + ' (DATE TO)',
73 9 Anonymous
        name : 'componentDefaultValue2',
74 9 Anonymous
        anchor : '100%',
75 9 Anonymous
        format : DEFAULT_DATE_FORMAT
76 9 Anonymous
    });
77 9 Anonymous
78 9 Anonymous
    this.add(this.componentDefaultValue1);
79 9 Anonymous
    this.add(this.componentDefaultValue2);
80 9 Anonymous
81 9 Anonymous
    
82 9 Anonymous
},
83 9 Anonymous
onRender : function () {
84 9 Anonymous
    sitools.component.forms.multiParam.DateBeginEnd.superclass.onRender.apply(this, arguments);
85 9 Anonymous
    if (this.action == 'modify') {
86 9 Anonymous
        if (!Ext.isEmpty(this.selectedRecord.data.defaultValues)) {
87 9 Anonymous
            if (Ext.isString(this.selectedRecord.data.defaultValues[0])) {
88 9 Anonymous
                this.componentDefaultValue1.setValue(this.selectedRecord.data.defaultValues[0].split('T')[0]);
89 9 Anonymous
            }
90 9 Anonymous
            else {
91 9 Anonymous
                this.componentDefaultValue1.setValue(this.selectedRecord.data.defaultValues[0].split('T')[0]);
92 9 Anonymous
            }
93 9 Anonymous
            if (Ext.isString(this.selectedRecord.data.defaultValues[1])) {
94 9 Anonymous
                this.componentDefaultValue2.setValue(this.selectedRecord.data.defaultValues[1].split('T')[0]);
95 9 Anonymous
            }
96 9 Anonymous
            else {
97 9 Anonymous
                this.componentDefaultValue2.setValue(this.selectedRecord.data.defaultValues[1].split('T')[0]);
98 9 Anonymous
            }
99 9 Anonymous
        }
100 9 Anonymous
    }
101 9 Anonymous
},
102 9 Anonymous
afterRender : function () {
103 9 Anonymous
    sitools.component.forms.multiParam.DateBeginEnd.superclass.afterRender.apply(this, arguments);
104 9 Anonymous
    if (this.action == 'modify') {
105 9 Anonymous
		if (!Ext.isEmpty(this.selectedRecord.data.defaultValues)) {
106 9 Anonymous
            this.componentDefaultValue1.setValue(this.selectedRecord.data.defaultValues[0]);
107 9 Anonymous
            this.componentDefaultValue2.setValue(this.selectedRecord.data.defaultValues[1]);
108 9 Anonymous
            
109 9 Anonymous
        }
110 9 Anonymous
    }
111 9 Anonymous
   
112 9 Anonymous
},
113 9 Anonymous
114 9 Anonymous
_onValidate : function (action, gridFormComponents) {
115 9 Anonymous
    var f = this.getForm();
116 9 Anonymous
    if (!f.isValid()) {
117 9 Anonymous
    	Ext.Msg.alert(i18n.get('label.error'), i18n.get('warning.invalidForm'));
118 9 Anonymous
        return false;
119 9 Anonymous
    }
120 9 Anonymous
    var defaultValue1 = Ext.isEmpty(f.findField('componentDefaultValue1')) ? "" : f.findField('componentDefaultValue1').getValue();
121 9 Anonymous
    var defaultValue2 = Ext.isEmpty(f.findField('componentDefaultValue2')) ? "" : f.findField('componentDefaultValue2').getValue();
122 9 Anonymous
123 9 Anonymous
	var columnObjects = this.find('specificType', 'mapParam');
124 9 Anonymous
	var code = [];
125 9 Anonymous
	Ext.each(columnObjects, function (columnObject) {
126 9 Anonymous
		code.push(columnObject.getValue());
127 9 Anonymous
	});
128 9 Anonymous
  
129 9 Anonymous
    if (action == 'modify') {
130 9 Anonymous
        var rec = gridFormComponents.getSelectionModel().getSelected();
131 9 Anonymous
        
132 9 Anonymous
        var labelParam1 = Ext.isEmpty(f.findField('LABEL_PARAM1')) ? "" : f.findField('LABEL_PARAM1').getValue();
133 9 Anonymous
        var css = Ext.isEmpty(f.findField('CSS')) ? "" : f.findField('CSS').getValue();
134 9 Anonymous
        
135 9 Anonymous
        rec.set('label', labelParam1);
136 9 Anonymous
        rec.set('code', code);
137 9 Anonymous
        rec.set('css', css);
138 9 Anonymous
        rec.set('componentDefaultHeight', f.findField('componentDefaultHeight').getValue());
139 9 Anonymous
        rec.set('componentDefaultWidth', f.findField('componentDefaultWidth').getValue());
140 9 Anonymous
141 9 Anonymous
        rec.set('defaultValues', [ defaultValue1, defaultValue2]);
142 9 Anonymous
    } else {
143 9 Anonymous
        var formComponentsStore = gridFormComponents.getStore();
144 9 Anonymous
        
145 9 Anonymous
        // Génération de l'id
146 9 Anonymous
        var lastId = 0;
147 9 Anonymous
        var greatY = 0;
148 9 Anonymous
        formComponentsStore.each(function (component) {
149 9 Anonymous
            if (component.data.id > lastId) {
150 9 Anonymous
                lastId = parseInt(component.data.id, 10);
151 9 Anonymous
            }
152 9 Anonymous
            if (component.data.ypos > greatY) {
153 9 Anonymous
                greatY = parseInt(component.data.ypos, 10)  + parseInt(component.data.height, 10);
154 9 Anonymous
            }
155 9 Anonymous
156 9 Anonymous
        });
157 9 Anonymous
        var componentId = lastId + 1;
158 9 Anonymous
        componentId = componentId.toString();
159 9 Anonymous
        var componentYpos = greatY + 10;
160 9 Anonymous
        
161 9 Anonymous
        formComponentsStore.add(new Ext.data.Record({
162 9 Anonymous
            label : f.findField('LABEL_PARAM1').getValue(),
163 9 Anonymous
            type : this.ctype,
164 9 Anonymous
            code : code,
165 9 Anonymous
            width : f.findField('componentDefaultWidth').getValue(),
166 9 Anonymous
            height : f.findField('componentDefaultHeight').getValue(),
167 9 Anonymous
            id : componentId,
168 9 Anonymous
            ypos : componentYpos,
169 9 Anonymous
            css : f.findField('CSS').getValue(),
170 9 Anonymous
            jsAdminObject : this.jsAdminObject,
171 9 Anonymous
            jsUserObject : this.jsUserObject,
172 9 Anonymous
            defaultValues : [ defaultValue1, defaultValue2 ]
173 9 Anonymous
        }));
174 9 Anonymous
    }
175 9 Anonymous
    return true;
176 9 Anonymous
}
177 9 Anonymous
178 9 Anonymous
});
179 9 Anonymous
180 9 Anonymous
</code></pre>
181 9 Anonymous
182 9 Anonymous
183 9 Anonymous
partie CLIENT : 
184 9 Anonymous
185 9 Anonymous
<pre><code class="javascript">
186 9 Anonymous
/***************************************
187 9 Anonymous
* Copyright 2011 CNES - CENTRE NATIONAL d'ETUDES SPATIALES
188 9 Anonymous
* 
189 9 Anonymous
* This file is part of SITools2.
190 9 Anonymous
* 
191 9 Anonymous
* SITools2 is free software: you can redistribute it and/or modify
192 9 Anonymous
* it under the terms of the GNU General Public License as published by
193 9 Anonymous
* the Free Software Foundation, either version 3 of the License, or
194 9 Anonymous
* (at your option) any later version.
195 9 Anonymous
* 
196 9 Anonymous
* SITools2 is distributed in the hope that it will be useful,
197 9 Anonymous
* but WITHOUT ANY WARRANTY; without even the implied warranty of
198 9 Anonymous
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
199 9 Anonymous
* GNU General Public License for more details.
200 9 Anonymous
* 
201 9 Anonymous
* You should have received a copy of the GNU General Public License
202 9 Anonymous
* along with SITools2.  If not, see <http://www.gnu.org/licenses/>.
203 9 Anonymous
***************************************/
204 9 Anonymous
/*global Ext, sitools*/
205 9 Anonymous
Ext.ns('sitools.component.users.SubSelectionParameters.SingleSelection');
206 9 Anonymous
207 9 Anonymous
sitools.component.users.SubSelectionParameters.SingleSelection.DateBeginEnd = Ext.extend(Ext.Container, {
208 9 Anonymous
209 9 Anonymous
    initComponent : function () {
210 9 Anonymous
        this.fieldFrom = new Ext.form.DateField({
211 9 Anonymous
            allowBlank : true,
212 9 Anonymous
            format : DEFAULT_DATE_FORMAT, 
213 9 Anonymous
            width : 165,
214 9 Anonymous
            height : this.height,
215 9 Anonymous
            value : new Date(this.defaultValues[0]).format(DEFAULT_DATE_FORMAT)
216 9 Anonymous
        });
217 9 Anonymous
        this.fieldTo = new Ext.form.DateField({
218 9 Anonymous
            allowBlank : true,
219 9 Anonymous
            format : DEFAULT_DATE_FORMAT, 
220 9 Anonymous
            width : 165,
221 9 Anonymous
            height : this.height,
222 9 Anonymous
            value : new Date(this.defaultValues[1]).format(DEFAULT_DATE_FORMAT)
223 9 Anonymous
        });
224 9 Anonymous
        Ext.apply(this, {
225 9 Anonymous
            layout : 'table',
226 9 Anonymous
            columns : 2,     /* 3*/
227 9 Anonymous
            fieldLabel : this.label,
228 9 Anonymous
            stype : "sitoolsFormContainer",
229 9 Anonymous
230 9 Anonymous
            items : [ new Ext.Container({
231 9 Anonymous
            	border : false,
232 9 Anonymous
            	html : this.label + " : ", 
233 9 Anonymous
            	width : "150"
234 9 Anonymous
            }), this.fieldFrom, new Ext.Container({
235 9 Anonymous
                border : false,
236 9 Anonymous
                html : '&nbsp;'
237 9 Anonymous
            }), this.fieldTo ]
238 9 Anonymous
        });
239 9 Anonymous
        sitools.component.users.SubSelectionParameters.SingleSelection.DateBeginEnd.superclass.initComponent.apply(
240 9 Anonymous
                this, arguments);
241 9 Anonymous
    },
242 9 Anonymous
243 9 Anonymous
    /**
244 9 Anonymous
     * The code of the parameter to notify changed event.
245 9 Anonymous
     */
246 9 Anonymous
    code : null,
247 9 Anonymous
248 9 Anonymous
    /**
249 9 Anonymous
     * The left bound of the period.
250 9 Anonymous
     */
251 9 Anonymous
    fieldFrom : null,
252 9 Anonymous
253 9 Anonymous
    /**
254 9 Anonymous
     * The right bound of the period.
255 9 Anonymous
     */
256 9 Anonymous
    fieldTo : null,
257 9 Anonymous
258 9 Anonymous
    notifyValueSelected : function () {
259 9 Anonymous
        this.parent.notifyValueChanged(this.code);
260 9 Anonymous
    },
261 9 Anonymous
262 9 Anonymous
    isValueDefined : function () {
263 9 Anonymous
        if (this.fieldFrom.getValue() && this.fieldTo.getValue()) {
264 9 Anonymous
            return true;
265 9 Anonymous
        } else {
266 9 Anonymous
            return false;
267 9 Anonymous
        }
268 9 Anonymous
    },
269 9 Anonymous
270 9 Anonymous
    getSelectedValue : function () {
271 9 Anonymous
        return {
272 9 Anonymous
            from : this.fieldFrom.getValue(),
273 9 Anonymous
            to : this.fieldTo.getValue()
274 9 Anonymous
        };
275 9 Anonymous
    },
276 9 Anonymous
    
277 9 Anonymous
    getParameterValue : function () {
278 9 Anonymous
        var value = this.getSelectedValue();
279 9 Anonymous
        if (Ext.isEmpty(value) || Ext.isEmpty(value.from) || Ext.isEmpty(value.to)) {
280 9 Anonymous
            return null;
281 9 Anonymous
        }
282 9 Anonymous
        return this.type + "|" + this.code + "|" + value.from.format('Y-m-d') + "|" + value.to.format('Y-m-d') ;
283 9 Anonymous
    }
284 9 Anonymous
});
285 9 Anonymous
</code></pre>
286 9 Anonymous
287 9 Anonymous
288 9 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*
289 9 Anonymous
290 9 Anonymous
<pre><code class="java">
291 10 Anonymous
/*******************************************************************************
292 10 Anonymous
 * Copyright 2011 CNES - CENTRE NATIONAL d'ETUDES SPATIALES
293 10 Anonymous
 * 
294 10 Anonymous
 * This file is part of SITools2.
295 10 Anonymous
 * 
296 10 Anonymous
 * SITools2 is free software: you can redistribute it and/or modify
297 10 Anonymous
 * it under the terms of the GNU General Public License as published by
298 10 Anonymous
 * the Free Software Foundation, either version 3 of the License, or
299 10 Anonymous
 * (at your option) any later version.
300 10 Anonymous
 * 
301 10 Anonymous
 * SITools2 is distributed in the hope that it will be useful,
302 10 Anonymous
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
303 10 Anonymous
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
304 10 Anonymous
 * GNU General Public License for more details.
305 10 Anonymous
 * 
306 10 Anonymous
 * You should have received a copy of the GNU General Public License
307 10 Anonymous
 * along with SITools2.  If not, see <http://www.gnu.org/licenses/>.
308 10 Anonymous
 ******************************************************************************/
309 10 Anonymous
package fr.cnes.sitools.filter.basic;
310 9 Anonymous
311 10 Anonymous
import java.util.Arrays;
312 10 Anonymous
import java.util.HashMap;
313 10 Anonymous
import java.util.List;
314 10 Anonymous
import java.util.Set;
315 10 Anonymous
316 10 Anonymous
import org.restlet.Request;
317 10 Anonymous
import org.restlet.data.Form;
318 10 Anonymous
import org.restlet.ext.wadl.ParameterInfo;
319 10 Anonymous
import org.restlet.ext.wadl.ParameterStyle;
320 10 Anonymous
321 10 Anonymous
import fr.cnes.sitools.common.validator.ConstraintViolation;
322 10 Anonymous
import fr.cnes.sitools.common.validator.Validator;
323 10 Anonymous
import fr.cnes.sitools.dataset.DataSetApplication;
324 10 Anonymous
import fr.cnes.sitools.dataset.filter.business.AbstractFilter;
325 10 Anonymous
import fr.cnes.sitools.dataset.model.Column;
326 10 Anonymous
import fr.cnes.sitools.dataset.model.DataSet;
327 10 Anonymous
import fr.cnes.sitools.dataset.model.Operator;
328 10 Anonymous
import fr.cnes.sitools.dataset.model.Predicat;
329 10 Anonymous
import fr.cnes.sitools.util.SQLUtils;
330 10 Anonymous
331 10 Anonymous
/**
332 10 Anonymous
 * Filter defined for Date Between Component
333 10 Anonymous
 * 
334 10 Anonymous
 * 
335 10 Anonymous
 * @author d.arpin
336 10 Anonymous
 * <a href="https://sourceforge.net/tracker/?func=detail&atid=2158259&aid=3411383&group_id=531341">[3411383]</a><br/>
337 10 Anonymous
 * 2011/09/19 d.arpin {add quotes arround date Value}
338 10 Anonymous
 */
339 10 Anonymous
public final class DateBeginEndFilter extends AbstractFilter {
340 10 Anonymous
  /**
341 10 Anonymous
   * The index of TYPE
342 10 Anonymous
   */
343 10 Anonymous
  private static final int TYPE = 0;
344 10 Anonymous
  /**
345 10 Anonymous
   * The index of COLUMN
346 10 Anonymous
   */
347 10 Anonymous
  private static final int COLUMN = 1;
348 10 Anonymous
  /**
349 10 Anonymous
   * The index of Values
350 10 Anonymous
   */
351 10 Anonymous
  private static final int VALUES = 2;
352 10 Anonymous
353 10 Anonymous
  /** The TEMPLATE_PARAM */
354 10 Anonymous
  private static final String TEMPLATE_PARAM = "p[#]";
355 10 Anonymous
  /**
356 10 Anonymous
   * the values from to
357 10 Anonymous
   */
358 10 Anonymous
  private String[] values;
359 10 Anonymous
360 10 Anonymous
  /**
361 10 Anonymous
   * The list of component that uses this filter
362 10 Anonymous
   */
363 10 Anonymous
  private enum TYPE_COMPONENT {
364 10 Anonymous
    /** DefaultType */
365 10 Anonymous
    DATE_BEGIN_END
366 10 Anonymous
  }
367 10 Anonymous
368 10 Anonymous
  /**
369 10 Anonymous
   * Default constructor
370 10 Anonymous
   */
371 10 Anonymous
  public DateBeginEndFilter() {
372 10 Anonymous
373 10 Anonymous
    super();
374 10 Anonymous
    this.setName("DateBeginEndFilter");
375 10 Anonymous
    this.setDescription("Required when using Date Between Components between 2 columns");
376 10 Anonymous
377 10 Anonymous
    this.setAuthor("HUSSON@IAS");
378 10 Anonymous
    this.setClassAuthor("HUSSON@IAS");
379 10 Anonymous
    this.setClassOwner("IAS");
380 10 Anonymous
    this.setVersion("0.1");
381 10 Anonymous
    this.setDefaultFilter(true);
382 10 Anonymous
383 10 Anonymous
    HashMap<String, ParameterInfo> rpd = new HashMap<String, ParameterInfo>();
384 10 Anonymous
385 10 Anonymous
    ParameterInfo paramInfo;
386 10 Anonymous
    paramInfo = new ParameterInfo("p[#]", false, "xs:string", ParameterStyle.QUERY,
387 10 Anonymous
    "DATE_BEGIN_END|columnFrom,columnTo|valueFrom|valueTo");
388 10 Anonymous
    rpd.put("0", paramInfo);
389 10 Anonymous
    this.setRequestParamsDescription(rpd);
390 10 Anonymous
    //
391 10 Anonymous
392 10 Anonymous
  }
393 10 Anonymous
394 10 Anonymous
  @Override
395 10 Anonymous
  public List<Predicat> createPredicats(Request request, List<Predicat> predicats) throws Exception {
396 10 Anonymous
    // Get the dataset
397 10 Anonymous
    DataSetApplication dsApplication = null;
398 10 Anonymous
    DataSet ds = null;
399 10 Anonymous
400 10 Anonymous
    Form params = request.getResourceRef().getQueryAsForm();
401 10 Anonymous
    boolean filterExists = true;
402 10 Anonymous
    int i = 0;
403 10 Anonymous
    // Build predicat for filters param
404 10 Anonymous
    while (filterExists) {
405 10 Anonymous
      String index = TEMPLATE_PARAM.replace("#", Integer.toString(i++));
406 10 Anonymous
      String formParam = params.getFirstValue(index);
407 10 Anonymous
      if (formParam != null) {
408 10 Anonymous
        String[] parameters = formParam.split("\\|");
409 10 Anonymous
        TYPE_COMPONENT[] types = TYPE_COMPONENT.values();
410 10 Anonymous
        Boolean trouve = false;
411 10 Anonymous
        for (TYPE_COMPONENT typeCmp : types) {
412 10 Anonymous
          if (typeCmp.name().equals(parameters[TYPE])) {
413 10 Anonymous
            trouve = true;
414 10 Anonymous
          }
415 10 Anonymous
        }
416 10 Anonymous
        if (trouve) {
417 10 Anonymous
          if (dsApplication == null) {
418 10 Anonymous
            dsApplication = (DataSetApplication) getContext().getAttributes().get("DataSetApplication");
419 10 Anonymous
            ds = dsApplication.getDataSet();
420 10 Anonymous
          }
421 10 Anonymous
          String columnfrom = null;
422 10 Anonymous
          String columnto = null;
423 10 Anonymous
          if (parameters.length >= VALUES) {
424 10 Anonymous
            columnfrom = parameters[COLUMN].split(",")[0];
425 10 Anonymous
            columnto = parameters[COLUMN].split(",")[1];
426 10 Anonymous
427 10 Anonymous
            Column colfrom = ds.findByColumnAlias(columnfrom);
428 10 Anonymous
            Column colto = ds.findByColumnAlias(columnto);
429 10 Anonymous
430 10 Anonymous
            if (colfrom != null && colfrom.getFilter() != null && colfrom.getFilter() && checkValues(parameters) && colto != null && colto.getFilter() != null && colto.getFilter()) {
431 10 Anonymous
              // escape the values to avoid SQL injection
432 10 Anonymous
              String valuefrom = "'" + SQLUtils.escapeString(values[0]) + "'";
433 10 Anonymous
              String valueto = "'" + SQLUtils.escapeString(values[1]) + "'";
434 10 Anonymous
435 10 Anonymous
              Predicat predicat = new Predicat();
436 10 Anonymous
              predicat.setLeftAttribute(colfrom);
437 10 Anonymous
              predicat.setNbOpenedParanthesis(1);
438 10 Anonymous
              predicat.setNbClosedParanthesis(0);
439 10 Anonymous
              predicat.setCompareOperator(Operator.GTE.value());
440 10 Anonymous
              predicat.setRightValue(valuefrom);
441 10 Anonymous
              predicats.add(predicat);
442 10 Anonymous
              predicat = new Predicat();
443 10 Anonymous
              predicat.setLeftAttribute(colto);
444 10 Anonymous
              predicat.setNbOpenedParanthesis(0);
445 10 Anonymous
              predicat.setNbClosedParanthesis(1);
446 10 Anonymous
              predicat.setCompareOperator(Operator.LTE.value());
447 10 Anonymous
              predicat.setRightValue(valueto);
448 10 Anonymous
              predicats.add(predicat);
449 10 Anonymous
            }
450 10 Anonymous
451 10 Anonymous
          }
452 10 Anonymous
        }
453 10 Anonymous
      }
454 10 Anonymous
455 10 Anonymous
      else {
456 10 Anonymous
        filterExists = false;
457 10 Anonymous
      }
458 10 Anonymous
    }
459 10 Anonymous
460 10 Anonymous
    return predicats;
461 10 Anonymous
  }
462 10 Anonymous
463 10 Anonymous
  /**
464 10 Anonymous
   * Check values of the form
465 10 Anonymous
   * 
466 10 Anonymous
   * @param parameters
467 10 Anonymous
   *          the parameters of the filter
468 10 Anonymous
   * @return true if values agree
469 10 Anonymous
   */
470 10 Anonymous
  private boolean checkValues(String[] parameters) {
471 10 Anonymous
    values = Arrays.copyOfRange(parameters, VALUES, parameters.length);
472 10 Anonymous
    if (values.length == 2) {
473 10 Anonymous
      return true;
474 10 Anonymous
    }
475 10 Anonymous
    return false;
476 10 Anonymous
  }
477 10 Anonymous
478 10 Anonymous
  /**
479 10 Anonymous
   * Gets the validator for this Filter
480 10 Anonymous
   * 
481 10 Anonymous
   * @return the validator for the filter
482 10 Anonymous
   */
483 10 Anonymous
  @Override
484 10 Anonymous
  public Validator<AbstractFilter> getValidator() {
485 10 Anonymous
    return new Validator<AbstractFilter>() {
486 10 Anonymous
      @Override
487 10 Anonymous
      public Set<ConstraintViolation> validate(AbstractFilter item) {
488 10 Anonymous
        return null;
489 10 Anonymous
      }
490 10 Anonymous
    };
491 10 Anonymous
  }
492 10 Anonymous
493 10 Anonymous
}
494 9 Anonymous
</code></pre>