Project

General

Profile

Revision 779bac69

Added by Marc Nicolas almost 9 years ago

Ajout derniere version de TAP

View differences:

sitools-idoc/hesiod/README.txt
1
This folder contains the developments of HESIOD.
sitools-idoc/hesiod/astronmy-extension/src/fr/cnes/sitools/astro/vo/conesearch/ConeSearchInputParameters.java
1
 /*******************************************************************************
2
 * Copyright 2010-2013 CNES - CENTRE NATIONAL d'ETUDES SPATIALES
3
 *
4
 * This file is part of SITools2.
5
 *
6
 * SITools2 is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * SITools2 is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with SITools2.  If not, see <http://www.gnu.org/licenses/>.
18
 ******************************************************************************/
19
package fr.cnes.sitools.astro.vo.conesearch;
20

  
21
import fr.cnes.sitools.dataset.DataSetApplication;
22
import fr.cnes.sitools.extensions.common.InputsValidation;
23
import fr.cnes.sitools.extensions.common.NotNullAndNotEmptyValidation;
24
import fr.cnes.sitools.extensions.common.RangeValidation;
25
import fr.cnes.sitools.extensions.common.StatusValidation;
26
import fr.cnes.sitools.extensions.common.Validation;
27
import java.util.ArrayList;
28
import java.util.Collections;
29
import java.util.HashMap;
30
import java.util.List;
31
import java.util.Map;
32
import java.util.Map.Entry;
33
import java.util.Set;
34
import java.util.logging.Level;
35
import java.util.logging.Logger;
36
import net.ivoa.xml.votable.v1.Info;
37
import org.restlet.Context;
38
import org.restlet.Request;
39

  
40
/**
41
 * This object provides methods to handle input parameters for the cone search protocol.
42
 *
43
 * @author Jean-Christophe Malapert
44
 */
45
public class ConeSearchInputParameters implements ConeSearchDataModelInterface {
46

  
47
  /**
48
   * Logger.
49
   */
50
  private static final Logger LOG = Logger.getLogger(ConeSearchInputParameters.class.getName());
51
  /**
52
   * Default verbosity mode.
53
   */
54
  private static final int DEFAULT_VERBOSITY_MODE = 0;
55
  /**
56
   * Verbosity mode.
57
   */
58
  private transient int verb = DEFAULT_VERBOSITY_MODE;
59
  /**
60
   * Data model.
61
   */
62
  private final transient Map dataModel = new HashMap();
63
  /**
64
   * User request.
65
   */
66
  private final transient Request request;
67
  /**
68
   * Application context.
69
   */
70
  private final transient Context context;
71
  /**
72
   * Application.
73
   */
74
  private final transient DataSetApplication datasetApp;
75
  /**
76
   * Right ascension of the cone center.
77
   */
78
  private transient double rightAscension;
79
  /**
80
   * Declination of the cone center.
81
   */
82
  private transient double declination;
83
  /**
84
   * Radius of the cone.
85
   */
86
  private transient double radius;
87

  
88
  /**
89
   * Constructor.
90
   *
91
   * @param datasetAppVal dataset application
92
   * @param requestVal Request
93
   * @param contextVal Context
94
   * @param maxSr maxSr for the cone search
95
   * @param verbosity verbosity
96
   * @param verbVal verbosity level
97
   */
98
  public ConeSearchInputParameters(final DataSetApplication datasetAppVal, final Request requestVal, final Context contextVal,
99
          final double maxSr, final boolean verbosity, final int verbVal) {
100
    this.datasetApp = datasetAppVal;
101
    this.context = contextVal;
102
    this.request = requestVal;
103
    final String raInput = this.request.getResourceRef().getQueryAsForm().getFirstValue(ConeSearchProtocolLibrary.RA);
104
    final String decInput = this.request.getResourceRef().getQueryAsForm().getFirstValue(ConeSearchProtocolLibrary.DEC);
105
    final String srInput = this.request.getResourceRef().getQueryAsForm().getFirstValue(ConeSearchProtocolLibrary.SR);
106
    final String verbInput = this.request.getResourceRef().getQueryAsForm().getFirstValue(ConeSearchProtocolLibrary.VERB);
107
    if(raInput == null && decInput == null && srInput == null){
108
        Info info = new Info();
109
        info.setName("QUERY_STATUS");
110
        info.setValueAttribute("ERROR");
111
        info.setValue("RA, DEC and SR must be not null");
112
        final List<Info> listInfos = new ArrayList<Info>();
113
        listInfos.add(info);
114
        this.dataModel.put("infos", listInfos);
115
    }else{
116
        checkInputParameters(raInput, decInput, srInput, maxSr, verbInput, verbosity, verbVal);
117
    }
118
  }
119

  
120
  /**
121
   * Check input parameters.
122
   *
123
   * @param raInput Ra
124
   * @param decInput Dec
125
   * @param srInput Sr
126
   * @param maxSr maxSr
127
   * @param verbosity verbosity
128
   * @param verbInput user inpur verb
129
   * @param verbVal verbosity from admin
130
   */
131
  private void checkInputParameters(final String raInput, final String decInput, final String srInput, final double maxSr,
132
          final String verbInput, final boolean verbosity, final int verbVal) {
133
    final List<Info> infos = new ArrayList<Info>();
134
    final Map<String, String> validationMap = new HashMap<String, String>();
135
    validationMap.put(ConeSearchProtocolLibrary.RA, raInput);
136
    validationMap.put(ConeSearchProtocolLibrary.DEC, decInput);
137
    validationMap.put(ConeSearchProtocolLibrary.SR, srInput);
138
    validationMap.put(ConeSearchProtocolLibrary.VERB, verbInput);
139
    validationMap.put(ConeSearchProtocolLibrary.VERBOSITY, String.valueOf(verbosity));
140
    Validation validation = new InputsValidation(validationMap);
141
    validation = new RangeValidation(validation, ConeSearchProtocolLibrary.RA, ConeSearchProtocolLibrary.RA_MIN, ConeSearchProtocolLibrary.RA_MAX);
142
    validation = new RangeValidation(validation, ConeSearchProtocolLibrary.DEC, ConeSearchProtocolLibrary.DEC_MIN, ConeSearchProtocolLibrary.DEC_MAX);
143
    validation = new RangeValidation(validation, ConeSearchProtocolLibrary.SR, 0, maxSr);
144
    validation = new NotNullAndNotEmptyValidation(validation, ConeSearchProtocolLibrary.VERBOSITY);
145
    validation = new NotNullAndNotEmptyValidation(validation, ConeSearchProtocolLibrary.VERB, String.valueOf(verbVal));
146
    final StatusValidation status = validation.validate();
147
    if (status.isValid()) {
148
        final Map<String, String> input = validation.getMap();
149
        this.rightAscension = Double.valueOf(input.get(ConeSearchProtocolLibrary.RA));
150
        this.declination = Double.valueOf(input.get(ConeSearchProtocolLibrary.DEC));
151
        this.radius = Double.valueOf(input.get(ConeSearchProtocolLibrary.SR));
152
        this.verb = Integer.valueOf(input.get(ConeSearchProtocolLibrary.VERB));
153
    } else {
154
        Info infoError = new Info();
155
        infoError.setName("QUERY_STATUS");
156
        infoError.setValueAttribute("ERROR");
157
        infos.add(infoError);
158
        final Map<String, String> errors = status.getMessages();
159
        final Set<Entry<String, String>> entries = errors.entrySet();
160
        for (Entry<String, String> entry : entries) {
161
            final Info info = new Info();
162
            info.setID(entry.getKey());
163
            info.setName("Error in " + entry.getKey());
164
            info.setValueAttribute("Error in input " + entry.getKey() + ": " + entry.getValue());
165
            infos.add(info);
166
            LOG.log(Level.FINEST, "{0}: {1}", new Object[]{entry.getKey(), entry.getValue()});
167
        }
168
    }
169
    if (!infos.isEmpty()) {
170
      this.dataModel.put("infos", infos);
171
    }
172
  }
173

  
174
  /**
175
   * Get Ra.
176
   *
177
   * @return Ra
178
   */
179
  public final double getRa() {
180
    return this.rightAscension;
181
  }
182

  
183
  /**
184
   * Get Dec.
185
   *
186
   * @return Dec
187
   */
188
  public final double getDec() {
189
    return this.declination;
190
  }
191

  
192
  /**
193
   * Get Sr.
194
   *
195
   * @return Sr
196
   */
197
  public final double getSr() {
198
    return this.radius;
199
  }
200

  
201
  /**
202
   * Get verbosity level.
203
   *
204
   * @return verbosity level
205
   */
206
  public final int getVerb() {
207
    return this.verb;
208
  }
209

  
210
  @Override
211
  public final Map getDataModel() {
212
    return Collections.unmodifiableMap(this.dataModel);
213
  }
214

  
215
  /**
216
   * Returns the request.
217
   *
218
   * @return Request
219
   */
220
  public final Request getRequest() {
221
    return this.request;
222
  }
223

  
224
  /**
225
   * Returns the context.
226
   *
227
   * @return Context
228
   */
229
  public final Context getContext() {
230
    return this.context;
231
  }
232

  
233
  /**
234
   * Get DatasetApplication.
235
   *
236
   * @return Dataset application
237
   */
238
  public final DataSetApplication getDatasetApplication() {
239
    return this.datasetApp;
240
  }
241
}
sitools-idoc/hesiod/astronmy-extension/src/fr/cnes/sitools/astro/vo/sia/SimpleImageAccessInputParameters.java
1
 /*******************************************************************************
2
 * Copyright 2010-2013 CNES - CENTRE NATIONAL d'ETUDES SPATIALES
3
 *
4
 * This file is part of SITools2.
5
 *
6
 * SITools2 is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * SITools2 is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with SITools2.  If not, see <http://www.gnu.org/licenses/>.
18
 ******************************************************************************/
