Project

General

Profile

Date Beginend » History » Version 1

Anonymous, 05/06/2012 17:15

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