Project

General

Profile

Corot » History » Version 12

Anonymous, 05/06/2012 17:13

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 2 Anonymous
h2. Export VOTABLE
9 3 Anonymous
10 3 Anonymous
Dans contextMenu.js (client) :
11 3 Anonymous
12 3 Anonymous
<pre><code class="javascript">
13 4 Anonymous
         // ligne 864 fichier version 0.9.1
14 3 Anonymous
        // on test que l'utilisateur ne selectionne pas CHR et MON en meme temps + qu'il n'a pas pris de WINDESC et d'IMAG
15 3 Anonymous
	if((request.search("EN2_STAR_CHR")!=-1 && request.search("EN2_STAR_MON")!=-1) || request.search("EN2_WIN")!=-1 || request.search("EN2_STAR_IMAG")!=-1){
16 3 Anonymous
                       // si oui on l'averti que ce n'est pas possible et on ne lance pas le VOTable
17 3 Anonymous
			Ext.Msg.alert("WARNING !", "DONT SELECT WINDESCRIPTOR OR IMAG" +  "<br/>"  + " ALSO DONT PICK EN2_STAR_MON AND EN2_STAR_CHR AT THE SAME TIME PLEASE !!!");
18 3 Anonymous
19 3 Anonymous
		}else{ 
20 3 Anonymous
 // sinon on lance exportVOTable
21 3 Anonymous
22 3 Anonymous
			
23 3 Anonymous
			url += "?1=1" + request;
24 3 Anonymous
			if (!Ext.isEmpty(limit)) {
25 3 Anonymous
				url += "&limit=" + limit;
26 3 Anonymous
			}
27 3 Anonymous
			if (! Ext.isEmpty(userParameters)) {
28 3 Anonymous
				Ext.iterate(userParameters, function (key, value) {
29 3 Anonymous
					url += "&" + key + "=" + value; 
30 3 Anonymous
				});
31 3 Anonymous
			}
32 3 Anonymous
			
33 3 Anonymous
			// If Get => the Resource MUST be synchrone and then send a representation
34 3 Anonymous
			if (method == "GET") {
35 3 Anonymous
				window.open(url);
36 3 Anonymous
				Ext.getBody().unmask();
37 3 Anonymous
				return;
38 3 Anonymous
			} else {
39 3 Anonymous
				this._executeRequestForResource(url, method);
40 3 Anonymous
			}
41 3 Anonymous
		}
42 3 Anonymous
43 6 Anonymous
</code></pre>
44 5 Anonymous
45 5 Anonymous
46 5 Anonymous
Puis dans ExportVORessource.java :
47 5 Anonymous
48 5 Anonymous
<pre><code class="java">
49 5 Anonymous
     // ligne 192
50 5 Anonymous
     // Execute request to know which value are selected
51 5 Anonymous
        String primkey=""; 
52 5 Anonymous
        Integer type=0;
53 5 Anonymous
        try {
54 5 Anonymous
            primkey = databaseRequest.getRequestAsString(); //.getSelectedPrimaryKey();
55 5 Anonymous
            boolean found = primkey.contains("AN2");
56 5 Anonymous
            if(found){
57 5 Anonymous
                System.out.println("J'ai trouvé AN2 !!!\n");
58 5 Anonymous
                type=1;
59 5 Anonymous
            }else{
60 5 Anonymous
            //System.out.println("AN2 non trouvé !!!\n");
61 5 Anonymous
            if((primkey.contains("EN2_STAR_CHR") && primkey.contains("EN2_STAR_MON")) || primkey.contains("EN2_WIN") || primkey.contains("EN2_STAR_IMAG")){
62 5 Anonymous
                System.out.println("Error j'ai trouvé CHR et MON !!!\n");
63 5 Anonymous
            }else{ 
64 5 Anonymous
                if(primkey.contains("EN2_STAR_CHR")){
65 5 Anonymous
                    System.out.println("J'ai trouvé CHR !!!\n");
66 5 Anonymous
                    type = 2;
67 5 Anonymous
                } else{ 
68 5 Anonymous
                    if(primkey.contains("EN2_STAR_MON")){
69 5 Anonymous
                        System.out.println("J'ai trouvé MON !!!\n");
70 5 Anonymous
                        type = 3;   
71 5 Anonymous
                    }
72 5 Anonymous
                    }
73 5 Anonymous
                }
74 5 Anonymous
            }
75 5 Anonymous
        System.out.println("Type vaux : " + type);
76 5 Anonymous
        } catch (SitoolsException ex) {
77 5 Anonymous
            Logger.getLogger(ExportVOResource.class.getName()).log(Level.SEVERE, null, ex);
78 5 Anonymous
        }
79 5 Anonymous
       System.out.println("primkey : " + primkey); // astero et AN2_STAR dans la requete !!!