19
package fr.cnes.sitools.astro.vo.sia;
20

  
21
import fr.cnes.sitools.dataset.DataSetApplication;
22
import fr.cnes.sitools.dataset.dto.ColumnConceptMappingDTO;
23
import fr.cnes.sitools.dictionary.model.Concept;
24
import fr.cnes.sitools.extensions.common.InputsValidation;
25
import fr.cnes.sitools.extensions.common.NotNullAndNotEmptyValidation;
26
import fr.cnes.sitools.extensions.common.NumberArrayValidation;
27
import fr.cnes.sitools.extensions.common.SpatialGeoValidation; 
28
import fr.cnes.sitools.extensions.common.StatusValidation;
29
import fr.cnes.sitools.extensions.common.Validation;
30
import fr.cnes.sitools.plugins.resources.model.ResourceModel;
31
import fr.cnes.sitools.util.Util;
32
import java.math.BigInteger;
33
import java.util.ArrayList;
34
import java.util.Collections;
35
import java.util.HashMap;
36
import java.util.List;
37
import java.util.Map;
38
import java.util.Set;
39
import java.util.logging.Level;
40
import java.util.logging.Logger;
41
import net.ivoa.xml.votable.v1.AnyTEXT;
42
import net.ivoa.xml.votable.v1.DataType;
43
import net.ivoa.xml.votable.v1.Field;
44
import net.ivoa.xml.votable.v1.Info;
45
import net.ivoa.xml.votable.v1.Option;
46
import net.ivoa.xml.votable.v1.Param;
47
import net.ivoa.xml.votable.v1.Values;
48
import org.restlet.Context;
49
import org.restlet.Request;
50

  
51

  
52
/**
53
 * Input parameters for SIA.
54
 *
55
 * @author Jean-Crhistophe Malapert <jean-christophe.malapert@cnes.fr>
56
 */
