Project

General

Profile

Corot » History » Version 11

Anonymous, 05/06/2012 17:12

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