80 5 Anonymous
81 5 Anonymous
      [ ........  ]
82 5 Anonymous
83 5 Anonymous
     // ligne 246
84 5 Anonymous
    String template_name = "";
85 5 Anonymous
        if (type==1)
86 5 Anonymous
            template_name = "template_astero.ftl";
87 5 Anonymous
        else if (type==2)
88 5 Anonymous
             template_name = "template_exo_chr.ftl";
89 5 Anonymous
        else if (type==3)
90 5 Anonymous
             template_name = "template_exo_mon.ftl";
91 5 Anonymous
        
92 5 Anonymous
        
93 5 Anonymous
        System.out.println("j'envoie le template : " + template_name);
94 5 Anonymous
        
95 5 Anonymous
        //Return the response
96 7 Anonymous
        if (type!=0)
97 7 Anonymous
           return new VOTableRepresentation(dataModel, template_name);
98 7 Anonymous
        else
99 7 Anonymous
           return null;
100 6 Anonymous
</code></pre>
101 6 Anonymous
102 6 Anonymous
103 6 Anonymous
104 6 Anonymous
Les templates.ftl doivent être dans le folder de VOTableRepresentation.java et doivent être bien définis.
105 6 Anonymous
106 6 Anonymous
Exemple :  Pour EN2_STAR_MON, template_exo_mon.ftl
107 6 Anonymous
108 6 Anonymous
<pre><code class="XML">
109 6 Anonymous
110 6 Anonymous
<?xml version="1.0" encoding="UTF-8"?>
111 6 Anonymous
<VOTABLE version="1.2" 
112 6 Anonymous
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
113 6 Anonymous
xsi:schemaLocation="http://www.ivoa.net/xml/VOTable/v1.2" 
114 6 Anonymous
xmlns="http://www.ivoa.net/xml/VOTable/v1.2">
115 6 Anonymous
<!--
116 6 Anonymous
 !  VOTable written by MHUSSON@IAS version 0.1 (mhusson@ias.u-psud.fr)
117 6 Anonymous
 !  at 2012-03-30
118 6 Anonymous
 !  Best use with TOPCAT 3.9 or higher version
119 6 Anonymous
 !-->
120 6 Anonymous
    <RESOURCE name="COROT N2 EN2MON">        
121 6 Anonymous
        <DESCRIPTION>COROT N2 PUBLIC DATA VOTABLE STREAM FORMAT</DESCRIPTION>          
122 6 Anonymous
	<PARAM name="COROT VERSION" datatype="char" arraysize="*" value="N2">
123 6 Anonymous
		<DESCRIPTION>COROT N2 FITS STREAM</DESCRIPTION>
124 6 Anonymous
	</PARAM>
125 6 Anonymous
	<INFO name="SITOOLS2 COROT PROJECT" value="http://idoc-corotn2-public-v2.ias.u-psud.fr">
126 6 Anonymous
		VOTABLE generated with SItools2 COROT and exportVO Ressource (J-C.Malapert@CNES, M.Husson@IAS)
127 6 Anonymous
	</INFO>
128 6 Anonymous
 	<TABLE ID="reference">
129 6 Anonymous
	<FIELD ID="date" arraysize="23" datatype="char" name="DATE" unit="yyyy-mm-jjThh:mi:ss"/>
130 6 Anonymous
	<FIELD ID="datejd" datatype="double" name="DATEJD" unit="COROT JULIAN DAY"/>
131 6 Anonymous
	<FIELD ID="datehel" datatype="double" name="DATEHEL" unit="COROT JULIAN DAY"/>
132 6 Anonymous
	<FIELD ID="status" datatype="int" name="STATUS"/>
133 6 Anonymous
	<FIELD ID="whiteflux" datatype="float" name="WHITEFLUX" unit="ELECTRONS"/>
134 6 Anonymous
	<FIELD ID="whitefluxdev" datatype="float" name="WHITEFLUXDEV" unit="ELECTRONS"/>
135 6 Anonymous
	<FIELD ID="bg" datatype="float" name="BG" unit="ELECTRONS PER PIXEL"/>
136 6 Anonymous
	<FIELD ID="correc" datatype="float" name="CORREC" unit="ELECTRONS"/>
137 6 Anonymous
	</TABLE>
138 6 Anonymous
	<#list rows as row>
139 6 Anonymous
	<TABLE ref="reference" name="${row["file"]}">
140 6 Anonymous
	<PARAM name="COROT ID" value="${row["corotid"]}"/>
141 6 Anonymous
	<PARAM name="COROT RUN" value="${row["run_code"]}"/>
142 6 Anonymous
        	<DATA>
143 6 Anonymous
			<FITS extnum="1">