57
import fr.cnes.sitools.common.exception.SitoolsException;
58
import fr.cnes.sitools.dataset.dto.DictionaryMappingDTO;
59
public class SimpleImageAccessInputParameters implements DataModelInterface {
60
  /**
61
   * Logger.
62
   */
63
  private static final Logger LOG = Logger.getLogger(SimpleImageAccessInputParameters.class.getName());
64
  /**
65
   * Init value for right ascension parameter of the user input.
66
   */
67
  private transient double ra = 0.0;
68
  /**
69
   * Init value for declination parameter of the user input.
70
   */
71
  private transient double dec = 0.0;
72
  /**
73
   * Array that stores the size parameter of the user input.
74
   */
75
  private transient double[] size;
76
  /**
77
   * Default value for the verb parameter of the user input.
78
   */
79
  private transient int verb = 0;
80
  /**
81
   * Data model that stores the metadata response of the service.
82
   */
83
  private final transient Map dataModel = new HashMap();
84
  /**
85
   * Request.
86
   */
87
  private final transient Request request;
88
  /**
89
   * Context.
90
   */
91
  private final transient Context context;
92
  /**
93
   * Application where this resources is linked.
94
   */
95
  private final transient DataSetApplication datasetApp;
96
  /**
97
   * Configuration parameters of this resource.
98
   */
99
  private final transient ResourceModel resourceModel;
100

  
101
  /**
102
   * Constructs the objet that returns the metadata of the service.
103
   * @param datasetAppVal application
104
   * @param requestVal request
105
   * @param contextVal context
106
   * @param resourceModelVal configuration parameters
107
   */
108
  public SimpleImageAccessInputParameters(final DataSetApplication datasetAppVal, final Request requestVal, final Context contextVal, final ResourceModel resourceModelVal) {
109
    this.datasetApp = datasetAppVal;
110
    this.context = contextVal;
111
    this.request = requestVal;
112
    this.resourceModel = resourceModelVal;
113
    final String posInput = this.request.getResourceRef().getQueryAsForm().getFirstValue(SimpleImageAccessProtocolLibrary.POS);
114
    final String sizeInput = this.request.getResourceRef().getQueryAsForm().getFirstValue(SimpleImageAccessProtocolLibrary.SIZE);
115
    final String format = this.request.getResourceRef().getQueryAsForm().getFirstValue(SimpleImageAccessProtocolLibrary.FORMAT);
116
    final String intersect = this.request.getResourceRef().getQueryAsForm().getFirstValue(SimpleImageAccessProtocolLibrary.INTERSECT);
117
    final String verbosity = this.request.getResourceRef().getQueryAsForm().getFirstValue(SimpleImageAccessProtocolLibrary.VERB);
118
    //TODO check the differentParameters
119
    if(posInput == null && sizeInput == null){
120
        Info info = new Info();
121
        info.setName("QUERY_STATUS");
122
        info.setValueAttribute("ERROR");
123
        final List<Info> listInfos = new ArrayList<Info>();
124
        listInfos.add(info);
125
        this.dataModel.put("infos", listInfos);
126
        if(format.equalsIgnoreCase("METADATA")){
127
            fillMetadataFormat();
128
        }
129
    }else{
130
        if (Util.isSet(format) && format.equals(SimpleImageAccessProtocolLibrary.ParamStandardFormat.METADATA.name())) {
131
            fillMetadataFormat();
132
        } else {
133
            checkInputParameters(posInput, sizeInput);
134
        }
135
    }
136
  }
137

  
138
  /**
139
   * Fills metadata response.
140
   */
141
  private void fillMetadataFormat() {
142
      
143
    this.dataModel.put("description", this.resourceModel.getParameterByName(SimpleImageAccessProtocolLibrary.DESCRIPTION).getValue());
144

  
145
    final Info info = new Info();
146
    info.setName("QUERY_STATUS");
147
    info.setValueAttribute("OK");
148
    final List<Info> listInfos = new ArrayList<Info>();
149
    listInfos.add(info);
150
    this.dataModel.put("infos", listInfos);
151
   
152
    final List<Param> listParam = new ArrayList<Param>();
153
    Param param = new Param();
154
    param.setName("INPUT:POS");
155
    param.setValue("0,0");
156
    param.setDatatype(DataType.DOUBLE);
157
    AnyTEXT anyText = new AnyTEXT();
158
    anyText.getContent().add("Search Position in the form ra,dec where ra and dec are given in decimal degrees in the ICRS coordinate system.");
159
    param.setDESCRIPTION(anyText);
160
    listParam.add(param);
161

  
162
    param = new Param();
163
    param.setName("INPUT:SIZE");
164
    param.setValue("0.05");
165
    param.setDatatype(DataType.DOUBLE);
166
    anyText = new AnyTEXT();
167
    anyText.getContent().add("Size of search region in the RA and Dec directions.");
168
    param.setDESCRIPTION(anyText);
169
    listParam.add(param);
170

  
171
    param = new Param();
172
    param.setName("INPUT:FORMAT");
173
    param.setValue(SimpleImageAccessProtocolLibrary.ParamStandardFormat.ALL.name());
174
    param.setDatatype(DataType.CHAR);
175
    param.setArraysize("*");
176
    anyText = new AnyTEXT();
177
    anyText.getContent().add("Requested format of images.");
178
    param.setDESCRIPTION(anyText);
179
    final List<String> formatList = SimpleImageAccessProtocolLibrary.ParamStandardFormat.getCtes();
180
    final Values values = new Values();
181
    for (String formatIter : formatList) {
182
      final Option option = new Option();
183
      option.setValue(formatIter);
184
      values.getOPTION().add(option);
185
    }
186
    param.setVALUES(values);
187
    //TODO : le faire pour chaque format
188
    listParam.add(param);
189
    
190
    param = new Param();
191
    param.setName("INPUT:INTERSECT");
192
    param.setValue(this.resourceModel.getParameterByName(SimpleImageAccessProtocolLibrary.INTERSECT).getValue());
193
    param.setDatatype(DataType.CHAR);
194
    anyText = new AnyTEXT();
195
    anyText.getContent().add("Choice of overlap with requested region.");
196
    param.setDESCRIPTION(anyText);
197
    listParam.add(param);
198

  
199
    param = new Param();
200
    param.setName("INPUT:VERB");
201
    param.setValue(this.resourceModel.getParameterByName(SimpleImageAccessProtocolLibrary.VERB).getValue());
202
    param.setDatatype(DataType.INT);
203
    anyText = new AnyTEXT();
204
    anyText.getContent().add("Verbosity level, controlling the number of columns returned.");
205
    param.setDESCRIPTION(anyText);
206
    listParam.add(param);
207

  
208
    dataModel.put("params", listParam);
209
    //******************************************************************************************************************
210
    //******************************************************************************************************************
211
    //******************************************************************************************************************
212
    String dictionaryName = resourceModel.getParameterByName(SimpleImageAccessProtocolLibrary.DICTIONARY).getValue();
213
    final List<String> columnList = new ArrayList<String>();
214
    List<Field> fieldList = new ArrayList<Field>();
215
    try {
216
        List<ColumnConceptMappingDTO> mappingList = getDicoFromConfiguration(datasetApp, dictionaryName);
217
        setFields(fieldList, columnList, mappingList);
218
    }catch (SitoolsException ex) {
219
             
220
    }
221
    
222
  }
223

  
224
  /**
225
   * Checks input parameters.
226
   * @param posInput input parameter for POS
227
   * @param sizeInput input parameter for SIZE
228
   */
229
  private void checkInputParameters(final String posInput, final String sizeInput) {
230
    final List<Info> infos = new ArrayList<Info>();
231
    final Map<String, String> validationMap = new HashMap<String, String>();
232
    validationMap.put(SimpleImageAccessProtocolLibrary.POS, posInput);
233
    validationMap.put(SimpleImageAccessProtocolLibrary.SIZE, sizeInput);    
234
    Validation validation = new InputsValidation(validationMap);
235
    validation = new NotNullAndNotEmptyValidation(validation, SimpleImageAccessProtocolLibrary.POS);
236
    validation = new NotNullAndNotEmptyValidation(validation, SimpleImageAccessProtocolLibrary.SIZE);
237
    if(validation.validate().isValid()){
238
        validation = new SpatialGeoValidation(validation, SimpleImageAccessProtocolLibrary.POS, 0, 1, new double[]{0.0, 360.0}, new double[]{-90.0, 90.0});
239
        // LA LIGNE SUIVANTE A ETE AJOUTEE POUR VERIFIER QUE LA SIZE EST BIEN UN ARRAY DE NOMBRE
240
        validation = new NumberArrayValidation(validation, SimpleImageAccessProtocolLibrary.SIZE, ",", 1, 2);
241
        //-----------------------------------------------------------------------------------------------
242
    }  
243
    StatusValidation status = validation.validate();
244
    if (status.isValid()) {
245
        final String pos = validation.getMap().get(SimpleImageAccessProtocolLibrary.POS);
246
        final String[] arrayPos = pos.split(",");
247
        this.ra = Double.valueOf(arrayPos[0]);
248
        this.dec = Double.valueOf(arrayPos[1]);
249
        final String size = validation.getMap().get(SimpleImageAccessProtocolLibrary.SIZE);
250
        final String[] arraySize = size.split(",");
251
        if(arraySize.length == 1) {
252
            this.size = new double[1];
253
            this.size[0] = Double.valueOf(arraySize[0]);
254
        } else {
255
            this.size = new double[2];
256
            this.size[0] = Double.valueOf(arraySize[0]);
257
            this.size[1] = Double.valueOf(arraySize[1]);
258
        }
259
        
260
    } else {
261
        Info info = new Info();
262
        info.setName("QUERY_STATUS");
263
        info.setValueAttribute("ERROR");
264
        infos.add(info);
265
        final Map<String, String> errors = status.getMessages();
266
        final Set<Map.Entry<String, String>> entries = errors.entrySet();        
267
        for (Map.Entry<String, String> entry : entries) {
268
            info = new Info();
269
            info.setID(entry.getKey());
270
            info.setName("Error in " + entry.getKey());
271
            info.setValueAttribute("Error in input " + entry.getKey() + ": " + entry.getValue());
272
            infos.add(info);
273
            LOG.log(Level.FINEST, "{0}: {1}", new Object[]{entry.getKey(), entry.getValue()});            
274
        }
275
        
276
    }
277
    
278
    if (!infos.isEmpty()) {
279
      this.dataModel.put("infos", infos);
280
    }
281
  }
282

  
283
  @Override
284
  public final Map getDataModel() {
285
    return Collections.unmodifiableMap(this.dataModel);
286
  }
287

  
288
  /**
289
   * Get Ra.
290
   *
291
   * @return Ra
292
   */
293
  public final double getRa() {
294
    return this.ra;
295
  }
296

  
297
  /**
298
   * Get Dec.
299
   *
300
   * @return Dec
301
   */
302
  public final double getDec() {
303
    return this.dec;
304
  }
305

  
306
  /**
307
   * Get Sr.
308
   *
309
   * @return Sr
310
   */
311
  public final double[] getSize() {
312
      final double[] copySize = new double[this.size.length];
313
      System.arraycopy(this.size, 0, copySize, 0, this.size.length);
314
      return copySize;
315
  }
316

  
317
  /**
318
   * Get the request.
319
   *
320
   * @return Request
321
   */
322
  public final Request getRequest() {
323
    return this.request;
324
  }
325

  
326
  /**
327
   * Get the context.
328
   *
329
   * @return Context
330
   */
331
  public final Context getContext() {
332
    return this.context;
333
  }
334

  
335
  /**
336
   * Get DatasetApplication.
337
   *
338
   * @return Dataset application
339
   */
340
  public final DataSetApplication getDatasetApplication() {
341
    return this.datasetApp;
342
  }
343

  
344
  /**
345
   * Get verb.
346
   * @return verb
347
   */
348
  public final int getVerb() {
349
    return this.verb;
350
  }
351
  
352
  //----------------------------------------------------------------------------
353
  //----------------------------------------------------------------------------
354
  //----------------------------------------------------------------------------
355
  /**
356
   * Set Fields and columnSqlAliasList.
357
   *
358
   * @param fieldList List of fields to display on the VOTable
359
   * @param columnList List of SQL column
360
   * @param mappingList List of SQL column/concept
361
   */
362
  private void setFields(final List<Field> fieldList, final List<String> columnList, final List<ColumnConceptMappingDTO> mappingList) {
363

  
364
    for (ColumnConceptMappingDTO mappingIter : mappingList) {
365

  
366
      String id = null;
367
      String name = null;
368
      String ucd = null;
369
      String utype = null;
370
      String ref = null;
371
      String datatype = null;
372
      String width = null;
373
      String precision = null;
374
      String unit = null;
375
      String type = null;
376
      String xtype = null;
377
      String arraysize = null;
378
      String descriptionValue = null;
379
      columnList.add(mappingIter.getColumnAlias());
380
      final Concept concept = mappingIter.getConcept();
381
      if (concept.getName() != null) {
382
        name = concept.getName();
383
      }
384
      if (concept.getPropertyFromName("ID").getValue() != null) {
385
        id = concept.getPropertyFromName("ID").getValue();
386
      }
387
      if (concept.getPropertyFromName("ucd").getValue() != null) {
388
        ucd = concept.getPropertyFromName("ucd").getValue();
389
      }
390
      if (concept.getPropertyFromName("utype").getValue() != null) {
391
        utype = concept.getPropertyFromName("utype").getValue();
392
      }
393
      if (concept.getPropertyFromName("ref").getValue() != null) {
394
        ref = concept.getPropertyFromName("ref").getValue();
395
      }
396
      if (concept.getPropertyFromName("datatype").getValue() != null) {
397
        datatype = concept.getPropertyFromName("datatype").getValue();
398
      }
399
      if (concept.getPropertyFromName("width").getValue() != null) {
400
        width = concept.getPropertyFromName("width").getValue();
401
      }
402
      if (concept.getPropertyFromName("precision").getValue() != null) {
403
        precision = concept.getPropertyFromName("precision").getValue();
404
      }
405
      if (concept.getPropertyFromName("unit").getValue() != null) {
406
        unit = concept.getPropertyFromName("unit").getValue();
407
      }
408
      if (concept.getPropertyFromName("type").getValue() != null) {
409
        type = concept.getPropertyFromName("type").getValue();
410
      }
411
      if (concept.getPropertyFromName("xtype").getValue() != null) {
412
        xtype = concept.getPropertyFromName("xtype").getValue();
413
      }
414
      if (concept.getPropertyFromName("arraysize").getValue() != null) {
415
        arraysize = concept.getPropertyFromName("arraysize").getValue();
416
      }
417
      if (concept.getDescription() != null) {
418
        descriptionValue = concept.getDescription();
419
      }
420
      final Field field = new Field();
421
      field.setID(id);
422
      field.setName(name);
423
      field.setUcd(ucd);
424
      field.setUtype(utype);
425
      field.setRef(ref);
426
      field.setDatatype(DataType.fromValue(datatype));
427
      if (width != null) {
428
        field.setWidth(BigInteger.valueOf(Long.valueOf(width)));
429
      }
430
      field.setPrecision(precision);
431
      field.setUnit(unit);
432
      field.setType(type);
433
      field.setXtype(xtype);
434
      field.setArraysize(arraysize);
435
      final AnyTEXT anyText = new AnyTEXT();
436
      anyText.getContent().add(descriptionValue);
437
      field.setDESCRIPTION(anyText);
438
      fieldList.add(field);
439
    }
440
    dataModel.put("fields", fieldList);
441
  }
442
  
443
  /**
444
   * Provide the mapping between SQL column/concept for a given dictionary.
445
   *
446
   * @param datasetApp Application where this service is attached
447
   * @param dicoToFind Dictionary name to find
448
   * @return Returns a mapping SQL column/Concept
449
   * @throws SitoolsException No mapping has been done or cannot find the dico
450
   */
451
  protected List<ColumnConceptMappingDTO> getDicoFromConfiguration(final DataSetApplication datasetApp,
452
          final String dicoToFind) throws SitoolsException {
453
    List<ColumnConceptMappingDTO> colConceptMappingDTOList = null;
454

  
455
    // Get the list of dictionnaries related to the datasetApplication
456
    final List<DictionaryMappingDTO> dicoMappingList = datasetApp.getDictionaryMappings();
457
    if (!Util.isSet(dicoMappingList) || dicoMappingList.isEmpty()) {
458
      throw new SitoolsException("No mapping with VO concepts has been done. please contact the administrator");
459
    }
460

  
461
    // For each dictionary, find the interesting one and return the mapping SQLcolumn/concept
462
    for (DictionaryMappingDTO dicoMappingIter : dicoMappingList) {
463
      final String dicoName = dicoMappingIter.getDictionaryName();
464
      if (dicoToFind.equals(dicoName)) {
465
        colConceptMappingDTOList = dicoMappingIter.getMapping();
466
        break;
467
      }
468
    }
469
    return colConceptMappingDTOList;
470
  }
471
  
472
  
473
  
474
}
sitools-idoc/hesiod/javaExt/README.txt
1
This folder contains the developments of HESIOD in Java.
sitools-idoc/hesiod/javaExt/src/META-INF/services/fr.cnes.sitools.converter.ConverterHelper
1
fr.ias.sitools.converters.FileSizeConverter
2
fr.ias.sitools.converters.RaDecToXYZConverter
sitools-idoc/hesiod/javaExt/src/META-INF/services/fr.cnes.sitools.filter.FilterHelper
1
fr.ias.sitools.filters.basic.BooleanCorotAsteroAndExo
2
fr.ias.sitools.filters.basic.BooleanCustom
3
fr.ias.sitools.filters.basic.GroupCheckBoxMasterLigthCurves
4
fr.ias.sitools.filters.basic.NThreeVariability
5
fr.ias.sitools.filters.basic.TextFieldSQLLikeFilter
6
fr.ias.sitools.filters.basic.DateBeginEndFilter
7
fr.ias.sitools.filters.basic.SingleValueLikeFilter
8
fr.ias.sitools.filters.basic.ListBoxSpectralTypeCorot
9
fr.ias.sitools.filters.basic.ListBoxLumClassCorot
10
fr.ias.sitools.filters.basic.TextAreaCorotFilter
sitools-idoc/hesiod/javaExt/src/META-INF/services/fr.cnes.sitools.plugins.resources.ResourceHelper
1
fr.ias.sitools.resources.spectrofits.GetFitsDataSpectroModel
2
fr.ias.sitools.resources.fits.ShowHeaderModel
3
fr.ias.sitools.astro.resolverName.CorotIdResolverModel
4
fr.ias.sitools.resources.vo.SimpleSpectralAccessResourceModel
5
fr.ias.sitools.resources.geojson.DatasetToJsonModel
sitools-idoc/hesiod/javaExt/src/fr/ias/sitools/converters/FileSizeConverter.java
1
/*
2
 * To change this license header, choose License Headers in Project Properties.
3
 * To change this template file, choose Tools | Templates
4
 * and open the template in the editor.
5
 */
6

  
7
package fr.ias.sitools.converters;
8

  
9
import fr.cnes.sitools.common.validator.ConstraintViolation;
10
import fr.cnes.sitools.common.validator.ConstraintViolationLevel;
11
import fr.cnes.sitools.common.validator.Validator;
12
import fr.cnes.sitools.dataset.converter.business.AbstractConverter;
13
import fr.cnes.sitools.dataset.converter.model.ConverterParameter;
14
import fr.cnes.sitools.dataset.converter.model.ConverterParameterType;
15
import fr.cnes.sitools.datasource.jdbc.model.AttributeValue;
16
import fr.cnes.sitools.datasource.jdbc.model.Record;
17
import java.util.HashSet;
18
import java.util.Map;
19
import java.util.Set;
20
import java.util.logging.Level;
21
import java.util.logging.Logger;
22

  
23
/**
24
 *
25
 * @author Marc
26
 */
27
public class FileSizeConverter extends AbstractConverter {
28
    
29
    /** Class logger */
30
    private static final Logger LOGGER = Logger.getLogger(FileSizeConverter.class.getName());
31

  
32
    public FileSizeConverter() {
33
        
34
        this.setName("FileSizeConverter");
35
        this.setDescription("A converter applying an unit conversion from bytes into Kb or Mb or Gb");
36
        this.setClassAuthor("Marc NICOLAS");
37
        this.setClassOwner("IAS");
38
        this.setClassVersion("0.1");
39
        
40
        ConverterParameter colFileSize = new ConverterParameter("colFileSizeInBytes", "row of dataset with the filesize in bytes",ConverterParameterType.CONVERTER_PARAMETER_IN);
41
        ConverterParameter colFileSizeConvert = new ConverterParameter("colFileSizeConvert", "File Size converted", ConverterParameterType.CONVERTER_PARAMETER_OUT);
42
        this.addParam(colFileSize);
43
        this.addParam(colFileSizeConvert);
44
        
45
        LOGGER.log(Level.INFO, "Converter :{0} version {1}", new Object[] { this.getName(), this.getClassVersion() });
46
    }   
47

  
48
    @Override
49
    public Record getConversionOf(Record record) throws Exception {
50
        Record out = record;
51
        String result = "";
52
        
53
        AttributeValue attrOut = this.getOutParam("colFileSizeConvert", out); 
54
        
55
        AttributeValue attrIn = this.getInParam("colFileSizeInBytes", out);
56
        
57
        if (!isNull(attrIn) && !isNull(attrOut)) {
58
            try{
59
                double input = Double.parseDouble(attrIn.getValue().toString());
60
                if(input>0 && input<1024){
61
                    result = (double)Math.round(input*10)/10 +" o";
62
                }else if(input >= 1024 && input < Math.pow(1024, 2) ){
63
                   result = (double)Math.round((input/1024)*10)/10+" Ko"; 
64
                }else if(input >=Math.pow(1024, 2) && input < Math.pow(1024, 3)){
65
                    result = (double)Math.round((input/Math.pow(1024, 2))*10)/10+" Mo" ;
66
                }else if( input >= Math.pow(1024, 3) && input < Math.pow(1024, 4)){
67
                    result = (double)Math.round((input/Math.pow(1024, 3))*10)/10+" Go" ;
68
                }
69
                
70
                if(!result.isEmpty()){
71
                    attrOut.setValue(result);
72
                }
73
            }catch (Exception e) {
74
                attrOut.setValue(Double.NaN);
75
            }
76
        }
77
        
78
        return out;
79
    }
80

  
81
   @Override
82
  public Validator<AbstractConverter> getValidator() {
83
    // TODO Auto-generated method stub
84
    return new Validator<AbstractConverter>() {
85

  
86
      @Override
87
      public Set<ConstraintViolation> validate(AbstractConverter item) {
88
        Set<ConstraintViolation> constraints = new HashSet<ConstraintViolation>();
89
        Map<String, ConverterParameter> params = item.getParametersMap();
90
        ConverterParameter param = params.get("colFileSizeInBytes");
91
        
92
        if(param.getAttachedColumn().isEmpty()){
93
          ConstraintViolation constraint = new ConstraintViolation();
94
          constraint.setMessage("You must choose the column with filesize in bytes data");
95
          constraint.setLevel(ConstraintViolationLevel.CRITICAL);
96
          constraint.setValueName(param.getName());
97
          constraints.add(constraint);
98
        }
99
        
100
        param = params.get("colFileSizeConvert");
101
        
102
        if(param.getAttachedColumn().isEmpty()){
103
          ConstraintViolation constraint = new ConstraintViolation();
104
          constraint.setMessage("You must choose the output column");
105
          constraint.setLevel(ConstraintViolationLevel.CRITICAL);
106
          constraint.setValueName(param.getName());
107
          constraints.add(constraint);
108
        }
109
        
110
        return constraints;
111
      }
112
    };
113
  }
114

  
115
    
116
}
sitools-idoc/hesiod/javaExt/src/fr/ias/sitools/converters/RaDecToXYZConverter.java
1
/*
2
 * To change this license header, choose License Headers in Project Properties.
3
 * To change this template file, choose Tools | Templates
4
 * and open the template in the editor.
5
 */