144 6 Anonymous
				<STREAM actuate="onRequest" href="${row["download"]}"/>
145 6 Anonymous
			</FITS>
146 6 Anonymous
        	   </DATA>
147 6 Anonymous
        </TABLE>
148 6 Anonymous
    	</#list>
149 6 Anonymous
    </RESOURCE>
150 6 Anonymous
</VOTABLE>
151 6 Anonymous
152 6 Anonymous
</code></pre> 
153 9 Anonymous
154 9 Anonymous
155 9 Anonymous
h2. Les composants de formulaire : 
156 9 Anonymous
157 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".
158 9 Anonymous
159 9 Anonymous
Le code javascript correspondant : 
160 9 Anonymous
161 9 Anonymous
Partie ADMIN : 
162 9 Anonymous
163 9 Anonymous
<pre><code class="javascript">
164 9 Anonymous
165 9 Anonymous
/*global Ext, sitools, ID, i18n, document, showResponse, alertFailure, LOCALE, ImageChooser, 
166 9 Anonymous
 showHelp*/
167 9 Anonymous
Ext.namespace('sitools.component.forms.multiParam');
168 9 Anonymous
169 9 Anonymous
sitools.component.forms.multiParam.DateBeginEnd = Ext.extend(sitools.component.forms.multiParam.abstractForm, {
170 9 Anonymous
    height : 250,
171 9 Anonymous
    id : 'sitools.component.forms.definitionId',
172 9 Anonymous
    initComponent : function () {
173 9 Anonymous
        this.winPropComponent.specificHeight = 350;
174 9 Anonymous
        this.winPropComponent.specificWidth = 400;
175 9 Anonymous
        sitools.component.forms.multiParam.DateBeginEnd.superclass.initComponent.call(this);
176 9 Anonymous
     
177 9 Anonymous
178 9 Anonymous
        
179 9 Anonymous
    /*
180 9 Anonymous
     * Build all the Columns mapping for the configuration, 
181 9 Anonymous
     * this object needs three columns
182 9 Anonymous
     */
183 9 Anonymous
    var labels = ['DATE FROM', 'DATE TO'];
184 9 Anonymous
    for (var i = 1; i <= 2; i++) {
185 9 Anonymous
		this['mapParam' + i] = new Ext.form.ComboBox({
186 9 Anonymous
		    fieldLabel : labels[i - 1],
187 9 Anonymous
		    triggerAction : 'all',
188 9 Anonymous
		    name : "PARAM" + i,
189 9 Anonymous
		    specificType : "mapParam", 
190 9 Anonymous
		    columnIndex : i, 
191 9 Anonymous
		    lazyRender : true,
192 9 Anonymous
		    mode : 'local',
193 9 Anonymous
		    store : this.storeColumn,
194 9 Anonymous
		    valueField : 'columnAlias',
195 9 Anonymous
		    displayField : 'header',
196 9 Anonymous
		    anchor : '100%', 
197 9 Anonymous
		    allowBlank : false 
198 9 Anonymous
		    
199 9 Anonymous
		}); 
200 9 Anonymous
		
201 9 Anonymous
		if (this.action == "modify") {
202 9 Anonymous
			Ext.apply(this['mapParam' + i], {
203 9 Anonymous
				value : this.selectedRecord.data.code[i - 1]
204 9 Anonymous
			});
205 9 Anonymous
		}
206 9 Anonymous
       
207 9 Anonymous
		this.insert(i, this['mapParam' + i]);
208 9 Anonymous
    }
209 9 Anonymous
210 9 Anonymous
    this.componentDefaultValue1 = new Ext.form.DateField({
211 9 Anonymous
        fieldLabel : i18n.get('label.defaultValue') + ' (DATE FROM)',
212 9 Anonymous
        name : 'componentDefaultValue1',
213 9 Anonymous
        anchor : '100%',
214 9 Anonymous
        format : DEFAULT_DATE_FORMAT
215 9 Anonymous
    });
216 9 Anonymous
    this.componentDefaultValue2 = new Ext.form.DateField({
217 9 Anonymous
        fieldLabel : i18n.get('label.defaultValue') + ' (DATE TO)',
218 9 Anonymous
        name : 'componentDefaultValue2',
219 9 Anonymous
        anchor : '100%',
220 9 Anonymous
        format : DEFAULT_DATE_FORMAT
221 9 Anonymous
    });
222 9 Anonymous
223 9 Anonymous
    this.add(this.componentDefaultValue1);
224 9 Anonymous
    this.add(this.componentDefaultValue2);
225 9 Anonymous
226 9 Anonymous
    
227 9 Anonymous
},
228 9 Anonymous
onRender : function () {
229 9 Anonymous
    sitools.component.forms.multiParam.DateBeginEnd.superclass.onRender.apply(this, arguments);
230 9 Anonymous
    if (this.action == 'modify') {
231 9 Anonymous
        if (!Ext.isEmpty(this.selectedRecord.data.defaultValues)) {
232 9 Anonymous
            if (Ext.isString(this.selectedRecord.data.defaultValues[0])) {
233 9 Anonymous
                this.componentDefaultValue1.setValue(this.selectedRecord.data.defaultValues[0].split('T')[0]);
234 9 Anonymous
            }
235 9 Anonymous
            else {
236 9 Anonymous
                this.componentDefaultValue1.setValue(this.selectedRecord.data.defaultValues[0].split('T')[0]);
237 9 Anonymous
            }
238 9 Anonymous
            if (Ext.isString(this.selectedRecord.data.defaultValues[1])) {
239 9 Anonymous
                this.componentDefaultValue2.setValue(this.selectedRecord.data.defaultValues[1].split('T')[0]);
240 9 Anonymous
            }
241 9 Anonymous
            else {
242 9 Anonymous
                this.componentDefaultValue2.setValue(this.selectedRecord.data.defaultValues[1].split('T')[0]);
243 9 Anonymous
            }
244 9 Anonymous
        }
245 9 Anonymous
    }
246 9 Anonymous
},
247 9 Anonymous
afterRender : function () {
248 9 Anonymous
    sitools.component.forms.multiParam.DateBeginEnd.superclass.afterRender.apply(this, arguments);
249 9 Anonymous
    if (this.action == 'modify') {
250 9 Anonymous
		if (!Ext.isEmpty(this.selectedRecord.data.defaultValues)) {
251 9 Anonymous
            this.componentDefaultValue1.setValue(this.selectedRecord.data.defaultValues[0]);
252 9 Anonymous
            this.componentDefaultValue2.setValue(this.selectedRecord.data.defaultValues[1]);
253 9 Anonymous
            
254 9 Anonymous
        }
255 9 Anonymous
    }
256 9 Anonymous
   
257 9 Anonymous
},
258 9 Anonymous
259 9 Anonymous
_onValidate : function (action, gridFormComponents) {
260 9 Anonymous
    var f = this.getForm();
261 9 Anonymous
    if (!f.isValid()) {
262 9 Anonymous
    	Ext.Msg.alert(i18n.get('label.error'), i18n.get('warning.invalidForm'));
263 9 Anonymous
        return false;
264 9 Anonymous
    }
265 9 Anonymous
    var defaultValue1 = Ext.isEmpty(f.findField('componentDefaultValue1')) ? "" : f.findField('componentDefaultValue1').getValue();
266 9 Anonymous
    var defaultValue2 = Ext.isEmpty(f.findField('componentDefaultValue2')) ? "" : f.findField('componentDefaultValue2').getValue();
267 9 Anonymous
268 9 Anonymous
	var columnObjects = this.find('specificType', 'mapParam');
269 9 Anonymous
	var code = [];
270 9 Anonymous
	Ext.each(columnObjects, function (columnObject) {
271 9 Anonymous
		code.push(columnObject.getValue());
272 9 Anonymous
	});
273 9 Anonymous
  
274 9 Anonymous
    if (action == 'modify') {
275 9 Anonymous
        var rec = gridFormComponents.getSelectionModel().getSelected();
276 9 Anonymous
        
277 9 Anonymous
        var labelParam1 = Ext.isEmpty(f.findField('LABEL_PARAM1')) ? "" : f.findField('LABEL_PARAM1').getValue();
278 9 Anonymous
        var css = Ext.isEmpty(f.findField('CSS')) ? "" : f.findField('CSS').getValue();
279 9 Anonymous
        
280 9 Anonymous
        rec.set('label', labelParam1);
281 9 Anonymous
        rec.set('code', code);
282 9 Anonymous
        rec.set('css', css);
283 9 Anonymous
        rec.set('componentDefaultHeight', f.findField('componentDefaultHeight').getValue());
284 9 Anonymous
        rec.set('componentDefaultWidth', f.findField('componentDefaultWidth').getValue());
285 9 Anonymous
286 9 Anonymous
        rec.set('defaultValues', [ defaultValue1, defaultValue2]);
287 9 Anonymous
    } else {
288 9 Anonymous
        var formComponentsStore = gridFormComponents.getStore();
289 9 Anonymous
        
290 9 Anonymous
        // Génération de l'id
291 9 Anonymous
        var lastId = 0;
292 9 Anonymous
        var greatY = 0;
293 9 Anonymous
        formComponentsStore.each(function (component) {
294 9 Anonymous
            if (component.data.id > lastId) {
295 9 Anonymous
                lastId = parseInt(component.data.id, 10);
296 9 Anonymous
            }
297 9 Anonymous
            if (component.data.ypos > greatY) {
298 9 Anonymous
                greatY = parseInt(component.data.ypos, 10)  + parseInt(component.data.height, 10);
299 9 Anonymous
            }
300 9 Anonymous
301 9 Anonymous
        });
302 9 Anonymous
        var componentId = lastId + 1;
303 9 Anonymous
        componentId = componentId.toString();
304 9 Anonymous
        var componentYpos = greatY + 10;
305 9 Anonymous
        
306 9 Anonymous
        formComponentsStore.add(new Ext.data.Record({
307 9 Anonymous
            label : f.findField('LABEL_PARAM1').getValue(),
308 9 Anonymous
            type : this.ctype,
309 9 Anonymous
            code : code,
310 9 Anonymous
            width : f.findField('componentDefaultWidth').getValue(),
311 9 Anonymous
            height : f.findField('componentDefaultHeight').getValue(),
312 9 Anonymous
            id : componentId,
313 9 Anonymous
            ypos : componentYpos,
314 9 Anonymous
            css : f.findField('CSS').getValue(),
315 9 Anonymous
            jsAdminObject : this.jsAdminObject,
316 9 Anonymous
            jsUserObject : this.jsUserObject,
317 9 Anonymous
            defaultValues : [ defaultValue1, defaultValue2 ]
318 9 Anonymous
        }));
319 9 Anonymous
    }
320 9 Anonymous
    return true;
321 9 Anonymous
}
322 9 Anonymous
323 9 Anonymous
});
324 9 Anonymous
325 9 Anonymous
</code></pre>
326 9 Anonymous
327 9 Anonymous
328 9 Anonymous
partie CLIENT : 
329 9 Anonymous
330 9 Anonymous
<pre><code class="javascript">
331 9 Anonymous
/***************************************
332 9 Anonymous
* Copyright 2011 CNES - CENTRE NATIONAL d'ETUDES SPATIALES
333 9 Anonymous
* 
334 9 Anonymous
* This file is part of SITools2.
335 9 Anonymous
* 
336 9 Anonymous
* SITools2 is free software: you can redistribute it and/or modify
337 9 Anonymous
* it under the terms of the GNU General Public License as published by
338 9 Anonymous
* the Free Software Foundation, either version 3 of the License, or
339 9 Anonymous
* (at your option) any later version.
340 9 Anonymous
* 
341 9 Anonymous
* SITools2 is distributed in the hope that it will be useful,
342 9 Anonymous
* but WITHOUT ANY WARRANTY; without even the implied warranty of
343 9 Anonymous
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
344 9 Anonymous
* GNU General Public License for more details.
345 9 Anonymous
* 
346 9 Anonymous
* You should have received a copy of the GNU General Public License
347 9 Anonymous
* along with SITools2.  If not, see <http://www.gnu.org/licenses/>.
348 9 Anonymous
***************************************/
349 9 Anonymous
/*global Ext, sitools*/
350 9 Anonymous
Ext.ns('sitools.component.users.SubSelectionParameters.SingleSelection');
351 9 Anonymous
352 9 Anonymous
sitools.component.users.SubSelectionParameters.SingleSelection.DateBeginEnd = Ext.extend(Ext.Container, {
353 9 Anonymous
354 9 Anonymous
    initComponent : function () {
355 9 Anonymous
        this.fieldFrom = new Ext.form.DateField({
356 9 Anonymous
            allowBlank : true,
357 9 Anonymous
            format : DEFAULT_DATE_FORMAT, 
358 9 Anonymous
            width : 165,
359 9 Anonymous
            height : this.height,
360 9 Anonymous
            value : new Date(this.defaultValues[0]).format(DEFAULT_DATE_FORMAT)
361 9 Anonymous
        });
362 9 Anonymous
        this.fieldTo = new Ext.form.DateField({
363 9 Anonymous
            allowBlank : true,
364 9 Anonymous
            format : DEFAULT_DATE_FORMAT, 
365 9 Anonymous
            width : 165,
366 9 Anonymous
            height : this.height,
367 9 Anonymous
            value : new Date(this.defaultValues[1]).format(DEFAULT_DATE_FORMAT)
368 9 Anonymous
        });
369 9 Anonymous
        Ext.apply(this, {
370 9 Anonymous
            layout : 'table',
371 9 Anonymous
            columns : 2,     /* 3*/
372 9 Anonymous
            fieldLabel : this.label,
373 9 Anonymous
            stype : "sitoolsFormContainer",
374 9 Anonymous
375 9 Anonymous
            items : [ new Ext.Container({
376 9 Anonymous
            	border : false,
377 9 Anonymous
            	html : this.label + " : ", 
378 9 Anonymous
            	width : "150"
379 9 Anonymous
            }), this.fieldFrom, new Ext.Container({
380 9 Anonymous
                border : false,
381 9 Anonymous
                html : '&nbsp;'
382 9 Anonymous
            }), this.fieldTo ]
383 9 Anonymous
        });
384 9 Anonymous
        sitools.component.users.SubSelectionParameters.SingleSelection.DateBeginEnd.superclass.initComponent.apply(
385 9 Anonymous
                this, arguments);
386 9 Anonymous
    },
387 9 Anonymous
388 9 Anonymous
    /**
389 9 Anonymous
     * The code of the parameter to notify changed event.
390 9 Anonymous
     */
391 9 Anonymous
    code : null,
392 9 Anonymous
393 9 Anonymous
    /**
394 9 Anonymous
     * The left bound of the period.
395 9 Anonymous
     */
396 9 Anonymous
    fieldFrom : null,
397 9 Anonymous
398 9 Anonymous
    /**
399 9 Anonymous
     * The right bound of the period.
400 9 Anonymous
     */
401 9 Anonymous
    fieldTo : null,
402 9 Anonymous
403 9 Anonymous
    notifyValueSelected : function () {
404 9 Anonymous
        this.parent.notifyValueChanged(this.code);
405 9 Anonymous
    },
406 9 Anonymous
407 9 Anonymous
    isValueDefined : function () {
408 9 Anonymous
        if (this.fieldFrom.getValue() && this.fieldTo.getValue()) {
409 9 Anonymous
            return true;
410 9 Anonymous
        } else {
411 9 Anonymous
            return false;
412 9 Anonymous
        }
413 9 Anonymous
    },
414 9 Anonymous
415 9 Anonymous
    getSelectedValue : function () {
416 9 Anonymous
        return {
417 9 Anonymous
            from : this.fieldFrom.getValue(),
418 9 Anonymous
            to : this.fieldTo.getValue()
419 9 Anonymous
        };
420 9 Anonymous
    },
421 9 Anonymous
    
422 9 Anonymous
    getParameterValue : function () {
423 9 Anonymous
        var value = this.getSelectedValue();
424 9 Anonymous
        if (Ext.isEmpty(value) || Ext.isEmpty(value.from) || Ext.isEmpty(value.to)) {
425 9 Anonymous
            return null;
426 9 Anonymous
        }
427 9 Anonymous
        return this.type + "|" + this.code + "|" + value.from.format('Y-m-d') + "|" + value.to.format('Y-m-d') ;
428 9 Anonymous
    }
429 9 Anonymous
});
430 9 Anonymous
</code></pre>
431 9 Anonymous
432 9 Anonymous
433 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*
434 9 Anonymous
435 9 Anonymous
<pre><code class="java">
436 10 Anonymous
/*******************************************************************************
437 10 Anonymous
 * Copyright 2011 CNES - CENTRE NATIONAL d'ETUDES SPATIALES
438 10 Anonymous
 * 
439 10 Anonymous
 * This file is part of SITools2.
440 10 Anonymous
 * 
441 10 Anonymous
 * SITools2 is free software: you can redistribute it and/or modify
442 10 Anonymous
 * it under the terms of the GNU General Public License as published by
443 10 Anonymous
 * the Free Software Foundation, either version 3 of the License, or
444 10 Anonymous
 * (at your option) any later version.
445 10 Anonymous
 * 
446 10 Anonymous
 * SITools2 is distributed in the hope that it will be useful,
447 10 Anonymous
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
448 10 Anonymous
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
449 10 Anonymous
 * GNU General Public License for more details.
450 10 Anonymous
 * 
451 10 Anonymous
 * You should have received a copy of the GNU General Public License
452 10 Anonymous
 * along with SITools2.  If not, see <http://www.gnu.org/licenses/>.
453 10 Anonymous
 ******************************************************************************/