6

  
7
package fr.ias.sitools.converters;
8

  
9
import fr.cnes.sitools.common.validator.ConstraintViolation;
10
import fr.cnes.sitools.common.validator.ConstraintViolationLevel;
11
import fr.cnes.sitools.common.validator.Validator;
12
import fr.cnes.sitools.dataset.converter.business.AbstractConverter;
13
import fr.cnes.sitools.dataset.converter.model.ConverterParameter;
14
import fr.cnes.sitools.dataset.converter.model.ConverterParameterType;
15
import fr.cnes.sitools.datasource.jdbc.model.AttributeValue;
16
import fr.cnes.sitools.datasource.jdbc.model.Record;
17
import java.util.HashSet;
18
import java.util.Map;
19
import java.util.Set;
20
import java.util.logging.Level;
21
import java.util.logging.Logger;
22

  
23
/**
24
 *
25
 * @author marc
26
 */
27
public class RaDecToXYZConverter extends AbstractConverter {
28
    
29
    /*
30
        Formule de changement de coordonée : 
31
    
32
            X=cos(DEC)*cos(RA)
33
            Y=cos(DEC)*sin(RA)
34
            Z=sin(DEC) 
35

  
36
    */
37
    
38
    /** Class logger */
39
    private static final Logger LOGGER = Logger.getLogger(RaDecToXYZConverter.class.getName());
40

  
41
    public RaDecToXYZConverter() {
42
         
43
        this.setName("RaDecToXYZConverter");
44
        this.setDescription("A converter applying an unit conversion from Ra and Dec into X, Y and Z coordinates");
45
        this.setClassAuthor("Marc NICOLAS");
46
        this.setClassOwner("IAS");
47
        this.setClassVersion("0.1");
48
        
49
        ConverterParameter colRa = new ConverterParameter("colRa", "row of dataset with the ra coordinate",ConverterParameterType.CONVERTER_PARAMETER_IN);
50
        ConverterParameter colDec = new ConverterParameter("colDec", "row of dataset with the dec coordinate",ConverterParameterType.CONVERTER_PARAMETER_IN);
51
        
52
        ConverterParameter colX = new ConverterParameter("colX", "Column for coordiante X", ConverterParameterType.CONVERTER_PARAMETER_OUT);
53
        ConverterParameter colY = new ConverterParameter("colY", "Column for coordiante Y", ConverterParameterType.CONVERTER_PARAMETER_OUT);
54
        ConverterParameter colZ = new ConverterParameter("colZ", "Column for coordiante Z", ConverterParameterType.CONVERTER_PARAMETER_OUT);
55
        
56
        this.addParam(colRa);
57
        this.addParam(colDec);
58
        this.addParam(colX);
59
        this.addParam(colY);
60
        this.addParam(colZ);
61
        
62
        LOGGER.log(Level.INFO, "Converter :{0} version {1}", new Object[] { this.getName(), this.getClassVersion() });
63
    }
64
    
65
    
66

  
67
    @Override
68
    public Record getConversionOf(Record record) throws Exception {
69
        Record out = record;
70
        Double x, y, z;
71

  
72
        AttributeValue attrOutX = this.getOutParam("colX", out); 
73
        AttributeValue attrOutY = this.getOutParam("colY", out); 
74
        AttributeValue attrOutZ = this.getOutParam("colZ", out); 
75
        
76
        AttributeValue attrInRa = this.getInParam("colRa", out);
77
        AttributeValue attrInDec = this.getInParam("colDec", out);
78
        
79
        if(!isNull(attrInRa) && !isNull(attrInRa)/* && !isNull(attrOutX) && !isNull(attrOutY) && !isNull(attrOutZ)*/){
80
            try{
81
                Double ra = Double.parseDouble(attrInRa.getValue().toString());
82
                Double dec = Double.parseDouble(attrInDec.getValue().toString());
83
            
84
                x = Math.cos(dec)*Math.cos(ra);
85
                y = Math.cos(dec)*Math.sin(ra);
86
                z = Math.sin(dec);
87
                
88
               if(!x.isNaN()){
89
                   attrOutX.setValue(x);
90
               }
91
               if(!y.isNaN()){
92
                   attrOutY.setValue(y);
93
               }
94
               if(!z.isNaN()){
95
                   
96
                   attrOutZ.setValue(z);
97
               }
98
            }catch(NumberFormatException e){
99
                
100
            }
101
        }
102
        
103
        return out;
104
    }
105

  
106
    @Override
107
    public Validator<?> getValidator() {
108
        // TODO Auto-generated method stub
109
    return new Validator<AbstractConverter>() {
110
        
111
      @Override
112
      public Set<ConstraintViolation> validate(AbstractConverter item) {
113
        Set<ConstraintViolation> constraints = new HashSet<ConstraintViolation>();
114
        /*Map<String, ConverterParameter> params = item.getParametersMap();
115
        ConverterParameter param = params.get("colFileSizeInBytes");
116
        
117
        if(param.getAttachedColumn().isEmpty()){
118
          ConstraintViolation constraint = new ConstraintViolation();
119
          constraint.setMessage("You must choose the column with filesize in bytes data");
120
          constraint.setLevel(ConstraintViolationLevel.CRITICAL);
121
          constraint.setValueName(param.getName());
122
          constraints.add(constraint);
123
        }
124
        
125
        param = params.get("colFileSizeConvert");
126
        
127
        if(param.getAttachedColumn().isEmpty()){
128
          ConstraintViolation constraint = new ConstraintViolation();
129
          constraint.setMessage("You must choose the output column");
130
          constraint.setLevel(ConstraintViolationLevel.CRITICAL);
131
          constraint.setValueName(param.getName());
132
          constraints.add(constraint);
133
        }*/
134
        
135
        return constraints;
136
      }
137
    };
138
    }
139
    
140
}
sitools-idoc/hesiod/javaExt/src/fr/ias/sitools/filters/basic/DateBeginEndFilter.java
1
/*******************************************************************************
2
 * Copyright 2011 CNES - CENTRE NATIONAL d'ETUDES SPATIALES
3
 * 
4
 * This file is part of SITools2.
5
 * 
6
 * SITools2 is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 * 
11
 * SITools2 is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License
17
 * along with SITools2.  If not, see <http://www.gnu.org/licenses/>.
18
 ******************************************************************************/