454 10 Anonymous
package fr.cnes.sitools.filter.basic;
455 9 Anonymous
456 10 Anonymous
import java.util.Arrays;
457 10 Anonymous
import java.util.HashMap;
458 10 Anonymous
import java.util.List;
459 10 Anonymous
import java.util.Set;
460 10 Anonymous
461 10 Anonymous
import org.restlet.Request;
462 10 Anonymous
import org.restlet.data.Form;
463 10 Anonymous
import org.restlet.ext.wadl.ParameterInfo;
464 10 Anonymous
import org.restlet.ext.wadl.ParameterStyle;
465 10 Anonymous
466 10 Anonymous
import fr.cnes.sitools.common.validator.ConstraintViolation;
467 10 Anonymous
import fr.cnes.sitools.common.validator.Validator;
468 10 Anonymous
import fr.cnes.sitools.dataset.DataSetApplication;
469 10 Anonymous
import fr.cnes.sitools.dataset.filter.business.AbstractFilter;
470 10 Anonymous
import fr.cnes.sitools.dataset.model.Column;
471 10 Anonymous
import fr.cnes.sitools.dataset.model.DataSet;
472 10 Anonymous
import fr.cnes.sitools.dataset.model.Operator;
473 10 Anonymous
import fr.cnes.sitools.dataset.model.Predicat;
474 10 Anonymous
import fr.cnes.sitools.util.SQLUtils;
475 10 Anonymous
476 10 Anonymous
/**
477 10 Anonymous
 * Filter defined for Date Between Component
478 10 Anonymous
 * 
479 10 Anonymous
 * 
480 10 Anonymous
 * @author d.arpin
481 10 Anonymous
 * <a href="https://sourceforge.net/tracker/?func=detail&atid=2158259&aid=3411383&group_id=531341">[3411383]</a><br/>
482 10 Anonymous
 * 2011/09/19 d.arpin {add quotes arround date Value}
483 10 Anonymous
 */