19
package fr.ias.sitools.filters.basic;
20

  
21
import java.util.Arrays;
22
import java.util.HashMap;
23
import java.util.List;
24
import java.util.Set;
25

  
26
import org.restlet.Request;
27
import org.restlet.data.Form;
28
import org.restlet.ext.wadl.ParameterInfo;
29
import org.restlet.ext.wadl.ParameterStyle;
30

  
31
import fr.cnes.sitools.common.validator.ConstraintViolation;
32
import fr.cnes.sitools.common.validator.Validator;
33
import fr.cnes.sitools.dataset.DataSetApplication;
34
import fr.cnes.sitools.dataset.filter.business.AbstractFilter;
35
import fr.cnes.sitools.dataset.model.Column;
36
import fr.cnes.sitools.dataset.model.DataSet;
37
import fr.cnes.sitools.dataset.model.Operator;
38
import fr.cnes.sitools.dataset.model.Predicat;
39
import fr.cnes.sitools.util.SQLUtils;
40

  
41
/**
42
 * Filter defined for Date Between Component
43
 * 
44
 * 
45
 * @author d.arpin
46
 * <a href="https://sourceforge.net/tracker/?func=detail&atid=2158259&aid=3411383&group_id=531341">[3411383]</a><br/>
47
 * 2011/09/19 d.arpin {add quotes arround date Value}
48
 */