484 10 Anonymous
public final class DateBeginEndFilter extends AbstractFilter {
485 10 Anonymous
  /**
486 10 Anonymous
   * The index of TYPE
487 10 Anonymous
   */
488 10 Anonymous
  private static final int TYPE = 0;
489 10 Anonymous
  /**
490 10 Anonymous
   * The index of COLUMN
491 10 Anonymous
   */
492 10 Anonymous
  private static final int COLUMN = 1;
493 10 Anonymous
  /**
494 10 Anonymous
   * The index of Values
495 10 Anonymous
   */
496 10 Anonymous
  private static final int VALUES = 2;
497 10 Anonymous
498 10 Anonymous
  /** The TEMPLATE_PARAM */
499 10 Anonymous
  private static final String TEMPLATE_PARAM = "p[#]";
500 10 Anonymous
  /**
501 10 Anonymous
   * the values from to
502 10 Anonymous
   */
503 10 Anonymous
  private String[] values;
504 10 Anonymous
505 10 Anonymous
  /**
506 10 Anonymous
   * The list of component that uses this filter
507 10 Anonymous
   */
508 10 Anonymous
  private enum TYPE_COMPONENT {
509 10 Anonymous
    /** DefaultType */
510 10 Anonymous
    DATE_BEGIN_END
511 10 Anonymous
  }
512 10 Anonymous
513 10 Anonymous
  /**
514 10 Anonymous
   * Default constructor
515 10 Anonymous
   */
516 10 Anonymous
  public DateBeginEndFilter() {
517 10 Anonymous
518 10 Anonymous
    super();
519 10 Anonymous
    this.setName("DateBeginEndFilter");
520 10 Anonymous
    this.setDescription("Required when using Date Between Components between 2 columns");
521 10 Anonymous
522 10 Anonymous
    this.setAuthor("HUSSON@IAS");
523 10 Anonymous
    this.setClassAuthor("HUSSON@IAS");
524 10 Anonymous
    this.setClassOwner("IAS");
525 10 Anonymous
    this.setVersion("0.1");
526 10 Anonymous
    this.setDefaultFilter(true);
527 10 Anonymous
528 10 Anonymous
    HashMap<String, ParameterInfo> rpd = new HashMap<String, ParameterInfo>();
529 10 Anonymous
530 10 Anonymous
    ParameterInfo paramInfo;
531 10 Anonymous
    paramInfo = new ParameterInfo("p[#]", false, "xs:string", ParameterStyle.QUERY,
532 10 Anonymous
    "DATE_BEGIN_END|columnFrom,columnTo|valueFrom|valueTo");
533 10 Anonymous
    rpd.put("0", paramInfo);
534 10 Anonymous
    this.setRequestParamsDescription(rpd);
535 10 Anonymous
    //
536 10 Anonymous
537 10 Anonymous
  }
538 10 Anonymous
539 10 Anonymous
  @Override
540 10 Anonymous
  public List<Predicat> createPredicats(Request request, List<Predicat> predicats) throws Exception {
541 10 Anonymous
    // Get the dataset
542 10 Anonymous
    DataSetApplication dsApplication = null;
543 10 Anonymous
    DataSet ds = null;
544 10 Anonymous
545 10 Anonymous
    Form params = request.getResourceRef().getQueryAsForm();
546 10 Anonymous
    boolean filterExists = true;
547 10 Anonymous
    int i = 0;
548 10 Anonymous
    // Build predicat for filters param
549 10 Anonymous
    while (filterExists) {
550 10 Anonymous
      String index = TEMPLATE_PARAM.replace("#", Integer.toString(i++));
551 10 Anonymous
      String formParam = params.getFirstValue(index);
552 10 Anonymous
      if (formParam != null) {
553 10 Anonymous
        String[] parameters = formParam.split("\\|");
554 10 Anonymous
        TYPE_COMPONENT[] types = TYPE_COMPONENT.values();
555 10 Anonymous
        Boolean trouve = false;
556 10 Anonymous
        for (TYPE_COMPONENT typeCmp : types) {
557 10 Anonymous
          if (typeCmp.name().equals(parameters[TYPE])) {
558 10 Anonymous
            trouve = true;
559 10 Anonymous
          }
560 10 Anonymous
        }
561 10 Anonymous
        if (trouve) {
562 10 Anonymous
          if (dsApplication == null) {
563 10 Anonymous
            dsApplication = (DataSetApplication) getContext().getAttributes().get("DataSetApplication");
564 10 Anonymous
            ds = dsApplication.getDataSet();
565 10 Anonymous
          }
566 10 Anonymous
          String columnfrom = null;
567 10 Anonymous
          String columnto = null;
568 10 Anonymous
          if (parameters.length >= VALUES) {
569 10 Anonymous
            columnfrom = parameters[COLUMN].split(",")[0];
570 10 Anonymous
            columnto = parameters[COLUMN].split(",")[1];
571 10 Anonymous
572 10 Anonymous
            Column colfrom = ds.findByColumnAlias(columnfrom);
573 10 Anonymous
            Column colto = ds.findByColumnAlias(columnto);
574 10 Anonymous
575 10 Anonymous
            if (colfrom != null && colfrom.getFilter() != null && colfrom.getFilter() && checkValues(parameters) && colto != null && colto.getFilter() != null && colto.getFilter()) {
576 10 Anonymous
              // escape the values to avoid SQL injection
577 10 Anonymous
              String valuefrom = "'" + SQLUtils.escapeString(values[0]) + "'";
578 10 Anonymous
              String valueto = "'" + SQLUtils.escapeString(values[1]) + "'";
579 10 Anonymous
580 10 Anonymous
              Predicat predicat = new Predicat();
581 10 Anonymous
              predicat.setLeftAttribute(colfrom);
582 10 Anonymous
              predicat.setNbOpenedParanthesis(1);
583 10 Anonymous
              predicat.setNbClosedParanthesis(0);
584 10 Anonymous
              predicat.setCompareOperator(Operator.GTE.value());
585 10 Anonymous
              predicat.setRightValue(valuefrom);
586 10 Anonymous
              predicats.add(predicat);
587 10 Anonymous
              predicat = new Predicat();
588 10 Anonymous
              predicat.setLeftAttribute(colto);
589 10 Anonymous
              predicat.setNbOpenedParanthesis(0);
590 10 Anonymous
              predicat.setNbClosedParanthesis(1);
591 10 Anonymous
              predicat.setCompareOperator(Operator.LTE.value());
592 10 Anonymous
              predicat.setRightValue(valueto);
593 10 Anonymous
              predicats.add(predicat);
594 10 Anonymous
            }
595 10 Anonymous
596 10 Anonymous
          }
597 10 Anonymous
        }
598 10 Anonymous
      }
599 10 Anonymous
600 10 Anonymous
      else {
601 10 Anonymous
        filterExists = false;
602 10 Anonymous
      }
603 10 Anonymous
    }
604 10 Anonymous
605 10 Anonymous
    return predicats;
606 10 Anonymous
  }
607 10 Anonymous
608 10 Anonymous
  /**
609 10 Anonymous
   * Check values of the form
610 10 Anonymous
   * 
611 10 Anonymous
   * @param parameters
612 10 Anonymous
   *          the parameters of the filter
613 10 Anonymous
   * @return true if values agree
614 10 Anonymous
   */
615 10 Anonymous
  private boolean checkValues(String[] parameters) {
616 10 Anonymous
    values = Arrays.copyOfRange(parameters, VALUES, parameters.length);
617 10 Anonymous
    if (values.length == 2) {
618 10 Anonymous
      return true;
619 10 Anonymous
    }
620 10 Anonymous
    return false;
621 10 Anonymous
  }
622 10 Anonymous
623 10 Anonymous
  /**
624 10 Anonymous
   * Gets the validator for this Filter
625 10 Anonymous
   * 
626 10 Anonymous
   * @return the validator for the filter
627 10 Anonymous
   */
628 10 Anonymous
  @Override
629 10 Anonymous
  public Validator<AbstractFilter> getValidator() {
630 10 Anonymous
    return new Validator<AbstractFilter>() {
631 10 Anonymous
      @Override
632 10 Anonymous
      public Set<ConstraintViolation> validate(AbstractFilter item) {
633 10 Anonymous
        return null;
634 10 Anonymous
      }
635 10 Anonymous
    };
636 10 Anonymous
  }
637 10 Anonymous
638 10 Anonymous
}
639 9 Anonymous
</code></pre>