49
public final class DateBeginEndFilter extends AbstractFilter {
50
  /**
51
   * The index of TYPE
52
   */
53
  private static final int TYPE = 0;
54
  /**
55
   * The index of COLUMN
56
   */
57
  private static final int COLUMN = 1;
58
  /**
59
   * The index of Values
60
   */
61
  private static final int VALUES = 2;
62

  
63
  /** The TEMPLATE_PARAM */
64
  private static final String TEMPLATE_PARAM = "p[#]";
65
  /**
66
   * the values from to
67
   */
68
  private String[] values;
69

  
70
  /**
71
   * The list of component that uses this filter
72
   */
73
  private enum TYPE_COMPONENT {
74
    /** DefaultType */
75
    DATE_BEGIN_END
76
  }
77

  
78
  /**
79
   * Default constructor
80
   */
81
  public DateBeginEndFilter() {
82

  
83
    super();
84
    this.setName("DateBeginEndFilter");
85
    this.setDescription("Required when using Date Between Components between 2 columns");
86

  
87
    this.setClassAuthor("HUSSON@IAS");
88
    this.setClassAuthor("HUSSON@IAS");
89
    this.setClassOwner("IAS");
90
    this.setClassVersion("0.1");
91
    this.setDefaultFilter(true);
92

  
93
    HashMap<String, ParameterInfo> rpd = new HashMap<String, ParameterInfo>();
94

  
95
    ParameterInfo paramInfo;
96
    paramInfo = new ParameterInfo("p[#]", false, "xs:string", ParameterStyle.QUERY,
97
    "DATE_BEGIN_END|columnFrom,columnTo|valueFrom|valueTo");
98
    rpd.put("0", paramInfo);
99
    this.setRequestParamsDescription(rpd);
100
    //
101

  
102
  }
103

  
104
  @Override
105
  public List<Predicat> createPredicats(Request request, List<Predicat> predicats) throws Exception {
106
    // Get the dataset
107
    DataSetApplication dsApplication = null;
108
    DataSet ds = null;
109

  
110
    Form params = request.getResourceRef().getQueryAsForm();
111
    boolean filterExists = true;
112
    int i = 0;
113
    // Build predicat for filters param
114
    while (filterExists) {
115
      String index = TEMPLATE_PARAM.replace("#", Integer.toString(i++));
116
      String formParam = params.getFirstValue(index);
117
      if (formParam != null) {
118
        String[] parameters = formParam.split("\\|");
119
        TYPE_COMPONENT[] types = TYPE_COMPONENT.values();
120
        Boolean trouve = false;
121
        for (TYPE_COMPONENT typeCmp : types) {
122
          if (typeCmp.name().equals(parameters[TYPE])) {
123
            trouve = true;
124
          }
125
        }
126
        if (trouve) {
127
          if (dsApplication == null) {
128
            dsApplication = (DataSetApplication) getContext().getAttributes().get("DataSetApplication");
129
            ds = dsApplication.getDataSet();
130
          }
131
          String columnfrom = null;
132
          String columnto = null;
133
          if (parameters.length >= VALUES) {
134
            columnfrom = parameters[COLUMN].split(",")[0];
135
            columnto = parameters[COLUMN].split(",")[1];
136

  
137
            Column colfrom = ds.findByColumnAlias(columnfrom);
138
            Column colto = ds.findByColumnAlias(columnto);
139

  
140
            if (colfrom != null && colfrom.getFilter() != null && colfrom.getFilter() && checkValues(parameters) && colto != null && colto.getFilter() != null && colto.getFilter()) {
141
              // escape the values to avoid SQL injection
142
              String valuefrom = "'" + SQLUtils.escapeString(values[0]) + "'";
143
              String valueto = "'" + SQLUtils.escapeString(values[1]) + "'";
144

  
145
              Predicat predicat = new Predicat();
146
              predicat.setLeftAttribute(colfrom);
147
              predicat.setNbOpenedParanthesis(1);
148
              predicat.setNbClosedParanthesis(0);
149
              predicat.setCompareOperator(Operator.GTE);
150
              predicat.setRightValue(valuefrom);
151
              predicats.add(predicat);
152
              predicat = new Predicat();
153
              predicat.setLeftAttribute(colto);
154
              predicat.setNbOpenedParanthesis(0);
155
              predicat.setNbClosedParanthesis(1);
156
              predicat.setCompareOperator(Operator.LTE);
157
              predicat.setRightValue(valueto);
158
              predicats.add(predicat);
159
            }
160

  
161
          }
162
        }
163
      }
164

  
165
      else {
166
        filterExists = false;
167
      }
168
    }
169

  
170
    return predicats;
171
  }
172

  
173
  /**
174
   * Check values of the form
175
   * 
176
   * @param parameters
177
   *          the parameters of the filter
178
   * @return true if values agree
179
   */
180
  private boolean checkValues(String[] parameters) {
181
    values = Arrays.copyOfRange(parameters, VALUES, parameters.length);
182
    if (values.length == 2) {
183
      return true;
184
    }
185
    return false;
186
  }
187

  
188
  /**
189
   * Gets the validator for this Filter
190
   * 
191
   * @return the validator for the filter
192
   */
193
  @Override
194
  public Validator<AbstractFilter> getValidator() {
195
    return new Validator<AbstractFilter>() {
196
      @Override
197
      public Set<ConstraintViolation> validate(AbstractFilter item) {
198
        return null;
199
      }
200
    };
201
  }
202

  
203
}
sitools-idoc/hesiod/javaExt/src/fr/ias/sitools/filters/basic/ListBoxMultipleIAS.java
1
     /*******************************************************************************
2
 * Copyright 2010-2013 CNES - CENTRE NATIONAL d'ETUDES SPATIALES
3
 *
4
 * This file is part of SITools2.
5
 *
6
 * SITools2 is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * SITools2 is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with SITools2.  If not, see <http://www.gnu.org/licenses/>.
18
 ******************************************************************************/
19
package fr.ias.sitools.filters.basic;
20

  
21
import java.util.ArrayList;
22
import java.util.Arrays;
23
import java.util.HashMap;
24
import java.util.List;
25
import java.util.Set;
26

  
27
import org.restlet.Request;
28
import org.restlet.data.Form;
29
import org.restlet.ext.wadl.ParameterInfo;
30
import org.restlet.ext.wadl.ParameterStyle;
31

  
32
import fr.cnes.sitools.common.validator.ConstraintViolation;
33
import fr.cnes.sitools.common.validator.Validator;
34
import fr.cnes.sitools.dataset.DataSetApplication;
35
import fr.cnes.sitools.dataset.filter.business.AbstractFilter;
36
import fr.cnes.sitools.dataset.model.Column;
37
import fr.cnes.sitools.dataset.model.DataSet;
38
import fr.cnes.sitools.dataset.model.Operator;
39
import fr.cnes.sitools.dataset.model.Predicat;
40
import fr.cnes.sitools.dataset.plugins.filters.core.AbstractFormFilter;
41
import static fr.cnes.sitools.dataset.plugins.filters.core.AbstractFormFilter.TEMPLATE_PARAM;
42
import static fr.cnes.sitools.dataset.plugins.filters.core.AbstractFormFilter.TEMPLATE_PARAM_CONCEPT;
43
import static fr.cnes.sitools.dataset.plugins.filters.core.AbstractFormFilter.VALUES;
44
import fr.cnes.sitools.util.SQLUtils;
45

  
46

  
47
/**
48
 * Filter defined for Multiple Value Component
49
 * 
50
 * 
51
 * @author d.arpin
52
 */
53
public final class ListBoxMultipleIAS extends AbstractFormFilter {
54

  
55
  /**
56
   * The list of component that uses this filter
57
   */
58
  private enum TYPE_COMPONENT {
59
    /** List box type */
60
    LISTBOXMULTIPLE_IAS,
61
  }
62

  
63
  /**
64
   * Default constructor
65
   */
66
  public ListBoxMultipleIAS() {
67

  
68
    super();
69
    this.setName("ListBoxMultipleIAS");
70
    this.setDescription("Required when using Multiple Value Components");
71

  
72
    this.setClassAuthor("Marc NICOLAS");
73
    this.setClassOwner("IAS");
74
    this.setClassVersion("0.1");
75
    this.setDefaultFilter(true);
76

  
77
    HashMap<String, ParameterInfo> rpd = new HashMap<String, ParameterInfo>();
78

  
79
    ParameterInfo paramInfo;
80
    paramInfo = new ParameterInfo("p[#]", false, "xs:string", ParameterStyle.QUERY,
81
        "LISTBOXMULTIPLE|columnAlias|value1|...|value n");
82
    rpd.put("0", paramInfo);
83
    paramInfo = new ParameterInfo("p[#]", false, "xs:string", ParameterStyle.QUERY,
84
        "CHECKBOX|columnAlias|value1|...|value n");
85
    rpd.put("1", paramInfo);
86

  
87
    paramInfo = new ParameterInfo("c[#]", false, "xs:string", ParameterStyle.QUERY,
88
        "LISTBOXMULTIPLE|dictionaryName,conceptName|value1|...|value n");
89
    rpd.put("2", paramInfo);
90
    /*paramInfo = new ParameterInfo("c[#]", false, "xs:string", ParameterStyle.QUERY,
91
        "CHECKBOX|dictionaryName,conceptName|value1|...|value n");
92
    rpd.put("3", paramInfo);
93
    this.setRequestParamsDescription(rpd);*/
94
    //
95

  
96
  }
97

  
98
  @Override
99
  public List<Predicat> createPredicats(Request request, List<Predicat> predicats) throws Exception {
100
    // Get the dataset
101
    DataSetApplication dsApplication = null;
102
    DataSet ds = null;
103
    boolean isConcept = true;
104
    Form params = request.getResourceRef().getQueryAsForm();
105
    boolean filterExists = true;
106
    int i = 0;
107
    // Build predicat for filters param
108
    while (filterExists) {
109
      // first check if the filter is applied on a Concept or not
110
      String index = TEMPLATE_PARAM_CONCEPT.replace("#", Integer.toString(i));
111
      String formParam = params.getFirstValue(index);
112
      if (formParam == null) {
113
        isConcept = false;
114
        index = TEMPLATE_PARAM.replace("#", Integer.toString(i));
115
        formParam = params.getFirstValue(index);
116
      }
117
      i++;
118
      if (formParam != null) {
119
        String[] parameters = formParam.split("\\|");
120
        TYPE_COMPONENT[] types = TYPE_COMPONENT.values();
121
        Boolean trouve = false;
122
        for (TYPE_COMPONENT typeCmp : types) {
123
          if (typeCmp.name().equals(parameters[TYPE])) {
124
            trouve = true;
125
          }
126
        }
127
        if (trouve) {
128
          if (dsApplication == null) {
129
            dsApplication = (DataSetApplication) getContext().getAttributes().get("DataSetApplication");
130
            ds = dsApplication.getDataSet();
131
          }
132
          String columnAlias = null;
133
          if (parameters.length >= VALUES) {
134

  
135
            /*
136
             * columnsAlias = parameters[COLUMN].split(","); ArrayList<Column> columns = new ArrayList<Column>(); for
137
             * (String columnAlias : columnsAlias) { Column col = ds.findByColumnAlias(columnAlias); if (col != null) {
138
             * columns.add(col); }
139
             * 
140
             * }
141
             */
142
            columnAlias = getColumnAlias(isConcept, parameters, dsApplication);
143
            if (columnAlias != null) {
144
              Column col = ds.findByColumnAlias(columnAlias);
145

  
146
              if (col != null && col.getFilter() != null && col.getFilter()) {
147
                String[] values = Arrays.copyOfRange(parameters, VALUES, parameters.length);
148
                Predicat predicat = new Predicat();
149
                if (values != null) {
150
                  predicat.setLeftAttribute(col);
151
                  predicat.setNbOpenedParanthesis(0);
152
                  predicat.setNbClosedParanthesis(0);
153
                  predicat.setCompareOperator(Operator.IN);
154

  
155
                  List<String> in = new ArrayList<String>();
156

  
157
                  for (String value : values) {
158
                    // escape every value to avoid SQL injections
159
                    in.add(SQLUtils.escapeString(value));
160
                  }
161
                  predicat.setRightValue(in);
162

  
163
                  predicats.add(predicat);
164
                }
165
              }
166
            }
167

  
168
          }
169
        }
170
      }
171

  
172
      else {
173
        filterExists = false;
174
      }
175
    }
176

  
177
    return predicats;
178
  }
179

  
180
  /**
181
   * Gets the validator for this Filter
182
   * 
183
   * @return the validator for the filter
184
   */
185
  @Override
186
  public Validator<AbstractFilter> getValidator() {
187
    return new Validator<AbstractFilter>() {
188
      @Override
189
      public Set<ConstraintViolation> validate(AbstractFilter item) {
190
        // TODO Auto-generated method stub
191
        return null;
192
      }
193
    };
194
  }
195

  
196
}
sitools-idoc/hesiod/javaExt/src/fr/ias/sitools/filters/basic/ListBoxSpectralTypeCorot.java
1
     /*******************************************************************************
2
 * Copyright 2010-2013 CNES - CENTRE NATIONAL d'ETUDES SPATIALES
3
 *
4
 * This file is part of SITools2.
5
 *
6
 * SITools2 is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * SITools2 is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with SITools2.  If not, see <http://www.gnu.org/licenses/>.
18
 ******************************************************************************/
19
package fr.ias.sitools.filters.basic;
20

  
21
import java.util.ArrayList;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff